@perses-dev/prometheus-plugin 0.38.0 → 0.40.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/dist/cjs/components/PromQL.js +9 -7
  2. package/dist/cjs/components/index.js +10 -8
  3. package/dist/cjs/index.js +33 -19
  4. package/dist/cjs/model/index.js +15 -13
  5. package/dist/cjs/model/parse-sample-values.js +6 -2
  6. package/dist/cjs/model/prometheus-client.js +24 -5
  7. package/dist/cjs/model/prometheus-selectors.js +13 -5
  8. package/dist/cjs/model/templating.js +7 -5
  9. package/dist/cjs/model/time.js +14 -8
  10. package/dist/cjs/plugins/MatcherEditor.js +13 -11
  11. package/dist/cjs/plugins/PrometheusDatasourceEditor/PrometheusDatasourceEditor.js +456 -0
  12. package/dist/cjs/plugins/PrometheusDatasourceEditor/index.js +31 -0
  13. package/dist/cjs/plugins/PrometheusDatasourceEditor/types.js +23 -0
  14. package/dist/cjs/plugins/prometheus-datasource.js +53 -6
  15. package/dist/cjs/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.js +10 -8
  16. package/dist/cjs/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js +44 -20
  17. package/dist/cjs/plugins/prometheus-time-series-query/get-time-series-data.js +41 -22
  18. package/dist/cjs/plugins/prometheus-time-series-query/index.js +10 -8
  19. package/dist/cjs/plugins/prometheus-time-series-query/query-editor-model.js +42 -9
  20. package/dist/cjs/plugins/prometheus-variables.js +60 -54
  21. package/dist/cjs/plugins/variable.js +9 -7
  22. package/dist/cjs/utils/index.js +10 -8
  23. package/dist/cjs/utils/utils.js +12 -6
  24. package/dist/components/PromQL.js.map +1 -1
  25. package/dist/components/index.js.map +1 -1
  26. package/dist/index.js.map +1 -1
  27. package/dist/model/index.js.map +1 -1
  28. package/dist/model/parse-sample-values.js.map +1 -1
  29. package/dist/model/prometheus-client.d.ts.map +1 -1
  30. package/dist/model/prometheus-client.js +9 -0
  31. package/dist/model/prometheus-client.js.map +1 -1
  32. package/dist/model/prometheus-selectors.js +1 -1
  33. package/dist/model/prometheus-selectors.js.map +1 -1
  34. package/dist/model/templating.js.map +1 -1
  35. package/dist/model/time.js +1 -1
  36. package/dist/model/time.js.map +1 -1
  37. package/dist/plugins/MatcherEditor.js.map +1 -1
  38. package/dist/plugins/PrometheusDatasourceEditor/PrometheusDatasourceEditor.d.ts +9 -0
  39. package/dist/plugins/PrometheusDatasourceEditor/PrometheusDatasourceEditor.d.ts.map +1 -0
  40. package/dist/plugins/PrometheusDatasourceEditor/PrometheusDatasourceEditor.js +404 -0
  41. package/dist/plugins/PrometheusDatasourceEditor/PrometheusDatasourceEditor.js.map +1 -0
  42. package/dist/plugins/PrometheusDatasourceEditor/index.d.ts +3 -0
  43. package/dist/plugins/PrometheusDatasourceEditor/index.d.ts.map +1 -0
  44. package/dist/plugins/PrometheusDatasourceEditor/index.js +16 -0
  45. package/dist/plugins/PrometheusDatasourceEditor/index.js.map +1 -0
  46. package/dist/plugins/PrometheusDatasourceEditor/types.d.ts +22 -0
  47. package/dist/plugins/PrometheusDatasourceEditor/types.d.ts.map +1 -0
  48. package/dist/plugins/PrometheusDatasourceEditor/types.js +15 -0
  49. package/dist/plugins/PrometheusDatasourceEditor/types.js.map +1 -0
  50. package/dist/plugins/prometheus-datasource.d.ts +5 -3
  51. package/dist/plugins/prometheus-datasource.d.ts.map +1 -1
  52. package/dist/plugins/prometheus-datasource.js +50 -5
  53. package/dist/plugins/prometheus-datasource.js.map +1 -1
  54. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.js +1 -1
  55. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.js.map +1 -1
  56. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.d.ts.map +1 -1
  57. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js +32 -10
  58. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js.map +1 -1
  59. package/dist/plugins/prometheus-time-series-query/get-time-series-data.d.ts.map +1 -1
  60. package/dist/plugins/prometheus-time-series-query/get-time-series-data.js +34 -17
  61. package/dist/plugins/prometheus-time-series-query/get-time-series-data.js.map +1 -1
  62. package/dist/plugins/prometheus-time-series-query/index.js.map +1 -1
  63. package/dist/plugins/prometheus-time-series-query/query-editor-model.d.ts +10 -1
  64. package/dist/plugins/prometheus-time-series-query/query-editor-model.d.ts.map +1 -1
  65. package/dist/plugins/prometheus-time-series-query/query-editor-model.js +36 -8
  66. package/dist/plugins/prometheus-time-series-query/query-editor-model.js.map +1 -1
  67. package/dist/plugins/prometheus-time-series-query/time-series-query-model.d.ts +2 -2
  68. package/dist/plugins/prometheus-time-series-query/time-series-query-model.d.ts.map +1 -1
  69. package/dist/plugins/prometheus-time-series-query/time-series-query-model.js.map +1 -1
  70. package/dist/plugins/prometheus-variables.js +27 -27
  71. package/dist/plugins/prometheus-variables.js.map +1 -1
  72. package/dist/plugins/types.d.ts +2 -2
  73. package/dist/plugins/types.d.ts.map +1 -1
  74. package/dist/plugins/types.js.map +1 -1
  75. package/dist/plugins/variable.js +2 -2
  76. package/dist/plugins/variable.js.map +1 -1
  77. package/dist/test/setup-tests.js.map +1 -1
  78. package/dist/utils/index.js.map +1 -1
  79. package/dist/utils/utils.d.ts +1 -1
  80. package/dist/utils/utils.js +3 -3
  81. package/dist/utils/utils.js.map +1 -1
  82. package/package.json +6 -6
