|
| 1 | +//go:build requires_docker |
| 2 | +// +build requires_docker |
| 3 | + |
| 4 | +package integration |
| 5 | + |
| 6 | +import ( |
| 7 | + "fmt" |
| 8 | + "testing" |
| 9 | + "time" |
| 10 | + |
| 11 | + "github.com/prometheus/common/model" |
| 12 | + "github.com/prometheus/prometheus/prompb" |
| 13 | + "github.com/stretchr/testify/assert" |
| 14 | + "github.com/stretchr/testify/require" |
| 15 | + |
| 16 | + "github.com/cortexproject/cortex/integration/e2e" |
| 17 | + e2edb "github.com/cortexproject/cortex/integration/e2e/db" |
| 18 | + "github.com/cortexproject/cortex/integration/e2ecortex" |
| 19 | +) |
| 20 | + |
| 21 | +func TestOTLP(t *testing.T) { |
| 22 | + s, err := e2e.NewScenario(networkName) |
| 23 | + require.NoError(t, err) |
| 24 | + defer s.Close() |
| 25 | + |
| 26 | + // Start dependencies. |
| 27 | + minio := e2edb.NewMinio(9000, bucketName) |
| 28 | + require.NoError(t, s.StartAndWaitReady(minio)) |
| 29 | + |
| 30 | + // Start Cortex components. |
| 31 | + require.NoError(t, copyFileToSharedDir(s, "docs/configuration/single-process-config-blocks.yaml", cortexConfigFile)) |
| 32 | + |
| 33 | + // Start Cortex in single binary mode, reading the config from file and overwriting |
| 34 | + // the backend config to make it work with Minio. |
| 35 | + flags := map[string]string{ |
| 36 | + "-blocks-storage.s3.access-key-id": e2edb.MinioAccessKey, |
| 37 | + "-blocks-storage.s3.secret-access-key": e2edb.MinioSecretKey, |
| 38 | + "-blocks-storage.s3.bucket-name": bucketName, |
| 39 | + "-blocks-storage.s3.endpoint": fmt.Sprintf("%s-minio-9000:9000", networkName), |
| 40 | + "-blocks-storage.s3.insecure": "true", |
| 41 | + } |
| 42 | + |
| 43 | + cortex := e2ecortex.NewSingleBinaryWithConfigFile("cortex-1", cortexConfigFile, flags, "", 9009, 9095) |
| 44 | + require.NoError(t, s.StartAndWaitReady(cortex)) |
| 45 | + |
| 46 | + c, err := e2ecortex.NewClient(cortex.HTTPEndpoint(), cortex.HTTPEndpoint(), "", "", "user-1") |
| 47 | + require.NoError(t, err) |
| 48 | + |
| 49 | + // Push some series to Cortex. |
| 50 | + now := time.Now() |
| 51 | + series, expectedVector := generateSeries("series_1", now, prompb.Label{Name: "foo", Value: "bar"}) |
| 52 | + |
| 53 | + res, err := c.OTLP(series) |
| 54 | + require.NoError(t, err) |
| 55 | + require.Equal(t, 200, res.StatusCode) |
| 56 | + |
| 57 | + // Query the series. |
| 58 | + result, err := c.Query("series_1", now) |
| 59 | + require.NoError(t, err) |
| 60 | + require.Equal(t, model.ValVector, result.Type()) |
| 61 | + assert.Equal(t, expectedVector, result.(model.Vector)) |
| 62 | + |
| 63 | + labelValues, err := c.LabelValues("foo", time.Time{}, time.Time{}, nil) |
| 64 | + require.NoError(t, err) |
| 65 | + require.Equal(t, model.LabelValues{"bar"}, labelValues) |
| 66 | + |
| 67 | + labelNames, err := c.LabelNames(time.Time{}, time.Time{}) |
| 68 | + require.NoError(t, err) |
| 69 | + require.Equal(t, []string{"__name__", "foo"}, labelNames) |
| 70 | + |
| 71 | + // Check that a range query does not return an error to sanity check the queryrange tripperware. |
| 72 | + _, err = c.QueryRange("series_1", now.Add(-15*time.Minute), now, 15*time.Second) |
| 73 | + require.NoError(t, err) |
| 74 | + |
| 75 | + //TODO(friedrichg): test histograms |
| 76 | +} |
0 commit comments