github.com/grafana/pyroscope@v1.18.0/pkg/ingester/query_test.go (about) 1 package ingester 2 3 import ( 4 "context" 5 "os" 6 "sort" 7 "testing" 8 "time" 9 10 "connectrpc.com/connect" 11 "github.com/go-kit/log" 12 "github.com/google/uuid" 13 "github.com/grafana/dskit/services" 14 "github.com/prometheus/client_golang/prometheus" 15 "github.com/stretchr/testify/require" 16 17 ingestv1 "github.com/grafana/pyroscope/api/gen/proto/go/ingester/v1" 18 pushv1 "github.com/grafana/pyroscope/api/gen/proto/go/push/v1" 19 typesv1 "github.com/grafana/pyroscope/api/gen/proto/go/types/v1" 20 phlaremodel "github.com/grafana/pyroscope/pkg/model" 21 "github.com/grafana/pyroscope/pkg/objstore/client" 22 "github.com/grafana/pyroscope/pkg/objstore/providers/filesystem" 23 "github.com/grafana/pyroscope/pkg/phlaredb" 24 phlarecontext "github.com/grafana/pyroscope/pkg/pyroscope/context" 25 "github.com/grafana/pyroscope/pkg/tenant" 26 ) 27 28 func Test_QueryMetadata(t *testing.T) { 29 dbPath := t.TempDir() 30 logger := log.NewJSONLogger(os.Stdout) 31 reg := prometheus.NewRegistry() 32 ctx := phlarecontext.WithLogger(context.Background(), logger) 33 ctx = phlarecontext.WithRegistry(ctx, reg) 34 cfg := client.Config{ 35 StorageBackendConfig: client.StorageBackendConfig{ 36 Backend: client.Filesystem, 37 Filesystem: filesystem.Config{ 38 Directory: dbPath, 39 }, 40 }, 41 } 42 43 fs, err := client.NewBucket(ctx, cfg, "storage") 44 require.NoError(t, err) 45 46 ing, err := New(ctx, defaultIngesterTestConfig(t), phlaredb.Config{ 47 DataPath: dbPath, 48 MaxBlockDuration: 30 * time.Hour, 49 }, fs, &fakeLimits{}, 0) 50 require.NoError(t, err) 51 require.NoError(t, services.StartAndAwaitRunning(context.Background(), ing)) 52 53 req := &connect.Request[pushv1.PushRequest]{ 54 Msg: &pushv1.PushRequest{ 55 Series: []*pushv1.RawProfileSeries{ 56 { 57 Samples: []*pushv1.RawSample{ 58 { 59 ID: uuid.NewString(), 60 RawProfile: testProfile(t), 61 }, 62 }, 63 }, 64 }, 65 }, 66 } 67 req.Msg.Series[0].Labels = phlaremodel.LabelsFromStrings("foo", "bar") 68 _, err = ing.Push(tenant.InjectTenantID(context.Background(), "foo"), req) 69 require.NoError(t, err) 70 71 labelsValues, err := ing.LabelValues(tenant.InjectTenantID(context.Background(), "foo"), connect.NewRequest(&typesv1.LabelValuesRequest{Name: "foo"})) 72 require.NoError(t, err) 73 require.Equal(t, []string{"bar"}, labelsValues.Msg.Names) 74 75 profileTypes, err := ing.ProfileTypes(tenant.InjectTenantID(context.Background(), "foo"), connect.NewRequest(&ingestv1.ProfileTypesRequest{})) 76 require.NoError(t, err) 77 expectedTypes := []string{ 78 ":alloc_objects:count:space:bytes", 79 ":alloc_space:bytes:space:bytes", 80 ":inuse_objects:count:space:bytes", 81 ":inuse_space:bytes:space:bytes", 82 } 83 sort.Strings(expectedTypes) 84 ids := make([]string, len(profileTypes.Msg.ProfileTypes)) 85 for i, t := range profileTypes.Msg.ProfileTypes { 86 ids[i] = t.ID 87 } 88 sort.Strings(ids) 89 require.Equal(t, expectedTypes, ids) 90 require.NoError(t, services.StopAndAwaitTerminated(context.Background(), ing)) 91 }