@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
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [0.19.83](https://github.com/parca-dev/parca/compare/@parca/profile@0.19.82...@parca/profile@0.19.83) (2025-11-26)
|
|
7
|
+
|
|
8
|
+
### Reverts
|
|
9
|
+
|
|
10
|
+
- Revert "Refactor ProfileSelector and MetricsGraphSection components (#6025)" (#6072) ([4dcbafb](https://github.com/parca-dev/parca/commit/4dcbafb3757dca64e2ce4f7a111208ca7ee88355)), closes [#6025](https://github.com/parca-dev/parca/issues/6025) [#6072](https://github.com/parca-dev/parca/issues/6072)
|
|
11
|
+
|
|
6
12
|
## 0.19.82 (2025-11-26)
|
|
7
13
|
|
|
8
14
|
**Note:** Version bump only for package @parca/profile
|
|
@@ -1,3 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { LabelsResponse, QueryServiceClient } from '@parca/client';
|
|
2
|
+
import { Query } from '@parca/parser';
|
|
3
|
+
import { UtilizationLabels } from '../ProfileSelector';
|
|
4
|
+
interface MatchersInputProps {
|
|
5
|
+
queryClient: QueryServiceClient;
|
|
6
|
+
setMatchersString: (arg: string) => void;
|
|
7
|
+
runQuery: () => void;
|
|
8
|
+
currentQuery: Query;
|
|
9
|
+
profileType: string;
|
|
10
|
+
start?: number;
|
|
11
|
+
end?: number;
|
|
12
|
+
}
|
|
13
|
+
export interface ILabelNamesResult {
|
|
14
|
+
response?: LabelsResponse;
|
|
15
|
+
error?: Error;
|
|
16
|
+
}
|
|
17
|
+
interface UseLabelNames {
|
|
18
|
+
result: ILabelNamesResult;
|
|
19
|
+
loading: boolean;
|
|
20
|
+
refetch: () => Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
export declare const useLabelNames: (client: QueryServiceClient, profileType: string, start?: number, end?: number, match?: string[]) => UseLabelNames;
|
|
23
|
+
interface UseLabelValues {
|
|
24
|
+
result: {
|
|
25
|
+
response: string[];
|
|
26
|
+
error?: Error;
|
|
27
|
+
};
|
|
28
|
+
loading: boolean;
|
|
29
|
+
refetch: () => Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
export declare const useLabelValues: (client: QueryServiceClient, labelName: string, profileType: string, start?: number, end?: number) => UseLabelValues;
|
|
32
|
+
export declare const useFetchUtilizationLabelValues: (labelName: string, utilizationLabels?: UtilizationLabels) => string[];
|
|
33
|
+
export default function MatchersInputWithProvider(props: MatchersInputProps): JSX.Element;
|
|
34
|
+
export {};
|
|
3
35
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/MatchersInput/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/MatchersInput/index.tsx"],"names":[],"mappings":"AAmBA,OAAO,EAAgB,cAAc,EAAE,kBAAkB,EAAgB,MAAM,eAAe,CAAC;AAE/F,OAAO,EAAC,KAAK,EAAC,MAAM,eAAe,CAAC;AAIpC,OAAO,EAAC,iBAAiB,EAAC,MAAM,oBAAoB,CAAC;AAKrD,UAAU,kBAAkB;IAC1B,WAAW,EAAE,kBAAkB,CAAC;IAChC,iBAAiB,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IACzC,QAAQ,EAAE,MAAM,IAAI,CAAC;IACrB,YAAY,EAAE,KAAK,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B,KAAK,CAAC,EAAE,KAAK,CAAC;CACf;AAED,UAAU,aAAa;IACrB,MAAM,EAAE,iBAAiB,CAAC;IAC1B,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B;AAED,eAAO,MAAM,aAAa,GACxB,QAAQ,kBAAkB,EAC1B,aAAa,MAAM,EACnB,QAAQ,MAAM,EACd,MAAM,MAAM,EACZ,QAAQ,MAAM,EAAE,KACf,aAkCF,CAAC;AAEF,UAAU,cAAc;IACtB,MAAM,EAAE;QACN,QAAQ,EAAE,MAAM,EAAE,CAAC;QACnB,KAAK,CAAC,EAAE,KAAK,CAAC;KACf,CAAC;IACF,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B;AAED,eAAO,MAAM,cAAc,GACzB,QAAQ,kBAAkB,EAC1B,WAAW,MAAM,EACjB,aAAa,MAAM,EACnB,QAAQ,MAAM,EACd,MAAM,MAAM,KACX,cAiCF,CAAC;AAEF,eAAO,MAAM,8BAA8B,GACzC,WAAW,MAAM,EACjB,oBAAoB,iBAAiB,KACpC,MAAM,EAWR,CAAC;AA2MF,MAAM,CAAC,OAAO,UAAU,yBAAyB,CAAC,KAAK,EAAE,kBAAkB,GAAG,GAAG,CAAC,OAAO,CAWxF"}
|
|
@@ -11,24 +11,99 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
11
11
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
12
|
// See the License for the specific language governing permissions and
|
|
13
13
|
// limitations under the License.
|
|
14
|
-
import { useMemo, useRef, useState } from 'react';
|
|
14
|
+
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
15
|
+
import { useQuery } from '@tanstack/react-query';
|
|
15
16
|
import cx from 'classnames';
|
|
16
17
|
import TextareaAutosize from 'react-textarea-autosize';
|
|
18
|
+
import { useGrpcMetadata } from '@parca/components';
|
|
17
19
|
import { Query } from '@parca/parser';
|
|
18
20
|
import { TEST_IDS, testId } from '@parca/test-utils';
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
+
import { millisToProtoTimestamp, sanitizeLabelValue } from '@parca/utilities';
|
|
22
|
+
import { LabelsProvider, useLabels } from '../contexts/MatchersInputLabelsContext';
|
|
23
|
+
import useGrpcQuery from '../useGrpcQuery';
|
|
21
24
|
import SuggestionsList, { Suggestion, Suggestions } from './SuggestionsList';
|
|
22
|
-
const
|
|
25
|
+
export const useLabelNames = (client, profileType, start, end, match) => {
|
|
26
|
+
const metadata = useGrpcMetadata();
|
|
27
|
+
const { data, isLoading, error, refetch } = useGrpcQuery({
|
|
28
|
+
key: ['labelNames', profileType, match?.join(','), start, end],
|
|
29
|
+
queryFn: async (signal) => {
|
|
30
|
+
const request = { match: match !== undefined ? match : [] };
|
|
31
|
+
if (start !== undefined && end !== undefined) {
|
|
32
|
+
request.start = millisToProtoTimestamp(start);
|
|
33
|
+
request.end = millisToProtoTimestamp(end);
|
|
34
|
+
}
|
|
35
|
+
if (profileType !== undefined) {
|
|
36
|
+
request.profileType = profileType;
|
|
37
|
+
}
|
|
38
|
+
const { response } = await client.labels(request, { meta: metadata, abort: signal });
|
|
39
|
+
return response;
|
|
40
|
+
},
|
|
41
|
+
options: {
|
|
42
|
+
enabled: profileType !== undefined && profileType !== '',
|
|
43
|
+
keepPreviousData: false,
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
console.log('Label names query result:', { data, error, isLoading });
|
|
48
|
+
}, [data, error, isLoading]);
|
|
49
|
+
return {
|
|
50
|
+
result: { response: data, error: error },
|
|
51
|
+
loading: isLoading,
|
|
52
|
+
refetch: async () => {
|
|
53
|
+
await refetch();
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
export const useLabelValues = (client, labelName, profileType, start, end) => {
|
|
58
|
+
const metadata = useGrpcMetadata();
|
|
59
|
+
const { data, isLoading, error, refetch } = useGrpcQuery({
|
|
60
|
+
key: ['labelValues', labelName, profileType, start, end],
|
|
61
|
+
queryFn: async (signal) => {
|
|
62
|
+
const request = { labelName, match: [], profileType };
|
|
63
|
+
if (start !== undefined && end !== undefined) {
|
|
64
|
+
request.start = millisToProtoTimestamp(start);
|
|
65
|
+
request.end = millisToProtoTimestamp(end);
|
|
66
|
+
}
|
|
67
|
+
const { response } = await client.values(request, { meta: metadata, abort: signal });
|
|
68
|
+
return sanitizeLabelValue(response.labelValues);
|
|
69
|
+
},
|
|
70
|
+
options: {
|
|
71
|
+
enabled: profileType !== undefined &&
|
|
72
|
+
profileType !== '' &&
|
|
73
|
+
labelName !== undefined &&
|
|
74
|
+
labelName !== '',
|
|
75
|
+
keepPreviousData: false,
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
console.log('Label values query result:', { data, error, isLoading, labelName });
|
|
79
|
+
return {
|
|
80
|
+
result: { response: data ?? [], error: error },
|
|
81
|
+
loading: isLoading,
|
|
82
|
+
refetch: async () => {
|
|
83
|
+
await refetch();
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
export const useFetchUtilizationLabelValues = (labelName, utilizationLabels) => {
|
|
88
|
+
const { data } = useQuery({
|
|
89
|
+
queryKey: ['utilizationLabelValues', labelName],
|
|
90
|
+
queryFn: async () => {
|
|
91
|
+
const result = await utilizationLabels?.utilizationFetchLabelValues?.(labelName);
|
|
92
|
+
return result ?? [];
|
|
93
|
+
},
|
|
94
|
+
enabled: utilizationLabels?.utilizationFetchLabelValues != null && labelName !== '',
|
|
95
|
+
});
|
|
96
|
+
return data ?? [];
|
|
97
|
+
};
|
|
98
|
+
const MatchersInput = ({ setMatchersString, runQuery, currentQuery, }) => {
|
|
23
99
|
const inputRef = useRef(null);
|
|
24
100
|
const [focusedInput, setFocusedInput] = useState(false);
|
|
25
101
|
const [lastCompleted, setLastCompleted] = useState(new Suggestion('', '', ''));
|
|
26
|
-
const { labelNames, labelValues,
|
|
27
|
-
const
|
|
28
|
-
const value = draftParsedQuery != null ? draftParsedQuery.matchersString() : '';
|
|
102
|
+
const { labelNames, labelValues, labelNameMappings, isLabelNamesLoading, isLabelValuesLoading, currentLabelName, setCurrentLabelName, shouldHandlePrefixes, refetchLabelValues, refetchLabelNames, } = useLabels();
|
|
103
|
+
const value = currentQuery.matchersString();
|
|
29
104
|
const suggestionSections = useMemo(() => {
|
|
30
105
|
const suggestionSections = new Suggestions();
|
|
31
|
-
Query.suggest(`${
|
|
106
|
+
Query.suggest(`${currentQuery.profileName()}{${value}`).forEach(function (s) {
|
|
32
107
|
// Skip suggestions that we just completed. This really only works,
|
|
33
108
|
// because we know the language is not repetitive. For a language that
|
|
34
109
|
// has a repeating word, this would not work.
|
|
@@ -91,7 +166,7 @@ const MatchersInput = () => {
|
|
|
91
166
|
});
|
|
92
167
|
return suggestionSections;
|
|
93
168
|
}, [
|
|
94
|
-
|
|
169
|
+
currentQuery,
|
|
95
170
|
lastCompleted,
|
|
96
171
|
labelNames,
|
|
97
172
|
labelValues,
|
|
@@ -104,7 +179,7 @@ const MatchersInput = () => {
|
|
|
104
179
|
const resetLastCompleted = () => setLastCompleted(new Suggestion('', '', ''));
|
|
105
180
|
const onChange = (e) => {
|
|
106
181
|
const newValue = e.target.value;
|
|
107
|
-
|
|
182
|
+
setMatchersString(newValue);
|
|
108
183
|
resetLastCompleted();
|
|
109
184
|
};
|
|
110
185
|
const complete = (suggestion) => {
|
|
@@ -122,7 +197,7 @@ const MatchersInput = () => {
|
|
|
122
197
|
const applySuggestion = (suggestion) => {
|
|
123
198
|
const newValue = complete(suggestion);
|
|
124
199
|
setLastCompleted(suggestion);
|
|
125
|
-
|
|
200
|
+
setMatchersString(newValue);
|
|
126
201
|
if (inputRef.current !== null) {
|
|
127
202
|
inputRef.current.value = newValue;
|
|
128
203
|
inputRef.current.focus();
|
|
@@ -134,11 +209,13 @@ const MatchersInput = () => {
|
|
|
134
209
|
const unfocus = () => {
|
|
135
210
|
setFocusedInput(false);
|
|
136
211
|
};
|
|
137
|
-
const profileSelected =
|
|
212
|
+
const profileSelected = currentQuery.profileName() === '';
|
|
138
213
|
return (_jsxs("div", { className: "w-full min-w-[300px] flex-1 font-mono relative", ...testId(TEST_IDS.MATCHERS_INPUT_CONTAINER), children: [_jsx(TextareaAutosize, { ref: inputRef, className: cx('block h-[38px] w-full flex-1 rounded-md border bg-white px-2 py-2 text-sm shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-1 focus:ring-indigo-500 dark:border-gray-600 dark:bg-gray-900', profileSelected && 'cursor-not-allowed'), placeholder: profileSelected
|
|
139
214
|
? 'Select a profile first to enter a filter...'
|
|
140
215
|
: 'filter profiles... eg. node="test"', onChange: onChange, value: value, onBlur: unfocus, ...testId(TEST_IDS.MATCHERS_TEXTAREA), onFocus: focus, disabled: profileSelected, title: profileSelected
|
|
141
216
|
? 'Select a profile first to enter a filter...'
|
|
142
|
-
: 'filter profiles... eg. node="test"', id: "matchers-input" }), _jsx(SuggestionsList, { isLabelNamesLoading: isLabelNamesLoading, suggestions: suggestionSections, applySuggestion: applySuggestion, inputRef: inputRef.current, runQuery:
|
|
217
|
+
: 'filter profiles... eg. node="test"', id: "matchers-input" }), _jsx(SuggestionsList, { isLabelNamesLoading: isLabelNamesLoading, suggestions: suggestionSections, applySuggestion: applySuggestion, inputRef: inputRef.current, runQuery: runQuery, focusedInput: focusedInput, isLabelValuesLoading: isLabelValuesLoading && lastCompleted.type === 'literal' && lastCompleted.value !== ',', shouldTrimPrefix: shouldHandlePrefixes, refetchLabelValues: refetchLabelValues, refetchLabelNames: refetchLabelNames })] }));
|
|
143
218
|
};
|
|
144
|
-
export default
|
|
219
|
+
export default function MatchersInputWithProvider(props) {
|
|
220
|
+
return (_jsx(LabelsProvider, { queryClient: props.queryClient, profileType: props.profileType, start: props.start, end: props.end, children: _jsx(MatchersInput, { ...props }) }));
|
|
221
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { DateTimeRange } from '@parca/components';
|
|
2
|
+
import { type UtilizationMetrics as MetricSeries } from '../../ProfileSelector';
|
|
3
|
+
interface CommonProps {
|
|
4
|
+
transmitData: MetricSeries[];
|
|
5
|
+
receiveData: MetricSeries[];
|
|
6
|
+
addLabelMatcher: (labels: {
|
|
7
|
+
key: string;
|
|
8
|
+
value: string;
|
|
9
|
+
} | Array<{
|
|
10
|
+
key: string;
|
|
11
|
+
value: string;
|
|
12
|
+
}>) => void;
|
|
13
|
+
setTimeRange: (range: DateTimeRange) => void;
|
|
14
|
+
name: string;
|
|
15
|
+
humanReadableName: string;
|
|
16
|
+
from: number;
|
|
17
|
+
to: number;
|
|
18
|
+
selectedSeries?: Array<{
|
|
19
|
+
key: string;
|
|
20
|
+
value: string;
|
|
21
|
+
}>;
|
|
22
|
+
onSeriesClick?: (name: string, seriesIndex: number) => void;
|
|
23
|
+
}
|
|
24
|
+
type Props = CommonProps & {
|
|
25
|
+
utilizationMetricsLoading?: boolean;
|
|
26
|
+
};
|
|
27
|
+
declare const AreaChart: ({ transmitData, receiveData, addLabelMatcher, setTimeRange, utilizationMetricsLoading, name, humanReadableName, from, to, selectedSeries, onSeriesClick, }: Props) => JSX.Element;
|
|
28
|
+
export default AreaChart;
|
|
29
|
+
//# sourceMappingURL=Throughput.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Throughput.d.ts","sourceRoot":"","sources":["../../../src/MetricsGraph/UtilizationMetrics/Throughput.tsx"],"names":[],"mappings":"AAkBA,OAAO,EACL,aAAa,EAId,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAC,KAAK,kBAAkB,IAAI,YAAY,EAAC,MAAM,uBAAuB,CAAC;AAiB9E,UAAU,WAAW;IACnB,YAAY,EAAE,YAAY,EAAE,CAAC;IAC7B,WAAW,EAAE,YAAY,EAAE,CAAC;IAC5B,eAAe,EAAE,CACf,MAAM,EAAE;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAC,GAAG,KAAK,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAC,CAAC,KACvE,IAAI,CAAC;IACV,YAAY,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;IAC7C,IAAI,EAAE,MAAM,CAAC;IACb,iBAAiB,EAAE,MAAM,CAAC;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,cAAc,CAAC,EAAE,KAAK,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAC,CAAC,CAAC;IACrD,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,KAAK,IAAI,CAAC;CAC7D;AAUD,KAAK,KAAK,GAAG,WAAW,GAAG;IACzB,yBAAyB,CAAC,EAAE,OAAO,CAAC;CACrC,CAAC;AAoRF,QAAA,MAAM,SAAS,GAAI,4JAYhB,KAAK,KAAG,GAAG,CAAC,OA8Cd,CAAC;AAEF,eAAe,SAAS,CAAC"}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// Copyright 2022 The Parca Authors
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
import { useMemo } from 'react';
|
|
15
|
+
import { Icon } from '@iconify/react';
|
|
16
|
+
import { AnimatePresence, motion } from 'framer-motion';
|
|
17
|
+
import { MetricsGraphSkeleton, TextWithTooltip, useParcaContext, } from '@parca/components';
|
|
18
|
+
import { formatDate, timePattern, valueFormatter } from '@parca/utilities';
|
|
19
|
+
import MetricsGraph from '../index';
|
|
20
|
+
import { useMetricsGraphDimensions } from '../useMetricsGraphDimensions';
|
|
21
|
+
const transformUtilizationLabels = (label) => {
|
|
22
|
+
return label.replace('attributes.', '').replace('attributes_resource.', '');
|
|
23
|
+
};
|
|
24
|
+
const createThroughputContextMenuItems = (addLabelMatcher, transmitData, receiveData) => {
|
|
25
|
+
const allData = [...transmitData, ...receiveData];
|
|
26
|
+
return [
|
|
27
|
+
{
|
|
28
|
+
id: 'focus-on-single-series',
|
|
29
|
+
label: 'Focus only on this series',
|
|
30
|
+
icon: 'ph:star',
|
|
31
|
+
onClick: (closestPoint, _series) => {
|
|
32
|
+
if (closestPoint != null &&
|
|
33
|
+
allData.length > 0 &&
|
|
34
|
+
allData[closestPoint.seriesIndex] != null) {
|
|
35
|
+
const originalSeriesData = allData[closestPoint.seriesIndex];
|
|
36
|
+
if (originalSeriesData.labelset?.labels != null) {
|
|
37
|
+
const labels = originalSeriesData.labelset.labels.filter(label => label.name !== '__name__');
|
|
38
|
+
const labelsToAdd = labels.map(label => ({
|
|
39
|
+
key: label.name,
|
|
40
|
+
value: label.value,
|
|
41
|
+
}));
|
|
42
|
+
addLabelMatcher(labelsToAdd);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
id: 'add-to-query',
|
|
49
|
+
label: 'Add to query',
|
|
50
|
+
icon: 'material-symbols:add',
|
|
51
|
+
createDynamicItems: (closestPoint, _series) => {
|
|
52
|
+
if (closestPoint == null ||
|
|
53
|
+
allData.length === 0 ||
|
|
54
|
+
allData[closestPoint.seriesIndex] == null) {
|
|
55
|
+
return [
|
|
56
|
+
{
|
|
57
|
+
id: 'no-labels-available',
|
|
58
|
+
label: 'No labels available',
|
|
59
|
+
icon: 'ph:warning',
|
|
60
|
+
disabled: () => true,
|
|
61
|
+
onClick: () => { }, // No-op for disabled item
|
|
62
|
+
},
|
|
63
|
+
];
|
|
64
|
+
}
|
|
65
|
+
const originalSeriesData = allData[closestPoint.seriesIndex];
|
|
66
|
+
if (originalSeriesData.labelset?.labels == null) {
|
|
67
|
+
return [
|
|
68
|
+
{
|
|
69
|
+
id: 'no-labels-available',
|
|
70
|
+
label: 'No labels available',
|
|
71
|
+
icon: 'ph:warning',
|
|
72
|
+
disabled: () => true,
|
|
73
|
+
onClick: () => { }, // No-op for disabled item
|
|
74
|
+
},
|
|
75
|
+
];
|
|
76
|
+
}
|
|
77
|
+
const labels = originalSeriesData.labelset.labels.filter(label => label.name !== '__name__');
|
|
78
|
+
return labels.map(label => ({
|
|
79
|
+
id: `add-label-${label.name}`,
|
|
80
|
+
label: (_jsx("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", children: `${transformUtilizationLabels(label.name)}="${label.value}"` })),
|
|
81
|
+
onClick: () => {
|
|
82
|
+
addLabelMatcher({
|
|
83
|
+
key: label.name,
|
|
84
|
+
value: label.value,
|
|
85
|
+
});
|
|
86
|
+
},
|
|
87
|
+
}));
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
];
|
|
91
|
+
};
|
|
92
|
+
function transformToSeries(data, isReceive = false) {
|
|
93
|
+
const series = data.reduce(function (agg, s) {
|
|
94
|
+
if (s.labelset !== undefined) {
|
|
95
|
+
const metric = s.labelset.labels.sort((a, b) => a.name.localeCompare(b.name));
|
|
96
|
+
agg.push({
|
|
97
|
+
metric,
|
|
98
|
+
values: s.samples.reduce(function (agg, d) {
|
|
99
|
+
if (d.timestamp !== undefined && d.value !== undefined) {
|
|
100
|
+
// Multiply receive values by -1 to display below zero
|
|
101
|
+
const value = isReceive ? -1 * d.value : d.value;
|
|
102
|
+
agg.push([d.timestamp, value]);
|
|
103
|
+
}
|
|
104
|
+
return agg;
|
|
105
|
+
}, []),
|
|
106
|
+
labelset: metric.map(m => `${m.name}=${m.value}`).join(','),
|
|
107
|
+
isReceive,
|
|
108
|
+
isSelected: s.isSelected,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
return agg;
|
|
112
|
+
}, []);
|
|
113
|
+
// Sort values by timestamp for each series
|
|
114
|
+
return series.map(series => ({
|
|
115
|
+
...series,
|
|
116
|
+
values: series.values.sort((a, b) => a[0] - b[0]),
|
|
117
|
+
}));
|
|
118
|
+
}
|
|
119
|
+
function transformNetworkSeriesToSeries(transmitData, receiveData) {
|
|
120
|
+
const transmitSeries = transformToSeries(transmitData);
|
|
121
|
+
const receiveSeries = transformToSeries(receiveData, true);
|
|
122
|
+
const allSeries = [...transmitSeries, ...receiveSeries];
|
|
123
|
+
return allSeries.map(networkSeries => {
|
|
124
|
+
const labels = networkSeries.metric ?? [];
|
|
125
|
+
const sortedLabels = labels
|
|
126
|
+
.filter(label => label.name !== '__name__')
|
|
127
|
+
.sort((a, b) => a.name.localeCompare(b.name));
|
|
128
|
+
const labelString = sortedLabels.map(label => `${label.name}=${label.value}`).join(',');
|
|
129
|
+
const id = (networkSeries.isReceive === true ? 'receive-' : 'transmit-') +
|
|
130
|
+
(labelString !== '' ? labelString : 'default');
|
|
131
|
+
return {
|
|
132
|
+
id,
|
|
133
|
+
values: networkSeries.values.map(([timestamp, value]) => [
|
|
134
|
+
timestamp,
|
|
135
|
+
value,
|
|
136
|
+
]),
|
|
137
|
+
highlighted: networkSeries.isSelected ?? false,
|
|
138
|
+
};
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
const RawAreaChart = ({ transmitData, receiveData, transformedData, addLabelMatcher: _addLabelMatcher, setTimeRange, width, height, margin, humanReadableName, from, to, selectedSeries: _selectedSeries, onSeriesClick, contextMenuItems, }) => {
|
|
142
|
+
const { timezone } = useParcaContext();
|
|
143
|
+
// Compute original series data for rich tooltip
|
|
144
|
+
const allOriginalData = useMemo(() => [...transmitData, ...receiveData], [transmitData, receiveData]);
|
|
145
|
+
return (_jsx(MetricsGraph, { data: transformedData, from: from, to: to, setTimeRange: setTimeRange, onSampleClick: closestPoint => {
|
|
146
|
+
if (onSeriesClick != null) {
|
|
147
|
+
onSeriesClick(humanReadableName, closestPoint.seriesIndex);
|
|
148
|
+
}
|
|
149
|
+
}, yAxisLabel: humanReadableName, yAxisUnit: "bytes_per_second", width: width, height: height, margin: margin, contextMenuItems: contextMenuItems, renderTooltipContent: (seriesIndex, pointIndex) => {
|
|
150
|
+
if (allOriginalData?.[seriesIndex]?.samples?.[pointIndex] != null) {
|
|
151
|
+
const originalSeriesData = allOriginalData[seriesIndex];
|
|
152
|
+
const originalPoint = allOriginalData[seriesIndex].samples[pointIndex];
|
|
153
|
+
const labels = originalSeriesData.labelset?.labels ?? [];
|
|
154
|
+
const nameLabel = labels.find(e => e.name === '__name__');
|
|
155
|
+
const highlightedNameLabel = nameLabel ?? { name: '', value: '' };
|
|
156
|
+
// Determine if this is receive data (negative values)
|
|
157
|
+
const isReceive = seriesIndex >= transmitData.length;
|
|
158
|
+
const valuePrefix = isReceive ? 'Receive ' : 'Transmit ';
|
|
159
|
+
return (_jsx("div", { className: "flex flex-row", children: _jsxs("div", { className: "ml-2 mr-6", children: [_jsx("span", { className: "font-semibold", children: highlightedNameLabel.value }), _jsx("span", { className: "my-2 block text-gray-700 dark:text-gray-300", children: _jsx("table", { className: "table-auto", children: _jsxs("tbody", { children: [_jsxs("tr", { children: [_jsxs("td", { className: "w-1/4", children: [valuePrefix, "Value"] }), _jsx("td", { className: "w-3/4", children: valueFormatter(Math.abs(originalPoint.value), 'bytes_per_second', 2) })] }), _jsxs("tr", { children: [_jsx("td", { className: "w-1/4", children: "At" }), _jsx("td", { className: "w-3/4", children: formatDate(new Date(originalPoint.timestamp), timePattern(timezone), timezone) })] })] }) }) }), _jsx("span", { className: "my-2 block text-gray-500", children: labels
|
|
160
|
+
.filter(label => label.name !== '__name__')
|
|
161
|
+
.map(label => (_jsx("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-400", children: _jsx(TextWithTooltip, { text: `${transformUtilizationLabels(label.name)}="${label.value}"`, maxTextLength: 37, id: `${seriesIndex.toString()}-${pointIndex.toString()}-tooltip-${label.name}` }) }, `${seriesIndex.toString()}-${pointIndex.toString()}-${label.name}`))) }), _jsxs("div", { className: "flex w-full items-center gap-1 text-xs text-gray-500", children: [_jsx(Icon, { icon: "iconoir:mouse-button-right" }), _jsx("div", { children: "Right click to add labels to query." })] })] }) }));
|
|
162
|
+
}
|
|
163
|
+
return null;
|
|
164
|
+
} }));
|
|
165
|
+
};
|
|
166
|
+
const AreaChart = ({ transmitData, receiveData, addLabelMatcher, setTimeRange, utilizationMetricsLoading, name, humanReadableName, from, to, selectedSeries, onSeriesClick, }) => {
|
|
167
|
+
const { isDarkMode } = useParcaContext();
|
|
168
|
+
const { width, height, margin, heightStyle } = useMetricsGraphDimensions(false, true);
|
|
169
|
+
const transformedData = useMemo(() => transformNetworkSeriesToSeries(transmitData, receiveData), [transmitData, receiveData]);
|
|
170
|
+
const contextMenuItems = useMemo(() => {
|
|
171
|
+
return createThroughputContextMenuItems(addLabelMatcher, transmitData, receiveData);
|
|
172
|
+
}, [addLabelMatcher, transmitData, receiveData]);
|
|
173
|
+
return (_jsx(AnimatePresence, { children: _jsx(motion.div, { className: "w-full relative", initial: false, animate: { display: 'block', opacity: 1 }, transition: { duration: 0.5 }, children: utilizationMetricsLoading === true ? (_jsx(MetricsGraphSkeleton, { heightStyle: heightStyle, isDarkMode: isDarkMode, isMini: true })) : (_jsx(RawAreaChart, { transmitData: transmitData, receiveData: receiveData, transformedData: transformedData, addLabelMatcher: addLabelMatcher, setTimeRange: setTimeRange, width: width, height: height, margin: margin, name: name, humanReadableName: humanReadableName, from: from, to: to, selectedSeries: selectedSeries, onSeriesClick: onSeriesClick, contextMenuItems: contextMenuItems })) }, "area-chart-graph-loaded") }));
|
|
174
|
+
};
|
|
175
|
+
export default AreaChart;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { DateTimeRange } from '@parca/components';
|
|
2
|
+
import { type UtilizationMetrics as MetricSeries } from '../../ProfileSelector';
|
|
3
|
+
interface CommonProps {
|
|
4
|
+
setTimeRange: (range: DateTimeRange) => void;
|
|
5
|
+
humanReadableName: string;
|
|
6
|
+
from: number;
|
|
7
|
+
to: number;
|
|
8
|
+
onSeriesClick?: (seriesIndex: number) => void;
|
|
9
|
+
}
|
|
10
|
+
type Props = CommonProps & {
|
|
11
|
+
data: MetricSeries[];
|
|
12
|
+
yAxisUnit: string;
|
|
13
|
+
utilizationMetricsLoading?: boolean;
|
|
14
|
+
addLabelMatcher?: (labels: {
|
|
15
|
+
key: string;
|
|
16
|
+
value: string;
|
|
17
|
+
} | Array<{
|
|
18
|
+
key: string;
|
|
19
|
+
value: string;
|
|
20
|
+
}>) => void;
|
|
21
|
+
onSelectedSeriesChange?: (series: Array<{
|
|
22
|
+
key: string;
|
|
23
|
+
value: string;
|
|
24
|
+
}>) => void;
|
|
25
|
+
};
|
|
26
|
+
declare const UtilizationMetrics: ({ data, setTimeRange, utilizationMetricsLoading, humanReadableName, from, to, yAxisUnit, addLabelMatcher, onSeriesClick, onSelectedSeriesChange: _onSelectedSeriesChange, }: Props) => JSX.Element;
|
|
27
|
+
export default UtilizationMetrics;
|
|
28
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/MetricsGraph/UtilizationMetrics/index.tsx"],"names":[],"mappings":"AAkBA,OAAO,EACL,aAAa,EAId,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAC,KAAK,kBAAkB,IAAI,YAAY,EAAC,MAAM,uBAAuB,CAAC;AAI9E,UAAU,WAAW;IACnB,YAAY,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;IAC7C,iBAAiB,EAAE,MAAM,CAAC;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,aAAa,CAAC,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,IAAI,CAAC;CAC/C;AAYD,KAAK,KAAK,GAAG,WAAW,GAAG;IACzB,IAAI,EAAE,YAAY,EAAE,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,yBAAyB,CAAC,EAAE,OAAO,CAAC;IACpC,eAAe,CAAC,EAAE,CAChB,MAAM,EAAE;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAC,GAAG,KAAK,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAC,CAAC,KACvE,IAAI,CAAC;IACV,sBAAsB,CAAC,EAAE,CAAC,MAAM,EAAE,KAAK,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAC,CAAC,KAAK,IAAI,CAAC;CAChF,CAAC;AA4TF,QAAA,MAAM,kBAAkB,GAAI,6KAWzB,KAAK,KAAG,GAAG,CAAC,OAwCd,CAAC;AAEF,eAAe,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// Copyright 2022 The Parca Authors
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
import { useMemo } from 'react';
|
|
15
|
+
import { Icon } from '@iconify/react';
|
|
16
|
+
import { AnimatePresence, motion } from 'framer-motion';
|
|
17
|
+
import { MetricsGraphSkeleton, TextWithTooltip, useParcaContext, } from '@parca/components';
|
|
18
|
+
import { formatDate, timePattern, valueFormatter } from '@parca/utilities';
|
|
19
|
+
import MetricsGraph from '../index';
|
|
20
|
+
import { useMetricsGraphDimensions } from '../useMetricsGraphDimensions';
|
|
21
|
+
const transformUtilizationLabels = (label) => {
|
|
22
|
+
return label.replace('attributes.', '').replace('attributes_resource.', '');
|
|
23
|
+
};
|
|
24
|
+
const createUtilizationContextMenuItems = (addLabelMatcher, originalData) => {
|
|
25
|
+
return [
|
|
26
|
+
{
|
|
27
|
+
id: 'focus-on-single-series',
|
|
28
|
+
label: 'Focus only on this series',
|
|
29
|
+
icon: 'ph:star',
|
|
30
|
+
onClick: (closestPoint, _series) => {
|
|
31
|
+
if (closestPoint != null &&
|
|
32
|
+
originalData.length > 0 &&
|
|
33
|
+
originalData[closestPoint.seriesIndex] != null) {
|
|
34
|
+
const originalSeriesData = originalData[closestPoint.seriesIndex];
|
|
35
|
+
if (originalSeriesData.labelset?.labels != null) {
|
|
36
|
+
const labels = originalSeriesData.labelset.labels.filter(label => label.name !== '__name__');
|
|
37
|
+
const labelsToAdd = labels.map(label => ({
|
|
38
|
+
key: label.name,
|
|
39
|
+
value: label.value,
|
|
40
|
+
}));
|
|
41
|
+
addLabelMatcher(labelsToAdd);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
id: 'add-to-query',
|
|
48
|
+
label: 'Add to query',
|
|
49
|
+
icon: 'material-symbols:add',
|
|
50
|
+
createDynamicItems: (closestPoint, _series) => {
|
|
51
|
+
if (closestPoint == null ||
|
|
52
|
+
originalData.length === 0 ||
|
|
53
|
+
originalData[closestPoint.seriesIndex] == null) {
|
|
54
|
+
return [
|
|
55
|
+
{
|
|
56
|
+
id: 'no-labels-available',
|
|
57
|
+
label: 'No labels available',
|
|
58
|
+
icon: 'ph:warning',
|
|
59
|
+
disabled: () => true,
|
|
60
|
+
onClick: () => { }, // No-op for disabled item
|
|
61
|
+
},
|
|
62
|
+
];
|
|
63
|
+
}
|
|
64
|
+
const originalSeriesData = originalData[closestPoint.seriesIndex];
|
|
65
|
+
if (originalSeriesData.labelset?.labels == null) {
|
|
66
|
+
return [
|
|
67
|
+
{
|
|
68
|
+
id: 'no-labels-available',
|
|
69
|
+
label: 'No labels available',
|
|
70
|
+
icon: 'ph:warning',
|
|
71
|
+
disabled: () => true,
|
|
72
|
+
onClick: () => { }, // No-op for disabled item
|
|
73
|
+
},
|
|
74
|
+
];
|
|
75
|
+
}
|
|
76
|
+
const labels = originalSeriesData.labelset.labels.filter(label => label.name !== '__name__');
|
|
77
|
+
return labels.map(label => ({
|
|
78
|
+
id: `add-label-${label.name}`,
|
|
79
|
+
label: (_jsx("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", children: `${transformUtilizationLabels(label.name)}="${label.value}"` })),
|
|
80
|
+
onClick: () => {
|
|
81
|
+
addLabelMatcher({
|
|
82
|
+
key: label.name,
|
|
83
|
+
value: label.value,
|
|
84
|
+
});
|
|
85
|
+
},
|
|
86
|
+
}));
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
];
|
|
90
|
+
};
|
|
91
|
+
const transformMetricSeriesToSeries = (data) => {
|
|
92
|
+
return data.map(metricSeries => {
|
|
93
|
+
if (metricSeries.labelset != null) {
|
|
94
|
+
const labels = metricSeries.labelset.labels ?? [];
|
|
95
|
+
const sortedLabels = labels.sort((a, b) => a.name.localeCompare(b.name));
|
|
96
|
+
const id = sortedLabels.map(label => `${label.name}=${label.value}`).join(',');
|
|
97
|
+
return {
|
|
98
|
+
id: id !== '' ? id : 'default',
|
|
99
|
+
values: metricSeries.samples.map((sample) => [
|
|
100
|
+
sample.timestamp,
|
|
101
|
+
sample.value,
|
|
102
|
+
]),
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
return {
|
|
106
|
+
id: 'default',
|
|
107
|
+
values: [],
|
|
108
|
+
};
|
|
109
|
+
});
|
|
110
|
+
};
|
|
111
|
+
const _getYAxisUnit = (name) => {
|
|
112
|
+
switch (name) {
|
|
113
|
+
case 'gpu_power_watt':
|
|
114
|
+
return 'watts';
|
|
115
|
+
case 'gpu_temperature_celsius':
|
|
116
|
+
return 'celsius';
|
|
117
|
+
case 'gpu_clock_hertz':
|
|
118
|
+
return 'hertz';
|
|
119
|
+
default:
|
|
120
|
+
return 'percent';
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
const RawUtilizationMetrics = ({ data, originalData, setTimeRange, width, height, margin, humanReadableName, from, to, yAxisUnit, contextMenuItems, onSeriesClick, }) => {
|
|
124
|
+
const { timezone } = useParcaContext();
|
|
125
|
+
return (_jsx(MetricsGraph, { data: data.map((val, idx) => ({
|
|
126
|
+
...val,
|
|
127
|
+
highlighted: originalData?.[idx]?.isSelected ?? false,
|
|
128
|
+
})), from: from, to: to, setTimeRange: setTimeRange, onSampleClick: closestPoint => {
|
|
129
|
+
if (onSeriesClick != null) {
|
|
130
|
+
onSeriesClick(closestPoint.seriesIndex);
|
|
131
|
+
}
|
|
132
|
+
}, yAxisLabel: humanReadableName, yAxisUnit: yAxisUnit, width: width, height: height, margin: margin, contextMenuItems: contextMenuItems, renderTooltipContent: (seriesIndex, pointIndex) => {
|
|
133
|
+
if (originalData?.[seriesIndex]?.samples?.[pointIndex] != null) {
|
|
134
|
+
const originalSeriesData = originalData[seriesIndex];
|
|
135
|
+
const originalPoint = originalData[seriesIndex].samples[pointIndex];
|
|
136
|
+
const labels = originalSeriesData.labelset?.labels ?? [];
|
|
137
|
+
const nameLabel = labels.find(e => e.name === '__name__');
|
|
138
|
+
const highlightedNameLabel = nameLabel ?? { name: '', value: '' };
|
|
139
|
+
// Calculate attributes maps for utilization metrics
|
|
140
|
+
const attributesMap = labels
|
|
141
|
+
.filter(label => label.name.startsWith('attributes.') &&
|
|
142
|
+
!label.name.startsWith('attributes_resource.'))
|
|
143
|
+
.reduce((acc, label) => {
|
|
144
|
+
const key = label.name.replace('attributes.', '');
|
|
145
|
+
acc[key] = label.value;
|
|
146
|
+
return acc;
|
|
147
|
+
}, {});
|
|
148
|
+
const attributesResourceMap = labels
|
|
149
|
+
.filter(label => label.name.startsWith('attributes_resource.'))
|
|
150
|
+
.reduce((acc, label) => {
|
|
151
|
+
const key = label.name.replace('attributes_resource.', '');
|
|
152
|
+
acc[key] = label.value;
|
|
153
|
+
return acc;
|
|
154
|
+
}, {});
|
|
155
|
+
return (_jsx("div", { className: "flex flex-row", children: _jsxs("div", { className: "ml-2 mr-6", children: [_jsx("span", { className: "font-semibold", children: highlightedNameLabel.value }), _jsx("span", { className: "my-2 block text-gray-700 dark:text-gray-300", children: _jsx("table", { className: "table-auto", children: _jsxs("tbody", { children: [_jsxs("tr", { children: [_jsx("td", { className: "w-1/4", children: "Value" }), _jsx("td", { className: "w-3/4", children: valueFormatter(originalPoint.value, yAxisUnit, 2) })] }), _jsxs("tr", { children: [_jsx("td", { className: "w-1/4", children: "At" }), _jsx("td", { className: "w-3/4", children: formatDate(new Date(originalPoint.timestamp), timePattern(timezone), timezone) })] })] }) }) }), _jsxs("span", { className: "my-2 block text-gray-500", children: [Object.keys(attributesResourceMap).length > 0 ? (_jsx("span", { className: "text-sm font-bold text-gray-700 dark:text-white", children: "Resource Attributes" })) : null, _jsx("span", { className: "my-2 block text-gray-500", children: Object.keys(attributesResourceMap).map(name => (_jsx("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-400", children: _jsx(TextWithTooltip, { text: `${transformUtilizationLabels(name)}="${attributesResourceMap[name] ?? ''}"`, maxTextLength: 48, id: `tooltip-${name}-${attributesResourceMap[name] ?? ''}` }) }, 'resourceattribute-' +
|
|
156
|
+
seriesIndex.toString() +
|
|
157
|
+
'-' +
|
|
158
|
+
pointIndex.toString() +
|
|
159
|
+
'-' +
|
|
160
|
+
name))) }), Object.keys(attributesMap).length > 0 ? (_jsx("span", { className: "text-sm font-bold text-gray-700 dark:text-white", children: "Attributes" })) : null, _jsx("span", { className: "my-2 block text-gray-500", children: Object.keys(attributesMap).map(name => (_jsx("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-400", children: _jsx(TextWithTooltip, { text: `${transformUtilizationLabels(name)}="${attributesMap[name] ?? ''}"`, maxTextLength: 48, id: `tooltip-${name}-${attributesMap[name] ?? ''}` }) }, 'attribute-' +
|
|
161
|
+
seriesIndex.toString() +
|
|
162
|
+
'-' +
|
|
163
|
+
pointIndex.toString() +
|
|
164
|
+
'-' +
|
|
165
|
+
name))) }), labels
|
|
166
|
+
.filter(label => label.name !== '__name__' && !label.name.startsWith('attributes'))
|
|
167
|
+
.map(label => (_jsx("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-400", children: _jsx(TextWithTooltip, { text: `${transformUtilizationLabels(label.name)}="${label.value}"`, maxTextLength: 37, id: `tooltip-${label.name}` }) }, 'attribute-' +
|
|
168
|
+
seriesIndex.toString() +
|
|
169
|
+
'-' +
|
|
170
|
+
pointIndex.toString() +
|
|
171
|
+
'-label-' +
|
|
172
|
+
label.name)))] }), _jsxs("div", { className: "flex w-full items-center gap-1 text-xs text-gray-500", children: [_jsx(Icon, { icon: "iconoir:mouse-button-right" }), _jsx("div", { children: "Right click to add labels to query." })] })] }) }));
|
|
173
|
+
}
|
|
174
|
+
return null;
|
|
175
|
+
} }));
|
|
176
|
+
};
|
|
177
|
+
const UtilizationMetrics = ({ data, setTimeRange, utilizationMetricsLoading, humanReadableName, from, to, yAxisUnit, addLabelMatcher, onSeriesClick, onSelectedSeriesChange: _onSelectedSeriesChange, }) => {
|
|
178
|
+
const { isDarkMode } = useParcaContext();
|
|
179
|
+
const { width, height, margin, heightStyle } = useMetricsGraphDimensions(false, true);
|
|
180
|
+
const transformedData = useMemo(() => transformMetricSeriesToSeries(data), [data]);
|
|
181
|
+
const contextMenuItems = useMemo(() => {
|
|
182
|
+
return addLabelMatcher != null ? createUtilizationContextMenuItems(addLabelMatcher, data) : [];
|
|
183
|
+
}, [addLabelMatcher, data]);
|
|
184
|
+
return (_jsx(AnimatePresence, { children: _jsx(motion.div, { className: "w-full relative", initial: false, animate: { display: 'block', opacity: 1 }, transition: { duration: 0.5 }, children: utilizationMetricsLoading === true ? (_jsx(MetricsGraphSkeleton, { heightStyle: heightStyle, isDarkMode: isDarkMode, isMini: true })) : (_jsx(RawUtilizationMetrics, { data: transformedData, originalData: data, setTimeRange: setTimeRange, width: width, height: height, margin: margin, humanReadableName: humanReadableName, from: from, to: to, yAxisUnit: yAxisUnit, contextMenuItems: contextMenuItems, onSeriesClick: onSeriesClick })) }, "utilization-metrics-graph-loaded") }));
|
|
185
|
+
};
|
|
186
|
+
export default UtilizationMetrics;
|