@parca/profile 0.16.447 → 0.16.449
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 +8 -0
- package/dist/ProfileSelector/MetricsGraphSection.d.ts +26 -0
- package/dist/ProfileSelector/MetricsGraphSection.d.ts.map +1 -0
- package/dist/ProfileSelector/MetricsGraphSection.js +80 -0
- package/dist/ProfileSelector/QueryControls.d.ts +41 -0
- package/dist/ProfileSelector/QueryControls.d.ts.map +1 -0
- package/dist/ProfileSelector/QueryControls.js +54 -0
- package/dist/ProfileSelector/index.d.ts +10 -4
- package/dist/ProfileSelector/index.d.ts.map +1 -1
- package/dist/ProfileSelector/index.js +7 -111
- package/dist/styles.css +1 -1
- package/package.json +10 -10
- package/src/ProfileSelector/MetricsGraphSection.tsx +172 -0
- package/src/ProfileSelector/QueryControls.tsx +233 -0
- package/src/ProfileSelector/index.tsx +70 -282
|
@@ -0,0 +1,172 @@
|
|
|
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 cx from 'classnames';
|
|
15
|
+
|
|
16
|
+
import {Label, QueryServiceClient} from '@parca/client';
|
|
17
|
+
import {DateTimeRange} from '@parca/components';
|
|
18
|
+
import {Query} from '@parca/parser';
|
|
19
|
+
|
|
20
|
+
import {MergedProfileSelection, ProfileSelection} from '..';
|
|
21
|
+
import ProfileMetricsGraph, {ProfileMetricsEmptyState} from '../ProfileMetricsGraph';
|
|
22
|
+
import {QuerySelection} from './index';
|
|
23
|
+
|
|
24
|
+
interface MetricsGraphSectionProps {
|
|
25
|
+
showMetricsGraph: boolean;
|
|
26
|
+
setDisplayHideMetricsGraphButton: (show: boolean) => void;
|
|
27
|
+
heightStyle: string;
|
|
28
|
+
querySelection: QuerySelection;
|
|
29
|
+
profileSelection: ProfileSelection | null;
|
|
30
|
+
comparing: boolean;
|
|
31
|
+
sumBy: string[] | null;
|
|
32
|
+
defaultSumByLoading: boolean;
|
|
33
|
+
queryClient: QueryServiceClient;
|
|
34
|
+
queryExpressionString: string;
|
|
35
|
+
setTimeRangeSelection: (range: DateTimeRange) => void;
|
|
36
|
+
selectQuery: (query: QuerySelection) => void;
|
|
37
|
+
selectProfile: (source: ProfileSelection) => void;
|
|
38
|
+
query: Query;
|
|
39
|
+
setNewQueryExpression: (queryExpression: string) => void;
|
|
40
|
+
setQueryExpression: (updateTs?: boolean) => void;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function MetricsGraphSection({
|
|
44
|
+
showMetricsGraph,
|
|
45
|
+
setDisplayHideMetricsGraphButton,
|
|
46
|
+
heightStyle,
|
|
47
|
+
querySelection,
|
|
48
|
+
profileSelection,
|
|
49
|
+
comparing,
|
|
50
|
+
sumBy,
|
|
51
|
+
defaultSumByLoading,
|
|
52
|
+
queryClient,
|
|
53
|
+
queryExpressionString,
|
|
54
|
+
setTimeRangeSelection,
|
|
55
|
+
selectQuery,
|
|
56
|
+
selectProfile,
|
|
57
|
+
query,
|
|
58
|
+
setNewQueryExpression,
|
|
59
|
+
}: MetricsGraphSectionProps): JSX.Element {
|
|
60
|
+
const handleTimeRangeChange = (range: DateTimeRange): void => {
|
|
61
|
+
const from = range.getFromMs();
|
|
62
|
+
const to = range.getToMs();
|
|
63
|
+
let mergedProfileParams = {};
|
|
64
|
+
if (query.profileType().delta) {
|
|
65
|
+
mergedProfileParams = {mergeFrom: from, mergeTo: to};
|
|
66
|
+
}
|
|
67
|
+
setTimeRangeSelection(range);
|
|
68
|
+
selectQuery({
|
|
69
|
+
expression: queryExpressionString,
|
|
70
|
+
from,
|
|
71
|
+
to,
|
|
72
|
+
timeSelection: range.getRangeKey(),
|
|
73
|
+
...mergedProfileParams,
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const addLabelMatcher = (
|
|
78
|
+
labels: {key: string; value: string} | Array<{key: string; value: string}>
|
|
79
|
+
): void => {
|
|
80
|
+
// When a user clicks on a label on the metrics graph tooltip,
|
|
81
|
+
// replace single `\` in the `value` string with doubles `\\` if available.
|
|
82
|
+
const replaceBackslash = (value: string): string => {
|
|
83
|
+
return value.includes('\\') ? value.replaceAll('\\', '\\\\') : value;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
let newQuery: Query;
|
|
87
|
+
let hasChanged: boolean;
|
|
88
|
+
|
|
89
|
+
if (Array.isArray(labels)) {
|
|
90
|
+
const newLabels = labels.map(({key, value}) => {
|
|
91
|
+
const newValue = replaceBackslash(value);
|
|
92
|
+
return {key, value: newValue};
|
|
93
|
+
});
|
|
94
|
+
const [query, changed] = Query.parse(queryExpressionString).setMultipleMatchers(newLabels);
|
|
95
|
+
hasChanged = changed;
|
|
96
|
+
newQuery = query;
|
|
97
|
+
} else {
|
|
98
|
+
const {key, value} = labels;
|
|
99
|
+
const newValue = replaceBackslash(value);
|
|
100
|
+
const [query, changed] = Query.parse(queryExpressionString).setMatcher(key, newValue);
|
|
101
|
+
hasChanged = changed;
|
|
102
|
+
newQuery = query;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (hasChanged) {
|
|
106
|
+
// TODO: Change this to store the query object
|
|
107
|
+
setNewQueryExpression(newQuery.toString());
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const handlePointClick = (
|
|
112
|
+
timestamp: number,
|
|
113
|
+
labels: Label[],
|
|
114
|
+
queryExpression: string,
|
|
115
|
+
duration: number
|
|
116
|
+
): void => {
|
|
117
|
+
let query = Query.parse(queryExpression);
|
|
118
|
+
labels.forEach(l => {
|
|
119
|
+
const [newQuery, updated] = query.setMatcher(l.name, l.value);
|
|
120
|
+
if (updated) {
|
|
121
|
+
query = newQuery;
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
const durationInMilliseconds = duration / 1000000; // duration is in nanoseconds
|
|
126
|
+
const mergeFrom = timestamp;
|
|
127
|
+
const mergeTo = query.profileType().delta ? mergeFrom + durationInMilliseconds : mergeFrom;
|
|
128
|
+
selectProfile(new MergedProfileSelection(mergeFrom, mergeTo, query));
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
return (
|
|
132
|
+
<div className={cx('relative', {'py-4': !showMetricsGraph})}>
|
|
133
|
+
<button
|
|
134
|
+
onClick={() => setDisplayHideMetricsGraphButton(!showMetricsGraph)}
|
|
135
|
+
className={cx(
|
|
136
|
+
'hidden z-10 px-3 py-1 text-sm font-medium text-gray-700 dark:text-gray-200 bg-gray-100 rounded-md hover:bg-gray-200 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 dark:bg-gray-900',
|
|
137
|
+
showMetricsGraph && 'absolute right-0 bottom-3 !flex',
|
|
138
|
+
!showMetricsGraph && 'relative !flex ml-auto'
|
|
139
|
+
)}
|
|
140
|
+
>
|
|
141
|
+
{showMetricsGraph ? 'Hide' : 'Show'} Metrics Graph
|
|
142
|
+
</button>
|
|
143
|
+
{showMetricsGraph && (
|
|
144
|
+
<div style={{height: heightStyle}}>
|
|
145
|
+
{querySelection.expression !== '' &&
|
|
146
|
+
querySelection.from !== undefined &&
|
|
147
|
+
querySelection.to !== undefined ? (
|
|
148
|
+
<ProfileMetricsGraph
|
|
149
|
+
queryClient={queryClient}
|
|
150
|
+
queryExpression={querySelection.expression}
|
|
151
|
+
from={querySelection.from}
|
|
152
|
+
to={querySelection.to}
|
|
153
|
+
profile={profileSelection}
|
|
154
|
+
comparing={comparing}
|
|
155
|
+
sumBy={querySelection.sumBy ?? sumBy ?? []}
|
|
156
|
+
sumByLoading={defaultSumByLoading}
|
|
157
|
+
setTimeRange={handleTimeRangeChange}
|
|
158
|
+
addLabelMatcher={addLabelMatcher}
|
|
159
|
+
onPointClick={handlePointClick}
|
|
160
|
+
/>
|
|
161
|
+
) : (
|
|
162
|
+
profileSelection === null && (
|
|
163
|
+
<div className="p-2">
|
|
164
|
+
<ProfileMetricsEmptyState message="Please select a profile type and click 'Search' to begin." />
|
|
165
|
+
</div>
|
|
166
|
+
)
|
|
167
|
+
)}
|
|
168
|
+
</div>
|
|
169
|
+
)}
|
|
170
|
+
</div>
|
|
171
|
+
);
|
|
172
|
+
}
|
|
@@ -0,0 +1,233 @@
|
|
|
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 {Switch} from '@headlessui/react';
|
|
15
|
+
import {RpcError} from '@protobuf-ts/runtime-rpc';
|
|
16
|
+
import Select, {type SelectInstance} from 'react-select';
|
|
17
|
+
|
|
18
|
+
import {ProfileTypesResponse, QueryServiceClient} from '@parca/client';
|
|
19
|
+
import {Button, ButtonGroup, DateTimeRange, DateTimeRangePicker} from '@parca/components';
|
|
20
|
+
import {ProfileType, Query} from '@parca/parser';
|
|
21
|
+
|
|
22
|
+
import MatchersInput from '../MatchersInput';
|
|
23
|
+
import ProfileTypeSelector from '../ProfileTypeSelector';
|
|
24
|
+
import SimpleMatchers from '../SimpleMatchers';
|
|
25
|
+
import ViewMatchers from '../ViewMatchers';
|
|
26
|
+
|
|
27
|
+
interface SelectOption {
|
|
28
|
+
label: string;
|
|
29
|
+
value: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface QueryControlsProps {
|
|
33
|
+
showProfileTypeSelector: boolean;
|
|
34
|
+
showSumBySelector: boolean;
|
|
35
|
+
disableExplorativeQuerying: boolean;
|
|
36
|
+
profileTypesData?: ProfileTypesResponse;
|
|
37
|
+
profileTypesLoading: boolean;
|
|
38
|
+
selectedProfileName: string;
|
|
39
|
+
setProfileName: (name: string | undefined) => void;
|
|
40
|
+
profileTypesError?: RpcError;
|
|
41
|
+
viewComponent?: {
|
|
42
|
+
disableProfileTypesDropdown?: boolean;
|
|
43
|
+
disableExplorativeQuerying?: boolean;
|
|
44
|
+
labelnames?: string[];
|
|
45
|
+
createViewComponent?: React.ReactNode;
|
|
46
|
+
};
|
|
47
|
+
queryBrowserMode: string;
|
|
48
|
+
setQueryBrowserMode: (mode: string) => void;
|
|
49
|
+
advancedModeForQueryBrowser: boolean;
|
|
50
|
+
setAdvancedModeForQueryBrowser: (mode: boolean) => void;
|
|
51
|
+
setMatchersString: (matchers: string) => void;
|
|
52
|
+
setQueryExpression: (updateTs?: boolean) => void;
|
|
53
|
+
query: Query;
|
|
54
|
+
queryBrowserRef: React.RefObject<HTMLDivElement>;
|
|
55
|
+
timeRangeSelection: DateTimeRange;
|
|
56
|
+
setTimeRangeSelection: (range: DateTimeRange) => void;
|
|
57
|
+
searchDisabled: boolean;
|
|
58
|
+
queryClient: QueryServiceClient;
|
|
59
|
+
labels: string[];
|
|
60
|
+
sumBySelection: string[];
|
|
61
|
+
setUserSumBySelection: (sumBy: string[]) => void;
|
|
62
|
+
sumByRef: React.RefObject<SelectInstance>;
|
|
63
|
+
profileType: ProfileType;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function QueryControls({
|
|
67
|
+
showProfileTypeSelector,
|
|
68
|
+
profileTypesData,
|
|
69
|
+
profileTypesLoading,
|
|
70
|
+
selectedProfileName,
|
|
71
|
+
setProfileName,
|
|
72
|
+
viewComponent,
|
|
73
|
+
setQueryBrowserMode,
|
|
74
|
+
advancedModeForQueryBrowser,
|
|
75
|
+
setAdvancedModeForQueryBrowser,
|
|
76
|
+
setMatchersString,
|
|
77
|
+
setQueryExpression,
|
|
78
|
+
query,
|
|
79
|
+
queryBrowserRef,
|
|
80
|
+
timeRangeSelection,
|
|
81
|
+
setTimeRangeSelection,
|
|
82
|
+
searchDisabled,
|
|
83
|
+
queryClient,
|
|
84
|
+
labels,
|
|
85
|
+
sumBySelection,
|
|
86
|
+
setUserSumBySelection,
|
|
87
|
+
sumByRef,
|
|
88
|
+
profileType,
|
|
89
|
+
showSumBySelector,
|
|
90
|
+
profileTypesError,
|
|
91
|
+
}: QueryControlsProps): JSX.Element {
|
|
92
|
+
return (
|
|
93
|
+
<div className="flex w-full flex-wrap items-end gap-2">
|
|
94
|
+
{showProfileTypeSelector && (
|
|
95
|
+
<div>
|
|
96
|
+
<label className="text-xs">Profile type</label>
|
|
97
|
+
<ProfileTypeSelector
|
|
98
|
+
profileTypesData={profileTypesData}
|
|
99
|
+
loading={profileTypesLoading}
|
|
100
|
+
selectedKey={selectedProfileName}
|
|
101
|
+
onSelection={setProfileName}
|
|
102
|
+
error={profileTypesError}
|
|
103
|
+
disabled={viewComponent?.disableProfileTypesDropdown}
|
|
104
|
+
/>
|
|
105
|
+
</div>
|
|
106
|
+
)}
|
|
107
|
+
|
|
108
|
+
<div className="w-full flex-1 flex flex-col gap-1" ref={queryBrowserRef}>
|
|
109
|
+
<div className="flex items-center justify-between">
|
|
110
|
+
<div className="flex items-center gap-3">
|
|
111
|
+
<label className="text-xs">Query</label>
|
|
112
|
+
{viewComponent?.disableExplorativeQuerying !== true && (
|
|
113
|
+
<>
|
|
114
|
+
<Switch
|
|
115
|
+
checked={advancedModeForQueryBrowser}
|
|
116
|
+
onChange={() => {
|
|
117
|
+
setAdvancedModeForQueryBrowser(!advancedModeForQueryBrowser);
|
|
118
|
+
setQueryBrowserMode(advancedModeForQueryBrowser ? 'simple' : 'advanced');
|
|
119
|
+
}}
|
|
120
|
+
className={`${
|
|
121
|
+
advancedModeForQueryBrowser ? 'bg-indigo-600' : 'bg-gray-400 dark:bg-gray-800'
|
|
122
|
+
} relative inline-flex h-[20px] w-[44px] shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none focus-visible:ring-2 focus-visible:ring-white/75`}
|
|
123
|
+
>
|
|
124
|
+
<span className="sr-only">Use setting</span>
|
|
125
|
+
<span
|
|
126
|
+
aria-hidden="true"
|
|
127
|
+
className={`${
|
|
128
|
+
advancedModeForQueryBrowser ? 'translate-x-6' : 'translate-x-0'
|
|
129
|
+
} pointer-events-none inline-block h-[16px] w-[16px] transform rounded-full bg-white shadow-lg ring-0 transition duration-200 ease-in-out`}
|
|
130
|
+
/>
|
|
131
|
+
</Switch>
|
|
132
|
+
<label className="text-xs">Advanced Mode</label>
|
|
133
|
+
</>
|
|
134
|
+
)}
|
|
135
|
+
</div>
|
|
136
|
+
</div>
|
|
137
|
+
|
|
138
|
+
{viewComponent?.disableExplorativeQuerying === true &&
|
|
139
|
+
viewComponent?.labelnames !== undefined &&
|
|
140
|
+
viewComponent?.labelnames.length >= 1 ? (
|
|
141
|
+
<ViewMatchers
|
|
142
|
+
labelNames={viewComponent.labelnames}
|
|
143
|
+
setMatchersString={setMatchersString}
|
|
144
|
+
profileType={selectedProfileName}
|
|
145
|
+
runQuery={setQueryExpression}
|
|
146
|
+
currentQuery={query}
|
|
147
|
+
queryClient={queryClient}
|
|
148
|
+
/>
|
|
149
|
+
) : advancedModeForQueryBrowser ? (
|
|
150
|
+
<MatchersInput
|
|
151
|
+
setMatchersString={setMatchersString}
|
|
152
|
+
runQuery={setQueryExpression}
|
|
153
|
+
currentQuery={query}
|
|
154
|
+
profileType={selectedProfileName}
|
|
155
|
+
queryClient={queryClient}
|
|
156
|
+
/>
|
|
157
|
+
) : (
|
|
158
|
+
<SimpleMatchers
|
|
159
|
+
setMatchersString={setMatchersString}
|
|
160
|
+
runQuery={setQueryExpression}
|
|
161
|
+
currentQuery={query}
|
|
162
|
+
profileType={selectedProfileName}
|
|
163
|
+
queryBrowserRef={queryBrowserRef}
|
|
164
|
+
queryClient={queryClient}
|
|
165
|
+
/>
|
|
166
|
+
)}
|
|
167
|
+
</div>
|
|
168
|
+
|
|
169
|
+
{showSumBySelector && (
|
|
170
|
+
<div>
|
|
171
|
+
<div className="mb-0.5 mt-1.5 flex items-center justify-between">
|
|
172
|
+
<label className="text-xs">Sum by</label>
|
|
173
|
+
</div>
|
|
174
|
+
<Select<SelectOption, true>
|
|
175
|
+
id="h-sum-by-selector"
|
|
176
|
+
defaultValue={[]}
|
|
177
|
+
isMulti
|
|
178
|
+
name="colors"
|
|
179
|
+
options={labels.map(label => ({label, value: label}))}
|
|
180
|
+
className="parca-select-container text-sm w-full max-w-80"
|
|
181
|
+
classNamePrefix="parca-select"
|
|
182
|
+
value={(sumBySelection ?? []).map(sumBy => ({label: sumBy, value: sumBy}))}
|
|
183
|
+
onChange={newValue => {
|
|
184
|
+
setUserSumBySelection(newValue.map(option => option.value));
|
|
185
|
+
}}
|
|
186
|
+
placeholder="Labels..."
|
|
187
|
+
styles={{
|
|
188
|
+
indicatorSeparator: () => ({display: 'none'}),
|
|
189
|
+
menu: provided => ({...provided, width: 'max-content'}),
|
|
190
|
+
}}
|
|
191
|
+
isDisabled={!profileType.delta}
|
|
192
|
+
// @ts-expect-error
|
|
193
|
+
ref={sumByRef}
|
|
194
|
+
onKeyDown={e => {
|
|
195
|
+
const currentRef = sumByRef.current as unknown as SelectInstance | null;
|
|
196
|
+
if (currentRef == null) {
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
const inputRef = currentRef.inputRef;
|
|
200
|
+
if (inputRef == null) {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (
|
|
205
|
+
e.key === 'Enter' &&
|
|
206
|
+
inputRef.value === '' &&
|
|
207
|
+
currentRef.state.focusedOptionId === null // menu is not open
|
|
208
|
+
) {
|
|
209
|
+
setQueryExpression(true);
|
|
210
|
+
currentRef.blur();
|
|
211
|
+
}
|
|
212
|
+
}}
|
|
213
|
+
/>
|
|
214
|
+
</div>
|
|
215
|
+
)}
|
|
216
|
+
|
|
217
|
+
<DateTimeRangePicker onRangeSelection={setTimeRangeSelection} range={timeRangeSelection} />
|
|
218
|
+
|
|
219
|
+
<ButtonGroup>
|
|
220
|
+
<Button
|
|
221
|
+
disabled={searchDisabled}
|
|
222
|
+
onClick={(e: React.MouseEvent<HTMLElement>) => {
|
|
223
|
+
e.preventDefault();
|
|
224
|
+
setQueryExpression(true);
|
|
225
|
+
}}
|
|
226
|
+
id="h-matcher-search-button"
|
|
227
|
+
>
|
|
228
|
+
Search
|
|
229
|
+
</Button>
|
|
230
|
+
</ButtonGroup>
|
|
231
|
+
</div>
|
|
232
|
+
);
|
|
233
|
+
}
|