-
Notifications
You must be signed in to change notification settings - Fork 609
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix (v2): add support for ProfileTypes requests (#3541)
* Add support for the profile types request in v2 * Fix query backend concurrency check * Retrieve profile types from block metadata instead * Add test for ProfileTypes in v2
- Loading branch information
Showing
9 changed files
with
522 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
pkg/frontend/read_path/query_frontend/query_profile_types.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package query_frontend | ||
|
||
import ( | ||
"context" | ||
"sort" | ||
|
||
"connectrpc.com/connect" | ||
"github.com/grafana/dskit/tenant" | ||
|
||
metastorev1 "github.com/grafana/pyroscope/api/gen/proto/go/metastore/v1" | ||
querierv1 "github.com/grafana/pyroscope/api/gen/proto/go/querier/v1" | ||
typesv1 "github.com/grafana/pyroscope/api/gen/proto/go/types/v1" | ||
phlaremodel "github.com/grafana/pyroscope/pkg/model" | ||
"github.com/grafana/pyroscope/pkg/validation" | ||
) | ||
|
||
func (q *QueryFrontend) ProfileTypes( | ||
ctx context.Context, | ||
req *connect.Request[querierv1.ProfileTypesRequest], | ||
) (*connect.Response[querierv1.ProfileTypesResponse], error) { | ||
|
||
tenants, err := tenant.TenantIDs(ctx) | ||
if err != nil { | ||
return nil, connect.NewError(connect.CodeInvalidArgument, err) | ||
} | ||
empty, err := validation.SanitizeTimeRange(q.limits, tenants, &req.Msg.Start, &req.Msg.End) | ||
if err != nil { | ||
return nil, connect.NewError(connect.CodeInvalidArgument, err) | ||
} | ||
if empty { | ||
return connect.NewResponse(&querierv1.ProfileTypesResponse{}), nil | ||
} | ||
|
||
md, err := q.metastore.QueryMetadata(ctx, &metastorev1.QueryMetadataRequest{ | ||
TenantId: tenants, | ||
StartTime: req.Msg.Start, | ||
EndTime: req.Msg.End, | ||
Query: "{}", | ||
}) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
pTypesFromMetadata := make(map[string]*typesv1.ProfileType) | ||
for _, b := range md.Blocks { | ||
for _, d := range b.Datasets { | ||
for _, pType := range d.ProfileTypes { | ||
if _, ok := pTypesFromMetadata[pType]; !ok { | ||
profileType, err := phlaremodel.ParseProfileTypeSelector(pType) | ||
if err != nil { | ||
return nil, err | ||
} | ||
pTypesFromMetadata[pType] = profileType | ||
} | ||
} | ||
} | ||
} | ||
|
||
var profileTypes []*typesv1.ProfileType | ||
for _, pType := range pTypesFromMetadata { | ||
profileTypes = append(profileTypes, pType) | ||
} | ||
|
||
sort.Slice(profileTypes, func(i, j int) bool { | ||
return profileTypes[i].ID < profileTypes[j].ID | ||
}) | ||
|
||
return connect.NewResponse(&querierv1.ProfileTypesResponse{ | ||
ProfileTypes: profileTypes, | ||
}), nil | ||
} |
72 changes: 72 additions & 0 deletions
72
pkg/frontend/read_path/query_frontend/query_profile_types_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package query_frontend | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"connectrpc.com/connect" | ||
"github.com/go-kit/log" | ||
"github.com/stretchr/testify/mock" | ||
"github.com/stretchr/testify/require" | ||
|
||
metastorev1 "github.com/grafana/pyroscope/api/gen/proto/go/metastore/v1" | ||
querierv1 "github.com/grafana/pyroscope/api/gen/proto/go/querier/v1" | ||
"github.com/grafana/pyroscope/pkg/tenant" | ||
"github.com/grafana/pyroscope/pkg/test/mocks/mockfrontend" | ||
"github.com/grafana/pyroscope/pkg/test/mocks/mockmetastorev1" | ||
) | ||
|
||
func TestQueryFrontend_ProfileTypes(t *testing.T) { | ||
metaClient := mockmetastorev1.NewMockMetastoreServiceClient(t) | ||
limits := mockfrontend.NewMockLimits(t) | ||
f := NewQueryFrontend(log.NewNopLogger(), limits, metaClient, nil) | ||
require.NotNil(t, f) | ||
|
||
limits.On("MaxQueryLookback", mock.Anything).Return(24 * time.Hour) | ||
limits.On("MaxQueryLength", mock.Anything).Return(2 * time.Hour) | ||
metaClient.On("QueryMetadata", mock.Anything, mock.Anything).Maybe().Return(&metastorev1.QueryMetadataResponse{ | ||
Blocks: []*metastorev1.BlockMeta{ | ||
{ | ||
Datasets: []*metastorev1.Dataset{ | ||
{ | ||
ProfileTypes: []string{ | ||
"memory:inuse_space:bytes:space:byte", | ||
"process_cpu:cpu:nanoseconds:cpu:nanoseconds", | ||
"mutex:delay:nanoseconds:mutex:count", | ||
}, | ||
}, | ||
{ | ||
ProfileTypes: []string{ | ||
"memory:alloc_in_new_tlab_objects:count:space:bytes", | ||
"process_cpu:cpu:nanoseconds:cpu:nanoseconds", | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
Datasets: []*metastorev1.Dataset{ | ||
{ | ||
ProfileTypes: []string{ | ||
"mutex:contentions:count:mutex:count", | ||
"mutex:delay:nanoseconds:mutex:count", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, nil) | ||
|
||
ctx := tenant.InjectTenantID(context.Background(), "tenant") | ||
types, err := f.ProfileTypes(ctx, connect.NewRequest(&querierv1.ProfileTypesRequest{ | ||
Start: time.Now().Add(-time.Hour).UnixMilli(), | ||
End: time.Now().UnixMilli(), | ||
})) | ||
require.NoError(t, err) | ||
require.Equal(t, 5, len(types.Msg.ProfileTypes)) | ||
require.Equal(t, "memory:alloc_in_new_tlab_objects:count:space:bytes", types.Msg.ProfileTypes[0].ID) | ||
require.Equal(t, "memory:inuse_space:bytes:space:byte", types.Msg.ProfileTypes[1].ID) | ||
require.Equal(t, "mutex:contentions:count:mutex:count", types.Msg.ProfileTypes[2].ID) | ||
require.Equal(t, "mutex:delay:nanoseconds:mutex:count", types.Msg.ProfileTypes[3].ID) | ||
require.Equal(t, "process_cpu:cpu:nanoseconds:cpu:nanoseconds", types.Msg.ProfileTypes[4].ID) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.