@perses-dev/prometheus-plugin 0.39.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 (78) 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 +127 -63
  12. package/dist/cjs/plugins/PrometheusDatasourceEditor/index.js +11 -9
  13. package/dist/cjs/plugins/PrometheusDatasourceEditor/types.js +7 -0
  14. package/dist/cjs/plugins/prometheus-datasource.js +53 -7
  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 +39 -21
  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.map +1 -1
  39. package/dist/plugins/PrometheusDatasourceEditor/PrometheusDatasourceEditor.js +95 -33
  40. package/dist/plugins/PrometheusDatasourceEditor/PrometheusDatasourceEditor.js.map +1 -1
  41. package/dist/plugins/PrometheusDatasourceEditor/index.js.map +1 -1
  42. package/dist/plugins/PrometheusDatasourceEditor/types.d.ts +6 -4
  43. package/dist/plugins/PrometheusDatasourceEditor/types.d.ts.map +1 -1
  44. package/dist/plugins/PrometheusDatasourceEditor/types.js +1 -1
  45. package/dist/plugins/PrometheusDatasourceEditor/types.js.map +1 -1
  46. package/dist/plugins/prometheus-datasource.d.ts +3 -2
  47. package/dist/plugins/prometheus-datasource.d.ts.map +1 -1
  48. package/dist/plugins/prometheus-datasource.js +48 -4
  49. package/dist/plugins/prometheus-datasource.js.map +1 -1
  50. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.js +1 -1
  51. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.js.map +1 -1
  52. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.d.ts.map +1 -1
  53. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js +32 -10
  54. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js.map +1 -1
  55. package/dist/plugins/prometheus-time-series-query/get-time-series-data.d.ts.map +1 -1
  56. package/dist/plugins/prometheus-time-series-query/get-time-series-data.js +32 -16
  57. package/dist/plugins/prometheus-time-series-query/get-time-series-data.js.map +1 -1
  58. package/dist/plugins/prometheus-time-series-query/index.js.map +1 -1
  59. package/dist/plugins/prometheus-time-series-query/query-editor-model.d.ts +10 -1
  60. package/dist/plugins/prometheus-time-series-query/query-editor-model.d.ts.map +1 -1
  61. package/dist/plugins/prometheus-time-series-query/query-editor-model.js +36 -8
  62. package/dist/plugins/prometheus-time-series-query/query-editor-model.js.map +1 -1
  63. package/dist/plugins/prometheus-time-series-query/time-series-query-model.d.ts +2 -2
  64. package/dist/plugins/prometheus-time-series-query/time-series-query-model.d.ts.map +1 -1
  65. package/dist/plugins/prometheus-time-series-query/time-series-query-model.js.map +1 -1
  66. package/dist/plugins/prometheus-variables.js +27 -27
  67. package/dist/plugins/prometheus-variables.js.map +1 -1
  68. package/dist/plugins/types.d.ts +2 -2
  69. package/dist/plugins/types.d.ts.map +1 -1
  70. package/dist/plugins/types.js.map +1 -1
  71. package/dist/plugins/variable.js +2 -2
  72. package/dist/plugins/variable.js.map +1 -1
  73. package/dist/test/setup-tests.js.map +1 -1
  74. package/dist/utils/index.js.map +1 -1
  75. package/dist/utils/utils.d.ts +1 -1
  76. package/dist/utils/utils.js +3 -3
  77. package/dist/utils/utils.js.map +1 -1
  78. package/package.json +6 -6
@@ -13,11 +13,12 @@
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
15
  import { Grid, IconButton, TextField, Typography } from '@mui/material';
16
- import React, { useState } from 'react';
16
+ import React, { Fragment, useState } from 'react';
17
17
  import MinusIcon from 'mdi-material-ui/Minus';
18
18
  import PlusIcon from 'mdi-material-ui/Plus';
19
+ import { DEFAULT_SCRAPE_INTERVAL } from './types';
19
20
  export function PrometheusDatasourceEditor(props) {
20
- var ref, ref1, ref2, ref3;
21
+ var _value_proxy, _value_proxy1, _value_proxy2, _value_proxy3;
21
22
  const { value , onChange , isReadonly } = props;
22
23
  const strDirect = 'Direct access';
23
24
  const strProxy = 'Proxy';
@@ -47,13 +48,16 @@ export function PrometheusDatasourceEditor(props) {
47
48
  children: /*#__PURE__*/ _jsx(TextField, {
48
49
  fullWidth: true,
49
50
  label: "URL",
50
- value: value.direct_url || '',
51
+ value: value.directUrl || '',
51
52
  InputProps: {
52
53
  readOnly: isReadonly
53
54
  },
55
+ InputLabelProps: {
56
+ shrink: isReadonly ? true : undefined
57
+ },
54
58
  onChange: (e)=>onChange({
55
59
  ...value,
56
- direct_url: e.target.value
60
+ directUrl: e.target.value
57
61
  })
58
62
  })
59
63
  })
