@perses-dev/prometheus-plugin 0.8.1 → 0.10.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 (86) hide show
  1. package/dist/cjs/index.js +21 -5
  2. package/dist/cjs/model/api-types.js +5 -3
  3. package/dist/cjs/model/index.js +34 -0
  4. package/dist/cjs/model/parse-sample-values.js +22 -16
  5. package/dist/cjs/model/prometheus-client.js +52 -66
  6. package/dist/cjs/model/prometheus-selectors.js +37 -0
  7. package/dist/cjs/model/templating.js +14 -10
  8. package/dist/cjs/model/time.js +35 -49
  9. package/dist/cjs/model/utils.js +21 -13
  10. package/dist/cjs/model/utils.test.js +57 -31
  11. package/dist/cjs/plugins/JSONSpecEditor.js +54 -0
  12. package/dist/cjs/plugins/PrometheusTimeSeriesQueryEditor.js +77 -0
  13. package/dist/cjs/plugins/prometheus-datasource.js +54 -0
  14. package/dist/cjs/plugins/prometheus-variables.js +76 -0
  15. package/dist/cjs/plugins/time-series-query.js +82 -0
  16. package/dist/cjs/plugins/variable.js +43 -0
  17. package/dist/cjs/test/setup-tests.js +4 -2
  18. package/dist/index.d.ts +5 -2
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +21 -1
  21. package/dist/index.js.map +1 -0
  22. package/dist/model/api-types.js +15 -1
  23. package/dist/model/api-types.js.map +1 -0
  24. package/dist/model/index.d.ts +8 -0
  25. package/dist/model/index.d.ts.map +1 -0
  26. package/dist/model/index.js +21 -0
  27. package/dist/model/index.js.map +1 -0
  28. package/dist/model/parse-sample-values.d.ts.map +1 -1
  29. package/dist/model/parse-sample-values.js +44 -1
  30. package/dist/model/parse-sample-values.js.map +1 -0
  31. package/dist/model/prometheus-client.d.ts +14 -11
  32. package/dist/model/prometheus-client.d.ts.map +1 -1
  33. package/dist/model/prometheus-client.js +81 -1
  34. package/dist/model/prometheus-client.js.map +1 -0
  35. package/dist/model/prometheus-selectors.d.ts +22 -0
  36. package/dist/model/prometheus-selectors.d.ts.map +1 -0
  37. package/dist/model/prometheus-selectors.js +30 -0
  38. package/dist/model/prometheus-selectors.js.map +1 -0
  39. package/dist/model/templating.js +21 -1
  40. package/dist/model/templating.js.map +1 -0
  41. package/dist/model/time.d.ts +7 -8
  42. package/dist/model/time.d.ts.map +1 -1
  43. package/dist/model/time.js +49 -1
  44. package/dist/model/time.js.map +1 -0
  45. package/dist/model/utils.d.ts +2 -1
  46. package/dist/model/utils.d.ts.map +1 -1
  47. package/dist/model/utils.js +55 -1
  48. package/dist/model/utils.js.map +1 -0
  49. package/dist/model/utils.test.js +110 -1
  50. package/dist/model/utils.test.js.map +1 -0
  51. package/dist/plugins/JSONSpecEditor.d.ts +4 -0
  52. package/dist/plugins/JSONSpecEditor.d.ts.map +1 -0
  53. package/dist/plugins/JSONSpecEditor.js +48 -0
  54. package/dist/plugins/JSONSpecEditor.js.map +1 -0
  55. package/dist/plugins/PrometheusTimeSeriesQueryEditor.d.ts +6 -0
  56. package/dist/plugins/PrometheusTimeSeriesQueryEditor.d.ts.map +1 -0
  57. package/dist/plugins/PrometheusTimeSeriesQueryEditor.js +66 -0
  58. package/dist/plugins/PrometheusTimeSeriesQueryEditor.js.map +1 -0
  59. package/dist/plugins/prometheus-datasource.d.ts +7 -0
  60. package/dist/plugins/prometheus-datasource.d.ts.map +1 -0
  61. package/dist/plugins/prometheus-datasource.js +48 -0
  62. package/dist/plugins/prometheus-datasource.js.map +1 -0
  63. package/dist/plugins/prometheus-variables.d.ts +16 -0
  64. package/dist/plugins/prometheus-variables.d.ts.map +1 -0
  65. package/dist/plugins/prometheus-variables.js +64 -0
  66. package/dist/plugins/prometheus-variables.js.map +1 -0
  67. package/dist/plugins/time-series-query.d.ts +14 -0
  68. package/dist/plugins/time-series-query.d.ts.map +1 -0
  69. package/dist/plugins/time-series-query.js +78 -0
  70. package/dist/plugins/time-series-query.js.map +1 -0
  71. package/dist/plugins/variable.d.ts +8 -0
  72. package/dist/plugins/variable.d.ts.map +1 -0
  73. package/dist/plugins/variable.js +37 -0
  74. package/dist/plugins/variable.js.map +1 -0
  75. package/dist/test/setup-tests.js +15 -1
  76. package/dist/test/setup-tests.js.map +1 -0
  77. package/package.json +11 -8
  78. package/plugin.json +17 -9
  79. package/dist/cjs/model/datasource.js +0 -36
  80. package/dist/cjs/plugins/graph-query.js +0 -84
  81. package/dist/model/datasource.d.ts +0 -11
  82. package/dist/model/datasource.d.ts.map +0 -1
  83. package/dist/model/datasource.js +0 -1
  84. package/dist/plugins/graph-query.d.ts +0 -14
  85. package/dist/plugins/graph-query.d.ts.map +0 -1
  86. package/dist/plugins/graph-query.js +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/model/utils.test.ts"],"sourcesContent":["// Copyright 2022 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 { parseTemplateVariables, replaceTemplateVariable, replaceTemplateVariables } from './utils';\n\ndescribe('parseTemplateVariables()', () => {\n const tests = [\n {\n text: 'hello $var1 world $var2',\n variables: ['var1', 'var2'],\n },\n ];\n\n tests.forEach(({ text, variables }) => {\n it(`parses ${text}`, () => {\n expect(parseTemplateVariables(text)).toEqual(variables);\n });\n });\n});\n\ndescribe('replaceTemplateVariable()', () => {\n const tests = [\n {\n text: 'hello $var1',\n varName: 'var1',\n value: 'world',\n expected: 'hello world',\n },\n {\n text: 'hello $var1 $var1',\n varName: 'var1',\n value: 'world',\n expected: 'hello world world',\n },\n {\n text: 'hello $var1',\n varName: 'var1',\n value: ['world', 'w'],\n expected: 'hello (world|w)',\n },\n {\n text: 'hello $var1 $var1',\n varName: 'var1',\n value: ['world', 'w'],\n expected: 'hello (world|w) (world|w)',\n },\n ];\n\n tests.forEach(({ text, value, varName, expected }) => {\n it(`replaces ${text} ${value}`, () => {\n expect(replaceTemplateVariable(text, varName, value)).toEqual(expected);\n });\n });\n});\n\ndescribe('replaceTemplateVariables()', () => {\n const tests = [\n {\n text: 'hello $var1 $var2',\n state: {\n var1: { value: 'world', loading: false },\n var2: { value: 'world', loading: false },\n },\n expected: 'hello world world',\n },\n {\n text: 'hello $var1 $var2',\n state: {\n var1: { value: 'world', loading: false },\n var2: { value: ['a', 'b'], loading: false },\n },\n expected: 'hello world (a|b)',\n },\n ];\n\n tests.forEach(({ text, state, expected }) => {\n it(`replaces ${text} ${JSON.stringify(state)}`, () => {\n expect(replaceTemplateVariables(text, state)).toEqual(expected);\n });\n });\n});\n"],"names":["parseTemplateVariables","replaceTemplateVariable","replaceTemplateVariables","describe","tests","text","variables","forEach","it","expect","toEqual","varName","value","expected","state","var1","loading","var2","JSON","stringify"],"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,SAASA,sBAAsB,EAAEC,uBAAuB,EAAEC,wBAAwB,QAAQ,SAAS,CAAC;AAEpGC,QAAQ,CAAC,0BAA0B,EAAE,IAAM;IACzC,MAAMC,KAAK,GAAG;QACZ;YACEC,IAAI,EAAE,yBAAyB;YAC/BC,SAAS,EAAE;gBAAC,MAAM;gBAAE,MAAM;aAAC;SAC5B;KACF,AAAC;IAEFF,KAAK,CAACG,OAAO,CAAC,CAAC,EAAEF,IAAI,CAAA,EAAEC,SAAS,CAAA,EAAE,GAAK;QACrCE,EAAE,CAAC,CAAC,OAAO,EAAEH,IAAI,CAAC,CAAC,EAAE,IAAM;YACzBI,MAAM,CAACT,sBAAsB,CAACK,IAAI,CAAC,CAAC,CAACK,OAAO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H,KAAK,EAAE,OAAO;oBAAEI,OAAO,EAAE,KAAK;iBAAE;gBACxCC,IAAI,EAAE;oBAAEL,KAAK,EAAE,OAAO;oBAAEI,OAAO,EAAE,KAAK;iBAAE;aACzC;YACDH,QAAQ,EAAE,mBAAmB;SAC9B;QACD;YACER,IAAI,EAAE,mBAAmB;YACzBS,KAAK,EAAE;gBACLC,IAAI,EAAE;oBAAEH,KAAK,EAAE,OAAO;oBAAEI,OAAO,EAAE,KAAK;iBAAE;gBACxCC,IAAI,EAAE;oBAAEL,KAAK,EAAE;wBAAC,GAAG;wBAAE,GAAG;qBAAC;oBAAEI,OAAO,EAAE,KAAK;iBAAE;aAC5C;YACDH,QAAQ,EAAE,mBAAmB;SAC9B;KACF,AAAC;IAEFT,KAAK,CAACG,OAAO,CAAC,CAAC,EAAEF,IAAI,CAAA,EAAES,KAAK,CAAA,EAAED,QAAQ,CAAA,EAAE,GAAK;QAC3CL,EAAE,CAAC,CAAC,SAAS,EAAEH,IAAI,CAAC,CAAC,EAAEa,IAAI,CAACC,SAAS,CAACL,KAAK,CAAC,CAAC,CAAC,EAAE,IAAM;YACpDL,MAAM,CAACP,wBAAwB,CAACG,IAAI,EAAES,KAAK,CAAC,CAAC,CAACJ,OAAO,CAACG,QAAQ,CAAC,CAAC;QAClE,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ import { OptionsEditorProps } from '@perses-dev/plugin-system';