@@ -0,0 +1,404 @@
1
+ // Copyright 2023 The Perses 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
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
14
+ import { OptionsEditorRadios } from '@perses-dev/plugin-system';
15
+ import { Grid, IconButton, TextField, Typography } from '@mui/material';
16
+ import React, { Fragment, useState } from 'react';
17
+ import MinusIcon from 'mdi-material-ui/Minus';
18
+ import PlusIcon from 'mdi-material-ui/Plus';
19
+ import { DEFAULT_SCRAPE_INTERVAL } from './types';
20
+ export function PrometheusDatasourceEditor(props) {
21
+ var _value_proxy, _value_proxy1, _value_proxy2, _value_proxy3;
22
+ const { value , onChange , isReadonly } = props;
23
+ const strDirect = 'Direct access';
24
+ const strProxy = 'Proxy';
25
+ // TODO refactor with useImmer to avoid doing so much destructuring? feasibility & performances to be checked
26
+ // utilitary function used for headers when renaming a property
27
+ // -> TODO it would be cleaner to manipulate headers as a list instead, to avoid doing this.
28
+ // This could be a pure frontend trick, but change in the backend datamodel should also be considered
29
+ const buildNewHeaders = (oldHeaders, oldName, newName)=>{
30
+ if (oldHeaders === undefined) return oldHeaders;
31
+ const keys = Object.keys(oldHeaders);
32
+ const newHeaders = keys.reduce((acc, val)=>{
33
+ if (val === oldName) {
34
+ acc[newName] = oldHeaders[oldName] || '';
35
+ } else {
36
+ acc[val] = oldHeaders[val] || '';
37
+ }
38
+ return acc;
39
+ }, {});
40
+ return {
41
+ ...newHeaders
42
+ };
43
+ };
44
+ const tabs = [
45
+ {
46
+ label: strDirect,
47
+ content: /*#__PURE__*/ _jsx(_Fragment, {
48
+ children: /*#__PURE__*/ _jsx(TextField, {
49
+ fullWidth: true,
50
+ label: "URL",
51
+ value: value.directUrl || '',
52
+ InputProps: {
53
+ readOnly: isReadonly
54
+ },
55
+ InputLabelProps: {
56
+ shrink: isReadonly ? true : undefined
57
+ },
58
+ onChange: (e)=>onChange({
59
+ ...value,
60
+ directUrl: e.target.value
61
+ })
62
+ })
63
+ })
64
+ },
65
+ {
66
+ label: strProxy,
67
+ content: /*#__PURE__*/ _jsxs(_Fragment, {
68
+ children: [
69
+ /*#__PURE__*/ _jsx(TextField, {
70
+ fullWidth: true,
71
+ label: "URL",
72
+ value: ((_value_proxy = value.proxy) === null || _value_proxy === void 0 ? void 0 : _value_proxy.spec.url) || '',
73
+ InputProps: {
74
+ readOnly: isReadonly
75
+ },
76
+ InputLabelProps: {
77
+ shrink: isReadonly ? true : undefined
78
+ },
79
+ onChange: (e)=>onChange({
80
+ ...value,
81
+ ...value.proxy && {
82
+ proxy: {
83
+ ...value.proxy,
84
+ spec: {
85
+ ...value.proxy.spec,
86
+ url: e.target.value
87
+ }
88
+ }
89
+ }
90
+ })
91
+ }),
92
+ /*#__PURE__*/ _jsx(Typography, {
93
+ variant: "h4",
94
+ mt: 2,
95
+ mb: 1,
96
+ children: "Allowed endpoints"
97
+ }),
98
+ /*#__PURE__*/ _jsx(Grid, {
99
+ container: true,
100
+ spacing: 2,
101
+ mb: 2,
102
+ children: ((_value_proxy1 = value.proxy) === null || _value_proxy1 === void 0 ? void 0 : _value_proxy1.spec.allowedEndpoints) ? value.proxy.spec.allowedEndpoints.map(({ endpointPattern , method }, i)=>{
103
+ return /*#__PURE__*/ _jsxs(Fragment, {
104
+ children: [
105
+ /*#__PURE__*/ _jsx(Grid, {
106
+ item: true,
107
+ xs: 8,
108
+ children: /*#__PURE__*/ _jsx(TextField, {
109
+ disabled: true,
110
+ fullWidth: true,
111
+ label: "Endpoint pattern",
112
+ value: endpointPattern,
113
+ InputProps: {
114
+ readOnly: isReadonly
115
+ },
116
+ InputLabelProps: {
117
+ shrink: isReadonly ? true : undefined
118
+ }
119
+ })
120
+ }),
121
+ /*#__PURE__*/ _jsx(Grid, {
122
+ item: true,
123
+ xs: 4,
124
+ children: /*#__PURE__*/ _jsx(TextField, {
125
+ disabled: true,
126
+ fullWidth: true,
127
+ label: "URL",
128
+ value: method,
129
+ InputProps: {
130
+ readOnly: isReadonly
131
+ },
132
+ InputLabelProps: {
133
+ shrink: isReadonly ? true : undefined
134
+ }
135
+ })
136
+ })
137
+ ]
138
+ }, i);
139
+ }) : /*#__PURE__*/ _jsxs(Grid, {
140
+ item: true,
141
+ xs: 4,
142
+ children: [
143
+ /*#__PURE__*/ _jsx(Typography, {
144
+ children: "None"
145
+ }),
146
+ " "
147
+ ]
148
+ })
149
+ }),
150
+ /*#__PURE__*/ _jsx(Typography, {
151
+ variant: "h4",
152
+ mb: 1,
153
+ children: "Request Headers"
154
+ }),
155
+ /*#__PURE__*/ _jsxs(Grid, {
156
+ container: true,
157
+ spacing: 2,
158
+ mb: 2,
159
+ children: [
160
+ ((_value_proxy2 = value.proxy) === null || _value_proxy2 === void 0 ? void 0 : _value_proxy2.spec.headers) && Object.keys(value.proxy.spec.headers).map((headerName, i)=>{
161
+ var _value_proxy_spec_headers, _value_proxy;
162
+ return /*#__PURE__*/ _jsxs(Fragment, {
163
+ children: [
164
+ /*#__PURE__*/ _jsx(Grid, {
165
+ item: true,
166
+ xs: 4,
167
+ children: /*#__PURE__*/ _jsx(TextField, {
168
+ fullWidth: true,
169
+ label: "Header name",
170
+ value: headerName,
171
+ InputProps: {
172
+ readOnly: isReadonly
173
+ },
174
+ InputLabelProps: {
175
+ shrink: isReadonly ? true : undefined
176
+ },
177
+ onChange: (e)=>onChange({
178
+ ...value,
179
+ ...value.proxy && {
180
+ proxy: {
181
+ ...value.proxy,
182
+ spec: {
183
+ ...value.proxy.spec,
184
+ headers: buildNewHeaders(value.proxy.spec.headers, headerName, e.target.value)
185
+ }
186
+ }
187
+ }
188
+ })
189
+ })
190
+ }),
191
+ /*#__PURE__*/ _jsx(Grid, {
192
+ item: true,
193
+ xs: 7,
194
+ children: /*#__PURE__*/ _jsx(TextField, {
195
+ fullWidth: true,
196
+ label: "Header value",
197
+ value: (_value_proxy_spec_headers = (_value_proxy = value.proxy) === null || _value_proxy === void 0 ? void 0 : _value_proxy.spec.headers) === null || _value_proxy_spec_headers === void 0 ? void 0 : _value_proxy_spec_headers[headerName],
198
+ InputProps: {
199
+ readOnly: isReadonly
200
+ },
201
+ InputLabelProps: {
202
+ shrink: isReadonly ? true : undefined
203
+ },
204
+ onChange: (e)=>onChange({
205
+ ...value,
206
+ ...value.proxy && {
207
+ proxy: {
208
+ ...value.proxy,
209
+ spec: {
210
+ ...value.proxy.spec,
211
+ headers: {
212
+ ...value.proxy.spec.headers,
213
+ [headerName]: e.target.value
214
+ }
215
+ }
216
+ }
217
+ }
218
+ })
219
+ })
220
+ }),
221
+ /*#__PURE__*/ _jsx(Grid, {
222
+ item: true,
223
+ xs: 1,
224
+ children: /*#__PURE__*/ _jsx(IconButton, {
225
+ disabled: isReadonly,
226
+ onClick: ()=>{
227
+ var _value_proxy;
228
+ const newHeaders = {
229
+ ...(_value_proxy = value.proxy) === null || _value_proxy === void 0 ? void 0 : _value_proxy.spec.headers
230
+ };
231
+ delete newHeaders[headerName];
232
+ onChange({
233
+ ...value,
234
+ ...value.proxy && {
235
+ proxy: {
236
+ ...value.proxy,
237
+ spec: {
238
+ ...value.proxy.spec,
239
+ headers: newHeaders
240
+ }
241
+ }
242
+ }
243
+ });
244
+ },
245
+ children: /*#__PURE__*/ _jsx(MinusIcon, {})
246
+ })
247
+ })
248
+ ]
249
+ }, i);
250
+ }),
251
+ /*#__PURE__*/ _jsx(Grid, {
252
+ item: true,
253
+ xs: 12,
254
+ sx: {
255
+ paddingTop: '5px !important'
256
+ },
257
+ children: /*#__PURE__*/ _jsx(IconButton, {
258
+ disabled: isReadonly,
259
+ onClick: ()=>onChange({
260
+ ...value,
261
+ ...value.proxy && {
262
+ proxy: {
263
+ ...value.proxy,
264
+ spec: {
265
+ ...value.proxy.spec,
266
+ headers: {
267
+ ...value.proxy.spec.headers,
268
+ '': ''
269
+ }
270
+ }
271
+ }
272
+ }
273
+ }),
274
+ children: /*#__PURE__*/ _jsx(PlusIcon, {})
275
+ })
276
+ })
277
+ ]
278
+ }),
279
+ /*#__PURE__*/ _jsx(TextField, {
280
+ fullWidth: true,
281
+ label: "Secret",
282
+ value: ((_value_proxy3 = value.proxy) === null || _value_proxy3 === void 0 ? void 0 : _value_proxy3.spec.secret) || '',
283
+ InputProps: {
284
+ readOnly: isReadonly
285
+ },
286
+ InputLabelProps: {
287
+ shrink: isReadonly ? true : undefined
288
+ },
289
+ onChange: (e)=>onChange({
290
+ ...value,
291
+ ...value.proxy && {
292
+ proxy: {
293
+ ...value.proxy,
294
+ spec: {
295
+ ...value.proxy.spec,
296
+ secret: e.target.value
297
+ }
298
+ }
299
+ }
300
+ })
301
+ })
302
+ ]
303
+ })
304
+ }
305
+ ];
306
+ // Use of findIndex instead of providing hardcoded values to avoid desynchronisatio or
307
+ // bug in case the tabs get eventually swapped in the future.
308
+ const directModeId = tabs.findIndex((tab)=>tab.label == strDirect);
309
+ const proxyModeId = tabs.findIndex((tab)=>tab.label == strProxy);
310
+ // In "update datasource" case, set defaultTab to the mode that this datasource is currently relying on.
311
+ // Otherwise (create datasource), set defaultTab to Direct access.
312
+ const defaultTab = value.proxy ? proxyModeId : directModeId;
313
+ const initialSpecDirect = {
314
+ directUrl: ''
315
+ };
316
+ const initialSpecProxy = {
317
+ proxy: {
318
+ kind: 'HTTPProxy',
319
+ spec: {
320
+ allowedEndpoints: [
321
+ // hardcoded list of allowed endpoints for now since those are enforced by the backend
322
+ {
323
+ endpointPattern: '/api/v1/labels',
324
+ method: 'POST'
325
+ },
326
+ {
327
+ endpointPattern: '/api/v1/series',
328
+ method: 'POST'
329
+ },
330
+ {
331
+ endpointPattern: '/api/v1/metadata',
332
+ method: 'GET'
333
+ },
334
+ {
335
+ endpointPattern: '/api/v1/query',
336
+ method: 'POST'
337
+ },
338
+ {
339
+ endpointPattern: '/api/v1/query_range',
340
+ method: 'POST'
341
+ },
342
+ {
343
+ endpointPattern: '/api/v1/label/([a-zA-Z0-9_-]+)/values',
344
+ method: 'GET'
345
+ }
346
+ ],
347
+ url: ''
348
+ }
349
+ }
350
+ };
351
+ // For better user experience, save previous states in mind for both mode.
352
+ // This avoids losing everything when the user changes their mind back.
353
+ const [previousSpecDirect, setPreviousSpecDirect] = useState(initialSpecDirect);
354
+ const [previousSpecProxy, setPreviousSpecProxy] = useState(initialSpecProxy);
355
+ // When changing mode, remove previous mode's config + append default values for the new mode.
356
+ const handleModeChange = (v)=>{
357
+ var _tabs_v, _tabs_v1;
358
+ if (((_tabs_v = tabs[v]) === null || _tabs_v === void 0 ? void 0 : _tabs_v.label) == strDirect) {
359
+ setPreviousSpecProxy(value);
360
+ onChange(previousSpecDirect);
361
+ } else if (((_tabs_v1 = tabs[v]) === null || _tabs_v1 === void 0 ? void 0 : _tabs_v1.label) == strProxy) {
362
+ setPreviousSpecDirect(value);
363
+ onChange(previousSpecProxy);
364
+ }
365
+ };
366
+ return /*#__PURE__*/ _jsxs(_Fragment, {
367
+ children: [
368
+ /*#__PURE__*/ _jsx(Typography, {
369
+ variant: "h4",
370
+ mb: 1,
371
+ children: "General Settings"
372
+ }),
373
+ /*#__PURE__*/ _jsx(TextField, {
374
+ fullWidth: true,
375
+ label: "Scrape Interval",
376
+ value: value.scrapeInterval || '',
377
+ placeholder: `Default: ${DEFAULT_SCRAPE_INTERVAL}`,
378
+ InputProps: {
379
+ readOnly: isReadonly
380
+ },
381
+ InputLabelProps: {
382
+ shrink: isReadonly ? true : undefined
383
+ },
384
+ onChange: (e)=>onChange({
385
+ ...value,
386
+ scrapeInterval: e.target.value
387
+ })
388
+ }),
389
+ /*#__PURE__*/ _jsx(Typography, {
390
+ variant: "h4",
391
+ mt: 2,
392
+ children: "HTTP Settings"
393
+ }),
394
+ /*#__PURE__*/ _jsx(OptionsEditorRadios, {
395
+ isReadonly: isReadonly,
396
+ tabs: tabs,
397
+ defaultTab: defaultTab,
398
+ onModeChange: handleModeChange
399
+ })
400
+ ]
401
+ });
402
+ }
403
+
404
+ //# sourceMappingURL=PrometheusDatasourceEditor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/plugins/PrometheusDatasourceEditor/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, TextField, Typography } from '@mui/material';\nimport React, { Fragment, useState } from 'react';\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 // TODO refactor with useImmer to avoid doing so much destructuring? feasibility & performances to be checked\n\n // utilitary function used for headers when renaming a property\n // -> TODO it would be cleaner to manipulate headers as a list instead, to avoid doing this.\n // This could be a pure frontend trick, but change in the backend datamodel should also be considered\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) => onChange({ ...value, directUrl: e.target.value })}\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 ...value,\n ...(value.proxy && {\n proxy: {\n ...value.proxy,\n spec: {\n ...value.proxy.spec,\n url: e.target.value,\n },\n },\n }),\n })\n }\n />\n <Typography variant=\"h4\" mt={2} mb={1}>\n Allowed endpoints\n </Typography>\n <Grid container spacing={2} mb={2}>\n {value.proxy?.spec.allowedEndpoints ? (\n value.proxy.spec.allowedEndpoints.map(({ endpointPattern, method }, i) => {\n return (\n <Fragment key={i}>\n <Grid item xs={8}>\n <TextField\n disabled // at the moment the allowed endpoints cannot be modified (enforced by backend)\n fullWidth\n label=\"Endpoint pattern\"\n value={endpointPattern}\n InputProps={{\n readOnly: isReadonly,\n }}\n InputLabelProps={{ shrink: isReadonly ? true : undefined }}\n />\n </Grid>\n <Grid item xs={4}>\n <TextField\n disabled // at the moment the allowed endpoints cannot be modified (enforced by backend)\n fullWidth\n label=\"URL\"\n value={method}\n InputProps={{\n readOnly: isReadonly,\n }}\n InputLabelProps={{ shrink: isReadonly ? true : undefined }}\n />\n </Grid>\n </Fragment>\n );\n })\n ) : (\n <Grid item xs={4}>\n <Typography>None</Typography> {/* TODO: in edit mode, allow user to add endpoints */}\n </Grid>\n )}\n </Grid>\n <Typography variant=\"h4\" mb={1}>\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 ...value,\n ...(value.proxy && {\n proxy: {\n ...value.proxy,\n spec: {\n ...value.proxy.spec,\n headers: buildNewHeaders(value.proxy.spec.headers, headerName, 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 ...value,\n ...(value.proxy && {\n proxy: {\n ...value.proxy,\n spec: {\n ...value.proxy.spec,\n headers: { ...value.proxy.spec.headers, [headerName]: e.target.value },\n },\n },\n }),\n })\n }\n />\n </Grid>\n <Grid item xs={1}>\n <IconButton\n disabled={isReadonly}\n onClick={() => {\n const newHeaders = { ...value.proxy?.spec.headers };\n delete newHeaders[headerName];\n onChange({\n ...value,\n ...(value.proxy && {\n proxy: {\n ...value.proxy,\n spec: {\n ...value.proxy.spec,\n headers: newHeaders,\n },\n },\n }),\n });\n }}\n >\n <MinusIcon />\n </IconButton>\n </Grid>\n </Fragment>\n );\n })}\n <Grid item xs={12} sx={{ paddingTop: '5px !important' }}>\n <IconButton\n disabled={isReadonly}\n onClick={() =>\n onChange({\n ...value,\n ...(value.proxy && {\n proxy: {\n ...value.proxy,\n spec: {\n ...value.proxy.spec,\n headers: { ...value.proxy.spec.headers, '': '' },\n },\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 ...value,\n ...(value.proxy && {\n proxy: {\n ...value.proxy,\n spec: {\n ...value.proxy.spec,\n secret: e.target.value,\n },\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 // hardcoded list of allowed endpoints for now since those are enforced by the backend\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={1}>\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","TextField","Typography","React","Fragment","useState","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","target","proxy","spec","url","variant","mt","mb","container","spacing","allowedEndpoints","map","endpointPattern","method","i","item","xs","disabled","headers","headerName","onClick","sx","paddingTop","secret","directModeId","findIndex","tab","proxyModeId","defaultTab","initialSpecDirect","initialSpecProxy","kind","previousSpecDirect","setPreviousSpecDirect","previousSpecProxy","setPreviousSpecProxy","handleModeChange","v","scrapeInterval","placeholder","onModeChange"],"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;;AAGjC,SAASA,mBAAmB,QAAQ,4BAA4B;AAChE,SAASC,IAAI,EAAEC,UAAU,EAAEC,SAAS,EAAEC,UAAU,QAAQ,gBAAgB;AACxE,OAAOC,SAASC,QAAQ,EAAEC,QAAQ,QAAQ,QAAQ;AAClD,OAAOC,eAAe,wBAAwB;AAC9C,OAAOC,cAAc,uBAAuB;AAC5C,SAASC,uBAAuB,QAAkC,UAAU;AAQ5E,OAAO,SAASC,2BAA2BC,KAAsC;QAkD9DC,cAwBNA,eAyCAA,eAyGMA;IA3NjB,MAAM,EAAEA,MAAK,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,CAAAA,CAAAA,WAAAA,IAAI,CAAC8C,EAAE,cAAP9C,sBAAAA,KAAAA,IAAAA,SAASC,KAAI,KAAKb,UAAU;YACrCsD,sBAAsB1D;YACtBC,SAAS0D;QACX;IACF;IAEA,qBACE;;0BACE,KAACpE;gBAAWuC,SAAQ;gBAAKE,IAAI;0BAAG;;0BAGhC,KAAC1C;gBACC6B,SAAS;gBACTF,OAAM;gBACNjB,OAAOA,MAAM+D,kBAAkB;gBAC/BC,aAAa,CAAC,SAAS,EAAEnE,wBAAwB,CAAC;gBAClDwB,YAAY;oBACVC,UAAUpB;gBACZ;gBACAqB,iBAAiB;oBAAEC,QAAQtB,aAAa,OAAOO;gBAAU;gBACzDR,UAAU,CAACwB,IAAMxB,SAAS;wBAAE,GAAGD,KAAK;wBAAE+D,gBAAgBtC,EAAEC,OAAO1B;oBAAwB;;0BAEzF,KAACT;gBAAWuC,SAAQ;gBAAKC,IAAI;0BAAG;;0BAGhC,KAAC5C;gBACCe,YAAYA;gBACZc,MAAMA;gBACNqC,YAAYA;gBACZY,cAAcJ;;;;AAItB"}
@@ -0,0 +1,3 @@
1
+ export * from './PrometheusDatasourceEditor';
2
+ export * from './types';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/PrometheusDatasourceEditor/index.ts"],"names":[],"mappings":"AAaA,cAAc,8BAA8B,CAAC;AAC7C,cAAc,SAAS,CAAC"}
@@ -0,0 +1,16 @@
1
+ // Copyright 2023 The Perses 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
+ export * from './PrometheusDatasourceEditor';
14
+ export * from './types';
15
+
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/plugins/PrometheusDatasourceEditor/index.ts"],"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\nexport * from './PrometheusDatasourceEditor';\nexport * from './types';\n"],"names":[],"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;AAEjC,cAAc,+BAA+B;AAC7C,cAAc,UAAU"}
@@ -0,0 +1,22 @@
1
+ import { DurationString, RequestHeaders } from '@perses-dev/core';
2
+ export declare const DEFAULT_SCRAPE_INTERVAL: DurationString;
3
+ export interface PrometheusDatasourceSpec {
4
+ directUrl?: string;
5
+ proxy?: HTTPProxy;
6
+ scrapeInterval?: DurationString;
7
+ }
8
+ export interface HTTPProxy {
9
+ kind: 'HTTPProxy';
10
+ spec: HTTPProxySpec;
11
+ }
12
+ export interface HTTPProxySpec {
13
+ url: string;
14
+ allowedEndpoints?: HTTPAllowedEndpoint[];
15
+ headers?: RequestHeaders;
16
+ secret?: string;
17
+ }
18
+ export interface HTTPAllowedEndpoint {
19
+ endpointPattern: string;
20
+ method: string;
21
+ }
22
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/plugins/PrometheusDatasourceEditor/types.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElE,eAAO,MAAM,uBAAuB,EAAE,cAAqB,CAAC;AAG5D,MAAM,WAAW,wBAAwB;IACvC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,cAAc,CAAC,EAAE,cAAc,CAAC;CACjC;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,WAAW,CAAC;IAClB,IAAI,EAAE,aAAa,CAAC;CACrB;AACD,MAAM,WAAW,aAAa;IAG5B,GAAG,EAAE,MAAM,CAAC;IAGZ,gBAAgB,CAAC,EAAE,mBAAmB,EAAE,CAAC;IAEzC,OAAO,CAAC,EAAE,cAAc,CAAC;IAGzB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,mBAAmB;IAClC,eAAe,EAAE,MAAM,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;CAChB"}
@@ -0,0 +1,15 @@
1
+ // Copyright 2023 The Perses 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
+ export const DEFAULT_SCRAPE_INTERVAL = '1m';
14
+
15
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/plugins/PrometheusDatasourceEditor/types.ts"],"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';\n\nexport const DEFAULT_SCRAPE_INTERVAL: DurationString = '1m';\n\n// TODO: unify this one with the other PrometheusDatasourceSpec used for datasource store manipulation\nexport interface PrometheusDatasourceSpec {\n directUrl?: string;\n proxy?: HTTPProxy;\n scrapeInterval?: DurationString; // default to 1m\n}\n\nexport interface HTTPProxy {\n kind: 'HTTPProxy';\n spec: HTTPProxySpec;\n}\nexport interface HTTPProxySpec {\n // url is the url of the datasource. It is not the url of the proxy.\n // The Perses server is the proxy, so it needs to know where to redirect the request.\n url: string;\n // allowedEndpoints is a list of tuples of http methods and http endpoints that will be accessible.\n // Leave it empty if you don't want to restrict the access to the datasource.\n allowedEndpoints?: HTTPAllowedEndpoint[];\n // headers can be used to provide additional headers that need to be forwarded when requesting the datasource\n headers?: RequestHeaders;\n // secret is the name of the secret that should be used for the proxy or discovery configuration\n // It will contain any sensitive information such as password, token, certificate.\n secret?: string;\n}\n\nexport interface HTTPAllowedEndpoint {\n endpointPattern: string;\n method: string;\n}\n"],"names":["DEFAULT_SCRAPE_INTERVAL"],"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,OAAO,MAAMA,0BAA0C,KAAK"}
@@ -1,9 +1,11 @@
1
- import { RequestHeaders } from '@perses-dev/core';
1
+ import { DurationString, RequestHeaders } from '@perses-dev/core';
2
2
  import { DatasourcePlugin } from '@perses-dev/plugin-system';