@@ -65,10 +69,13 @@ export function PrometheusDatasourceEditor(props) {
65
69
  /*#__PURE__*/ _jsx(TextField, {
66
70
  fullWidth: true,
67
71
  label: "URL",
68
- value: ((ref = value.proxy) === null || ref === void 0 ? void 0 : ref.spec.url) || '',
72
+ value: ((_value_proxy = value.proxy) === null || _value_proxy === void 0 ? void 0 : _value_proxy.spec.url) || '',
69
73
  InputProps: {
70
74
  readOnly: isReadonly
71
75
  },
76
+ InputLabelProps: {
77
+ shrink: isReadonly ? true : undefined
78
+ },
72
79
  onChange: (e)=>onChange({
73
80
  ...value,
74
81
  ...value.proxy && {
@@ -83,16 +90,17 @@ export function PrometheusDatasourceEditor(props) {
83
90
  })
84
91
  }),
85
92
  /*#__PURE__*/ _jsx(Typography, {
86
- py: 2,
87
93
  variant: "h4",
94
+ mt: 2,
95
+ mb: 1,
88
96
  children: "Allowed endpoints"
89
97
  }),
90
98
  /*#__PURE__*/ _jsx(Grid, {
91
99
  container: true,
92
100
  spacing: 2,
93
101
  mb: 2,
94
- children: ((ref1 = value.proxy) === null || ref1 === void 0 ? void 0 : ref1.spec.allowed_endpoints) && value.proxy.spec.allowed_endpoints.map(({ endpoint_pattern , method }, i)=>{
95
- return /*#__PURE__*/ _jsxs(React.Fragment, {
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, {
96
104
  children: [
97
105
  /*#__PURE__*/ _jsx(Grid, {
98
106
  item: true,
@@ -101,9 +109,12 @@ export function PrometheusDatasourceEditor(props) {
101
109
  disabled: true,
102
110
  fullWidth: true,
103
111
  label: "Endpoint pattern",
104
- value: endpoint_pattern,
112
+ value: endpointPattern,
105
113
  InputProps: {
106
114
  readOnly: isReadonly
115
+ },
116
+ InputLabelProps: {
117
+ shrink: isReadonly ? true : undefined
107
118
  }
108
119
  })
109
120
  }),
@@ -117,16 +128,28 @@ export function PrometheusDatasourceEditor(props) {
117
128
  value: method,
118
129
  InputProps: {
119
130
  readOnly: isReadonly
131
+ },
132
+ InputLabelProps: {
133
+ shrink: isReadonly ? true : undefined
120
134
  }
121
135
  })
122
136
  })
123
137
  ]
124
138
  }, i);
139
+ }) : /*#__PURE__*/ _jsxs(Grid, {
140
+ item: true,
141
+ xs: 4,
142
+ children: [
143
+ /*#__PURE__*/ _jsx(Typography, {
144
+ children: "None"
145
+ }),
146
+ " "
147
+ ]
125
148
  })
126
149
  }),
127
150
  /*#__PURE__*/ _jsx(Typography, {
128
- pb: 2,
129
151
  variant: "h4",
152
+ mb: 1,
130
153
  children: "Request Headers"
131
154
  }),
