@parca/profile 0.19.82 → 0.19.83
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/MatchersInput/index.d.ts +34 -2
- package/dist/MatchersInput/index.d.ts.map +1 -1
- package/dist/MatchersInput/index.js +91 -14
- package/dist/MetricsGraph/UtilizationMetrics/Throughput.d.ts +29 -0
- package/dist/MetricsGraph/UtilizationMetrics/Throughput.d.ts.map +1 -0
- package/dist/MetricsGraph/UtilizationMetrics/Throughput.js +175 -0
- package/dist/MetricsGraph/UtilizationMetrics/index.d.ts +28 -0
- package/dist/MetricsGraph/UtilizationMetrics/index.d.ts.map +1 -0
- package/dist/MetricsGraph/UtilizationMetrics/index.js +186 -0
- package/dist/MetricsGraph/index.d.ts.map +1 -1
- package/dist/MetricsGraph/index.js +1 -13
- package/dist/ProfileMetricsGraph/index.d.ts.map +1 -1
- package/dist/ProfileMetricsGraph/index.js +29 -6
- package/dist/ProfileSelector/MetricsGraphSection.d.ts +9 -2
- package/dist/ProfileSelector/MetricsGraphSection.d.ts.map +1 -1
- package/dist/ProfileSelector/MetricsGraphSection.js +38 -3
- package/dist/ProfileSelector/QueryControls.d.ts +43 -0
- package/dist/ProfileSelector/QueryControls.d.ts.map +1 -0
- package/dist/{QueryControls/index.js → ProfileSelector/QueryControls.js} +13 -16
- package/dist/ProfileSelector/index.d.ts +29 -1
- package/dist/ProfileSelector/index.d.ts.map +1 -1
- package/dist/ProfileSelector/index.js +9 -12
- package/dist/SimpleMatchers/Select.js +1 -1
- package/dist/SimpleMatchers/index.d.ts +11 -2
- package/dist/SimpleMatchers/index.d.ts.map +1 -1
- package/dist/SimpleMatchers/index.js +45 -34
- package/dist/ViewMatchers/index.d.ts +9 -0
- package/dist/ViewMatchers/index.d.ts.map +1 -1
- package/dist/ViewMatchers/index.js +12 -20
- package/dist/contexts/MatchersInputLabelsContext.d.ts +29 -0
- package/dist/contexts/MatchersInputLabelsContext.d.ts.map +1 -0
- package/dist/contexts/MatchersInputLabelsContext.js +79 -0
- package/dist/contexts/SimpleMatchersLabelContext.d.ts +25 -0
- package/dist/contexts/SimpleMatchersLabelContext.d.ts.map +1 -0
- package/dist/contexts/SimpleMatchersLabelContext.js +115 -0
- package/dist/contexts/UtilizationLabelsContext.d.ts +15 -0
- package/dist/contexts/UtilizationLabelsContext.d.ts.map +1 -0
- package/dist/contexts/UtilizationLabelsContext.js +25 -0
- package/dist/hooks/useQueryState.d.ts +0 -2
- package/dist/hooks/useQueryState.d.ts.map +1 -1
- package/dist/hooks/useQueryState.js +0 -18
- package/dist/index.d.ts +3 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -9
- package/dist/styles.css +1 -1
- package/dist/useSumBy.js +1 -1
- package/package.json +2 -2
- package/src/MatchersInput/index.tsx +163 -17
- package/src/MetricsGraph/UtilizationMetrics/Throughput.tsx +405 -0
- package/src/MetricsGraph/UtilizationMetrics/index.tsx +426 -0
- package/src/MetricsGraph/index.tsx +1 -17
- package/src/ProfileMetricsGraph/index.tsx +98 -17
- package/src/ProfileSelector/MetricsGraphSection.tsx +115 -14
- package/src/{QueryControls/index.tsx → ProfileSelector/QueryControls.tsx} +84 -66
- package/src/ProfileSelector/index.tsx +109 -106
- package/src/SimpleMatchers/Select.tsx +1 -1
- package/src/SimpleMatchers/index.tsx +85 -46
- package/src/ViewMatchers/index.tsx +30 -22
- package/src/contexts/MatchersInputLabelsContext.tsx +141 -0
- package/src/contexts/SimpleMatchersLabelContext.tsx +189 -0
- package/src/contexts/UtilizationLabelsContext.tsx +45 -0
- package/src/hooks/useQueryState.ts +0 -25
- package/src/index.tsx +3 -29
- package/src/useSumBy.ts +1 -1
- package/dist/QueryControls/index.d.ts +0 -42
- package/dist/QueryControls/index.d.ts.map +0 -1
- package/dist/contexts/LabelsQueryProvider.d.ts +0 -35
- package/dist/contexts/LabelsQueryProvider.d.ts.map +0 -1
- package/dist/contexts/LabelsQueryProvider.js +0 -70
- package/dist/contexts/UnifiedLabelsContext.d.ts +0 -37
- package/dist/contexts/UnifiedLabelsContext.d.ts.map +0 -1
- package/dist/contexts/UnifiedLabelsContext.js +0 -88
- package/dist/contexts/utils.d.ts +0 -10
- package/dist/contexts/utils.d.ts.map +0 -1
- package/dist/contexts/utils.js +0 -31
- package/dist/hooks/useLabels.d.ts +0 -23
- package/dist/hooks/useLabels.d.ts.map +0 -1
- package/dist/hooks/useLabels.js +0 -75
- package/src/contexts/LabelsQueryProvider.tsx +0 -142
- package/src/contexts/UnifiedLabelsContext.tsx +0 -155
- package/src/contexts/utils.ts +0 -43
- package/src/hooks/useLabels.ts +0 -121
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
// Copyright 2022 The Parca Authors
|
|
2
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
-
// you may not use this file except in compliance with the License.
|
|
4
|
-
// You may obtain a copy of the License at
|
|
5
|
-
//
|
|
6
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
-
//
|
|
8
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
-
// See the License for the specific language governing permissions and
|
|
12
|
-
// limitations under the License.
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* LabelsQueryProvider - Data Fetching Layer
|
|
16
|
-
*
|
|
17
|
-
* This context provider is responsible for fetching label data from the Parca API
|
|
18
|
-
* and making it available to child components through React Context.
|
|
19
|
-
*
|
|
20
|
-
* Purpose:
|
|
21
|
-
* - Fetches label names and values from the Parca profiling API
|
|
22
|
-
* - Manages loading states for label data
|
|
23
|
-
* - Provides refetch functions for manual data refresh
|
|
24
|
-
* - Acts as the primary data source in the label provider architecture
|
|
25
|
-
*
|
|
26
|
-
* Architecture Pattern:
|
|
27
|
-
* This is the first layer in a three-layer architecture:
|
|
28
|
-
* 1. LabelsQueryProvider (this file) - Fetches data from API
|
|
29
|
-
* 2. LabelsSource (in ProfileSelector) - Transforms/merges data
|
|
30
|
-
* 3. UnifiedLabelsProvider - Provides unified interface to UI components
|
|
31
|
-
*
|
|
32
|
-
* Consumer Hook: useLabelsQueryProvider()
|
|
33
|
-
*/
|
|
34
|
-
|
|
35
|
-
import {createContext, useContext, useState} from 'react';
|
|
36
|
-
|
|
37
|
-
import {QueryServiceClient} from '@parca/client';
|
|
38
|
-
import {Query} from '@parca/parser';
|
|
39
|
-
|
|
40
|
-
import {useLabelNames, useLabelValues} from '../hooks/useLabels';
|
|
41
|
-
import {useExtractedLabelNames} from './utils';
|
|
42
|
-
|
|
43
|
-
export interface LabelsQueryProviderContextType {
|
|
44
|
-
isLabelNamesLoading: boolean;
|
|
45
|
-
isLabelValuesLoading: boolean;
|
|
46
|
-
currentLabelName: string | null;
|
|
47
|
-
setCurrentLabelName: (name: string | null) => void;
|
|
48
|
-
refetchLabelValues: () => Promise<void>;
|
|
49
|
-
refetchLabelNames: () => Promise<void>;
|
|
50
|
-
|
|
51
|
-
labelNames: string[];
|
|
52
|
-
labelValues: string[];
|
|
53
|
-
|
|
54
|
-
queryClient: QueryServiceClient;
|
|
55
|
-
setMatchersString: (arg: string) => void;
|
|
56
|
-
runQuery: () => void;
|
|
57
|
-
currentQuery: Query;
|
|
58
|
-
profileType: string;
|
|
59
|
-
start?: number;
|
|
60
|
-
end?: number;
|
|
61
|
-
|
|
62
|
-
suffix?: '_a' | '_b';
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const LabelsQueryProviderContext = createContext<LabelsQueryProviderContextType | null>(null);
|
|
66
|
-
|
|
67
|
-
interface LabelsQueryProviderProps {
|
|
68
|
-
children: React.ReactNode;
|
|
69
|
-
|
|
70
|
-
queryClient: QueryServiceClient;
|
|
71
|
-
setMatchersString: (arg: string) => void;
|
|
72
|
-
runQuery: () => void;
|
|
73
|
-
currentQuery: Query;
|
|
74
|
-
profileType: string;
|
|
75
|
-
start?: number;
|
|
76
|
-
end?: number;
|
|
77
|
-
|
|
78
|
-
suffix?: '_a' | '_b';
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export function LabelsQueryProvider({
|
|
82
|
-
children,
|
|
83
|
-
queryClient,
|
|
84
|
-
setMatchersString,
|
|
85
|
-
runQuery,
|
|
86
|
-
currentQuery,
|
|
87
|
-
profileType,
|
|
88
|
-
start,
|
|
89
|
-
end,
|
|
90
|
-
suffix,
|
|
91
|
-
}: LabelsQueryProviderProps): JSX.Element {
|
|
92
|
-
const [currentLabelName, setCurrentLabelName] = useState<string | null>(null);
|
|
93
|
-
|
|
94
|
-
const {
|
|
95
|
-
result: labelNamesResponse,
|
|
96
|
-
loading: isLabelNamesLoading,
|
|
97
|
-
refetch: labelNamesRefetch,
|
|
98
|
-
} = useLabelNames(queryClient, profileType, start, end);
|
|
99
|
-
|
|
100
|
-
const labelNames = useExtractedLabelNames(labelNamesResponse.response, labelNamesResponse.error);
|
|
101
|
-
|
|
102
|
-
const {
|
|
103
|
-
result: labelValuesOriginal,
|
|
104
|
-
loading: isLabelValuesLoading,
|
|
105
|
-
refetch: labelValuesRefetch,
|
|
106
|
-
} = useLabelValues(queryClient, currentLabelName ?? '', profileType, start, end);
|
|
107
|
-
|
|
108
|
-
const labelValues = labelValuesOriginal.response;
|
|
109
|
-
|
|
110
|
-
const value = {
|
|
111
|
-
labelNames,
|
|
112
|
-
labelValues,
|
|
113
|
-
isLabelNamesLoading,
|
|
114
|
-
isLabelValuesLoading,
|
|
115
|
-
refetchLabelValues: labelValuesRefetch,
|
|
116
|
-
refetchLabelNames: labelNamesRefetch,
|
|
117
|
-
queryClient,
|
|
118
|
-
setMatchersString,
|
|
119
|
-
runQuery,
|
|
120
|
-
currentQuery,
|
|
121
|
-
profileType,
|
|
122
|
-
start,
|
|
123
|
-
end,
|
|
124
|
-
setCurrentLabelName,
|
|
125
|
-
currentLabelName,
|
|
126
|
-
suffix,
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
return (
|
|
130
|
-
<LabelsQueryProviderContext.Provider value={value}>
|
|
131
|
-
{children}
|
|
132
|
-
</LabelsQueryProviderContext.Provider>
|
|
133
|
-
);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
export function useLabelsQueryProvider(): LabelsQueryProviderContextType {
|
|
137
|
-
const context = useContext(LabelsQueryProviderContext);
|
|
138
|
-
if (context === null) {
|
|
139
|
-
throw new Error('useLabelsQueryProvider must be used within a LabelsQueryProvider');
|
|
140
|
-
}
|
|
141
|
-
return context;
|
|
142
|
-
}
|
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
// Copyright 2022 The Parca Authors
|
|
2
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
-
// you may not use this file except in compliance with the License.
|
|
4
|
-
// You may obtain a copy of the License at
|
|
5
|
-
//
|
|
6
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
-
//
|
|
8
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
-
// See the License for the specific language governing permissions and
|
|
12
|
-
// limitations under the License.
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* UnifiedLabelsProvider - UI Presentation Layer
|
|
16
|
-
*
|
|
17
|
-
* This context provider transforms raw label data into a format optimized for
|
|
18
|
-
* UI components (QueryControls, SimpleMatchers, etc.).
|
|
19
|
-
*
|
|
20
|
-
* Purpose:
|
|
21
|
-
* - Transforms label arrays into structured formats for dropdowns and selectors
|
|
22
|
-
* - Groups labels by type (e.g., 'cpu', 'gpu') for organized display
|
|
23
|
-
* - Handles label name prefixes and mappings for user-friendly display
|
|
24
|
-
* - Provides a unified interface regardless of data source(s)
|
|
25
|
-
*
|
|
26
|
-
* Architecture Pattern:
|
|
27
|
-
* This is the final layer in a three-layer architecture:
|
|
28
|
-
* 1. LabelsQueryProvider - Fetches data from API
|
|
29
|
-
* 2. LabelsSource (in ProfileSelector) - Transforms/merges data
|
|
30
|
-
* 3. UnifiedLabelsProvider (this file) - Presents data to UI components
|
|
31
|
-
*
|
|
32
|
-
* Consumer Hook: useUnifiedLabels()
|
|
33
|
-
*/
|
|
34
|
-
|
|
35
|
-
import {createContext, useContext} from 'react';
|
|
36
|
-
|
|
37
|
-
import {transformLabelsForSelect} from '../SimpleMatchers';
|
|
38
|
-
import type {SelectItem} from '../SimpleMatchers/Select';
|
|
39
|
-
import {useLabelNameMappings, type LabelNameMapping} from './utils';
|
|
40
|
-
|
|
41
|
-
interface LabelNameSection {
|
|
42
|
-
type: string;
|
|
43
|
-
values: SelectItem[];
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
interface UnifiedLabelsContextType {
|
|
47
|
-
labelNameMappingsForMatchersInput: LabelNameMapping[];
|
|
48
|
-
labelNameMappingsForSimpleMatchers: LabelNameSection[];
|
|
49
|
-
labelNames: string[];
|
|
50
|
-
labelValues: string[];
|
|
51
|
-
|
|
52
|
-
isLabelNamesLoading: boolean;
|
|
53
|
-
isLabelValuesLoading: boolean;
|
|
54
|
-
currentLabelName: string | null;
|
|
55
|
-
setCurrentLabelName: (name: string | null) => void;
|
|
56
|
-
shouldHandlePrefixes: boolean;
|
|
57
|
-
refetchLabelValues: () => Promise<void>;
|
|
58
|
-
refetchLabelNames: () => Promise<void>;
|
|
59
|
-
labelNameFromMatchers: string[];
|
|
60
|
-
|
|
61
|
-
suffix?: '_a' | '_b';
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const UnifiedLabelsContext = createContext<UnifiedLabelsContextType | null>(null);
|
|
65
|
-
|
|
66
|
-
interface UnifiedLabelsProviderProps {
|
|
67
|
-
children: React.ReactNode;
|
|
68
|
-
|
|
69
|
-
currentLabelName: string | null;
|
|
70
|
-
setCurrentLabelName: (name: string | null) => void;
|
|
71
|
-
|
|
72
|
-
labelNames: string[];
|
|
73
|
-
labelValues: string[];
|
|
74
|
-
isLabelNamesLoading: boolean;
|
|
75
|
-
isLabelValuesLoading: boolean;
|
|
76
|
-
|
|
77
|
-
refetchLabelValues: () => Promise<void>;
|
|
78
|
-
refetchLabelNames: () => Promise<void>;
|
|
79
|
-
|
|
80
|
-
suffix?: '_a' | '_b';
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export function UnifiedLabelsProvider({
|
|
84
|
-
children,
|
|
85
|
-
labelNames,
|
|
86
|
-
isLabelNamesLoading,
|
|
87
|
-
isLabelValuesLoading,
|
|
88
|
-
refetchLabelValues,
|
|
89
|
-
refetchLabelNames,
|
|
90
|
-
currentLabelName,
|
|
91
|
-
setCurrentLabelName,
|
|
92
|
-
labelValues,
|
|
93
|
-
suffix,
|
|
94
|
-
}: UnifiedLabelsProviderProps): JSX.Element {
|
|
95
|
-
const labelNameFromMatchers: string[] = [];
|
|
96
|
-
|
|
97
|
-
const labelNamesFromAPI = labelNames;
|
|
98
|
-
|
|
99
|
-
const labelNameMappingsForMatchersInput = useLabelNameMappings(labelNamesFromAPI);
|
|
100
|
-
|
|
101
|
-
const allLabelNames = new Set(labelNamesFromAPI);
|
|
102
|
-
|
|
103
|
-
const nonMatchingLabels = labelNameFromMatchers.filter(label => !allLabelNames.has(label));
|
|
104
|
-
|
|
105
|
-
const labelNameMappingsForSimpleMatchers: LabelNameSection[] = [];
|
|
106
|
-
|
|
107
|
-
const labels = {
|
|
108
|
-
type: 'cpu',
|
|
109
|
-
labelNames: labelNamesFromAPI,
|
|
110
|
-
isLoading: isLabelNamesLoading,
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
labelNameMappingsForSimpleMatchers.push({
|
|
114
|
-
type: labels.type,
|
|
115
|
-
values: transformLabelsForSelect(labels.labelNames),
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
if (nonMatchingLabels.length > 0) {
|
|
119
|
-
const uniqueNonMatchingLabels = Array.from(new Set(nonMatchingLabels));
|
|
120
|
-
labelNameMappingsForSimpleMatchers.push({
|
|
121
|
-
type: '',
|
|
122
|
-
values: transformLabelsForSelect(uniqueNonMatchingLabels),
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
const value = {
|
|
127
|
-
labelNames: labelNamesFromAPI,
|
|
128
|
-
labelNameMappingsForMatchersInput,
|
|
129
|
-
isLabelNamesLoading,
|
|
130
|
-
isLabelValuesLoading,
|
|
131
|
-
currentLabelName,
|
|
132
|
-
labelValues,
|
|
133
|
-
setCurrentLabelName,
|
|
134
|
-
shouldHandlePrefixes: false,
|
|
135
|
-
refetchLabelValues: async () => {
|
|
136
|
-
await refetchLabelValues();
|
|
137
|
-
},
|
|
138
|
-
refetchLabelNames: async () => {
|
|
139
|
-
await refetchLabelNames();
|
|
140
|
-
},
|
|
141
|
-
labelNameFromMatchers,
|
|
142
|
-
labelNameMappingsForSimpleMatchers,
|
|
143
|
-
suffix,
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
return <UnifiedLabelsContext.Provider value={value}>{children}</UnifiedLabelsContext.Provider>;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
export function useUnifiedLabels(): UnifiedLabelsContextType {
|
|
150
|
-
const context = useContext(UnifiedLabelsContext);
|
|
151
|
-
if (context === null) {
|
|
152
|
-
throw new Error('useUnifiedLabels must be used within a UnifiedLabelsProvider');
|
|
153
|
-
}
|
|
154
|
-
return context;
|
|
155
|
-
}
|
package/src/contexts/utils.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
// Copyright 2022 The Parca Authors
|
|
2
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
-
// you may not use this file except in compliance with the License.
|
|
4
|
-
// You may obtain a copy of the License at
|
|
5
|
-
//
|
|
6
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
-
//
|
|
8
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
-
// See the License for the specific language governing permissions and
|
|
12
|
-
// limitations under the License.
|
|
13
|
-
|
|
14
|
-
import {useMemo} from 'react';
|
|
15
|
-
|
|
16
|
-
export interface LabelNameMapping {
|
|
17
|
-
displayName: string;
|
|
18
|
-
fullName: string;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export const transformLabelName = (labelName: string): string => {
|
|
22
|
-
return labelName.replace(/^(attributes\.|attributes_resource\.)/, '');
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export const useLabelNameMappings = (labelNames: string[]): LabelNameMapping[] => {
|
|
26
|
-
return useMemo(() => {
|
|
27
|
-
return labelNames.map(name => ({
|
|
28
|
-
displayName: transformLabelName(name),
|
|
29
|
-
fullName: name,
|
|
30
|
-
}));
|
|
31
|
-
}, [labelNames]);
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export const useExtractedLabelNames = (
|
|
35
|
-
response: {labelNames?: string[]} | undefined,
|
|
36
|
-
error: Error | undefined | null
|
|
37
|
-
): string[] => {
|
|
38
|
-
return useMemo(() => {
|
|
39
|
-
return (error === undefined || error == null) && response !== undefined && response != null
|
|
40
|
-
? response.labelNames?.filter(e => e !== '__name__') ?? []
|
|
41
|
-
: [];
|
|
42
|
-
}, [response, error]);
|
|
43
|
-
};
|
package/src/hooks/useLabels.ts
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
// Copyright 2022 The Parca Authors
|
|
2
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
-
// you may not use this file except in compliance with the License.
|
|
4
|
-
// You may obtain a copy of the License at
|
|
5
|
-
//
|
|
6
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
-
//
|
|
8
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
-
// See the License for the specific language governing permissions and
|
|
12
|
-
// limitations under the License.
|
|
13
|
-
|
|
14
|
-
import {LabelsRequest, LabelsResponse, QueryServiceClient, ValuesRequest} from '@parca/client';
|
|
15
|
-
import {useGrpcMetadata} from '@parca/components';
|
|
16
|
-
import {millisToProtoTimestamp, sanitizeLabelValue} from '@parca/utilities';
|
|
17
|
-
|
|
18
|
-
import useGrpcQuery from '../useGrpcQuery';
|
|
19
|
-
|
|
20
|
-
export interface ILabelValuesResult {
|
|
21
|
-
response: string[];
|
|
22
|
-
error?: Error;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
interface UseLabelValues {
|
|
26
|
-
result: ILabelValuesResult;
|
|
27
|
-
loading: boolean;
|
|
28
|
-
refetch: () => Promise<void>;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export interface ILabelNamesResult {
|
|
32
|
-
response?: LabelsResponse;
|
|
33
|
-
error?: Error;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
interface UseLabelNames {
|
|
37
|
-
result: ILabelNamesResult;
|
|
38
|
-
loading: boolean;
|
|
39
|
-
refetch: () => Promise<void>;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export const useLabelNames = (
|
|
43
|
-
client: QueryServiceClient,
|
|
44
|
-
profileType: string,
|
|
45
|
-
start?: number,
|
|
46
|
-
end?: number,
|
|
47
|
-
match?: string[]
|
|
48
|
-
): UseLabelNames => {
|
|
49
|
-
const metadata = useGrpcMetadata();
|
|
50
|
-
|
|
51
|
-
const {data, isLoading, error, refetch} = useGrpcQuery<LabelsResponse>({
|
|
52
|
-
key: ['labelNames', profileType, match?.join(','), start, end],
|
|
53
|
-
queryFn: async signal => {
|
|
54
|
-
const request: LabelsRequest = {match: match !== undefined ? match : []};
|
|
55
|
-
if (start !== undefined && end !== undefined) {
|
|
56
|
-
request.start = millisToProtoTimestamp(start);
|
|
57
|
-
request.end = millisToProtoTimestamp(end);
|
|
58
|
-
}
|
|
59
|
-
if (profileType !== undefined) {
|
|
60
|
-
request.profileType = profileType;
|
|
61
|
-
}
|
|
62
|
-
const {response} = await client.labels(request, {meta: metadata, abort: signal});
|
|
63
|
-
return response;
|
|
64
|
-
},
|
|
65
|
-
options: {
|
|
66
|
-
enabled: profileType !== undefined && profileType !== '',
|
|
67
|
-
keepPreviousData: false,
|
|
68
|
-
},
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
console.log('Label names query result:', {data, error, isLoading});
|
|
72
|
-
|
|
73
|
-
return {
|
|
74
|
-
result: {response: data, error: error as Error},
|
|
75
|
-
loading: isLoading,
|
|
76
|
-
refetch: async () => {
|
|
77
|
-
await refetch();
|
|
78
|
-
},
|
|
79
|
-
};
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
export const useLabelValues = (
|
|
83
|
-
client: QueryServiceClient,
|
|
84
|
-
labelName: string,
|
|
85
|
-
profileType: string,
|
|
86
|
-
start?: number,
|
|
87
|
-
end?: number
|
|
88
|
-
): UseLabelValues => {
|
|
89
|
-
const metadata = useGrpcMetadata();
|
|
90
|
-
|
|
91
|
-
const {data, isLoading, error, refetch} = useGrpcQuery<string[]>({
|
|
92
|
-
key: ['labelValues', labelName, profileType, start, end],
|
|
93
|
-
queryFn: async signal => {
|
|
94
|
-
const request: ValuesRequest = {labelName, match: [], profileType};
|
|
95
|
-
if (start !== undefined && end !== undefined) {
|
|
96
|
-
request.start = millisToProtoTimestamp(start);
|
|
97
|
-
request.end = millisToProtoTimestamp(end);
|
|
98
|
-
}
|
|
99
|
-
const {response} = await client.values(request, {meta: metadata, abort: signal});
|
|
100
|
-
return sanitizeLabelValue(response.labelValues);
|
|
101
|
-
},
|
|
102
|
-
options: {
|
|
103
|
-
enabled:
|
|
104
|
-
profileType !== undefined &&
|
|
105
|
-
profileType !== '' &&
|
|
106
|
-
labelName !== undefined &&
|
|
107
|
-
labelName !== '',
|
|
108
|
-
keepPreviousData: false,
|
|
109
|
-
},
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
console.log('Label values query result:', {data, error, isLoading, labelName});
|
|
113
|
-
|
|
114
|
-
return {
|
|
115
|
-
result: {response: data ?? [], error: error as Error},
|
|
116
|
-
loading: isLoading,
|
|
117
|
-
refetch: async () => {
|
|
118
|
-
await refetch();
|
|
119
|
-
},
|
|
120
|
-
};
|
|
121
|
-
};
|