3
3
  import { PrometheusClient } from '../model';
4
+ import { PrometheusDatasourceSpec as PrometheusDatasourceSpecFull } from './PrometheusDatasourceEditor';
4
5
  export interface PrometheusDatasourceSpec {
5
- direct_url?: string;
6
+ directUrl?: string;
6
7
  headers?: RequestHeaders;
8
+ scrapeInterval?: DurationString;
7
9
  }
8
- export declare const PrometheusDatasource: DatasourcePlugin<PrometheusDatasourceSpec, PrometheusClient>;
10
+ export declare const PrometheusDatasource: DatasourcePlugin<PrometheusDatasourceSpecFull, PrometheusClient>;
9
11
  //# sourceMappingURL=prometheus-datasource.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"prometheus-datasource.d.ts","sourceRoot":"","sources":["../../src/plugins/prometheus-datasource.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAqD,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE/F,MAAM,WAAW,wBAAwB;IACvC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,cAAc,CAAC;CAC1B;AA2BD,eAAO,MAAM,oBAAoB,EAAE,gBAAgB,CAAC,wBAAwB,EAAE,gBAAgB,CAI7F,CAAC"}
1
+ {"version":3,"file":"prometheus-datasource.d.ts","sourceRoot":"","sources":["../../src/plugins/prometheus-datasource.tsx"],"names":[],"mappings":"AAaA,OAAO,EAA6B,cAAc,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC7F,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAqD,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC/F,OAAO,EAEL,wBAAwB,IAAI,4BAA4B,EACzD,MAAM,8BAA8B,CAAC;AAEtC,MAAM,WAAW,wBAAwB;IACvC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB,cAAc,CAAC,EAAE,cAAc,CAAC;CACjC;AA0ED,eAAO,MAAM,oBAAoB,EAAE,gBAAgB,CAAC,4BAA4B,EAAE,gBAAgB,CAKjG,CAAC"}
@@ -11,15 +11,16 @@
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
13
  import { instantQuery, rangeQuery, labelNames, labelValues } from '../model';
