diff --git a/pyroscope/src/components/ProfileTypeSelector.tsx b/pyroscope/src/components/ProfileTypeSelector.tsx index a7a7aa85f..f9985632f 100644 --- a/pyroscope/src/components/ProfileTypeSelector.tsx +++ b/pyroscope/src/components/ProfileTypeSelector.tsx @@ -20,13 +20,14 @@ import { useProfileTypes } from '../utils/use-query'; export interface ProfileTypeSelectorProps { datasource: PyroscopeDatasourceSelector; value: string; + service?: string; onChange?(value: string): void; } export function ProfileTypeSelector(props: ProfileTypeSelectorProps): ReactElement { - const { datasource, value, onChange } = props; + const { datasource, value, service, onChange } = props; - const { data: profileTypesOptions, isLoading: isProfileTypesOptionsLoading } = useProfileTypes(datasource); + const { data: profileTypesOptions, isLoading: isProfileTypesOptionsLoading } = useProfileTypes(datasource, service); return ( diff --git a/pyroscope/src/model/pyroscope-client.ts b/pyroscope/src/model/pyroscope-client.ts index f172b52b7..1afaae2c3 100644 --- a/pyroscope/src/model/pyroscope-client.ts +++ b/pyroscope/src/model/pyroscope-client.ts @@ -53,7 +53,7 @@ export interface PyroscopeClient extends DatasourceClient { searchLabelValues( params: SearchLabelValuesParameters, headers: RequestHeaders, - body: Record, + body: Record, ): Promise; searchServices( params: SearchLabelValuesParameters, @@ -168,7 +168,7 @@ export function searchLabelNames( export function searchLabelValues( params: SearchLabelValuesParameters, queryOptions: QueryOptions, - body: Record, + body: Record, ): Promise { return fetchWithPost( '/querier.v1.QuerierService/LabelValues', diff --git a/pyroscope/src/plugins/pyroscope-profile-query/PyroscopeProfileQueryEditor.tsx b/pyroscope/src/plugins/pyroscope-profile-query/PyroscopeProfileQueryEditor.tsx index f6ce06805..87fdaa8b8 100644 --- a/pyroscope/src/plugins/pyroscope-profile-query/PyroscopeProfileQueryEditor.tsx +++ b/pyroscope/src/plugins/pyroscope-profile-query/PyroscopeProfileQueryEditor.tsx @@ -87,7 +87,12 @@ export function PyroscopeProfileQueryEditor(props: ProfileQueryEditorProps): Rea }} > - + { const { data: client } = useDatasourceClient(datasource); const { absoluteTimeRange } = useTimeRange(); @@ -76,13 +77,35 @@ export function useProfileTypes( return useQuery({ enabled: !!client, - queryKey: ['searchProfileTypes', client], + queryKey: ['searchProfileTypes', service, client], queryFn: async () => { - return await client!.searchProfileTypes( + const profileTypesResponse = await client!.searchProfileTypes( {}, { 'content-type': 'application/json' }, { start: start * MILLISECONDS, end: end * MILLISECONDS }, ); + + // if a service name is given, narrow profile types list to only the existing ones for this service + // otherwise return all existing profile types on the server + if (!service) { + return profileTypesResponse; + } + + const labelValuesResponse = await client!.searchLabelValues( + {}, + { 'content-type': 'application/json' }, + { + name: '__name__', + matchers: [`{service_name="${service}"}`], + start: start * MILLISECONDS, + end: end * MILLISECONDS, + }, + ); + const profileTypeNames = new Set(labelValuesResponse.names); + + return { + profileTypes: profileTypesResponse.profileTypes.filter((profileType) => profileTypeNames.has(profileType.name)), + }; }, }); }