132
155
  /*#__PURE__*/ _jsxs(Grid, {
@@ -134,9 +157,9 @@ export function PrometheusDatasourceEditor(props) {
134
157
  spacing: 2,
135
158
  mb: 2,
136
159
  children: [
137
- ((ref2 = value.proxy) === null || ref2 === void 0 ? void 0 : ref2.spec.headers) !== undefined && Object.keys(value.proxy.spec.headers).map((headerName, i)=>{
138
- var ref, ref1;
139
- return /*#__PURE__*/ _jsxs(React.Fragment, {
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, {
140
163
  children: [
141
164
  /*#__PURE__*/ _jsx(Grid, {
142
165
  item: true,
@@ -148,6 +171,9 @@ export function PrometheusDatasourceEditor(props) {
148
171
  InputProps: {
149
172
  readOnly: isReadonly
150
173
  },
174
+ InputLabelProps: {
175
+ shrink: isReadonly ? true : undefined
176
+ },
151
177
  onChange: (e)=>onChange({
152
178
  ...value,
153
179
  ...value.proxy && {
@@ -168,10 +194,13 @@ export function PrometheusDatasourceEditor(props) {
168
194
  children: /*#__PURE__*/ _jsx(TextField, {
169
195
  fullWidth: true,
170
196
  label: "Header value",
171
- value: (ref1 = (ref = value.proxy) === null || ref === void 0 ? void 0 : ref.spec.headers) === null || ref1 === void 0 ? void 0 : ref1[headerName],
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],
172
198
  InputProps: {
173
199
  readOnly: isReadonly
174
200
  },
201
+ InputLabelProps: {
202
+ shrink: isReadonly ? true : undefined
203
+ },
175
204
  onChange: (e)=>onChange({
176
205
  ...value,
177
206
  ...value.proxy && {
@@ -195,9 +224,9 @@ export function PrometheusDatasourceEditor(props) {
195
224
  children: /*#__PURE__*/ _jsx(IconButton, {
196
225
  disabled: isReadonly,
197
226
  onClick: ()=>{
198
- var ref;
227
+ var _value_proxy;
199
228
  const newHeaders = {
200
- ...(ref = value.proxy) === null || ref === void 0 ? void 0 : ref.spec.headers
229
+ ...(_value_proxy = value.proxy) === null || _value_proxy === void 0 ? void 0 : _value_proxy.spec.headers
201
230
  };
202
231
  delete newHeaders[headerName];
203
232
  onChange({
@@ -250,10 +279,13 @@ export function PrometheusDatasourceEditor(props) {
250
279
  /*#__PURE__*/ _jsx(TextField, {
251
280
  fullWidth: true,
252
281
  label: "Secret",
253
- value: ((ref3 = value.proxy) === null || ref3 === void 0 ? void 0 : ref3.spec.secret) || '',
282
+ value: ((_value_proxy3 = value.proxy) === null || _value_proxy3 === void 0 ? void 0 : _value_proxy3.spec.secret) || '',
254
283
  InputProps: {
255
284
  readOnly: isReadonly
256
285
  },
286
+ InputLabelProps: {
287
+ shrink: isReadonly ? true : undefined
288
+ },
257
289
  onChange: (e)=>onChange({
258
290
  ...value,
259
291
  ...value.proxy && {
@@ -279,36 +311,36 @@ export function PrometheusDatasourceEditor(props) {
279
311
  // Otherwise (create datasource), set defaultTab to Direct access.
280
312
  const defaultTab = value.proxy ? proxyModeId : directModeId;
281
313
  const initialSpecDirect = {
282
- direct_url: ''
314
+ directUrl: ''
283
315
  };
284
316
  const initialSpecProxy = {
285
317
  proxy: {
286
318
  kind: 'HTTPProxy',
287
319
  spec: {
288
- allowed_endpoints: [
320
+ allowedEndpoints: [
289
321
  // hardcoded list of allowed endpoints for now since those are enforced by the backend
290
322
  {
291
- endpoint_pattern: '/api/v1/labels',
323
+ endpointPattern: '/api/v1/labels',
292
324
  method: 'POST'
293
325
  },
294
326
  {
295
- endpoint_pattern: '/api/v1/series',
327
+ endpointPattern: '/api/v1/series',
296
328
  method: 'POST'
297
329
  },
298
330
  {
299
- endpoint_pattern: '/api/v1/metadata',
331
+ endpointPattern: '/api/v1/metadata',
300
332
  method: 'GET'
301
333
  },
302
334
  {
303
- endpoint_pattern: '/api/v1/query',
335
+ endpointPattern: '/api/v1/query',
304
336
  method: 'POST'
305
337
  },
306
338
  {
307
- endpoint_pattern: '/api/v1/query_range',
339
+ endpointPattern: '/api/v1/query_range',
308
340
  method: 'POST'
309
341
  },
310
342
  {
311
- endpoint_pattern: '/api/v1/label/([a-zA-Z0-9_-]+)/values',
343
+ endpointPattern: '/api/v1/label/([a-zA-Z0-9_-]+)/values',
312
344
  method: 'GET'
313
345
  }
314
346
  ],
@@ -322,20 +354,50 @@ export function PrometheusDatasourceEditor(props) {
322
354
  const [previousSpecProxy, setPreviousSpecProxy] = useState(initialSpecProxy);
323
355
  // When changing mode, remove previous mode's config + append default values for the new mode.
324
356
  const handleModeChange = (v)=>{
325
- var ref, ref1;
326
- if (((ref = tabs[v]) === null || ref === void 0 ? void 0 : ref.label) == strDirect) {
357
+ var _tabs_v, _tabs_v1;
358
+ if (((_tabs_v = tabs[v]) === null || _tabs_v === void 0 ? void 0 : _tabs_v.label) == strDirect) {
327
359
  setPreviousSpecProxy(value);
328
360
  onChange(previousSpecDirect);
329
- } else if (((ref1 = tabs[v]) === null || ref1 === void 0 ? void 0 : ref1.label) == strProxy) {
361
+ } else if (((_tabs_v1 = tabs[v]) === null || _tabs_v1 === void 0 ? void 0 : _tabs_v1.label) == strProxy) {
330
362
  setPreviousSpecDirect(value);
331
363
  onChange(previousSpecProxy);
332
364
  }
333
365
  };
334
- return /*#__PURE__*/ _jsx(OptionsEditorRadios, {
335
- isReadonly: isReadonly,
336
- tabs: tabs,
337
- defaultTab: defaultTab,
338
- onModeChange: handleModeChange
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
+ ]
339
401
  });
340
402
  }
341
403
 
@@ -1 +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 { RequestHeaders } from '@perses-dev/core';\nimport { OptionsEditorRadios } from '@perses-dev/plugin-system';\nimport { Grid, IconButton, TextField, Typography } from '@mui/material';\nimport React, { useState } from 'react';\nimport MinusIcon from 'mdi-material-ui/Minus';\nimport PlusIcon from 'mdi-material-ui/Plus';\nimport { 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.direct_url || ''}\n InputProps={{\n readOnly: isReadonly,\n }}\n onChange={(e) => onChange({ ...value, direct_url: 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 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 py={2} variant=\"h4\">\n Allowed endpoints\n </Typography>\n <Grid container spacing={2} mb={2}>\n {value.proxy?.spec.allowed_endpoints &&\n value.proxy.spec.allowed_endpoints.map(({ endpoint_pattern, method }, i) => {\n return (\n <React.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={endpoint_pattern}\n InputProps={{\n readOnly: isReadonly,\n }}\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 />\n </Grid>\n </React.Fragment>\n );\n })}\n </Grid>\n <Typography pb={2} variant=\"h4\">\n Request Headers\n </Typography>\n <Grid container spacing={2} mb={2}>\n {value.proxy?.spec.headers !== undefined &&\n Object.keys(value.proxy.spec.headers).map((headerName, i) => {\n return (\n <React.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 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 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 </React.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 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 direct_url: '',\n };\n\n const initialSpecProxy: PrometheusDatasourceSpec = {\n proxy: {\n kind: 'HTTPProxy',\n spec: {\n allowed_endpoints: [\n // hardcoded list of allowed endpoints for now since those are enforced by the backend\n {\n endpoint_pattern: '/api/v1/labels',\n method: 'POST',\n },\n {\n endpoint_pattern: '/api/v1/series',\n method: 'POST',\n },\n {\n endpoint_pattern: '/api/v1/metadata',\n method: 'GET',\n },\n {\n endpoint_pattern: '/api/v1/query',\n method: 'POST',\n },\n {\n endpoint_pattern: '/api/v1/query_range',\n method: 'POST',\n },\n {\n endpoint_pattern: '/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 <OptionsEditorRadios isReadonly={isReadonly} tabs={tabs} defaultTab={defaultTab} onModeChange={handleModeChange} />\n );\n}\n"],"names":["OptionsEditorRadios","Grid","IconButton","TextField","Typography","React","useState","MinusIcon","PlusIcon","PrometheusDatasourceEditor","props","value","onChange","isReadonly","strDirect","strProxy","buildNewHeaders","oldHeaders","oldName","newName","undefined","keys","Object","newHeaders","reduce","acc","val","tabs","label","content","fullWidth","direct_url","InputProps","readOnly","e","target","proxy","spec","url","py","variant","container","spacing","mb","allowed_endpoints","map","endpoint_pattern","method","i","Fragment","item","xs","disabled","pb","headers","headerName","onClick","sx","paddingTop","secret","directModeId","findIndex","tab","proxyModeId","defaultTab","initialSpecDirect","initialSpecProxy","kind","previousSpecDirect","setPreviousSpecDirect","previousSpecProxy","setPreviousSpecProxy","handleModeChange","v","onMode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B,CAAC,GAAG/D,QAAQ,CAAC2D,iBAAiB,CAAC,AAAC;IAChF,MAAM,CAACK,iBAAiB,EAAEC,oBAAoB,CAAC,GAAGjE,QAAQ,CAAC4D,gBAAgB,CAAC,AAAC;IAE7E,8FAA8F;IAC9F,MAAMM,gBAAgB,GAAG,CAACC,CAAS,GAAK;YAClC9C,GAAO,EAGAA,IAAO;QAHlB,IAAIA,CAAAA,CAAAA,GAAO,GAAPA,IAAI,CAAC8C,CAAC,CAAC,cAAP9C,GAAO,WAAO,GAAdA,KAAAA,CAAc,GAAdA,GAAO,CAAEC,KAAK,CAAA,IAAId,SAAS,EAAE;YAC/ByD,oBAAoB,CAAC5D,KAAK,CAAC,CAAC;YAC5BC,QAAQ,CAACwD,kBAAkB,CAAC,CAAC;QAC/B,OAAO,IAAIzC,CAAAA,CAAAA,IAAO,GAAPA,IAAI,CAAC8C,CAAC,CAAC,cAAP9C,IAAO,WAAO,GAAdA,KAAAA,CAAc,GAAdA,IAAO,CAAEC,KAAK,CAAA,IAAIb,QAAQ,EAAE;YACrCsD,qBAAqB,CAAC1D,KAAK,CAAC,CAAC;YAC7BC,QAAQ,CAAC0D,iBAAiB,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC,AAAC;IAEF,qBACE,KAACtE,mBAAmB;QAACa,UAAU,EAAEA,UAAU;QAAEc,IAAI,EAAEA,IAAI;QAAEqC,UAAU,EAAEA,UAAU;QAAEU,YAAY,EAAEF,gBAAgB;MAAI,CACnH;AACJ,CAAC"}
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,EAAEC,SAAQ,EAAEC,WAAU,EAAE,GAAGH;IACxC,MAAMI,YAAY;IAClB,MAAMC,WAAW;IAEjB,6GAA6G;IAE7G,+DAA+D;IAC/D,4FAA4F;IAC5F,wGAAwG;IACxG,MAAMC,kBAAkB,CAACC,YAAwCC,SAAiBC;QAChF,IAAIF,eAAeG,WAAW,OAA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C,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"}
@@ -1 +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,8BAA8B,CAAC;AAC7C,cAAc,SAAS,CAAC"}
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"}
@@ -1,7 +1,9 @@
1
- import { RequestHeaders } from '@perses-dev/core';
1
+ import { DurationString, RequestHeaders } from '@perses-dev/core';
2
+ export declare const DEFAULT_SCRAPE_INTERVAL: DurationString;
2
3
  export interface PrometheusDatasourceSpec {
3
- direct_url?: string;
4
+ directUrl?: string;
4
5
  proxy?: HTTPProxy;
6
+ scrapeInterval?: DurationString;
5
7
  }
6
8
  export interface HTTPProxy {
7
9
  kind: 'HTTPProxy';
@@ -9,12 +11,12 @@ export interface HTTPProxy {
9
11
  }
10
12
  export interface HTTPProxySpec {
11
13
  url: string;
12
- allowed_endpoints?: HTTPAllowedEndpoint[];
14
+ allowedEndpoints?: HTTPAllowedEndpoint[];
13
15
  headers?: RequestHeaders;
14
16
  secret?: string;
15
17
  }
16
18
  export interface HTTPAllowedEndpoint {
17
- endpoint_pattern: string;
19
+ endpointPattern: string;
18
20
  method: string;
19
21
  }
20
22
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/plugins/PrometheusDatasourceEditor/types.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAGlD,MAAM,WAAW,wBAAwB;IACvC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB;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,iBAAiB,CAAC,EAAE,mBAAmB,EAAE,CAAC;IAE1C,OAAO,CAAC,EAAE,cAAc,CAAC;IAGzB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,mBAAmB;IAClC,gBAAgB,EAAE,MAAM,CAAC;IACzB,MAAM,EAAE,MAAM,CAAC;CAChB"}
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"}
@@ -10,6 +10,6 @@
10
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
- export { };
13
+ export const DEFAULT_SCRAPE_INTERVAL = '1m';
14
14
 
15
15
  //# sourceMappingURL=types.js.map
@@ -1 +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 { RequestHeaders } from '@perses-dev/core';\n\n// TODO unify this one with the other PrometheusDatasourceSpec used for datasource store manipulation\nexport interface PrometheusDatasourceSpec {\n direct_url?: string;\n proxy?: HTTPProxy;\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 // allowed_endpoints 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 allowed_endpoints?: 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 endpoint_pattern: string;\n method: string;\n}\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,WA6BC"}
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,10 +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
4
  import { PrometheusDatasourceSpec as PrometheusDatasourceSpecFull } from './PrometheusDatasourceEditor';
5
5
  export interface PrometheusDatasourceSpec {
6
- direct_url?: string;
6
+ directUrl?: string;
7
7
  headers?: RequestHeaders;
8
+ scrapeInterval?: DurationString;
8
9
  }
9
10
  export declare const PrometheusDatasource: DatasourcePlugin<PrometheusDatasourceSpecFull, PrometheusClient>;
10
11
  //# 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":"AAaA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,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,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,cAAc,CAAC;CAC1B;AA2BD,eAAO,MAAM,oBAAoB,EAAE,gBAAgB,CAAC,4BAA4B,EAAE,gBAAgB,CAIjG,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"}
@@ -15,12 +15,12 @@ import { PrometheusDatasourceEditor } from './PrometheusDatasourceEditor';
15
15
  /**
16
16
  * Creates a PrometheusClient for a specific datasource spec.
17
17
  */ const createClient = (spec, options)=>{
18
- const { direct_url , headers: specHeaders } = spec;
18
+ const { directUrl , headers: specHeaders } = 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
- const datasourceUrl = direct_url !== null && direct_url !== void 0 ? direct_url : proxyUrl;
21
+ const datasourceUrl = directUrl !== null && directUrl !== void 0 ? directUrl : proxyUrl;
22
22
  if (datasourceUrl === undefined) {
23
- 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.');
24
24
  }
25
25
  // Could think about this becoming a class, although it definitely doesn't have to be
26
26
  return {
@@ -45,11 +45,55 @@ import { PrometheusDatasourceEditor } from './PrometheusDatasourceEditor';
45
45
  })
46
46
  };
47
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
+ };
48
91
  export const PrometheusDatasource = {
49
92
  createClient,
93
+ getBuiltinVariableDefinitions,
50
94
  OptionsEditorComponent: PrometheusDatasourceEditor,
51
95
  createInitialOptions: ()=>({
52
- direct_url: ''
96
+ directUrl: ''
53
97
  })
54
98
  };
55
99
 
@@ -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 { RequestHeaders } from '@perses-dev/core';\nimport { DatasourcePlugin } from '@perses-dev/plugin-system';\nimport { instantQuery, rangeQuery, labelNames, labelValues, PrometheusClient } from '../model';\nimport {\n PrometheusDatasourceEditor,\n PrometheusDatasourceSpec as PrometheusDatasourceSpecFull,\n} from './PrometheusDatasourceEditor';\n\nexport interface PrometheusDatasourceSpec {\n direct_url?: string;\n headers?: RequestHeaders;\n}\n\n/**\n * Creates a PrometheusClient for a specific datasource spec.\n */\nconst createClient: DatasourcePlugin<PrometheusDatasourceSpec, PrometheusClient>['createClient'] = (spec, options) => {\n const { direct_url, headers: specHeaders } = 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 = direct_url ?? proxyUrl;\n if (datasourceUrl === undefined) {\n throw new Error('No URL specified for Prometheus client. You can use direct_url in the spec to configure it.');\n }\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\nexport const PrometheusDatasource: DatasourcePlugin<PrometheusDatasourceSpecFull, PrometheusClient> = {\n createClient,\n OptionsEditorComponent: PrometheusDatasourceEditor,\n createInitialOptions: () => ({ direct_url: '' }),\n};\n"],"names":["instantQuery","rangeQuery","labelNames","labelValues","PrometheusDatasourceEditor","createClient","spec","options","direct_url","headers","specHeaders","proxyUrl","datasourceUrl","undefined","Error","params","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,UAAU,CAAC;AAC/F,SACEC,0BAA0B,QAErB,8BAA8B,CAAC;AAOtC;;CAEC,GACD,MAAMC,YAAY,GAAiF,CAACC,IAAI,EAAEC,OAAO,GAAK;IACpH,MAAM,EAAEC,UAAU,CAAA,EAAE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AA,AAAC;CACjD,CAAC"}
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, DurationString, RequestHeaders } from '@perses-dev/core';\nimport { DatasourcePlugin } from '@perses-dev/plugin-system';\nimport { instantQuery, rangeQuery, labelNames, labelValues, PrometheusClient } from '../model';\nimport {\n PrometheusDatasourceEditor,\n PrometheusDatasourceSpec as PrometheusDatasourceSpecFull,\n} from './PrometheusDatasourceEditor';\n\nexport interface PrometheusDatasourceSpec {\n directUrl?: string;\n headers?: RequestHeaders;\n scrapeInterval?: DurationString;\n}\n\n/**\n * Creates a PrometheusClient for a specific datasource spec.\n */\nconst createClient: DatasourcePlugin<PrometheusDatasourceSpec, PrometheusClient>['createClient'] = (spec, options) => {\n const { directUrl, headers: specHeaders } = 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 // 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<PrometheusDatasourceSpecFull, PrometheusClient> = {\n createClient,\n getBuiltinVariableDefinitions,\n OptionsEditorComponent: PrometheusDatasourceEditor,\n createInitialOptions: () => ({ directUrl: '' }),\n};\n"],"names":["instantQuery","rangeQuery","labelNames","labelValues","PrometheusDatasourceEditor","createClient","spec","options","directUrl","headers","specHeaders","proxyUrl","datasourceUrl","undefined","Error","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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BACPH,MAAM;oBACNI,aACE;oBACFC,QAAQ;gBACV;YACF;QACF;KACD;AACH;AAEA,OAAO,MAAMC,uBAAyF;IACpGnB;IACAW;IACAS,wBAAwBrB;IACxBsB,sBAAsB,IAAO,CAAA;YAAElB,WAAW;QAAG,CAAA;AAC/C,EAAE"}
@@ -25,7 +25,7 @@ import { PrometheusTimeSeriesQueryEditor } from './PrometheusTimeSeriesQueryEdit
25
25
  dependsOn: (spec)=>{
26
26
  // Variables can be used in the query and/or in the legend format string
27
27
  const queryVariables = parseTemplateVariables(spec.query);
28
- const legendVariables = parseTemplateVariables(spec.series_name_format || '');
28
+ const legendVariables = parseTemplateVariables(spec.seriesNameFormat || '');
29
29
  const allVariables = [
30
30
  ...new Set([
31
31
  ...queryVariables,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.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 { TimeSeriesQueryPlugin, parseTemplateVariables } from '@perses-dev/plugin-system';\nimport { getTimeSeriesData } from './get-time-series-data';\nimport { PrometheusTimeSeriesQueryEditor } from './PrometheusTimeSeriesQueryEditor';\nimport { PrometheusTimeSeriesQuerySpec } from './time-series-query-model';\n\n/**\n * The core Prometheus TimeSeriesQuery plugin for Perses.\n */\nexport const PrometheusTimeSeriesQuery: TimeSeriesQueryPlugin<PrometheusTimeSeriesQuerySpec> = {\n getTimeSeriesData,\n OptionsEditorComponent: PrometheusTimeSeriesQueryEditor,\n createInitialOptions: () => ({\n query: '',\n datasource: undefined,\n }),\n dependsOn: (spec) => {\n // Variables can be used in the query and/or in the legend format string\n const queryVariables = parseTemplateVariables(spec.query);\n const legendVariables = parseTemplateVariables(spec.series_name_format || '');\n const allVariables = [...new Set([...queryVariables, ...legendVariables])];\n return {\n variables: allVariables,\n };\n },\n};\n"],"names":["parseTemplateVariables","getTimeSeriesData","PrometheusTimeSeriesQueryEditor","PrometheusTimeSeriesQuery","OptionsEditorComponent","createInitialOptions","query","datasource","undefined","dependsOn","spec","queryVariables","legendVariables","series_name_format","allVariables","Set","variables"],"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,SAAgCA,sBAAsB,QAAQ,2BAA2B,CAAC;AAC1F,SAASC,iBAAiB,QAAQ,wBAAwB,CAAC;AAC3D,SAASC,+BAA+B,QAAQ,mCAAmC,CAAC;AAGpF;;CAEC,GACD,OAAO,MAAMC,yBAAyB,GAAyD;IAC7FF,iBAAiB;IACjBG,sBAAsB,EAAEF,+BAA+B;IACvDG,oBAAoB,EAAE,IAAO,CAAA;YAC3BC,KAAK,EAAE,EAAE;YACTC,UAAU,EAAEC,SAAS;SACtB,CAAA,AAAC;IACFC,SAAS,EAAE,CAACC,IAAI,GAAK;QACnB,wEAAwE;QACxE,MAAMC,cAAc,GAAGX,sBAAsB,CAACU,IAAI,CAACJ,KAAK,CAAC,AAAC;QAC1D,MAAMM,eAAe,GAAGZ,sBAAsB,CAACU,IAAI,CAACG,kBAAkB,IAAI,EAAE,CAAC,AAAC;QAC9E,MAAMC,YAAY,GAAG;eAAI,IAAIC,GAAG,CAAC;mBAAIJ,cAAc;mBAAKC,eAAe;aAAC,CAAC;SAAC,AAAC;QAC3E,OAAO;YACLI,SAAS,EAAEF,YAAY;SACxB,CAAC;IACJ,CAAC;CACF,CAAC"}
1
+ {"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.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 { TimeSeriesQueryPlugin, parseTemplateVariables } from '@perses-dev/plugin-system';\nimport { getTimeSeriesData } from './get-time-series-data';\nimport { PrometheusTimeSeriesQueryEditor } from './PrometheusTimeSeriesQueryEditor';\nimport { PrometheusTimeSeriesQuerySpec } from './time-series-query-model';\n\n/**\n * The core Prometheus TimeSeriesQuery plugin for Perses.\n */\nexport const PrometheusTimeSeriesQuery: TimeSeriesQueryPlugin<PrometheusTimeSeriesQuerySpec> = {\n getTimeSeriesData,\n OptionsEditorComponent: PrometheusTimeSeriesQueryEditor,\n createInitialOptions: () => ({\n query: '',\n datasource: undefined,\n }),\n dependsOn: (spec) => {\n // Variables can be used in the query and/or in the legend format string\n const queryVariables = parseTemplateVariables(spec.query);\n const legendVariables = parseTemplateVariables(spec.seriesNameFormat || '');\n const allVariables = [...new Set([...queryVariables, ...legendVariables])];\n return {\n variables: allVariables,\n };\n },\n};\n"],"names":["parseTemplateVariables","getTimeSeriesData","PrometheusTimeSeriesQueryEditor","PrometheusTimeSeriesQuery","OptionsEditorComponent","createInitialOptions","query","datasource","undefined","dependsOn","spec","queryVariables","legendVariables","seriesNameFormat","allVariables","Set","variables"],"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,SAAgCA,sBAAsB,QAAQ,4BAA4B;AAC1F,SAASC,iBAAiB,QAAQ,yBAAyB;AAC3D,SAASC,+BAA+B,QAAQ,oCAAoC;AAGpF;;CAEC,GACD,OAAO,MAAMC,4BAAkF;IAC7FF;IACAG,wBAAwBF;IACxBG,sBAAsB,IAAO,CAAA;YAC3BC,OAAO;YACPC,YAAYC;QACd,CAAA;IACAC,WAAW,CAACC;QACV,wEAAwE;QACxE,MAAMC,iBAAiBX,uBAAuBU,KAAKJ;QACnD,MAAMM,kBAAkBZ,uBAAuBU,KAAKG,oBAAoB;QACxE,MAAMC,eAAe;eAAI,IAAIC,IAAI;mBAAIJ;mBAAmBC;aAAgB;SAAE;QAC1E,OAAO;YACLI,WAAWF;QACb;IACF;AACF,EAAE"}
@@ -1 +1 @@
1
- {"version":3,"file":"PrometheusTimeSeriesQueryEditor.d.ts","sourceRoot":"","sources":["../../../src/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.tsx"],"names":[],"mappings":";AAwBA,OAAO,EAAE,oCAAoC,EAAiC,MAAM,sBAAsB,CAAC;AAE3G;;GAEG;AACH,wBAAgB,+BAA+B,CAAC,KAAK,EAAE,oCAAoC,eAyD1F"}
1
+ {"version":3,"file":"PrometheusTimeSeriesQueryEditor.d.ts","sourceRoot":"","sources":["../../../src/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.tsx"],"names":[],"mappings":";AA2BA,OAAO,EACL,oCAAoC,EAIrC,MAAM,sBAAsB,CAAC;AAE9B;;GAEG;AACH,wBAAgB,+BAA+B,CAAC,KAAK,EAAE,oCAAoC,eA0E1F"}