3
+ export declare function JSONSpecEditor<T>(props: OptionsEditorProps<T>): JSX.Element;
4
+ //# sourceMappingURL=JSONSpecEditor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JSONSpecEditor.d.ts","sourceRoot":"","sources":["../../src/plugins/JSONSpecEditor.tsx"],"names":[],"mappings":";AAeA,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAE/D,wBAAgB,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,kBAAkB,CAAC,CAAC,CAAC,eAgC7D"}
@@ -0,0 +1,48 @@
1
+ // Copyright 2022 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 } from "react/jsx-runtime";
14
+ import { useEffect, useRef, useState } from 'react';
15
+ import { TextField } from '@mui/material';
16
+ export function JSONSpecEditor(props) {
17
+ const ref = useRef(null);
18
+ const [value, setValue] = useState(JSON.stringify(props.value, null, 2));
19
+ const [invalidJSON, setInvalidJSON] = useState(false);
20
+ useEffect(()=>{
21
+ setValue(JSON.stringify(props.value, null, 2));
22
+ setInvalidJSON(false);
23
+ }, [
24
+ props.value
25
+ ]);
26
+ return /*#__PURE__*/ _jsx(TextField, {
27
+ label: "JSON",
28
+ error: invalidJSON,
29
+ helperText: invalidJSON ? 'Invalid JSON' : '',
30
+ multiline: true,
31
+ inputRef: ref,
32
+ value: value,
33
+ onChange: (event)=>{
34
+ setValue(event.target.value);
35
+ },
36
+ onBlur: ()=>{
37
+ try {
38
+ const json = JSON.parse(value !== null && value !== void 0 ? value : '{}');
39
+ setInvalidJSON(false);
40
+ props.onChange(json);
41
+ } catch (e) {
42
+ setInvalidJSON(true);
43
+ }
44
+ }
45
+ });
46
+ }
47
+
48
+ //# sourceMappingURL=JSONSpecEditor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/plugins/JSONSpecEditor.tsx"],"sourcesContent":["// Copyright 2022 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 { useEffect, useRef, useState } from 'react';\nimport { TextField } from '@mui/material';\nimport { OptionsEditorProps } from '@perses-dev/plugin-system';\n\nexport function JSONSpecEditor<T>(props: OptionsEditorProps<T>) {\n const ref = useRef<HTMLInputElement>(null);\n const [value, setValue] = useState(JSON.stringify(props.value, null, 2));\n const [invalidJSON, setInvalidJSON] = useState(false);\n\n useEffect(() => {\n setValue(JSON.stringify(props.value, null, 2));\n setInvalidJSON(false);\n }, [props.value]);\n\n return (\n <TextField\n label=\"JSON\"\n error={invalidJSON}\n helperText={invalidJSON ? 'Invalid JSON' : ''}\n multiline\n inputRef={ref}\n value={value}\n onChange={(event) => {\n setValue(event.target.value);\n }}\n onBlur={() => {\n try {\n const json = JSON.parse(value ?? '{}');\n setInvalidJSON(false);\n props.onChange(json);\n } catch (e) {\n setInvalidJSON(true);\n }\n }}\n />\n );\n}\n"],"names":["useEffect","useRef","useState","TextField","JSONSpecEditor","props","ref","value","setValue","JSON","stringify","invalidJSON","setInvalidJSON","label","error","helperText","multiline","inputRef","onChange","event","target","onBlur","json","parse","e"],"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;AAAA,SAASA,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO,CAAC;AACpD,SAASC,SAAS,QAAQ,eAAe,CAAC;AAG1C,OAAO,SAASC,cAAc,CAAIC,KAA4B,EAAE;IAC9D,MAAMC,GAAG,GAAGL,MAAM,CAAmB,IAAI,CAAC,AAAC;IAC3C,MAAM,CAACM,KAAK,EAAEC,QAAQ,CAAC,GAAGN,QAAQ,CAACO,IAAI,CAACC,SAAS,CAACL,KAAK,CAACE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,AAAC;IACzE,MAAM,CAACI,WAAW,EAAEC,cAAc,CAAC,GAAGV,QAAQ,CAAC,KAAK,CAAC,AAAC;IAEtDF,SAAS,CAAC,IAAM;QACdQ,QAAQ,CAACC,IAAI,CAACC,SAAS,CAACL,KAAK,CAACE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;QAC/CK,cAAc,CAAC,KAAK,CAAC,CAAC;IACxB,CAAC,EAAE;QAACP,KAAK,CAACE,KAAK;KAAC,CAAC,CAAC;IAElB,qBACE,KAACJ,SAAS;QACRU,KAAK,EAAC,MAAM;QACZC,KAAK,EAAEH,WAAW;QAClBI,UAAU,EAAEJ,WAAW,GAAG,cAAc,GAAG,EAAE;QAC7CK,SAAS;QACTC,QAAQ,EAAEX,GAAG;QACbC,KAAK,EAAEA,KAAK;QACZW,QAAQ,EAAE,CAACC,KAAK,GAAK;YACnBX,QAAQ,CAACW,KAAK,CAACC,MAAM,CAACb,KAAK,CAAC,CAAC;QAC/B,CAAC;QACDc,MAAM,EAAE,IAAM;YACZ,IAAI;gBACF,MAAMC,IAAI,GAAGb,IAAI,CAACc,KAAK,CAAChB,KAAK,aAALA,KAAK,cAALA,KAAK,GAAI,IAAI,CAAC,AAAC;gBACvCK,cAAc,CAAC,KAAK,CAAC,CAAC;gBACtBP,KAAK,CAACa,QAAQ,CAACI,IAAI,CAAC,CAAC;YACvB,EAAE,OAAOE,CAAC,EAAE;gBACVZ,cAAc,CAAC,IAAI,CAAC,CAAC;YACvB,CAAC;QACH,CAAC;MACD,CACF;AACJ,CAAC"}
@@ -0,0 +1,6 @@
1
+ /// <reference types="react" />
2
+ import { OptionsEditorProps } from '@perses-dev/plugin-system';
3
+ import { PrometheusTimeSeriesQuerySpec } from './time-series-query';
4
+ export declare type PrometheusTimeSeriesQueryEditorProps = OptionsEditorProps<PrometheusTimeSeriesQuerySpec>;
5
+ export declare function PrometheusTimeSeriesQueryEditor(props: PrometheusTimeSeriesQueryEditorProps): JSX.Element;
6
+ //# sourceMappingURL=PrometheusTimeSeriesQueryEditor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PrometheusTimeSeriesQueryEditor.d.ts","sourceRoot":"","sources":["../../src/plugins/PrometheusTimeSeriesQueryEditor.tsx"],"names":[],"mappings":";AAgBA,OAAO,EAAE,kBAAkB,EAA2C,MAAM,2BAA2B,CAAC;AAExG,OAAO,EAAE,6BAA6B,EAAE,MAAM,qBAAqB,CAAC;AAEpE,oBAAY,oCAAoC,GAAG,kBAAkB,CAAC,6BAA6B,CAAC,CAAC;AAErG,wBAAgB,+BAA+B,CAAC,KAAK,EAAE,oCAAoC,eA4C1F"}
@@ -0,0 +1,66 @@
1
+ // Copyright 2022 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 } from "react/jsx-runtime";
14
+ import produce from 'immer';
15
+ import { Box, TextField, FormControl, InputLabel } from '@mui/material';
16
+ import { DatasourceSelect } from '@perses-dev/plugin-system';
17
+ import { DEFAULT_PROM, isDefaultPromSelector, isPrometheusDatasourceSelector } from '../model';
18
+ export function PrometheusTimeSeriesQueryEditor(props) {
19
+ const { onChange , value } = props;
20
+ const { query , datasource } = value;
21
+ const handleQueryChange = (e)=>{
22
+ onChange(produce(value, (draft)=>{
23
+ draft.query = e.target.value;
24
+ }));
25
+ };
26
+ const handleDatasourceChange = (next)=>{
27
+ if (isPrometheusDatasourceSelector(next)) {
28
+ onChange(produce(value, (draft)=>{
29
+ // If they're using the default, just omit the datasource prop (i.e. set to undefined)
30
+ const nextDatasource = isDefaultPromSelector(next) ? undefined : next;
31
+ draft.datasource = nextDatasource;
32
+ }));
33
+ return;
34
+ }
35
+ throw new Error('Got unexpected non-Prometheus datasource selector');
36
+ };
37
+ return /*#__PURE__*/ _jsxs(Box, {
38
+ children: [
39
+ /*#__PURE__*/ _jsx(TextField, {
40
+ label: "Query",
41
+ value: query,
42
+ onChange: handleQueryChange,
43
+ margin: "dense"
44
+ }),
45
+ /*#__PURE__*/ _jsxs(FormControl, {
46
+ margin: "dense",
47
+ fullWidth: false,
48
+ children: [
49
+ /*#__PURE__*/ _jsx(InputLabel, {
50
+ id: "prom-datasource-label",
51
+ children: "Prometheus Datasource"
52
+ }),
53
+ /*#__PURE__*/ _jsx(DatasourceSelect, {
54
+ datasourcePluginKind: "PrometheusDatasource",
55
+ value: datasource !== null && datasource !== void 0 ? datasource : DEFAULT_PROM,
56
+ onChange: handleDatasourceChange,
57
+ labelId: "prom-datasource-label",
58
+ label: "Prometheus Datasource"
59
+ })
60
+ ]
61
+ })
62
+ ]
63
+ });
64
+ }
65
+
66
+ //# sourceMappingURL=PrometheusTimeSeriesQueryEditor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/plugins/PrometheusTimeSeriesQueryEditor.tsx"],"sourcesContent":["// Copyright 2022 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 { ChangeEvent } from 'react';\nimport produce from 'immer';\nimport { Box, TextField, FormControl, InputLabel } from '@mui/material';\nimport { OptionsEditorProps, DatasourceSelect, DatasourceSelectProps } from '@perses-dev/plugin-system';\nimport { DEFAULT_PROM, isDefaultPromSelector, isPrometheusDatasourceSelector } from '../model';\nimport { PrometheusTimeSeriesQuerySpec } from './time-series-query';\n\nexport type PrometheusTimeSeriesQueryEditorProps = OptionsEditorProps<PrometheusTimeSeriesQuerySpec>;\n\nexport function PrometheusTimeSeriesQueryEditor(props: PrometheusTimeSeriesQueryEditorProps) {\n const { onChange, value } = props;\n const { query, datasource } = value;\n\n const handleQueryChange = (e: ChangeEvent<HTMLInputElement>) => {\n onChange(\n produce(value, (draft) => {\n draft.query = e.target.value;\n })\n );\n };\n\n const handleDatasourceChange: DatasourceSelectProps['onChange'] = (next) => {\n if (isPrometheusDatasourceSelector(next)) {\n onChange(\n produce(value, (draft) => {\n // If they're using the default, just omit the datasource prop (i.e. set to undefined)\n const nextDatasource = isDefaultPromSelector(next) ? undefined : next;\n draft.datasource = nextDatasource;\n })\n );\n return;\n }\n\n throw new Error('Got unexpected non-Prometheus datasource selector');\n };\n\n return (\n <Box>\n <TextField label=\"Query\" value={query} onChange={handleQueryChange} margin=\"dense\" />\n <FormControl margin=\"dense\" fullWidth={false}>\n {/* TODO: How do we ensure unique ID values if there are multiple of these? Can we use React 18 useId and\n maintain 17 compatibility somehow with a polyfill/shim? */}\n <InputLabel id=\"prom-datasource-label\">Prometheus Datasource</InputLabel>\n <DatasourceSelect\n datasourcePluginKind=\"PrometheusDatasource\"\n value={datasource ?? DEFAULT_PROM}\n onChange={handleDatasourceChange}\n labelId=\"prom-datasource-label\"\n label=\"Prometheus Datasource\"\n />\n </FormControl>\n </Box>\n );\n}\n"],"names":["produce","Box","TextField","FormControl","InputLabel","DatasourceSelect","DEFAULT_PROM","isDefaultPromSelector","isPrometheusDatasourceSelector","PrometheusTimeSeriesQueryEditor","props","onChange","value","query","datasource","handleQueryChange","e","draft","target","handleDatasourceChange","next","nextDatasource","undefined","Error","label","margin","fullWidth","id","datasourcePluginKind","labelId"],"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;AACA,OAAOA,OAAO,MAAM,OAAO,CAAC;AAC5B,SAASC,GAAG,EAAEC,SAAS,EAAEC,WAAW,EAAEC,UAAU,QAAQ,eAAe,CAAC;AACxE,SAA6BC,gBAAgB,QAA+B,2BAA2B,CAAC;AACxG,SAASC,YAAY,EAAEC,qBAAqB,EAAEC,8BAA8B,QAAQ,UAAU,CAAC;AAK/F,OAAO,SAASC,+BAA+B,CAACC,KAA2C,EAAE;IAC3F,MAAM,EAAEC,QAAQ,CAAA,EAAEC,KAAK,CAAA,EAAE,GAAGF,KAAK,AAAC;IAClC,MAAM,EAAEG,KAAK,CAAA,EAAEC,UAAU,CAAA,EAAE,GAAGF,KAAK,AAAC;IAEpC,MAAMG,iBAAiB,GAAG,CAACC,CAAgC,GAAK;QAC9DL,QAAQ,CACNX,OAAO,CAACY,KAAK,EAAE,CAACK,KAAK,GAAK;YACxBA,KAAK,CAACJ,KAAK,GAAGG,CAAC,CAACE,MAAM,CAACN,KAAK,CAAC;QAC/B,CAAC,CAAC,CACH,CAAC;IACJ,CAAC,AAAC;IAEF,MAAMO,sBAAsB,GAAsC,CAACC,IAAI,GAAK;QAC1E,IAAIZ,8BAA8B,CAACY,IAAI,CAAC,EAAE;YACxCT,QAAQ,CACNX,OAAO,CAACY,KAAK,EAAE,CAACK,KAAK,GAAK;gBACxB,sFAAsF;gBACtF,MAAMI,cAAc,GAAGd,qBAAqB,CAACa,IAAI,CAAC,GAAGE,SAAS,GAAGF,IAAI,AAAC;gBACtEH,KAAK,CAACH,UAAU,GAAGO,cAAc,CAAC;YACpC,CAAC,CAAC,CACH,CAAC;YACF,OAAO;QACT,CAAC;QAED,MAAM,IAAIE,KAAK,CAAC,mDAAmD,CAAC,CAAC;IACvE,CAAC,AAAC;IAEF,qBACE,MAACtB,GAAG;;0BACF,KAACC,SAAS;gBAACsB,KAAK,EAAC,OAAO;gBAACZ,KAAK,EAAEC,KAAK;gBAAEF,QAAQ,EAAEI,iBAAiB;gBAAEU,MAAM,EAAC,OAAO;cAAG;0BACrF,MAACtB,WAAW;gBAACsB,MAAM,EAAC,OAAO;gBAACC,SAAS,EAAE,KAAK;;kCAG1C,KAACtB,UAAU;wBAACuB,EAAE,EAAC,uBAAuB;kCAAC,uBAAqB;sBAAa;kCACzE,KAACtB,gBAAgB;wBACfuB,oBAAoB,EAAC,sBAAsB;wBAC3ChB,KAAK,EAAEE,UAAU,aAAVA,UAAU,cAAVA,UAAU,GAAIR,YAAY;wBACjCK,QAAQ,EAAEQ,sBAAsB;wBAChCU,OAAO,EAAC,uBAAuB;wBAC/BL,KAAK,EAAC,uBAAuB;sBAC7B;;cACU;;MACV,CACN;AACJ,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { DatasourcePlugin } from '@perses-dev/plugin-system';
2
+ import { PrometheusClient } from '../model';
3
+ export interface PrometheusDatasourceSpec {
4
+ direct_url?: string;
5
+ }
6
+ export declare const PrometheusDatasource: DatasourcePlugin<PrometheusDatasourceSpec, PrometheusClient>;
7
+ //# sourceMappingURL=prometheus-datasource.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prometheus-datasource.d.ts","sourceRoot":"","sources":["../../src/plugins/prometheus-datasource.ts"],"names":[],"mappings":"AAaA,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;CACrB;AAwBD,eAAO,MAAM,oBAAoB,EAAE,gBAAgB,CAAC,wBAAwB,EAAE,gBAAgB,CAI7F,CAAC"}
@@ -0,0 +1,48 @@
1
+ // Copyright 2022 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 { instantQuery, rangeQuery, labelNames, labelValues } from '../model';
14
+ /**
15
+ * Creates a PrometheusClient for a specific datasource spec.
16
+ */ const createClient = (spec, options)=>{
17
+ const { direct_url } = spec;
18
+ const { proxyUrl } = options;
19
+ // 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
+ 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
+ }
24
+ // Could think about this becoming a class, although it definitely doesn't have to be
25
+ return {
26
+ instantQuery: (params)=>instantQuery(params, {
27
+ datasourceUrl
28
+ }),
29
+ rangeQuery: (params)=>rangeQuery(params, {
30
+ datasourceUrl
31
+ }),
32
+ labelNames: (params)=>labelNames(params, {
33
+ datasourceUrl
34
+ }),
35
+ labelValues: (params)=>labelValues(params, {
36
+ datasourceUrl
37
+ })
38
+ };
39
+ };
40
+ export const PrometheusDatasource = {
41
+ createClient,
42
+ OptionsEditorComponent: ()=>null,
43
+ createInitialOptions: ()=>({
44
+ direct_url: ''
45
+ })
46
+ };
47
+
48
+ //# sourceMappingURL=prometheus-datasource.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/plugins/prometheus-datasource.ts"],"sourcesContent":["// Copyright 2022 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 { DatasourcePlugin } from '@perses-dev/plugin-system';\nimport { instantQuery, rangeQuery, labelNames, labelValues, PrometheusClient } from '../model';\n\nexport interface PrometheusDatasourceSpec {\n direct_url?: string;\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 } = 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 instantQuery: (params) => instantQuery(params, { datasourceUrl }),\n rangeQuery: (params) => rangeQuery(params, { datasourceUrl }),\n labelNames: (params) => labelNames(params, { datasourceUrl }),\n labelValues: (params) => labelValues(params, { datasourceUrl }),\n };\n};\n\nexport const PrometheusDatasource: DatasourcePlugin<PrometheusDatasourceSpec, PrometheusClient> = {\n createClient,\n OptionsEditorComponent: () => null,\n createInitialOptions: () => ({ direct_url: '' }),\n};\n"],"names":["instantQuery","rangeQuery","labelNames","labelValues","createClient","spec","options","direct_url","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;AAGjC,SAASA,YAAY,EAAEC,UAAU,EAAEC,UAAU,EAAEC,WAAW,QAA0B,UAAU,CAAC;AAM/F;;CAEC,GACD,MAAMC,YAAY,GAAiF,CAACC,IAAI,EAAEC,OAAO,GAAK;IACpH,MAAM,EAAEC,UAAU,CAAA,EAAE,GAAGF,IAAI,AAAC;IAC5B,MAAM,EAAEG,QAAQ,CAAA,EAAE,GAAGF,OAAO,AAAC;IAE7B,4FAA4F;IAC5F,MAAMG,aAAa,GAAGF,UAAU,aAAVA,UAAU,cAAVA,UAAU,GAAIC,QAAQ,AAAC;IAC7C,IAAIC,aAAa,KAAKC,SAAS,EAAE;QAC/B,MAAM,IAAIC,KAAK,CAAC,6FAA6F,CAAC,CAAC;IACjH,CAAC;IAED,qFAAqF;IACrF,OAAO;QACLX,YAAY,EAAE,CAACY,MAAM,GAAKZ,YAAY,CAACY,MAAM,EAAE;gBAAEH,aAAa;aAAE,CAAC;QACjER,UAAU,EAAE,CAACW,MAAM,GAAKX,UAAU,CAACW,MAAM,EAAE;gBAAEH,aAAa;aAAE,CAAC;QAC7DP,UAAU,EAAE,CAACU,MAAM,GAAKV,UAAU,CAACU,MAAM,EAAE;gBAAEH,aAAa;aAAE,CAAC;QAC7DN,WAAW,EAAE,CAACS,MAAM,GAAKT,WAAW,CAACS,MAAM,EAAE;gBAAEH,aAAa;aAAE,CAAC;KAChE,CAAC;AACJ,CAAC,AAAC;AAEF,OAAO,MAAMI,oBAAoB,GAAiE;IAChGT,YAAY;IACZU,sBAAsB,EAAE,IAAM,IAAI;IAClCC,oBAAoB,EAAE,IAAO,CAAA;YAAER,UAAU,EAAE,EAAE;SAAE,CAAA,AAAC;CACjD,CAAC"}
@@ -0,0 +1,16 @@
1
+ import { VariablePlugin } from '@perses-dev/plugin-system';
2
+ import { PrometheusDatasourceSelector } from '../model';
3
+ interface PrometheusVariableOptionsBase {
4
+ datasource?: PrometheusDatasourceSelector;
5
+ }
6
+ declare type PrometheusLabelNamesVariableOptions = PrometheusVariableOptionsBase & {
7
+ matchers?: [string];
8
+ };
9
+ declare type PrometheusLabelValuesVariableOptions = PrometheusVariableOptionsBase & {
10
+ label_name: string;
11
+ matchers?: [string];
12
+ };
13
+ export declare const PrometheusLabelNamesVariable: VariablePlugin<PrometheusLabelNamesVariableOptions>;
14
+ export declare const PrometheusLabelValuesVariable: VariablePlugin<PrometheusLabelValuesVariableOptions>;
15
+ export {};
16
+ //# sourceMappingURL=prometheus-variables.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prometheus-variables.d.ts","sourceRoot":"","sources":["../../src/plugins/prometheus-variables.tsx"],"names":[],"mappings":"AAYA,OAAO,EAAE,cAAc,EAAkB,MAAM,2BAA2B,CAAC;AAC3E,OAAO,EAKL,4BAA4B,EAC7B,MAAM,UAAU,CAAC;AAGlB,UAAU,6BAA6B;IACrC,UAAU,CAAC,EAAE,4BAA4B,CAAC;CAC3C;AAED,aAAK,mCAAmC,GAAG,6BAA6B,GAAG;IACzE,QAAQ,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC;CACrB,CAAC;AAEF,aAAK,oCAAoC,GAAG,6BAA6B,GAAG;IAC1E,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC;CACrB,CAAC;AAaF,eAAO,MAAM,4BAA4B,EAAE,cAAc,CAAC,mCAAmC,CAY5F,CAAC;AAEF,eAAO,MAAM,6BAA6B,EAAE,cAAc,CAAC,oCAAoC,CAiB9F,CAAC"}
@@ -0,0 +1,64 @@
1
+ // Copyright 2022 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 { replaceTemplateVariables, parseTemplateVariables, DEFAULT_PROM } from '../model';
14
+ import { JSONSpecEditor } from './JSONSpecEditor';
15
+ /**
16
+ * Takes a list of strings and returns a list of VariableOptions
17
+ */ const stringArrayToVariableOptions = (values)=>{
18
+ if (!values) return [];
19
+ return values.map((value)=>({
20
+ value,
21
+ label: value
22
+ }));
23
+ };
24
+ export const PrometheusLabelNamesVariable = {
25
+ getVariableOptions: async (spec, ctx)=>{
26
+ var _datasource;
27
+ const client = await ctx.datasourceStore.getDatasourceClient((_datasource = spec.datasource) !== null && _datasource !== void 0 ? _datasource : DEFAULT_PROM);
28
+ const match = spec.matchers ? spec.matchers.map((m)=>replaceTemplateVariables(m, ctx.variables)) : undefined;
29
+ const { data: options } = await client.labelNames({
30
+ 'match[]': match
31
+ });
32
+ return {
33
+ data: stringArrayToVariableOptions(options)
34
+ };
35
+ },
36
+ dependsOn: ()=>[],
37
+ OptionsEditorComponent: JSONSpecEditor,
38
+ createInitialOptions: ()=>({})
39
+ };
40
+ export const PrometheusLabelValuesVariable = {
41
+ getVariableOptions: async (spec, ctx)=>{
42
+ const pluginDef = spec;
43
+ var _datasource;
44
+ const client = await ctx.datasourceStore.getDatasourceClient((_datasource = spec.datasource) !== null && _datasource !== void 0 ? _datasource : DEFAULT_PROM);
45
+ const match = pluginDef.matchers ? pluginDef.matchers.map((m)=>replaceTemplateVariables(m, ctx.variables)) : undefined;
46
+ const { data: options } = await client.labelValues({
47
+ labelName: pluginDef.label_name,
48
+ 'match[]': match
49
+ });
50
+ return {
51
+ data: stringArrayToVariableOptions(options)
52
+ };
53
+ },
54
+ dependsOn: (spec)=>{
55
+ var ref;
56
+ return ((ref = spec.matchers) === null || ref === void 0 ? void 0 : ref.map((m)=>parseTemplateVariables(m)).flat()) || [];
57
+ },
58
+ OptionsEditorComponent: JSONSpecEditor,
59
+ createInitialOptions: ()=>({
60
+ label_name: ''
61
+ })
62
+ };
63
+
64
+ //# sourceMappingURL=prometheus-variables.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/plugins/prometheus-variables.tsx"],"sourcesContent":["// Copyright 2022 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.\nimport { VariablePlugin, VariableOption } from '@perses-dev/plugin-system';\nimport {\n replaceTemplateVariables,\n parseTemplateVariables,\n PrometheusClient,\n DEFAULT_PROM,\n PrometheusDatasourceSelector,\n} from '../model';\nimport { JSONSpecEditor } from './JSONSpecEditor';\n\ninterface PrometheusVariableOptionsBase {\n datasource?: PrometheusDatasourceSelector;\n}\n\ntype PrometheusLabelNamesVariableOptions = PrometheusVariableOptionsBase & {\n matchers?: [string];\n};\n\ntype PrometheusLabelValuesVariableOptions = PrometheusVariableOptionsBase & {\n label_name: string;\n matchers?: [string];\n};\n\n/**\n * Takes a list of strings and returns a list of VariableOptions\n */\nconst stringArrayToVariableOptions = (values?: string[]): VariableOption[] => {\n if (!values) return [];\n return values.map((value) => ({\n value,\n label: value,\n }));\n};\n\nexport const PrometheusLabelNamesVariable: VariablePlugin<PrometheusLabelNamesVariableOptions> = {\n getVariableOptions: async (spec, ctx) => {\n const client: PrometheusClient = await ctx.datasourceStore.getDatasourceClient(spec.datasource ?? DEFAULT_PROM);\n const match = spec.matchers ? spec.matchers.map((m) => replaceTemplateVariables(m, ctx.variables)) : undefined;\n const { data: options } = await client.labelNames({ 'match[]': match });\n return {\n data: stringArrayToVariableOptions(options),\n };\n },\n dependsOn: () => [],\n OptionsEditorComponent: JSONSpecEditor,\n createInitialOptions: () => ({}),\n};\n\nexport const PrometheusLabelValuesVariable: VariablePlugin<PrometheusLabelValuesVariableOptions> = {\n getVariableOptions: async (spec, ctx) => {\n const pluginDef = spec;\n const client: PrometheusClient = await ctx.datasourceStore.getDatasourceClient(spec.datasource ?? DEFAULT_PROM);\n const match = pluginDef.matchers\n ? pluginDef.matchers.map((m) => replaceTemplateVariables(m, ctx.variables))\n : undefined;\n const { data: options } = await client.labelValues({ labelName: pluginDef.label_name, 'match[]': match });\n return {\n data: stringArrayToVariableOptions(options),\n };\n },\n dependsOn: (spec) => {\n return spec.matchers?.map((m) => parseTemplateVariables(m)).flat() || [];\n },\n OptionsEditorComponent: JSONSpecEditor,\n createInitialOptions: () => ({ label_name: '' }),\n};\n"],"names":["replaceTemplateVariables","parseTemplateVariables","DEFAULT_PROM","JSONSpecEditor","stringArrayToVariableOptions","values","map","value","label","PrometheusLabelNamesVariable","getVariableOptions","spec","ctx","client","datasourceStore","getDatasourceClient","datasource","match","matchers","m","variables","undefined","data","options","labelNames","dependsOn","OptionsEditorComponent","createInitialOptions","PrometheusLabelValuesVariable","pluginDef","labelValues","labelName","label_name","flat"],"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,SACEA,wBAAwB,EACxBC,sBAAsB,EAEtBC,YAAY,QAEP,UAAU,CAAC;AAClB,SAASC,cAAc,QAAQ,kBAAkB,CAAC;AAelD;;CAEC,GACD,MAAMC,4BAA4B,GAAG,CAACC,MAAiB,GAAuB;IAC5E,IAAI,CAACA,MAAM,EAAE,OAAO,EAAE,CAAC;IACvB,OAAOA,MAAM,CAACC,GAAG,CAAC,CAACC,KAAK,GAAM,CAAA;YAC5BA,KAAK;YACLC,KAAK,EAAED,KAAK;SACb,CAAA,AAAC,CAAC,CAAC;AACN,CAAC,AAAC;AAEF,OAAO,MAAME,4BAA4B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ACQ,SAAS,CAAC,CAAC,GACzEC,SAAS,AAAC;QACd,MAAM,EAAEC,IAAI,EAAEC,OAAO,CAAA,EAAE,GAAG,MAAMV,MAAM,CAACiB,WAAW,CAAC;YAAEC,SAAS,EAAEF,SAAS,CAACG,UAAU;YAAE,SAAS,EAAEf,KAAK;SAAE,CAAC,AAAC;QAC1G,OAAO;YACLK,IAAI,EAAElB,4BAA4B,CAACmB,OAAO,CAAC;SAC5C,CAAC;IACJ,CAAC;IACDE,SAAS,EAAE,CAACd,IAAI,GAAK;YACZA,GAAa;QAApB,OAAOA,CAAAA,CAAAA,GAAa,GAAbA,IAAI,CAACO,QAAQ,cAAbP,GAAa,WAAK,GAAlBA,KAAAA,CAAkB,GAAlBA,GAAa,CAAEL,GAAG,CAAC,CAACa,CAAC,GAAKlB,sBAAsB,CAACkB,CAAC,CAAC,CAAC,CAACc,IAAI,EAAE,CAAA,IAAI,EAAE,CAAC;IAC3E,CAAC;IACDP,sBAAsB,EAAEvB,cAAc;IACtCwB,oBAAoB,EAAE,IAAO,CAAA;YAAEK,UAAU,EAAE,EAAE;SAAE,CAAA,AAAC;CACjD,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { DurationString } from '@perses-dev/core';
2
+ import { TimeSeriesQueryPlugin } from '@perses-dev/plugin-system';
3
+ import { PrometheusDatasourceSelector, TemplateString } from '../model';
4
+ export interface PrometheusTimeSeriesQuerySpec {
5
+ query: TemplateString;
6
+ min_step?: DurationString;
7
+ resolution?: number;
8
+ datasource?: PrometheusDatasourceSelector;
9
+ }
10
+ /**
11
+ * The core Prometheus TimeSeriesQuery plugin for Perses.
12
+ */
13
+ export declare const PrometheusTimeSeriesQuery: TimeSeriesQueryPlugin<PrometheusTimeSeriesQuerySpec>;
14
+ //# sourceMappingURL=time-series-query.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"time-series-query.d.ts","sourceRoot":"","sources":["../../src/plugins/time-series-query.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAkB,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAElF,OAAO,EAEL,4BAA4B,EAE5B,cAAc,EAMf,MAAM,UAAU,CAAC;AAGlB,MAAM,WAAW,6BAA6B;IAC5C,KAAK,EAAE,cAAc,CAAC;IACtB,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,4BAA4B,CAAC;CAC3C;AAgED;;GAEG;AACH,eAAO,MAAM,yBAAyB,EAAE,qBAAqB,CAAC,6BAA6B,CAM1F,CAAC"}
@@ -0,0 +1,78 @@
1
+ // Copyright 2022 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 { fromUnixTime } from 'date-fns';
14
+ import { parseValueTuple, getDurationStringSeconds, getPrometheusTimeRange, getRangeStep, replaceTemplateVariables, DEFAULT_PROM } from '../model';
15
+ import { PrometheusTimeSeriesQueryEditor } from './PrometheusTimeSeriesQueryEditor';
16
+ const getTimeSeriesData = async (spec, context)=>{
17
+ var ref;
18
+ const minStep = getDurationStringSeconds(spec.min_step);
19
+ const timeRange = getPrometheusTimeRange(context.timeRange);
20
+ const step = getRangeStep(timeRange, minStep, undefined, context.suggestedStepMs);
21
+ // Align the time range so that it's a multiple of the step
22
+ let { start , end } = timeRange;
23
+ const utcOffsetSec = new Date().getTimezoneOffset() * 60;
24
+ const alignedEnd = Math.floor((end + utcOffsetSec) / step) * step - utcOffsetSec;
25
+ const alignedStart = Math.floor((start + utcOffsetSec) / step) * step - utcOffsetSec;
26
+ start = alignedStart;
27
+ end = alignedEnd;
28
+ // Replace template variable placeholders in PromQL query
29
+ let query = spec.query.replace('$__rate_interval', `15s`);
30
+ query = replaceTemplateVariables(query, context.variableState);
31
+ var _datasource;
32
+ // Get the datasource, using the default Prom Datasource if one isn't specified in the query
33
+ const client = await context.datasourceStore.getDatasourceClient((_datasource = spec.datasource) !== null && _datasource !== void 0 ? _datasource : DEFAULT_PROM);
34
+ // Make the request to Prom
35
+ const response = await client.rangeQuery({
36
+ query,
37
+ start,
38
+ end,
39
+ step
40
+ });
41
+ var ref1;
42
+ // TODO: What about error responses from Prom that have a response body?
43
+ const result = (ref1 = (ref = response.data) === null || ref === void 0 ? void 0 : ref.result) !== null && ref1 !== void 0 ? ref1 : [];
44
+ // Transform response
45
+ const chartData = {
46
+ // Return the time range and step we actually used for the query
47
+ timeRange: {
48
+ start: fromUnixTime(start),
49
+ end: fromUnixTime(end)
50
+ },
51
+ stepMs: step * 1000,
52
+ // TODO: Maybe do a proper Iterable implementation that defers some of this
53
+ // processing until its needed
54
+ series: result.map((value)=>{
55
+ const { metric , values } = value;
56
+ // Name the series after the metric labels or if no metric, just use the
57
+ // overall query
58
+ let name = Object.entries(metric).map(([labelName, labelValue])=>`${labelName}="${labelValue}"`).join(', ');
59
+ if (name === '') name = query;
60
+ return {
61
+ name,
62
+ values: values.map(parseValueTuple)
63
+ };
64
+ })
65
+ };
66
+ return chartData;
67
+ };
68
+ /**
69
+ * The core Prometheus TimeSeriesQuery plugin for Perses.
70
+ */ export const PrometheusTimeSeriesQuery = {
71
+ getTimeSeriesData,
72
+ OptionsEditorComponent: PrometheusTimeSeriesQueryEditor,
73
+ createInitialOptions: ()=>({
74
+ query: ''
75
+ })
76
+ };
77
+
78
+ //# sourceMappingURL=time-series-query.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/plugins/time-series-query.ts"],"sourcesContent":["// Copyright 2022 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 } from '@perses-dev/core';\nimport { TimeSeriesData, TimeSeriesQueryPlugin } from '@perses-dev/plugin-system';\nimport { fromUnixTime } from 'date-fns';\nimport {\n parseValueTuple,\n PrometheusDatasourceSelector,\n PrometheusClient,\n TemplateString,\n getDurationStringSeconds,\n getPrometheusTimeRange,\n getRangeStep,\n replaceTemplateVariables,\n DEFAULT_PROM,\n} from '../model';\nimport { PrometheusTimeSeriesQueryEditor } from './PrometheusTimeSeriesQueryEditor';\n\nexport interface PrometheusTimeSeriesQuerySpec {\n query: TemplateString;\n min_step?: DurationString;\n resolution?: number;\n datasource?: PrometheusDatasourceSelector;\n}\n\nconst getTimeSeriesData: TimeSeriesQueryPlugin<PrometheusTimeSeriesQuerySpec>['getTimeSeriesData'] = async (\n spec,\n context\n) => {\n const minStep = getDurationStringSeconds(spec.min_step);\n const timeRange = getPrometheusTimeRange(context.timeRange);\n const step = getRangeStep(timeRange, minStep, undefined, context.suggestedStepMs);\n\n // Align the time range so that it's a multiple of the step\n let { start, end } = timeRange;\n const utcOffsetSec = new Date().getTimezoneOffset() * 60;\n\n const alignedEnd = Math.floor((end + utcOffsetSec) / step) * step - utcOffsetSec;\n const alignedStart = Math.floor((start + utcOffsetSec) / step) * step - utcOffsetSec;\n start = alignedStart;\n end = alignedEnd;\n\n // Replace template variable placeholders in PromQL query\n let query = spec.query.replace('$__rate_interval', `15s`);\n query = replaceTemplateVariables(query, context.variableState);\n\n // Get the datasource, using the default Prom Datasource if one isn't specified in the query\n const client: PrometheusClient = await context.datasourceStore.getDatasourceClient(spec.datasource ?? DEFAULT_PROM);\n\n // Make the request to Prom\n const response = await client.rangeQuery({\n query,\n start,\n end,\n step,\n });\n\n // TODO: What about error responses from Prom that have a response body?\n const result = response.data?.result ?? [];\n\n // Transform response\n const chartData: TimeSeriesData = {\n // Return the time range and step we actually used for the query\n timeRange: { start: fromUnixTime(start), end: fromUnixTime(end) },\n stepMs: step * 1000,\n\n // TODO: Maybe do a proper Iterable implementation that defers some of this\n // processing until its needed\n series: result.map((value) => {\n const { metric, values } = value;\n\n // Name the series after the metric labels or if no metric, just use the\n // overall query\n let name = Object.entries(metric)\n .map(([labelName, labelValue]) => `${labelName}=\"${labelValue}\"`)\n .join(', ');\n if (name === '') name = query;\n\n return {\n name,\n values: values.map(parseValueTuple),\n };\n }),\n };\n return chartData;\n};\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 }),\n};\n"],"names":["fromUnixTime","parseValueTuple","getDurationStringSeconds","getPrometheusTimeRange","getRangeStep","replaceTemplateVariables","DEFAULT_PROM","PrometheusTimeSeriesQueryEditor","getTimeSeriesData","spec","context","response","minStep","min_step","timeRange","step","undefined","suggestedStepMs","start","end","utcOffsetSec","Date","getTimezoneOffset","alignedEnd","Math","floor","alignedStart","query","replace","variableState","client","datasourceStore","getDatasourceClient","datasource","rangeQuery","result","data","chartData","stepMs","series","map","value","metric","values","name","Object","entries","labelName","labelValue","join","PrometheusTimeSeriesQuery","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,QAA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C;YACd,IAAIL,IAAI,KAAK,EAAE,EAAEA,IAAI,GAAGjB,KAAK,CAAC;YAE9B,OAAO;gBACLiB,IAAI;gBACJD,MAAM,EAAEA,MAAM,CAACH,GAAG,CAACvC,eAAe,CAAC;aACpC,CAAC;QACJ,CAAC,CAAC;KACH,AAAC;IACF,OAAOoC,SAAS,CAAC;AACnB,CAAC,AAAC;AAEF;;CAEC,GACD,OAAO,MAAMa,yBAAyB,GAAyD;IAC7F1C,iBAAiB;IACjB2C,sBAAsB,EAAE5C,+BAA+B;IACvD6C,oBAAoB,EAAE,IAAO,CAAA;YAC3BzB,KAAK,EAAE,EAAE;SACV,CAAA,AAAC;CACH,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { VariablePlugin, VariableOption } from '@perses-dev/plugin-system';
2
+ declare type StaticListOption = string | VariableOption;
3
+ declare type StaticListVariableOptions = {
4
+ values: StaticListOption[];
5
+ };
6
+ export declare const StaticListVariable: VariablePlugin<StaticListVariableOptions>;
7
+ export {};
8
+ //# sourceMappingURL=variable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"variable.d.ts","sourceRoot":"","sources":["../../src/plugins/variable.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAG3E,aAAK,gBAAgB,GAAG,MAAM,GAAG,cAAc,CAAC;AAEhD,aAAK,yBAAyB,GAAG;IAC/B,MAAM,EAAE,gBAAgB,EAAE,CAAC;CAC5B,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,cAAc,CAAC,yBAAyB,CAexE,CAAC"}
@@ -0,0 +1,37 @@
1
+ // Copyright 2022 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 { JSONSpecEditor } from './JSONSpecEditor';
14
+ export const StaticListVariable = {
15
+ getVariableOptions: async (spec)=>{
16
+ var ref;
17
+ const values = (ref = spec.values) === null || ref === void 0 ? void 0 : ref.map((v)=>{
18
+ if (typeof v === 'string') {
19
+ return {
20
+ label: v,
21
+ value: v
22
+ };
23
+ }
24
+ return v;
25
+ });
26
+ return {
27
+ data: values
28
+ };
29
+ },
30
+ dependsOn: ()=>[],
31
+ OptionsEditorComponent: JSONSpecEditor,
32
+ createInitialOptions: ()=>({
33
+ values: []
34
+ })
35
+ };
36
+
37
+ //# sourceMappingURL=variable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/plugins/variable.ts"],"sourcesContent":["// Copyright 2022 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 { VariablePlugin, VariableOption } from '@perses-dev/plugin-system';\nimport { JSONSpecEditor } from './JSONSpecEditor';\n\ntype StaticListOption = string | VariableOption;\n\ntype StaticListVariableOptions = {\n values: StaticListOption[];\n};\n\nexport const StaticListVariable: VariablePlugin<StaticListVariableOptions> = {\n getVariableOptions: async (spec) => {\n const values = spec.values?.map((v) => {\n if (typeof v === 'string') {\n return { label: v, value: v };\n }\n return v;\n });\n return {\n data: values,\n };\n },\n dependsOn: () => [],\n OptionsEditorComponent: JSONSpecEditor,\n createInitialOptions: () => ({ values: [] }),\n};\n"],"names":["JSONSpecEditor","StaticListVariable","getVariableOptions","spec","values","map","v","label","value","data","dependsOn","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;AAGjC,SAASA,cAAc,QAAQ,kBAAkB,CAAC;AAQlD,OAAO,MAAMC,kBAAkB,GAA8C;IAC3EC,kBAAkB,EAAE,OAAOC,IAAI,GAAK;YACnBA,GAAW;QAA1B,MAAMC,MAAM,GAAGD,CAAAA,GAAW,GAAXA,IAAI,CAACC,MAAM,cAAXD,GAAW,WAAK,GAAhBA,KAAAA,CAAgB,GAAhBA,GAAW,CAAEE,GAAG,CAAC,CAACC,CAAC,GAAK;YACrC,IAAI,OAAOA,CAAC,KAAK,QAAQ,EAAE;gBACzB,OAAO;oBAAEC,KAAK,EAAED,CAAC;oBAAEE,KAAK,EAAEF,CAAC;iBAAE,CAAC;YAChC,CAAC;YACD,OAAOA,CAAC,CAAC;QACX,CAAC,CAAC,AAAC;QACH,OAAO;YACLG,IAAI,EAAEL,MAAM;SACb,CAAC;IACJ,CAAC;IACDM,SAAS,EAAE,IAAM,EAAE;IACnBC,sBAAsB,EAAEX,cAAc;IACtCY,oBAAoB,EAAE,IAAO,CAAA;YAAER,MAAM,EAAE,EAAE;SAAE,CAAA,AAAC;CAC7C,CAAC"}
@@ -1 +1,15 @@
1
- import"@testing-library/jest-dom/extend-expect";
1
+ // Copyright 2022 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 '@testing-library/jest-dom/extend-expect';
14
+
15
+ //# sourceMappingURL=setup-tests.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/test/setup-tests.ts"],"sourcesContent":["// Copyright 2022 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 '@testing-library/jest-dom/extend-expect';\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,OAAO,yCAAyC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@perses-dev/prometheus-plugin",
3
- "version": "0.8.1",
3
+ "version": "0.10.0",
4
4
  "description": "Prometheus plugin for Perses",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/perses/perses/blob/main/README.md",