14
+ import { PrometheusDatasourceEditor } from './PrometheusDatasourceEditor';
14
15
  /**
15
16
  * Creates a PrometheusClient for a specific datasource spec.
16
17
  */ const createClient = (spec, options)=>{
17
- const { direct_url , headers: specHeaders } = spec;
18
+ const { directUrl , headers: specHeaders } = spec;
18
19
  const { proxyUrl } = options;
19
20
  // Use the direct URL if specified, but fallback to the proxyUrl by default if not specified
20
- const datasourceUrl = direct_url !== null && direct_url !== void 0 ? direct_url : proxyUrl;
21
+ const datasourceUrl = directUrl !== null && directUrl !== void 0 ? directUrl : proxyUrl;
21
22
  if (datasourceUrl === undefined) {
22
- throw new Error('No URL specified for Prometheus client. You can use direct_url in the spec to configure it.');
23
+ throw new Error('No URL specified for Prometheus client. You can use directUrl in the spec to configure it.');
23
24
  }
24
25
  // Could think about this becoming a class, although it definitely doesn't have to be
25
26
  return {
@@ -44,11 +45,55 @@ import { instantQuery, rangeQuery, labelNames, labelValues } from '../model';
44
45
  })
45
46
  };
46
47
  };
48
+ const getBuiltinVariableDefinitions = ()=>{
49
+ return [
50
+ {
51
+ kind: 'BuiltinVariable',
52
+ spec: {
53
+ name: '__interval',
54
+ value: ()=>'$__interval',
55
+ source: 'Prometheus',
56
+ display: {
57
+ name: '__interval',
58
+ description: '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.',
59
+ hidden: true
60
+ }
61
+ }
62
+ },
63
+ {
64
+ kind: 'BuiltinVariable',
65
+ spec: {
66
+ name: '__interval_ms',
67
+ value: ()=>'$__interval_ms',
68
+ source: 'Prometheus',
69
+ display: {
70
+ name: '__interval_ms',
71
+ description: '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.',
72
+ hidden: true
73
+ }
74
+ }
75
+ },
76
+ {
77
+ kind: 'BuiltinVariable',
78
+ spec: {
79
+ name: '__rate_interval',
80
+ value: ()=>'$__rate_interval',
81
+ source: 'Prometheus',
82
+ display: {
83
+ name: '__rate_interval',
84
+ description: "Interval at least four times the value of the scrape interval. It avoids problems specific to Prometheus when using 'rate' and 'increase' functions.",
85
+ hidden: true
86
+ }
87
+ }
88
+ }
89
+ ];
90
+ };
47
91
  export const PrometheusDatasource = {
48
92
  createClient,
49
- OptionsEditorComponent: ()=>null,
93
+ getBuiltinVariableDefinitions,
94
+ OptionsEditorComponent: PrometheusDatasourceEditor,
50
95
  createInitialOptions: ()=>({
51
- direct_url: ''
96
+ directUrl: ''
52
97
  })
53
98
  };
54
99