|
| 1 | +//go:build requires_docker |
| 2 | + |
| 3 | +package integration |
| 4 | + |
| 5 | +import ( |
| 6 | + "context" |
| 7 | + "fmt" |
| 8 | + "math/rand" |
| 9 | + "path/filepath" |
| 10 | + "testing" |
| 11 | + "time" |
| 12 | + |
| 13 | + "github.com/prometheus/prometheus/model/labels" |
| 14 | + "github.com/stretchr/testify/require" |
| 15 | + "github.com/thanos-io/objstore" |
| 16 | + "github.com/thanos-io/thanos/pkg/block" |
| 17 | + "github.com/thanos-io/thanos/pkg/block/metadata" |
| 18 | + |
| 19 | + "github.com/cortexproject/cortex/integration/e2e" |
| 20 | + e2ecache "github.com/cortexproject/cortex/integration/e2e/cache" |
| 21 | + e2edb "github.com/cortexproject/cortex/integration/e2e/db" |
| 22 | + "github.com/cortexproject/cortex/integration/e2ecortex" |
| 23 | + "github.com/cortexproject/cortex/pkg/storage/bucket" |
| 24 | + "github.com/cortexproject/cortex/pkg/storage/tsdb" |
| 25 | + "github.com/cortexproject/cortex/pkg/util/log" |
| 26 | + cortex_testutil "github.com/cortexproject/cortex/pkg/util/test" |
| 27 | +) |
| 28 | + |
| 29 | +func TestParquetConverter_NoConvertMarkWithTooManyLabels(t *testing.T) { |
| 30 | + s, err := e2e.NewScenario(networkName) |
| 31 | + require.NoError(t, err) |
| 32 | + defer s.Close() |
| 33 | + |
| 34 | + consul := e2edb.NewConsulWithName("consul") |
| 35 | + memcached := e2ecache.NewMemcached() |
| 36 | + require.NoError(t, s.StartAndWaitReady(consul, memcached)) |
| 37 | + |
| 38 | + baseFlags := mergeFlags(AlertmanagerLocalFlags(), BlocksStorageFlags()) |
| 39 | + flags := mergeFlags( |
| 40 | + baseFlags, |
| 41 | + map[string]string{ |
| 42 | + "-target": "all,parquet-converter", |
| 43 | + "-blocks-storage.tsdb.block-ranges-period": "1m,24h", |
| 44 | + "-blocks-storage.tsdb.ship-interval": "1s", |
| 45 | + "-blocks-storage.bucket-store.sync-interval": "1s", |
| 46 | + "-blocks-storage.bucket-store.metadata-cache.bucket-index-content-ttl": "1s", |
| 47 | + "-blocks-storage.bucket-store.bucket-index.idle-timeout": "1s", |
| 48 | + "-blocks-storage.bucket-store.bucket-index.enabled": "true", |
| 49 | + "-blocks-storage.bucket-store.index-cache.backend": tsdb.IndexCacheBackendInMemory, |
| 50 | + // compactor |
| 51 | + "-compactor.cleanup-interval": "1s", |
| 52 | + // Ingester. |
| 53 | + "-ring.store": "consul", |
| 54 | + "-consul.hostname": consul.NetworkHTTPEndpoint(), |
| 55 | + // Distributor. |
| 56 | + "-distributor.replication-factor": "1", |
| 57 | + // Store-gateway. |
| 58 | + "-store-gateway.sharding-enabled": "false", |
| 59 | + "--querier.store-gateway-addresses": "nonExistent", // Make sure we do not call Store gateways |
| 60 | + // alert manager |
| 61 | + "-alertmanager.web.external-url": "http://localhost/alertmanager", |
| 62 | + // Enable vertical sharding. |
| 63 | + "-frontend.query-vertical-shard-size": "3", |
| 64 | + "-frontend.max-cache-freshness": "1m", |
| 65 | + // enable experimental promQL funcs |
| 66 | + "-querier.enable-promql-experimental-functions": "true", |
| 67 | + // parquet-converter |
| 68 | + "-parquet-converter.ring.consul.hostname": consul.NetworkHTTPEndpoint(), |
| 69 | + "-parquet-converter.conversion-interval": "1s", |
| 70 | + "-parquet-converter.enabled": "true", |
| 71 | + "-parquet-converter.max-block-label-names": "1", |
| 72 | + // Querier |
| 73 | + "-querier.enable-parquet-queryable": "true", |
| 74 | + // Enable cache for parquet labels and chunks |
| 75 | + "-blocks-storage.bucket-store.parquet-labels-cache.backend": "inmemory,memcached", |
| 76 | + "-blocks-storage.bucket-store.parquet-labels-cache.memcached.addresses": "dns+" + memcached.NetworkEndpoint(e2ecache.MemcachedPort), |
| 77 | + "-blocks-storage.bucket-store.chunks-cache.backend": "inmemory,memcached", |
| 78 | + "-blocks-storage.bucket-store.chunks-cache.memcached.addresses": "dns+" + memcached.NetworkEndpoint(e2ecache.MemcachedPort), |
| 79 | + }, |
| 80 | + ) |
| 81 | + |
| 82 | + // make alert manager config dir |
| 83 | + require.NoError(t, writeFileToSharedDir(s, "alertmanager_configs", []byte{})) |
| 84 | + |
| 85 | + ctx := context.Background() |
| 86 | + rnd := rand.New(rand.NewSource(time.Now().Unix())) |
| 87 | + dir := filepath.Join(s.SharedDir(), "data") |
| 88 | + lbls := []labels.Labels{ |
| 89 | + labels.FromStrings("__name__", "test_series_a", "job", "test"), |
| 90 | + } |
| 91 | + |
| 92 | + numSamples := 60 |
| 93 | + scrapeInterval := time.Minute |
| 94 | + now := time.Now() |
| 95 | + start := now.Add(-time.Hour * 24) |
| 96 | + end := now.Add(-time.Hour) |
| 97 | + |
| 98 | + minio := e2edb.NewMinio(9000, flags["-blocks-storage.s3.bucket-name"]) |
| 99 | + require.NoError(t, s.StartAndWaitReady(minio)) |
| 100 | + |
| 101 | + cortex := e2ecortex.NewSingleBinary("cortex", flags, "") |
| 102 | + require.NoError(t, s.StartAndWaitReady(cortex)) |
| 103 | + storage, err := e2ecortex.NewS3ClientForMinio(minio, flags["-blocks-storage.s3.bucket-name"]) |
| 104 | + require.NoError(t, err) |
| 105 | + bkt := bucket.NewUserBucketClient("user-1", storage.GetBucket(), nil) |
| 106 | + |
| 107 | + id, err := e2e.CreateBlock(ctx, rnd, dir, lbls, numSamples, |
| 108 | + start.UnixMilli(), |
| 109 | + end.UnixMilli(), |
| 110 | + scrapeInterval.Milliseconds(), 10, |
| 111 | + ) |
| 112 | + require.NoError(t, err) |
| 113 | + |
| 114 | + err = block.Upload(ctx, log.Logger, bkt, filepath.Join(dir, id.String()), metadata.NoneFunc) |
| 115 | + require.NoError(t, err) |
| 116 | + |
| 117 | + // Wait for the converter to write the no-convert marker |
| 118 | + cortex_testutil.Poll(t, 30*time.Second, true, func() interface{} { |
| 119 | + noConvertMarkerPath := fmt.Sprintf("%s/parquet-no-convert-mark.json", id.String()) |
| 120 | + found := false |
| 121 | + err := bkt.Iter(ctx, "", func(name string) error { |
| 122 | + if name == noConvertMarkerPath { |
| 123 | + found = true |
| 124 | + } |
| 125 | + return nil |
| 126 | + }, objstore.WithRecursiveIter()) |
| 127 | + require.NoError(t, err) |
| 128 | + return found |
| 129 | + }) |
| 130 | + |
| 131 | + // confirm the conversion did not happen (check both paths) |
| 132 | + blockID := id.String() |
| 133 | + markerPaths := []string{ |
| 134 | + fmt.Sprintf("%s/parquet-converter-mark.json", blockID), |
| 135 | + fmt.Sprintf("parquet-markers/%s-parquet-converter-mark.json", blockID), |
| 136 | + } |
| 137 | + for _, markerPath := range markerPaths { |
| 138 | + exists, err := bkt.Exists(ctx, markerPath) |
| 139 | + require.NoError(t, err) |
| 140 | + require.False(t, exists, "converter mark should not exist at %s", markerPath) |
| 141 | + } |
| 142 | +} |
0 commit comments