@parca/profile 0.19.80 → 0.19.82

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.
Files changed (86) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/MatchersInput/index.d.ts +2 -34
  3. package/dist/MatchersInput/index.d.ts.map +1 -1
  4. package/dist/MatchersInput/index.js +14 -91
  5. package/dist/MetricsGraph/index.d.ts.map +1 -1
  6. package/dist/MetricsGraph/index.js +13 -1
  7. package/dist/ProfileMetricsGraph/index.d.ts.map +1 -1
  8. package/dist/ProfileMetricsGraph/index.js +24 -33
  9. package/dist/ProfileSelector/MetricsGraphSection.d.ts +2 -9
  10. package/dist/ProfileSelector/MetricsGraphSection.d.ts.map +1 -1
  11. package/dist/ProfileSelector/MetricsGraphSection.js +3 -38
  12. package/dist/ProfileSelector/index.d.ts +1 -29
  13. package/dist/ProfileSelector/index.d.ts.map +1 -1
  14. package/dist/ProfileSelector/index.js +12 -9
  15. package/dist/ProfileView/components/ProfileFilters/filterPresets.d.ts.map +1 -1
  16. package/dist/ProfileView/components/ProfileFilters/filterPresets.js +15 -3
  17. package/dist/QueryControls/index.d.ts +42 -0
  18. package/dist/QueryControls/index.d.ts.map +1 -0
  19. package/dist/{ProfileSelector/QueryControls.js → QueryControls/index.js} +16 -13
  20. package/dist/SimpleMatchers/Select.js +1 -1
  21. package/dist/SimpleMatchers/index.d.ts +2 -11
  22. package/dist/SimpleMatchers/index.d.ts.map +1 -1
  23. package/dist/SimpleMatchers/index.js +34 -45
  24. package/dist/ViewMatchers/index.d.ts +0 -9
  25. package/dist/ViewMatchers/index.d.ts.map +1 -1
  26. package/dist/ViewMatchers/index.js +20 -12
  27. package/dist/contexts/LabelsQueryProvider.d.ts +35 -0
  28. package/dist/contexts/LabelsQueryProvider.d.ts.map +1 -0
  29. package/dist/contexts/LabelsQueryProvider.js +70 -0
  30. package/dist/contexts/UnifiedLabelsContext.d.ts +37 -0
  31. package/dist/contexts/UnifiedLabelsContext.d.ts.map +1 -0
  32. package/dist/contexts/UnifiedLabelsContext.js +88 -0
  33. package/dist/contexts/utils.d.ts +10 -0
  34. package/dist/contexts/utils.d.ts.map +1 -0
  35. package/dist/contexts/utils.js +31 -0
  36. package/dist/hooks/useLabels.d.ts +23 -0
  37. package/dist/hooks/useLabels.d.ts.map +1 -0
  38. package/dist/hooks/useLabels.js +75 -0
  39. package/dist/hooks/useQueryState.d.ts +2 -0
  40. package/dist/hooks/useQueryState.d.ts.map +1 -1
  41. package/dist/hooks/useQueryState.js +18 -0
  42. package/dist/index.d.ts +9 -3
  43. package/dist/index.d.ts.map +1 -1
  44. package/dist/index.js +9 -3
  45. package/dist/styles.css +1 -1
  46. package/dist/useSumBy.js +1 -1
  47. package/package.json +2 -2
  48. package/src/MatchersInput/index.tsx +17 -163
  49. package/src/MetricsGraph/index.tsx +17 -1
  50. package/src/ProfileMetricsGraph/index.tsx +37 -102
  51. package/src/ProfileSelector/MetricsGraphSection.tsx +14 -115
  52. package/src/ProfileSelector/index.tsx +106 -109
  53. package/src/ProfileView/components/ProfileFilters/filterPresets.ts +15 -3
  54. package/src/{ProfileSelector/QueryControls.tsx → QueryControls/index.tsx} +66 -84
  55. package/src/SimpleMatchers/Select.tsx +1 -1
  56. package/src/SimpleMatchers/index.tsx +46 -85
  57. package/src/ViewMatchers/index.tsx +22 -30
  58. package/src/contexts/LabelsQueryProvider.tsx +142 -0
  59. package/src/contexts/UnifiedLabelsContext.tsx +155 -0
  60. package/src/contexts/utils.ts +43 -0
  61. package/src/hooks/useLabels.ts +121 -0
  62. package/src/hooks/useQueryState.ts +25 -0
  63. package/src/index.tsx +29 -3
  64. package/src/useSumBy.ts +1 -1
  65. package/dist/MetricsGraph/UtilizationMetrics/Throughput.d.ts +0 -29
  66. package/dist/MetricsGraph/UtilizationMetrics/Throughput.d.ts.map +0 -1
  67. package/dist/MetricsGraph/UtilizationMetrics/Throughput.js +0 -175
  68. package/dist/MetricsGraph/UtilizationMetrics/index.d.ts +0 -28
  69. package/dist/MetricsGraph/UtilizationMetrics/index.d.ts.map +0 -1
  70. package/dist/MetricsGraph/UtilizationMetrics/index.js +0 -186
  71. package/dist/ProfileSelector/QueryControls.d.ts +0 -43
  72. package/dist/ProfileSelector/QueryControls.d.ts.map +0 -1
  73. package/dist/contexts/MatchersInputLabelsContext.d.ts +0 -29
  74. package/dist/contexts/MatchersInputLabelsContext.d.ts.map +0 -1
  75. package/dist/contexts/MatchersInputLabelsContext.js +0 -79
  76. package/dist/contexts/SimpleMatchersLabelContext.d.ts +0 -25
  77. package/dist/contexts/SimpleMatchersLabelContext.d.ts.map +0 -1
  78. package/dist/contexts/SimpleMatchersLabelContext.js +0 -115
  79. package/dist/contexts/UtilizationLabelsContext.d.ts +0 -15
  80. package/dist/contexts/UtilizationLabelsContext.d.ts.map +0 -1
  81. package/dist/contexts/UtilizationLabelsContext.js +0 -25
  82. package/src/MetricsGraph/UtilizationMetrics/Throughput.tsx +0 -405
  83. package/src/MetricsGraph/UtilizationMetrics/index.tsx +0 -426
  84. package/src/contexts/MatchersInputLabelsContext.tsx +0 -141
  85. package/src/contexts/SimpleMatchersLabelContext.tsx +0 -189
  86. package/src/contexts/UtilizationLabelsContext.tsx +0 -45
