@perses-dev/prometheus-plugin 0.40.1 → 0.41.1
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/dist/cjs/plugins/{PrometheusDatasourceEditor/PrometheusDatasourceEditor.js → PrometheusDatasourceEditor.js} +203 -133
- package/dist/cjs/plugins/prometheus-datasource.js +2 -1
- package/dist/cjs/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js +2 -2
- package/dist/cjs/plugins/prometheus-time-series-query/get-time-series-data.js +2 -2
- package/dist/cjs/plugins/types.js +7 -0
- package/dist/plugins/PrometheusDatasourceEditor.d.ts.map +1 -0
- package/dist/plugins/{PrometheusDatasourceEditor/PrometheusDatasourceEditor.js → PrometheusDatasourceEditor.js} +204 -134
- package/dist/plugins/PrometheusDatasourceEditor.js.map +1 -0
- package/dist/plugins/prometheus-datasource.d.ts +2 -8
- package/dist/plugins/prometheus-datasource.d.ts.map +1 -1
- package/dist/plugins/prometheus-datasource.js +2 -1
- package/dist/plugins/prometheus-datasource.js.map +1 -1
- package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.d.ts.map +1 -1
- package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js +1 -1
- package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js.map +1 -1
- package/dist/plugins/prometheus-time-series-query/get-time-series-data.js +1 -1
- package/dist/plugins/prometheus-time-series-query/get-time-series-data.js.map +1 -1
- package/dist/plugins/types.d.ts +21 -0
- package/dist/plugins/types.d.ts.map +1 -1
- package/dist/plugins/types.js +1 -1
- package/dist/plugins/types.js.map +1 -1
- package/package.json +4 -4
- package/dist/cjs/plugins/PrometheusDatasourceEditor/index.js +0 -31
- package/dist/cjs/plugins/PrometheusDatasourceEditor/types.js +0 -23
- package/dist/plugins/PrometheusDatasourceEditor/PrometheusDatasourceEditor.d.ts.map +0 -1
- package/dist/plugins/PrometheusDatasourceEditor/PrometheusDatasourceEditor.js.map +0 -1
- package/dist/plugins/PrometheusDatasourceEditor/index.d.ts +0 -3
- package/dist/plugins/PrometheusDatasourceEditor/index.d.ts.map +0 -1
- package/dist/plugins/PrometheusDatasourceEditor/index.js +0 -16
- package/dist/plugins/PrometheusDatasourceEditor/index.js.map +0 -1
- package/dist/plugins/PrometheusDatasourceEditor/types.d.ts +0 -22
- package/dist/plugins/PrometheusDatasourceEditor/types.d.ts.map +0 -1
- package/dist/plugins/PrometheusDatasourceEditor/types.js +0 -15
- package/dist/plugins/PrometheusDatasourceEditor/types.js.map +0 -1
- /package/dist/plugins/{PrometheusDatasourceEditor/PrometheusDatasourceEditor.d.ts → PrometheusDatasourceEditor.d.ts} +0 -0
|
@@ -12,20 +12,19 @@
|
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
14
14
|
import { OptionsEditorRadios } from '@perses-dev/plugin-system';
|
|
15
|
-
import { Grid, IconButton, TextField, Typography } from '@mui/material';
|
|
15
|
+
import { Grid, IconButton, MenuItem, TextField, Typography } from '@mui/material';
|
|
16
16
|
import React, { Fragment, useState } from 'react';
|
|
17
|
+
import { produce } from 'immer';
|
|
17
18
|
import MinusIcon from 'mdi-material-ui/Minus';
|
|
18
19
|
import PlusIcon from 'mdi-material-ui/Plus';
|
|
19
20
|
import { DEFAULT_SCRAPE_INTERVAL } from './types';
|
|
20
21
|
export function PrometheusDatasourceEditor(props) {
|
|
21
|
-
var _value_proxy, _value_proxy1, _value_proxy2, _value_proxy3;
|
|
22
|
+
var _value_proxy, _value_proxy1, _value_proxy2, _value_proxy3, _value_proxy4;
|
|
22
23
|
const { value , onChange , isReadonly } = props;
|
|
23
24
|
const strDirect = 'Direct access';
|
|
24
25
|
const strProxy = 'Proxy';
|
|
25
|
-
// TODO refactor with useImmer to avoid doing so much destructuring? feasibility & performances to be checked
|
|
26
26
|
// utilitary function used for headers when renaming a property
|
|
27
|
-
// -> TODO it would be cleaner to manipulate headers as
|
|
28
|
-
// This could be a pure frontend trick, but change in the backend datamodel should also be considered
|
|
27
|
+
// -> TODO it would be cleaner to manipulate headers as an intermediary list instead, to avoid doing this.
|
|
29
28
|
const buildNewHeaders = (oldHeaders, oldName, newName)=>{
|
|
30
29
|
if (oldHeaders === undefined) return oldHeaders;
|
|
31
30
|
const keys = Object.keys(oldHeaders);
|
|
@@ -55,10 +54,11 @@ export function PrometheusDatasourceEditor(props) {
|
|
|
55
54
|
InputLabelProps: {
|
|
56
55
|
shrink: isReadonly ? true : undefined
|
|
57
56
|
},
|
|
58
|
-
onChange: (e)=>
|
|
59
|
-
|
|
60
|
-
directUrl
|
|
61
|
-
})
|
|
57
|
+
onChange: (e)=>{
|
|
58
|
+
onChange(produce(value, (draft)=>{
|
|
59
|
+
draft.directUrl = e.target.value;
|
|
60
|
+
}));
|
|
61
|
+
}
|
|
62
62
|
})
|
|
63
63
|
})
|
|
64
64
|
},
|
|
@@ -76,80 +76,180 @@ export function PrometheusDatasourceEditor(props) {
|
|
|
76
76
|
InputLabelProps: {
|
|
77
77
|
shrink: isReadonly ? true : undefined
|
|
78
78
|
},
|
|
79
|
-
onChange: (e)=>
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
proxy
|
|
83
|
-
...value.proxy,
|
|
84
|
-
spec: {
|
|
85
|
-
...value.proxy.spec,
|
|
86
|
-
url: e.target.value
|
|
87
|
-
}
|
|
88
|
-
}
|
|
79
|
+
onChange: (e)=>{
|
|
80
|
+
onChange(produce(value, (draft)=>{
|
|
81
|
+
if (draft.proxy !== undefined) {
|
|
82
|
+
draft.proxy.spec.url = e.target.value;
|
|
89
83
|
}
|
|
90
|
-
})
|
|
84
|
+
}));
|
|
85
|
+
},
|
|
86
|
+
sx: {
|
|
87
|
+
mb: 2
|
|
88
|
+
}
|
|
91
89
|
}),
|
|
92
90
|
/*#__PURE__*/ _jsx(Typography, {
|
|
93
91
|
variant: "h4",
|
|
94
|
-
|
|
95
|
-
mb: 1,
|
|
92
|
+
mb: 2,
|
|
96
93
|
children: "Allowed endpoints"
|
|
97
94
|
}),
|
|
98
|
-
/*#__PURE__*/
|
|
95
|
+
/*#__PURE__*/ _jsxs(Grid, {
|
|
99
96
|
container: true,
|
|
100
97
|
spacing: 2,
|
|
101
98
|
mb: 2,
|
|
102
|
-
children:
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
99
|
+
children: [
|
|
100
|
+
((_value_proxy1 = value.proxy) === null || _value_proxy1 === void 0 ? void 0 : _value_proxy1.spec.allowedEndpoints) && ((_value_proxy2 = value.proxy) === null || _value_proxy2 === void 0 ? void 0 : _value_proxy2.spec.allowedEndpoints.length) != 0 ? value.proxy.spec.allowedEndpoints.map(({ endpointPattern , method }, i)=>{
|
|
101
|
+
return /*#__PURE__*/ _jsxs(Fragment, {
|
|
102
|
+
children: [
|
|
103
|
+
/*#__PURE__*/ _jsx(Grid, {
|
|
104
|
+
item: true,
|
|
105
|
+
xs: 8,
|
|
106
|
+
children: /*#__PURE__*/ _jsx(TextField, {
|
|
107
|
+
fullWidth: true,
|
|
108
|
+
label: "Endpoint pattern",
|
|
109
|
+
value: endpointPattern,
|
|
110
|
+
InputProps: {
|
|
111
|
+
readOnly: isReadonly
|
|
112
|
+
},
|
|
113
|
+
InputLabelProps: {
|
|
114
|
+
shrink: isReadonly ? true : undefined
|
|
115
|
+
},
|
|
116
|
+
onChange: (e)=>{
|
|
117
|
+
onChange(produce(value, (draft)=>{
|
|
118
|
+
if (draft.proxy !== undefined) {
|
|
119
|
+
var _draft_proxy_spec_allowedEndpoints;
|
|
120
|
+
draft.proxy.spec.allowedEndpoints = (_draft_proxy_spec_allowedEndpoints = draft.proxy.spec.allowedEndpoints) === null || _draft_proxy_spec_allowedEndpoints === void 0 ? void 0 : _draft_proxy_spec_allowedEndpoints.map((item, itemIndex)=>{
|
|
121
|
+
if (i === itemIndex) {
|
|
122
|
+
return {
|
|
123
|
+
endpointPattern: e.target.value,
|
|
124
|
+
method: item.method
|
|
125
|
+
};
|
|
126
|
+
} else {
|
|
127
|
+
return item;
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}));
|
|
132
|
+
}
|
|
133
|
+
})
|
|
134
|
+
}),
|
|
135
|
+
/*#__PURE__*/ _jsx(Grid, {
|
|
136
|
+
item: true,
|
|
137
|
+
xs: 3,
|
|
138
|
+
children: /*#__PURE__*/ _jsxs(TextField, {
|
|
139
|
+
select: true,
|
|
140
|
+
fullWidth: true,
|
|
141
|
+
label: "Method",
|
|
142
|
+
value: method,
|
|
143
|
+
InputProps: {
|
|
144
|
+
readOnly: isReadonly
|
|
145
|
+
},
|
|
146
|
+
InputLabelProps: {
|
|
147
|
+
shrink: isReadonly ? true : undefined
|
|
148
|
+
},
|
|
149
|
+
onChange: (e)=>{
|
|
150
|
+
onChange(produce(value, (draft)=>{
|
|
151
|
+
if (draft.proxy !== undefined) {
|
|
152
|
+
var _draft_proxy_spec_allowedEndpoints;
|
|
153
|
+
draft.proxy.spec.allowedEndpoints = (_draft_proxy_spec_allowedEndpoints = draft.proxy.spec.allowedEndpoints) === null || _draft_proxy_spec_allowedEndpoints === void 0 ? void 0 : _draft_proxy_spec_allowedEndpoints.map((item, itemIndex)=>{
|
|
154
|
+
if (i === itemIndex) {
|
|
155
|
+
return {
|
|
156
|
+
endpointPattern: item.endpointPattern,
|
|
157
|
+
method: e.target.value
|
|
158
|
+
};
|
|
159
|
+
} else {
|
|
160
|
+
return item;
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
}));
|
|
165
|
+
},
|
|
166
|
+
children: [
|
|
167
|
+
/*#__PURE__*/ _jsx(MenuItem, {
|
|
168
|
+
value: "GET",
|
|
169
|
+
children: "GET"
|
|
170
|
+
}),
|
|
171
|
+
/*#__PURE__*/ _jsx(MenuItem, {
|
|
172
|
+
value: "POST",
|
|
173
|
+
children: "POST"
|
|
174
|
+
}),
|
|
175
|
+
/*#__PURE__*/ _jsx(MenuItem, {
|
|
176
|
+
value: "PUT",
|
|
177
|
+
children: "PUT"
|
|
178
|
+
}),
|
|
179
|
+
/*#__PURE__*/ _jsx(MenuItem, {
|
|
180
|
+
value: "PATCH",
|
|
181
|
+
children: "PATCH"
|
|
182
|
+
}),
|
|
183
|
+
/*#__PURE__*/ _jsx(MenuItem, {
|
|
184
|
+
value: "DELETE",
|
|
185
|
+
children: "DELETE"
|
|
186
|
+
})
|
|
187
|
+
]
|
|
188
|
+
})
|
|
189
|
+
}),
|
|
190
|
+
/*#__PURE__*/ _jsx(Grid, {
|
|
191
|
+
item: true,
|
|
192
|
+
xs: 1,
|
|
193
|
+
children: /*#__PURE__*/ _jsx(IconButton, {
|
|
194
|
+
disabled: isReadonly,
|
|
195
|
+
// Remove the given allowed endpoint from the list
|
|
196
|
+
onClick: ()=>{
|
|
197
|
+
onChange(produce(value, (draft)=>{
|
|
198
|
+
if (draft.proxy !== undefined) {
|
|
199
|
+
var _draft_proxy_spec_allowedEndpoints;
|
|
200
|
+
draft.proxy.spec.allowedEndpoints = [
|
|
201
|
+
...((_draft_proxy_spec_allowedEndpoints = draft.proxy.spec.allowedEndpoints) === null || _draft_proxy_spec_allowedEndpoints === void 0 ? void 0 : _draft_proxy_spec_allowedEndpoints.filter((item, itemIndex)=>{
|
|
202
|
+
return itemIndex !== i;
|
|
203
|
+
})) || []
|
|
204
|
+
];
|
|
205
|
+
}
|
|
206
|
+
}));
|
|
207
|
+
},
|
|
208
|
+
children: /*#__PURE__*/ _jsx(MinusIcon, {})
|
|
209
|
+
})
|
|
135
210
|
})
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
},
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
211
|
+
]
|
|
212
|
+
}, i);
|
|
213
|
+
}) : /*#__PURE__*/ _jsx(Grid, {
|
|
214
|
+
item: true,
|
|
215
|
+
xs: 4,
|
|
216
|
+
children: /*#__PURE__*/ _jsx(Typography, {
|
|
217
|
+
sx: {
|
|
218
|
+
fontStyle: 'italic'
|
|
219
|
+
},
|
|
144
220
|
children: "None"
|
|
145
|
-
})
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
221
|
+
})
|
|
222
|
+
}),
|
|
223
|
+
/*#__PURE__*/ _jsx(Grid, {
|
|
224
|
+
item: true,
|
|
225
|
+
xs: 12,
|
|
226
|
+
sx: {
|
|
227
|
+
paddingTop: '0px !important',
|
|
228
|
+
paddingLeft: '5px !important'
|
|
229
|
+
},
|
|
230
|
+
children: /*#__PURE__*/ _jsx(IconButton, {
|
|
231
|
+
disabled: isReadonly,
|
|
232
|
+
// Add a new (empty) allowed endpoint to the list
|
|
233
|
+
onClick: ()=>onChange(produce(value, (draft)=>{
|
|
234
|
+
if (draft.proxy !== undefined) {
|
|
235
|
+
var _draft_proxy_spec_allowedEndpoints;
|
|
236
|
+
draft.proxy.spec.allowedEndpoints = [
|
|
237
|
+
...(_draft_proxy_spec_allowedEndpoints = draft.proxy.spec.allowedEndpoints) !== null && _draft_proxy_spec_allowedEndpoints !== void 0 ? _draft_proxy_spec_allowedEndpoints : [],
|
|
238
|
+
{
|
|
239
|
+
endpointPattern: '',
|
|
240
|
+
method: ''
|
|
241
|
+
}
|
|
242
|
+
];
|
|
243
|
+
}
|
|
244
|
+
})),
|
|
245
|
+
children: /*#__PURE__*/ _jsx(PlusIcon, {})
|
|
246
|
+
})
|
|
247
|
+
})
|
|
248
|
+
]
|
|
149
249
|
}),
|
|
150
250
|
/*#__PURE__*/ _jsx(Typography, {
|
|
151
251
|
variant: "h4",
|
|
152
|
-
mb:
|
|
252
|
+
mb: 2,
|
|
153
253
|
children: "Request Headers"
|
|
154
254
|
}),
|
|
155
255
|
/*#__PURE__*/ _jsxs(Grid, {
|
|
@@ -157,7 +257,7 @@ export function PrometheusDatasourceEditor(props) {
|
|
|
157
257
|
spacing: 2,
|
|
158
258
|
mb: 2,
|
|
159
259
|
children: [
|
|
160
|
-
((
|
|
260
|
+
((_value_proxy3 = value.proxy) === null || _value_proxy3 === void 0 ? void 0 : _value_proxy3.spec.headers) && Object.keys(value.proxy.spec.headers).map((headerName, i)=>{
|
|
161
261
|
var _value_proxy_spec_headers, _value_proxy;
|
|
162
262
|
return /*#__PURE__*/ _jsxs(Fragment, {
|
|
163
263
|
children: [
|
|
@@ -174,18 +274,11 @@ export function PrometheusDatasourceEditor(props) {
|
|
|
174
274
|
InputLabelProps: {
|
|
175
275
|
shrink: isReadonly ? true : undefined
|
|
176
276
|
},
|
|
177
|
-
onChange: (e)=>onChange({
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
proxy: {
|
|
181
|
-
...value.proxy,
|
|
182
|
-
spec: {
|
|
183
|
-
...value.proxy.spec,
|
|
184
|
-
headers: buildNewHeaders(value.proxy.spec.headers, headerName, e.target.value)
|
|
185
|
-
}
|
|
186
|
-
}
|
|
277
|
+
onChange: (e)=>onChange(produce(value, (draft)=>{
|
|
278
|
+
if (draft.proxy !== undefined) {
|
|
279
|
+
draft.proxy.spec.headers = buildNewHeaders(draft.proxy.spec.headers, headerName, e.target.value);
|
|
187
280
|
}
|
|
188
|
-
})
|
|
281
|
+
}))
|
|
189
282
|
})
|
|
190
283
|
}),
|
|
191
284
|
/*#__PURE__*/ _jsx(Grid, {
|
|
@@ -201,21 +294,14 @@ export function PrometheusDatasourceEditor(props) {
|
|
|
201
294
|
InputLabelProps: {
|
|
202
295
|
shrink: isReadonly ? true : undefined
|
|
203
296
|
},
|
|
204
|
-
onChange: (e)=>onChange({
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
...value.proxy.spec,
|
|
211
|
-
headers: {
|
|
212
|
-
...value.proxy.spec.headers,
|
|
213
|
-
[headerName]: e.target.value
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
}
|
|
297
|
+
onChange: (e)=>onChange(produce(value, (draft)=>{
|
|
298
|
+
if (draft.proxy !== undefined) {
|
|
299
|
+
draft.proxy.spec.headers = {
|
|
300
|
+
...draft.proxy.spec.headers,
|
|
301
|
+
[headerName]: e.target.value
|
|
302
|
+
};
|
|
217
303
|
}
|
|
218
|
-
})
|
|
304
|
+
}))
|
|
219
305
|
})
|
|
220
306
|
}),
|
|
221
307
|
/*#__PURE__*/ _jsx(Grid, {
|
|
@@ -223,24 +309,18 @@ export function PrometheusDatasourceEditor(props) {
|
|
|
223
309
|
xs: 1,
|
|
224
310
|
children: /*#__PURE__*/ _jsx(IconButton, {
|
|
225
311
|
disabled: isReadonly,
|
|
312
|
+
// Remove the given header from the list
|
|
226
313
|
onClick: ()=>{
|
|
227
314
|
var _value_proxy;
|
|
228
315
|
const newHeaders = {
|
|
229
316
|
...(_value_proxy = value.proxy) === null || _value_proxy === void 0 ? void 0 : _value_proxy.spec.headers
|
|
230
317
|
};
|
|
231
318
|
delete newHeaders[headerName];
|
|
232
|
-
onChange({
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
proxy: {
|
|
236
|
-
...value.proxy,
|
|
237
|
-
spec: {
|
|
238
|
-
...value.proxy.spec,
|
|
239
|
-
headers: newHeaders
|
|
240
|
-
}
|
|
241
|
-
}
|
|
319
|
+
onChange(produce(value, (draft)=>{
|
|
320
|
+
if (draft.proxy !== undefined) {
|
|
321
|
+
draft.proxy.spec.headers = newHeaders;
|
|
242
322
|
}
|
|
243
|
-
});
|
|
323
|
+
}));
|
|
244
324
|
},
|
|
245
325
|
children: /*#__PURE__*/ _jsx(MinusIcon, {})
|
|
246
326
|
})
|
|
@@ -252,25 +332,20 @@ export function PrometheusDatasourceEditor(props) {
|
|
|
252
332
|
item: true,
|
|
253
333
|
xs: 12,
|
|
254
334
|
sx: {
|
|
255
|
-
paddingTop: '
|
|
335
|
+
paddingTop: '0px !important',
|
|
336
|
+
paddingLeft: '5px !important'
|
|
256
337
|
},
|
|
257
338
|
children: /*#__PURE__*/ _jsx(IconButton, {
|
|
258
339
|
disabled: isReadonly,
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
proxy
|
|
263
|
-
...
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
headers: {
|
|
267
|
-
...value.proxy.spec.headers,
|
|
268
|
-
'': ''
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
}
|
|
340
|
+
// Add a new (empty) header to the list
|
|
341
|
+
onClick: ()=>onChange(produce(value, (draft)=>{
|
|
342
|
+
if (draft.proxy !== undefined) {
|
|
343
|
+
draft.proxy.spec.headers = {
|
|
344
|
+
...draft.proxy.spec.headers,
|
|
345
|
+
'': ''
|
|
346
|
+
};
|
|
272
347
|
}
|
|
273
|
-
}),
|
|
348
|
+
})),
|
|
274
349
|
children: /*#__PURE__*/ _jsx(PlusIcon, {})
|
|
275
350
|
})
|
|
276
351
|
})
|
|
@@ -279,25 +354,20 @@ export function PrometheusDatasourceEditor(props) {
|
|
|
279
354
|
/*#__PURE__*/ _jsx(TextField, {
|
|
280
355
|
fullWidth: true,
|
|
281
356
|
label: "Secret",
|
|
282
|
-
value: ((
|
|
357
|
+
value: ((_value_proxy4 = value.proxy) === null || _value_proxy4 === void 0 ? void 0 : _value_proxy4.spec.secret) || '',
|
|
283
358
|
InputProps: {
|
|
284
359
|
readOnly: isReadonly
|
|
285
360
|
},
|
|
286
361
|
InputLabelProps: {
|
|
287
362
|
shrink: isReadonly ? true : undefined
|
|
288
363
|
},
|
|
289
|
-
onChange: (e)=>
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
proxy
|
|
293
|
-
...value.proxy,
|
|
294
|
-
spec: {
|
|
295
|
-
...value.proxy.spec,
|
|
296
|
-
secret: e.target.value
|
|
297
|
-
}
|
|
298
|
-
}
|
|
364
|
+
onChange: (e)=>{
|
|
365
|
+
onChange(produce(value, (draft)=>{
|
|
366
|
+
if (draft.proxy !== undefined) {
|
|
367
|
+
draft.proxy.spec.secret = e.target.value;
|
|
299
368
|
}
|
|
300
|
-
})
|
|
369
|
+
}));
|
|
370
|
+
}
|
|
301
371
|
})
|
|
302
372
|
]
|
|
303
373
|
})
|
|
@@ -318,7 +388,7 @@ export function PrometheusDatasourceEditor(props) {
|
|
|
318
388
|
kind: 'HTTPProxy',
|
|
319
389
|
spec: {
|
|
320
390
|
allowedEndpoints: [
|
|
321
|
-
//
|
|
391
|
+
// list of standard endpoints suggested by default
|
|
322
392
|
{
|
|
323
393
|
endpointPattern: '/api/v1/labels',
|
|
324
394
|
method: 'POST'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/plugins/PrometheusDatasourceEditor.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { DurationString, RequestHeaders } from '@perses-dev/core';\nimport { OptionsEditorRadios } from '@perses-dev/plugin-system';\nimport { Grid, IconButton, MenuItem, TextField, Typography } from '@mui/material';\nimport React, { Fragment, useState } from 'react';\nimport { produce } from 'immer';\nimport MinusIcon from 'mdi-material-ui/Minus';\nimport PlusIcon from 'mdi-material-ui/Plus';\nimport { DEFAULT_SCRAPE_INTERVAL, PrometheusDatasourceSpec } from './types';\n\nexport interface PrometheusDatasourceEditorProps {\n value: PrometheusDatasourceSpec;\n onChange: (next: PrometheusDatasourceSpec) => void;\n isReadonly?: boolean;\n}\n\nexport function PrometheusDatasourceEditor(props: PrometheusDatasourceEditorProps) {\n const { value, onChange, isReadonly } = props;\n const strDirect = 'Direct access';\n const strProxy = 'Proxy';\n\n // utilitary function used for headers when renaming a property\n // -> TODO it would be cleaner to manipulate headers as an intermediary list instead, to avoid doing this.\n const buildNewHeaders = (oldHeaders: RequestHeaders | undefined, oldName: string, newName: string) => {\n if (oldHeaders === undefined) return oldHeaders;\n const keys = Object.keys(oldHeaders);\n const newHeaders = keys.reduce<Record<string, string>>((acc, val) => {\n if (val === oldName) {\n acc[newName] = oldHeaders[oldName] || '';\n } else {\n acc[val] = oldHeaders[val] || '';\n }\n return acc;\n }, {});\n\n return { ...newHeaders };\n };\n\n const tabs = [\n {\n label: strDirect,\n content: (\n <>\n <TextField\n fullWidth\n label=\"URL\"\n value={value.directUrl || ''}\n InputProps={{\n readOnly: isReadonly,\n }}\n InputLabelProps={{ shrink: isReadonly ? true : undefined }}\n onChange={(e) => {\n onChange(\n produce(value, (draft) => {\n draft.directUrl = e.target.value;\n })\n );\n }}\n />\n </>\n ),\n },\n {\n label: strProxy,\n content: (\n <>\n <TextField\n fullWidth\n label=\"URL\"\n value={value.proxy?.spec.url || ''}\n InputProps={{\n readOnly: isReadonly,\n }}\n InputLabelProps={{ shrink: isReadonly ? true : undefined }}\n onChange={(e) => {\n onChange(\n produce(value, (draft) => {\n if (draft.proxy !== undefined) {\n draft.proxy.spec.url = e.target.value;\n }\n })\n );\n }}\n sx={{ mb: 2 }}\n />\n <Typography variant=\"h4\" mb={2}>\n Allowed endpoints\n </Typography>\n <Grid container spacing={2} mb={2}>\n {value.proxy?.spec.allowedEndpoints && value.proxy?.spec.allowedEndpoints.length != 0 ? (\n value.proxy.spec.allowedEndpoints.map(({ endpointPattern, method }, i) => {\n return (\n <Fragment key={i}>\n <Grid item xs={8}>\n <TextField\n fullWidth\n label=\"Endpoint pattern\"\n value={endpointPattern}\n InputProps={{\n readOnly: isReadonly,\n }}\n InputLabelProps={{ shrink: isReadonly ? true : undefined }}\n onChange={(e) => {\n onChange(\n produce(value, (draft) => {\n if (draft.proxy !== undefined) {\n draft.proxy.spec.allowedEndpoints = draft.proxy.spec.allowedEndpoints?.map(\n (item, itemIndex) => {\n if (i === itemIndex) {\n return {\n endpointPattern: e.target.value,\n method: item.method,\n };\n } else {\n return item;\n }\n }\n );\n }\n })\n );\n }}\n />\n </Grid>\n <Grid item xs={3}>\n <TextField\n select\n fullWidth\n label=\"Method\"\n value={method}\n InputProps={{\n readOnly: isReadonly,\n }}\n InputLabelProps={{ shrink: isReadonly ? true : undefined }}\n onChange={(e) => {\n onChange(\n produce(value, (draft) => {\n if (draft.proxy !== undefined) {\n draft.proxy.spec.allowedEndpoints = draft.proxy.spec.allowedEndpoints?.map(\n (item, itemIndex) => {\n if (i === itemIndex) {\n return {\n endpointPattern: item.endpointPattern,\n method: e.target.value,\n };\n } else {\n return item;\n }\n }\n );\n }\n })\n );\n }}\n >\n <MenuItem value=\"GET\">GET</MenuItem>\n <MenuItem value=\"POST\">POST</MenuItem>\n <MenuItem value=\"PUT\">PUT</MenuItem>\n <MenuItem value=\"PATCH\">PATCH</MenuItem>\n <MenuItem value=\"DELETE\">DELETE</MenuItem>\n </TextField>\n </Grid>\n <Grid item xs={1}>\n <IconButton\n disabled={isReadonly}\n // Remove the given allowed endpoint from the list\n onClick={() => {\n onChange(\n produce(value, (draft) => {\n if (draft.proxy !== undefined) {\n draft.proxy.spec.allowedEndpoints = [\n ...(draft.proxy.spec.allowedEndpoints?.filter((item, itemIndex) => {\n return itemIndex !== i;\n }) || []),\n ];\n }\n })\n );\n }}\n >\n <MinusIcon />\n </IconButton>\n </Grid>\n </Fragment>\n );\n })\n ) : (\n <Grid item xs={4}>\n <Typography sx={{ fontStyle: 'italic' }}>None</Typography>\n </Grid>\n )}\n <Grid item xs={12} sx={{ paddingTop: '0px !important', paddingLeft: '5px !important' }}>\n <IconButton\n disabled={isReadonly}\n // Add a new (empty) allowed endpoint to the list\n onClick={() =>\n onChange(\n produce(value, (draft) => {\n if (draft.proxy !== undefined) {\n draft.proxy.spec.allowedEndpoints = [\n ...(draft.proxy.spec.allowedEndpoints ?? []),\n { endpointPattern: '', method: '' },\n ];\n }\n })\n )\n }\n >\n <PlusIcon />\n </IconButton>\n </Grid>\n </Grid>\n <Typography variant=\"h4\" mb={2}>\n Request Headers\n </Typography>\n <Grid container spacing={2} mb={2}>\n {value.proxy?.spec.headers &&\n Object.keys(value.proxy.spec.headers).map((headerName, i) => {\n return (\n <Fragment key={i}>\n <Grid item xs={4}>\n <TextField\n fullWidth\n label=\"Header name\"\n value={headerName}\n InputProps={{\n readOnly: isReadonly,\n }}\n InputLabelProps={{ shrink: isReadonly ? true : undefined }}\n onChange={(e) =>\n onChange(\n produce(value, (draft) => {\n if (draft.proxy !== undefined) {\n draft.proxy.spec.headers = buildNewHeaders(\n draft.proxy.spec.headers,\n headerName,\n e.target.value\n );\n }\n })\n )\n }\n />\n </Grid>\n <Grid item xs={7}>\n <TextField\n fullWidth\n label=\"Header value\"\n value={value.proxy?.spec.headers?.[headerName]}\n InputProps={{\n readOnly: isReadonly,\n }}\n InputLabelProps={{ shrink: isReadonly ? true : undefined }}\n onChange={(e) =>\n onChange(\n produce(value, (draft) => {\n if (draft.proxy !== undefined) {\n draft.proxy.spec.headers = {\n ...draft.proxy.spec.headers,\n [headerName]: e.target.value,\n };\n }\n })\n )\n }\n />\n </Grid>\n <Grid item xs={1}>\n <IconButton\n disabled={isReadonly}\n // Remove the given header from the list\n onClick={() => {\n const newHeaders = { ...value.proxy?.spec.headers };\n delete newHeaders[headerName];\n onChange(\n produce(value, (draft) => {\n if (draft.proxy !== undefined) {\n draft.proxy.spec.headers = newHeaders;\n }\n })\n );\n }}\n >\n <MinusIcon />\n </IconButton>\n </Grid>\n </Fragment>\n );\n })}\n <Grid item xs={12} sx={{ paddingTop: '0px !important', paddingLeft: '5px !important' }}>\n <IconButton\n disabled={isReadonly}\n // Add a new (empty) header to the list\n onClick={() =>\n onChange(\n produce(value, (draft) => {\n if (draft.proxy !== undefined) {\n draft.proxy.spec.headers = { ...draft.proxy.spec.headers, '': '' };\n }\n })\n )\n }\n >\n <PlusIcon />\n </IconButton>\n </Grid>\n </Grid>\n <TextField\n fullWidth\n label=\"Secret\"\n value={value.proxy?.spec.secret || ''}\n InputProps={{\n readOnly: isReadonly,\n }}\n InputLabelProps={{ shrink: isReadonly ? true : undefined }}\n onChange={(e) => {\n onChange(\n produce(value, (draft) => {\n if (draft.proxy !== undefined) {\n draft.proxy.spec.secret = e.target.value;\n }\n })\n );\n }}\n />\n </>\n ),\n },\n ];\n\n // Use of findIndex instead of providing hardcoded values to avoid desynchronisatio or\n // bug in case the tabs get eventually swapped in the future.\n const directModeId = tabs.findIndex((tab) => tab.label == strDirect);\n const proxyModeId = tabs.findIndex((tab) => tab.label == strProxy);\n\n // In \"update datasource\" case, set defaultTab to the mode that this datasource is currently relying on.\n // Otherwise (create datasource), set defaultTab to Direct access.\n const defaultTab = value.proxy ? proxyModeId : directModeId;\n\n const initialSpecDirect: PrometheusDatasourceSpec = {\n directUrl: '',\n };\n\n const initialSpecProxy: PrometheusDatasourceSpec = {\n proxy: {\n kind: 'HTTPProxy',\n spec: {\n allowedEndpoints: [\n // list of standard endpoints suggested by default\n {\n endpointPattern: '/api/v1/labels',\n method: 'POST',\n },\n {\n endpointPattern: '/api/v1/series',\n method: 'POST',\n },\n {\n endpointPattern: '/api/v1/metadata',\n method: 'GET',\n },\n {\n endpointPattern: '/api/v1/query',\n method: 'POST',\n },\n {\n endpointPattern: '/api/v1/query_range',\n method: 'POST',\n },\n {\n endpointPattern: '/api/v1/label/([a-zA-Z0-9_-]+)/values',\n method: 'GET',\n },\n ],\n url: '',\n },\n },\n };\n\n // For better user experience, save previous states in mind for both mode.\n // This avoids losing everything when the user changes their mind back.\n const [previousSpecDirect, setPreviousSpecDirect] = useState(initialSpecDirect);\n const [previousSpecProxy, setPreviousSpecProxy] = useState(initialSpecProxy);\n\n // When changing mode, remove previous mode's config + append default values for the new mode.\n const handleModeChange = (v: number) => {\n if (tabs[v]?.label == strDirect) {\n setPreviousSpecProxy(value);\n onChange(previousSpecDirect);\n } else if (tabs[v]?.label == strProxy) {\n setPreviousSpecDirect(value);\n onChange(previousSpecProxy);\n }\n };\n\n return (\n <>\n <Typography variant=\"h4\" mb={2}>\n General Settings\n </Typography>\n <TextField\n fullWidth\n label=\"Scrape Interval\"\n value={value.scrapeInterval || ''}\n placeholder={`Default: ${DEFAULT_SCRAPE_INTERVAL}`}\n InputProps={{\n readOnly: isReadonly,\n }}\n InputLabelProps={{ shrink: isReadonly ? true : undefined }}\n onChange={(e) => onChange({ ...value, scrapeInterval: e.target.value as DurationString })}\n />\n <Typography variant=\"h4\" mt={2}>\n HTTP Settings\n </Typography>\n <OptionsEditorRadios\n isReadonly={isReadonly}\n tabs={tabs}\n defaultTab={defaultTab}\n onModeChange={handleModeChange}\n />\n </>\n );\n}\n"],"names":["OptionsEditorRadios","Grid","IconButton","MenuItem","TextField","Typography","React","Fragment","useState","produce","MinusIcon","PlusIcon","DEFAULT_SCRAPE_INTERVAL","PrometheusDatasourceEditor","props","value","onChange","isReadonly","strDirect","strProxy","buildNewHeaders","oldHeaders","oldName","newName","undefined","keys","Object","newHeaders","reduce","acc","val","tabs","label","content","fullWidth","directUrl","InputProps","readOnly","InputLabelProps","shrink","e","draft","target","proxy","spec","url","sx","mb","variant","container","spacing","allowedEndpoints","length","map","endpointPattern","method","i","item","xs","itemIndex","select","disabled","onClick","filter","fontStyle","paddingTop","paddingLeft","headers","headerName","secret","directModeId","findIndex","tab","proxyModeId","defaultTab","initialSpecDirect","initialSpecProxy","kind","previousSpecDirect","setPreviousSpecDirect","previousSpec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8B,SAAS;gBACTF,OAAM;gBACNjB,OAAOA,MAAMqE,kBAAkB;gBAC/BC,aAAa,CAAC,SAAS,EAAEzE,wBAAwB,CAAC;gBAClDwB,YAAY;oBACVC,UAAUpB;gBACZ;gBACAqB,iBAAiB;oBAAEC,QAAQtB,aAAa,OAAOO;gBAAU;gBACzDR,UAAU,CAACwB,IAAMxB,SAAS;wBAAE,GAAGD,KAAK;wBAAEqE,gBAAgB5C,EAAEE,OAAO3B;oBAAwB;;0BAEzF,KAACV;gBAAW2C,SAAQ;gBAAKsC,IAAI;0BAAG;;0BAGhC,KAACtF;gBACCiB,YAAYA;gBACZc,MAAMA;gBACN2C,YAAYA;gBACZa,cAAcL;;;;AAItB"}
|
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
import { DurationString, RequestHeaders } from '@perses-dev/core';
|
|
2
1
|
import { DatasourcePlugin } from '@perses-dev/plugin-system';
|
|
3
2
|
import { PrometheusClient } from '../model';
|
|
4
|
-
import { PrometheusDatasourceSpec
|
|
5
|
-
export
|
|
6
|
-
directUrl?: string;
|
|
7
|
-
headers?: RequestHeaders;
|
|
8
|
-
scrapeInterval?: DurationString;
|
|
9
|
-
}
|
|
10
|
-
export declare const PrometheusDatasource: DatasourcePlugin<PrometheusDatasourceSpecFull, PrometheusClient>;
|
|
3
|
+
import { PrometheusDatasourceSpec } from './types';
|
|
4
|
+
export declare const PrometheusDatasource: DatasourcePlugin<PrometheusDatasourceSpec, PrometheusClient>;
|
|
11
5
|
//# sourceMappingURL=prometheus-datasource.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prometheus-datasource.d.ts","sourceRoot":"","sources":["../../src/plugins/prometheus-datasource.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"prometheus-datasource.d.ts","sourceRoot":"","sources":["../../src/plugins/prometheus-datasource.tsx"],"names":[],"mappings":"AAcA,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAqD,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC/F,OAAO,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AA6EnD,eAAO,MAAM,oBAAoB,EAAE,gBAAgB,CAAC,wBAAwB,EAAE,gBAAgB,CAK7F,CAAC"}
|
|
@@ -15,13 +15,14 @@ import { PrometheusDatasourceEditor } from './PrometheusDatasourceEditor';
|
|
|
15
15
|
/**
|
|
16
16
|
* Creates a PrometheusClient for a specific datasource spec.
|
|
17
17
|
*/ const createClient = (spec, options)=>{
|
|
18
|
-
const { directUrl ,
|
|
18
|
+
const { directUrl , proxy } = spec;
|
|
19
19
|
const { proxyUrl } = options;
|
|
20
20
|
// Use the direct URL if specified, but fallback to the proxyUrl by default if not specified
|
|
21
21
|
const datasourceUrl = directUrl !== null && directUrl !== void 0 ? directUrl : proxyUrl;
|
|
22
22
|
if (datasourceUrl === undefined) {
|
|
23
23
|
throw new Error('No URL specified for Prometheus client. You can use directUrl in the spec to configure it.');
|
|
24
24
|
}
|
|
25
|
+
const specHeaders = proxy === null || proxy === void 0 ? void 0 : proxy.spec.headers;
|
|
25
26
|
// Could think about this becoming a class, although it definitely doesn't have to be
|
|
26
27
|
return {
|
|
27
28
|
options: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/plugins/prometheus-datasource.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { BuiltinVariableDefinition
|
|
1
|
+
{"version":3,"sources":["../../src/plugins/prometheus-datasource.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { BuiltinVariableDefinition } from '@perses-dev/core';\nimport { DatasourcePlugin } from '@perses-dev/plugin-system';\nimport { instantQuery, rangeQuery, labelNames, labelValues, PrometheusClient } from '../model';\nimport { PrometheusDatasourceSpec } from './types';\nimport { PrometheusDatasourceEditor } from './PrometheusDatasourceEditor';\n\n/**\n * Creates a PrometheusClient for a specific datasource spec.\n */\nconst createClient: DatasourcePlugin<PrometheusDatasourceSpec, PrometheusClient>['createClient'] = (spec, options) => {\n const { directUrl, proxy } = spec;\n const { proxyUrl } = options;\n\n // Use the direct URL if specified, but fallback to the proxyUrl by default if not specified\n const datasourceUrl = directUrl ?? proxyUrl;\n if (datasourceUrl === undefined) {\n throw new Error('No URL specified for Prometheus client. You can use directUrl in the spec to configure it.');\n }\n\n const specHeaders = proxy?.spec.headers;\n\n // Could think about this becoming a class, although it definitely doesn't have to be\n return {\n options: {\n datasourceUrl,\n },\n instantQuery: (params, headers) => instantQuery(params, { datasourceUrl, headers: headers ?? specHeaders }),\n rangeQuery: (params, headers) => rangeQuery(params, { datasourceUrl, headers: headers ?? specHeaders }),\n labelNames: (params, headers) => labelNames(params, { datasourceUrl, headers: headers ?? specHeaders }),\n labelValues: (params, headers) => labelValues(params, { datasourceUrl, headers: headers ?? specHeaders }),\n };\n};\n\nconst getBuiltinVariableDefinitions: () => BuiltinVariableDefinition[] = () => {\n return [\n {\n kind: 'BuiltinVariable',\n spec: {\n name: '__interval',\n value: () => '$__interval', // will be overriden when time series query is called\n source: 'Prometheus',\n display: {\n name: '__interval',\n description:\n 'Interval that can be used to group by time in queries. When there are more data points than can be shown on a graph then queries can be made more efficient by grouping by a larger interval.',\n hidden: true,\n },\n },\n },\n {\n kind: 'BuiltinVariable',\n spec: {\n name: '__interval_ms',\n value: () => '$__interval_ms', // will be overriden when time series query is called\n source: 'Prometheus',\n display: {\n name: '__interval_ms',\n description:\n 'Interval in millisecond that can be used to group by time in queries. When there are more data points than can be shown on a graph then queries can be made more efficient by grouping by a larger interval.',\n hidden: true,\n },\n },\n },\n {\n kind: 'BuiltinVariable',\n spec: {\n name: '__rate_interval',\n value: () => '$__rate_interval', // will be overriden when time series query is called\n source: 'Prometheus',\n display: {\n name: '__rate_interval',\n description:\n \"Interval at least four times the value of the scrape interval. It avoids problems specific to Prometheus when using 'rate' and 'increase' functions.\",\n hidden: true,\n },\n },\n },\n ] as BuiltinVariableDefinition[];\n};\n\nexport const PrometheusDatasource: DatasourcePlugin<PrometheusDatasourceSpec, PrometheusClient> = {\n createClient,\n getBuiltinVariableDefinitions,\n OptionsEditorComponent: PrometheusDatasourceEditor,\n createInitialOptions: () => ({ directUrl: '' }),\n};\n"],"names":["instantQuery","rangeQuery","labelNames","labelValues","PrometheusDatasourceEditor","createClient","spec","options","directUrl","proxy","proxyUrl","datasourceUrl","undefined","Error","specHeaders","headers","params","getBuiltinVariableDefinitions","kind","name","value","source","display","description","hidden","PrometheusDatasource","OptionsEditorComponent","createInitialOptions"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC,SAASA,YAAY,EAAEC,UAAU,EAAEC,UAAU,EAAEC,WAAW,QAA0B,WAAW;AAE/F,SAASC,0BAA0B,QAAQ,+BAA+B;AAE1E;;CAEC,GACD,MAAMC,eAA6F,CAACC,MAAMC;IACxG,MAAM,EAAEC,UAAS,EAAEC,MAAK,EAAE,GAAGH;IAC7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;IACxBuB,sBAAsB,IAAO,CAAA;YAAEnB,WAAW;QAAG,CAAA;AAC/C,EAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrometheusTimeSeriesQueryEditor.d.ts","sourceRoot":"","sources":["../../../src/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"PrometheusTimeSeriesQueryEditor.d.ts","sourceRoot":"","sources":["../../../src/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.tsx"],"names":[],"mappings":";AA0BA,OAAO,EACL,oCAAoC,EAIrC,MAAM,sBAAsB,CAAC;AAE9B;;GAEG;AACH,wBAAgB,+BAA+B,CAAC,KAAK,EAAE,oCAAoC,eA0E1F"}
|
|
@@ -16,7 +16,7 @@ import { Stack, TextField, FormControl, InputLabel } from '@mui/material';
|
|
|
16
16
|
import { DatasourceSelect, useDatasource, useDatasourceClient } from '@perses-dev/plugin-system';
|
|
17
17
|
import { DEFAULT_PROM, isDefaultPromSelector, isPrometheusDatasourceSelector, PROM_DATASOURCE_KIND } from '../../model';
|
|
18
18
|
import { PromQLEditor } from '../../components';
|
|
19
|
-
import { DEFAULT_SCRAPE_INTERVAL } from '../
|
|
19
|
+
import { DEFAULT_SCRAPE_INTERVAL } from '../types';
|
|
20
20
|
import { useQueryState, useFormatState, useMinStepState } from './query-editor-model';
|
|
21
21
|
/**
|
|
22
22
|
* The options editor component for editing a PrometheusTimeSeriesQuery's spec.
|