@@ -16,8 +16,11 @@
16
16
  "types": "dist/index.d.ts",
17
17
  "scripts": {
18
18
  "clean": "rimraf dist/",
19
- "build": "tsc --build",
20
- "build:cjs": "tsc --project ./tsconfig.cjs.json",
19
+ "build": "concurrently \"npm:build:*\"",
20
+ "build:cjs": "swc ./src -d dist/cjs --config-file ../.cjs.swcrc",
21
+ "build:esm": "swc ./src -d dist --config-file ../.swcrc",
22
+ "build:types": "tsc --emitDeclarationOnly --declaration --preserveWatchOutput",
23
+ "start": "concurrently -P \"npm:build:* -- {*}\" -- --watch",
21
24
  "test": "TZ=UTC jest",
22
25
  "test:watch": "TZ=UTC jest --watch",
23
26
  "lint": "eslint src --ext .ts,.tsx",
@@ -26,14 +29,14 @@
26
29
  "dependencies": {
27
30
  "@lezer/highlight": "^1.0.0",
28
31
  "@lezer/lr": "^1.2.0",
29
- "@perses-dev/core": "^0.8.1",
30
- "@perses-dev/plugin-system": "^0.8.1",
32
+ "@perses-dev/core": "^0.10.0",
33
+ "@perses-dev/plugin-system": "^0.10.0",
31
34
  "@prometheus-io/lezer-promql": "^0.37.0",
32
- "date-fns": "^2.28.0"
35
+ "date-fns": "^2.28.0",
36
+ "immer": "^9.0.15"
33
37
  },
34
38
  "peerDependencies": {
35
- "react": "^17.0.2 || ^18.0.0",
36
- "react-query": "^3.34.16"
39
+ "react": "^17.0.2 || ^18.0.0"
37
40
  },
38
41
  "files": [
39
42
  "dist",