@@ -1,426 +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
- import {Icon} from '@iconify/react';
17
- import {AnimatePresence, motion} from 'framer-motion';
18
-
19
- import {
20
- DateTimeRange,
21
- MetricsGraphSkeleton,
22
- TextWithTooltip,
23
- useParcaContext,
24
- } from '@parca/components';
25
- import {formatDate, timePattern, valueFormatter} from '@parca/utilities';
26
-
27
- import {type UtilizationMetrics as MetricSeries} from '../../ProfileSelector';
28
- import MetricsGraph, {type ContextMenuItemOrSubmenu, type Series} from '../index';
29
- import {useMetricsGraphDimensions} from '../useMetricsGraphDimensions';
30
-
31
- interface CommonProps {
32
- setTimeRange: (range: DateTimeRange) => void;
33
- humanReadableName: string;
34
- from: number;
35
- to: number;
36
- onSeriesClick?: (seriesIndex: number) => void;
37
- }
38
-
39
- type RawUtilizationMetricsProps = CommonProps & {
40
- data: Series[];
41
- originalData: MetricSeries[];
42
- width: number;
43
- height: number;
44
- margin: number;
45
- yAxisUnit: string;
46
- contextMenuItems?: ContextMenuItemOrSubmenu[];
47
- };
48
-
49
- type Props = CommonProps & {
50
- data: MetricSeries[];
51
- yAxisUnit: string;
52
- utilizationMetricsLoading?: boolean;
53
- addLabelMatcher?: (
54
- labels: {key: string; value: string} | Array<{key: string; value: string}>
55
- ) => void;
56
- onSelectedSeriesChange?: (series: Array<{key: string; value: string}>) => void;
57
- };
58
-
59
- const transformUtilizationLabels = (label: string): string => {
60
- return label.replace('attributes.', '').replace('attributes_resource.', '');
61
- };
62
-
63
- const createUtilizationContextMenuItems = (
64
- addLabelMatcher: (
65
- labels: {key: string; value: string} | Array<{key: string; value: string}>
66
- ) => void,
67
- originalData: MetricSeries[]
68
- ): ContextMenuItemOrSubmenu[] => {
69
- return [
70
- {
71
- id: 'focus-on-single-series',
72
- label: 'Focus only on this series',
73
- icon: 'ph:star',
74
- onClick: (closestPoint, _series) => {
75
- if (
76
- closestPoint != null &&
77
- originalData.length > 0 &&
78
- originalData[closestPoint.seriesIndex] != null
79
- ) {
80
- const originalSeriesData = originalData[closestPoint.seriesIndex];
81
- if (originalSeriesData.labelset?.labels != null) {
82
- const labels = originalSeriesData.labelset.labels.filter(
83
- label => label.name !== '__name__'
84
- );
85
- const labelsToAdd = labels.map(label => ({
86
- key: label.name,
87
- value: label.value,
88
- }));
89
- addLabelMatcher(labelsToAdd);
90
- }
91
- }
92
- },
93
- },
94
- {
95
- id: 'add-to-query',
96
- label: 'Add to query',
97
- icon: 'material-symbols:add',
98
- createDynamicItems: (closestPoint, _series) => {
99
- if (
100
- closestPoint == null ||
101
- originalData.length === 0 ||
102
- originalData[closestPoint.seriesIndex] == null
103
- ) {
104
- return [
105
- {
106
- id: 'no-labels-available',
107
- label: 'No labels available',
108
- icon: 'ph:warning',
109
- disabled: () => true,
110
- onClick: () => {}, // No-op for disabled item
111
- },
112
- ];
113
- }
114
-
115
- const originalSeriesData = originalData[closestPoint.seriesIndex];
116
- if (originalSeriesData.labelset?.labels == null) {
117
- return [
118
- {
119
- id: 'no-labels-available',
120
- label: 'No labels available',
121
- icon: 'ph:warning',
122
- disabled: () => true,
123
- onClick: () => {}, // No-op for disabled item
124
- },
125
- ];
126
- }
127
-
128
- const labels = originalSeriesData.labelset.labels.filter(
129
- label => label.name !== '__name__'
130
- );
131
-
132
- return labels.map(label => ({
133
- id: `add-label-${label.name}`,
134
- label: (
135
- <div className="mr-3 inline-block rounded-lg bg-gray-200 px-2 py-1 text-xs font-bold text-gray-700 dark:bg-gray-700 dark:text-gray-300">
136
- {`${transformUtilizationLabels(label.name)}="${label.value}"`}
137
- </div>
138
- ),
139
- onClick: () => {
140
- addLabelMatcher({
141
- key: label.name,
142
- value: label.value,
143
- });
144
- },
145
- }));
146
- },
147
- },
148
- ];
149
- };
150
-
151
- const transformMetricSeriesToSeries = (data: MetricSeries[]): Series[] => {
152
- return data.map(metricSeries => {
153
- if (metricSeries.labelset != null) {
154
- const labels = metricSeries.labelset.labels ?? [];
155
- const sortedLabels = labels.sort((a, b) => a.name.localeCompare(b.name));
156
- const id = sortedLabels.map(label => `${label.name}=${label.value}`).join(',');
157
-
158
- return {
159
- id: id !== '' ? id : 'default',
160
- values: metricSeries.samples.map((sample): [number, number] => [
161
- sample.timestamp,
162
- sample.value,
163
- ]),
164
- };
165
- }
166
- return {
167
- id: 'default',
168
- values: [],
169
- };
170
- });
171
- };
172
-
173
- const _getYAxisUnit = (name: string): string => {
174
- switch (name) {
175
- case 'gpu_power_watt':
176
- return 'watts';
177
- case 'gpu_temperature_celsius':
178
- return 'celsius';
179
- case 'gpu_clock_hertz':
180
- return 'hertz';
181
- default:
182
- return 'percent';
183
- }
184
- };
185
-
186
- const RawUtilizationMetrics = ({
187
- data,
188
- originalData,
189
- setTimeRange,
190
- width,
191
- height,
192
- margin,
193
- humanReadableName,
194
- from,
195
- to,
196
- yAxisUnit,
197
- contextMenuItems,
198
- onSeriesClick,
199
- }: RawUtilizationMetricsProps): JSX.Element => {
200
- const {timezone} = useParcaContext();
201
-
202
- return (
203
- <MetricsGraph
204
- data={data.map((val, idx) => ({
205
- ...val,
206
- highlighted: originalData?.[idx]?.isSelected ?? false,
207
- }))}
208
- from={from}
209
- to={to}
210
- setTimeRange={setTimeRange}
211
- onSampleClick={closestPoint => {
212
- if (onSeriesClick != null) {
213
- onSeriesClick(closestPoint.seriesIndex);
214
- }
215
- }}
216
- yAxisLabel={humanReadableName}
217
- yAxisUnit={yAxisUnit}
218
- width={width}
219
- height={height}
220
- margin={margin}
221
- contextMenuItems={contextMenuItems}
222
- renderTooltipContent={(seriesIndex: number, pointIndex: number) => {
223
- if (originalData?.[seriesIndex]?.samples?.[pointIndex] != null) {
224
- const originalSeriesData = originalData[seriesIndex];
225
- const originalPoint = originalData[seriesIndex].samples[pointIndex];
226
-
227
- const labels = originalSeriesData.labelset?.labels ?? [];
228
- const nameLabel = labels.find(e => e.name === '__name__');
229
- const highlightedNameLabel = nameLabel ?? {name: '', value: ''};
230
-
231
- // Calculate attributes maps for utilization metrics
232
- const attributesMap = labels
233
- .filter(
234
- label =>
235
- label.name.startsWith('attributes.') &&
236
- !label.name.startsWith('attributes_resource.')
237
- )
238
- .reduce<Record<string, string>>((acc, label) => {
239
- const key = label.name.replace('attributes.', '');
240
- acc[key] = label.value;
241
- return acc;
242
- }, {});
243
-
244
- const attributesResourceMap = labels
245
- .filter(label => label.name.startsWith('attributes_resource.'))
246
- .reduce<Record<string, string>>((acc, label) => {
247
- const key = label.name.replace('attributes_resource.', '');
248
- acc[key] = label.value;
249
- return acc;
250
- }, {});
251
-
252
- return (
253
- <div className="flex flex-row">
254
- <div className="ml-2 mr-6">
255
- <span className="font-semibold">{highlightedNameLabel.value}</span>
256
- <span className="my-2 block text-gray-700 dark:text-gray-300">
257
- <table className="table-auto">
258
- <tbody>
259
- <tr>
260
- <td className="w-1/4">Value</td>
261
- <td className="w-3/4">
262
- {valueFormatter(originalPoint.value, yAxisUnit, 2)}
263
- </td>
264
- </tr>
265
- <tr>
266
- <td className="w-1/4">At</td>
267
- <td className="w-3/4">
268
- {formatDate(
269
- new Date(originalPoint.timestamp),
270
- timePattern(timezone as string),
271
- timezone
272
- )}
273
- </td>
274
- </tr>
275
- </tbody>
276
- </table>
277
- </span>
278
- <span className="my-2 block text-gray-500">
279
- {Object.keys(attributesResourceMap).length > 0 ? (
280
- <span className="text-sm font-bold text-gray-700 dark:text-white">
281
- Resource Attributes
282
- </span>
283
- ) : null}
284
- <span className="my-2 block text-gray-500">
285
- {Object.keys(attributesResourceMap).map(name => (
286
- <div
287
- key={
288
- 'resourceattribute-' +
289
- seriesIndex.toString() +
290
- '-' +
291
- pointIndex.toString() +
292
- '-' +
293
- name
294
- }
295
- className="mr-3 inline-block rounded-lg bg-gray-200 px-2 py-1 text-xs font-bold text-gray-700 dark:bg-gray-700 dark:text-gray-400"
296
- >
297
- <TextWithTooltip
298
- text={`${transformUtilizationLabels(name)}="${
299
- attributesResourceMap[name] ?? ''
300
- }"`}
301
- maxTextLength={48}
302
- id={`tooltip-${name}-${attributesResourceMap[name] ?? ''}`}
303
- />
304
- </div>
305
- ))}
306
- </span>
307
- {Object.keys(attributesMap).length > 0 ? (
308
- <span className="text-sm font-bold text-gray-700 dark:text-white">
309
- Attributes
310
- </span>
311
- ) : null}
312
- <span className="my-2 block text-gray-500">
313
- {Object.keys(attributesMap).map(name => (
314
- <div
315
- key={
316
- 'attribute-' +
317
- seriesIndex.toString() +
318
- '-' +
319
- pointIndex.toString() +
320
- '-' +
321
- name
322
- }
323
- className="mr-3 inline-block rounded-lg bg-gray-200 px-2 py-1 text-xs font-bold text-gray-700 dark:bg-gray-700 dark:text-gray-400"
324
- >
325
- <TextWithTooltip
326
- text={`${transformUtilizationLabels(name)}="${
327
- attributesMap[name] ?? ''
328
- }"`}
329
- maxTextLength={48}
330
- id={`tooltip-${name}-${attributesMap[name] ?? ''}`}
331
- />
332
- </div>
333
- ))}
334
- </span>
335
- {labels
336
- .filter(
337
- label => label.name !== '__name__' && !label.name.startsWith('attributes')
338
- )
339
- .map(label => (
340
- <div
341
- key={
342
- 'attribute-' +
343
- seriesIndex.toString() +
344
- '-' +
345
- pointIndex.toString() +
346
- '-label-' +
347
- label.name
348
- }
349
- className="mr-3 inline-block rounded-lg bg-gray-200 px-2 py-1 text-xs font-bold text-gray-700 dark:bg-gray-700 dark:text-gray-400"
350
- >
351
- <TextWithTooltip
352
- text={`${transformUtilizationLabels(label.name)}="${label.value}"`}
353
- maxTextLength={37}
354
- id={`tooltip-${label.name}`}
355
- />
356
- </div>
357
- ))}
358
- </span>
359
- <div className="flex w-full items-center gap-1 text-xs text-gray-500">
360
- <Icon icon="iconoir:mouse-button-right" />
361
- <div>Right click to add labels to query.</div>
362
- </div>
363
- </div>
364
- </div>
365
- );
366
- }
367
- return null;
368
- }}
369
- />
370
- );
371
- };
372
-
373
- const UtilizationMetrics = ({
374
- data,
375
- setTimeRange,
376
- utilizationMetricsLoading,
377
- humanReadableName,
378
- from,
379
- to,
380
- yAxisUnit,
381
- addLabelMatcher,
382
- onSeriesClick,
383
- onSelectedSeriesChange: _onSelectedSeriesChange,
384
- }: Props): JSX.Element => {
385
- const {isDarkMode} = useParcaContext();
386
- const {width, height, margin, heightStyle} = useMetricsGraphDimensions(false, true);
387
-
388
- const transformedData = useMemo(() => transformMetricSeriesToSeries(data), [data]);
389
-
390
- const contextMenuItems = useMemo(() => {
391
- return addLabelMatcher != null ? createUtilizationContextMenuItems(addLabelMatcher, data) : [];
392
- }, [addLabelMatcher, data]);
393
-
394
- return (
395
- <AnimatePresence>
396
- <motion.div
397
- className="w-full relative"
398
- key="utilization-metrics-graph-loaded"
399
- initial={false}
400
- animate={{display: 'block', opacity: 1}}
401
- transition={{duration: 0.5}}
402
- >
403
- {utilizationMetricsLoading === true ? (
404
- <MetricsGraphSkeleton heightStyle={heightStyle} isDarkMode={isDarkMode} isMini={true} />
405
- ) : (
406
- <RawUtilizationMetrics
407
- data={transformedData}
408
- originalData={data}
409
- setTimeRange={setTimeRange}
410
- width={width}
411
- height={height}
412
- margin={margin}
413
- humanReadableName={humanReadableName}
414
- from={from}
415
- to={to}
416
- yAxisUnit={yAxisUnit}
417
- contextMenuItems={contextMenuItems}
418
- onSeriesClick={onSeriesClick}
419
- />
420
- )}
421
- </motion.div>
422
- </AnimatePresence>
423
- );
424
- };
425
-
426
- export default UtilizationMetrics;
@@ -1,141 +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 React, {createContext, useContext, useMemo} from 'react';
15
-
16
- import {QueryServiceClient} from '@parca/client';
17
-
18
- import {useFetchUtilizationLabelValues, useLabelNames, useLabelValues} from '../MatchersInput';
19
- import {useUtilizationLabels} from './UtilizationLabelsContext';
20
-
21
- interface LabelNameMapping {
22
- displayName: string;
23
- fullName: string;
24
- }
25
-
26
- interface LabelsContextType {
27
- labelNames: string[];
28
- labelValues: string[];
29
- labelNameMappings: LabelNameMapping[];
30
- isLabelNamesLoading: boolean;
31
- isLabelValuesLoading: boolean;
32
- currentLabelName: string | null;
33
- setCurrentLabelName: (name: string | null) => void;
34
- shouldHandlePrefixes: boolean;
35
- refetchLabelValues: () => Promise<void>;
36
- refetchLabelNames: () => Promise<void>;
37
- }
38
-
39
- const LabelsContext = createContext<LabelsContextType | null>(null);
40
-
41
- interface LabelsProviderProps {
42
- children: React.ReactNode;
43
- queryClient: QueryServiceClient;
44
- profileType: string;
45
- start?: number;
46
- end?: number;
47
- }
48
-
49
- // With there being the possibility of having utilization labels, we need to be able to determine whether the labels to be used are utilization labels or profiling data labels.
50
- // This context is used to determine this.
51
- export function LabelsProvider({
52
- children,
53
- queryClient,
54
- profileType,
55
- start,
56
- end,
57
- }: LabelsProviderProps): JSX.Element {
58
- const [currentLabelName, setCurrentLabelName] = React.useState<string | null>(null);
59
- const utilizationLabels = useUtilizationLabels();
60
-
61
- const {
62
- result: labelNamesResponse,
63
- loading: isLabelNamesLoading,
64
- refetch: refetchLabelNames,
65
- } = useLabelNames(queryClient, profileType, start, end);
66
-
67
- const labelNamesFromAPI = useMemo(() => {
68
- return (labelNamesResponse.error === undefined || labelNamesResponse.error == null) &&
69
- labelNamesResponse !== undefined &&
70
- labelNamesResponse != null
71
- ? labelNamesResponse.response?.labelNames.filter(e => e !== '__name__') ?? []
72
- : [];
73
- }, [labelNamesResponse]);
74
-
75
- const {
76
- result: labelValuesOriginal,
77
- loading: isLabelValuesLoading,
78
- refetch: refetchLabelValues,
79
- } = useLabelValues(queryClient, currentLabelName ?? '', profileType, start, end);
80
-
81
- const utilizationLabelValues = useFetchUtilizationLabelValues(
82
- currentLabelName ?? '',
83
- utilizationLabels
84
- );
85
-
86
- const shouldHandlePrefixes = utilizationLabels?.utilizationLabelNames !== undefined;
87
-
88
- const labelNameMappings = useMemo(() => {
89
- const names = utilizationLabels?.utilizationLabelNames ?? labelNamesFromAPI;
90
- return names.map(name => ({
91
- displayName: name.replace(/^(attributes\.|attributes_resource\.)/, ''),
92
- fullName: name,
93
- }));
94
- }, [labelNamesFromAPI, utilizationLabels?.utilizationLabelNames]);
95
-
96
- const labelNames = useMemo(() => {
97
- return shouldHandlePrefixes ? labelNameMappings.map(m => m.displayName) : labelNamesFromAPI;
98
- }, [labelNameMappings, labelNamesFromAPI, shouldHandlePrefixes]);
99
-
100
- const labelValues = useMemo(() => {
101
- return utilizationLabels?.utilizationFetchLabelValues !== undefined
102
- ? utilizationLabelValues
103
- : labelValuesOriginal.response;
104
- }, [labelValuesOriginal, utilizationLabelValues, utilizationLabels]);
105
-
106
- const value = useMemo(
107
- () => ({
108
- labelNames,
109
- labelValues,
110
- labelNameMappings,
111
- isLabelNamesLoading,
112
- isLabelValuesLoading,
113
- currentLabelName,
114
- setCurrentLabelName,
115
- shouldHandlePrefixes,
116
- refetchLabelValues,
117
- refetchLabelNames,
118
- }),
119
- [
120
- labelNames,
121
- labelValues,
122
- labelNameMappings,
123
- isLabelNamesLoading,
124
- isLabelValuesLoading,
125
- currentLabelName,
126
- shouldHandlePrefixes,
127
- refetchLabelValues,
128
- refetchLabelNames,
129
- ]
130
- );
131
-
132
- return <LabelsContext.Provider value={value}>{children}</LabelsContext.Provider>;
133
- }
134
-
135
- export function useLabels(): LabelsContextType {
136
- const context = useContext(LabelsContext);
137
- if (context === null) {
138
- throw new Error('useLabels must be used within a LabelsProvider');
139
- }
140
- return context;
141
- }