@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
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  // Copyright 2022 The Perses Authors
3
2
  // Licensed under the Apache License, Version 2.0 (the "License");
4
3
  // you may not use this file except in compliance with the License.
@@ -11,76 +10,103 @@
11
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
11
  // See the License for the specific language governing permissions and
13
12
  // limitations under the License.
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const utils_1 = require("./utils");
16
- describe('parseTemplateVariables()', () => {
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ const _utils = require("./utils");
18
+ describe('parseTemplateVariables()', ()=>{
17
19
  const tests = [
18
20
  {
19
21
  text: 'hello $var1 world $var2',
20
- variables: ['var1', 'var2'],
21
- },
22
+ variables: [
23
+ 'var1',
24
+ 'var2'
25
+ ]
26
+ }
22
27
  ];
23
- tests.forEach(({ text, variables }) => {
24
- it(`parses ${text}`, () => {
25
- expect((0, utils_1.parseTemplateVariables)(text)).toEqual(variables);
28
+ tests.forEach(({ text , variables })=>{
29
+ it(`parses ${text}`, ()=>{
30
+ expect((0, _utils.parseTemplateVariables)(text)).toEqual(variables);
26
31
  });
27
32
  });
28
33
  });
29
- describe('replaceTemplateVariable()', () => {
34
+ describe('replaceTemplateVariable()', ()=>{
30
35
  const tests = [
31
36
  {
32
37
  text: 'hello $var1',
33
38
  varName: 'var1',
34
39
  value: 'world',
35
- expected: 'hello world',
40
+ expected: 'hello world'
36
41
  },
37
42
  {
38
43
  text: 'hello $var1 $var1',
39
44
  varName: 'var1',
40
45
  value: 'world',
41
- expected: 'hello world world',
46
+ expected: 'hello world world'
42
47
  },
43
48
  {
44
49
  text: 'hello $var1',
45
50
  varName: 'var1',
46
- value: ['world', 'w'],
47
- expected: 'hello (world|w)',
51
+ value: [
52
+ 'world',
53
+ 'w'
54
+ ],
55
+ expected: 'hello (world|w)'
48
56
  },
49
57
  {
50
58
  text: 'hello $var1 $var1',
51
59
  varName: 'var1',
52
- value: ['world', 'w'],
53
- expected: 'hello (world|w) (world|w)',
54
- },
60
+ value: [
61
+ 'world',
62
+ 'w'
63
+ ],
64
+ expected: 'hello (world|w) (world|w)'
65
+ }
55
66
  ];
56
- tests.forEach(({ text, value, varName, expected }) => {
57
- it(`replaces ${text} ${value}`, () => {
58
- expect((0, utils_1.replaceTemplateVariable)(text, varName, value)).toEqual(expected);
67
+ tests.forEach(({ text , value , varName , expected })=>{
68
+ it(`replaces ${text} ${value}`, ()=>{
69
+ expect((0, _utils.replaceTemplateVariable)(text, varName, value)).toEqual(expected);
59
70
  });
60
71
  });
61
72
  });
62
- describe('replaceTemplateVariables()', () => {
73
+ describe('replaceTemplateVariables()', ()=>{
63
74
  const tests = [
64
75
  {
65
76
  text: 'hello $var1 $var2',
66
77
  state: {
67
- var1: { value: 'world', loading: false },
68
- var2: { value: 'world', loading: false },
78
+ var1: {
79
+ value: 'world',
80
+ loading: false
81
+ },
82
+ var2: {
83
+ value: 'world',
84
+ loading: false
85
+ }
69
86
  },
70
- expected: 'hello world world',
87
+ expected: 'hello world world'
71
88
  },
72
89
  {
73
90
  text: 'hello $var1 $var2',
74
91
  state: {
75
- var1: { value: 'world', loading: false },
76
- var2: { value: ['a', 'b'], loading: false },
92
+ var1: {
93
+ value: 'world',
94
+ loading: false
95
+ },
96
+ var2: {
97
+ value: [
98
+ 'a',
99
+ 'b'
100
+ ],
101
+ loading: false
102
+ }
77
103
  },
78
- expected: 'hello world (a|b)',
79
- },
104
+ expected: 'hello world (a|b)'
105
+ }
80
106
  ];
81
- tests.forEach(({ text, state, expected }) => {
82
- it(`replaces ${text} ${JSON.stringify(state)}`, () => {
83
- expect((0, utils_1.replaceTemplateVariables)(text, state)).toEqual(expected);
107
+ tests.forEach(({ text , state , expected })=>{
108
+ it(`replaces ${text} ${JSON.stringify(state)}`, ()=>{
109
+ expect((0, _utils.replaceTemplateVariables)(text, state)).toEqual(expected);
84
110
  });
85
111
  });
86
112
  });
@@ -0,0 +1,54 @@
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
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ Object.defineProperty(exports, "JSONSpecEditor", {
18
+ enumerable: true,
19
+ get: ()=>JSONSpecEditor
20
+ });
21
+ const _jsxRuntime = require("react/jsx-runtime");
22
+ const _react = require("react");
23
+ const _material = require("@mui/material");
24
+ function JSONSpecEditor(props) {
25
+ const ref = (0, _react.useRef)(null);
26
+ const [value, setValue] = (0, _react.useState)(JSON.stringify(props.value, null, 2));
27
+ const [invalidJSON, setInvalidJSON] = (0, _react.useState)(false);
28
+ (0, _react.useEffect)(()=>{
29
+ setValue(JSON.stringify(props.value, null, 2));
30
+ setInvalidJSON(false);
31
+ }, [
32
+ props.value
33
+ ]);
34
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
35
+ label: "JSON",
36
+ error: invalidJSON,
37
+ helperText: invalidJSON ? 'Invalid JSON' : '',
38
+ multiline: true,
39
+ inputRef: ref,
40
+ value: value,
41
+ onChange: (event)=>{
42
+ setValue(event.target.value);
43
+ },
44
+ onBlur: ()=>{
45
+ try {
46
+ const json = JSON.parse(value !== null && value !== void 0 ? value : '{}');
47
+ setInvalidJSON(false);
48
+ props.onChange(json);
49
+ } catch (e) {
50
+ setInvalidJSON(true);
51
+ }
52
+ }
53
+ });
54
+ }
@@ -0,0 +1,77 @@
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
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ Object.defineProperty(exports, "PrometheusTimeSeriesQueryEditor", {
18
+ enumerable: true,
19
+ get: ()=>PrometheusTimeSeriesQueryEditor
20
+ });
21
+ const _jsxRuntime = require("react/jsx-runtime");
22
+ const _immer = /*#__PURE__*/ _interopRequireDefault(require("immer"));
23
+ const _material = require("@mui/material");
24
+ const _pluginSystem = require("@perses-dev/plugin-system");
25
+ const _model = require("../model");
26
+ function _interopRequireDefault(obj) {
27
+ return obj && obj.__esModule ? obj : {
28
+ default: obj
29
+ };
30
+ }
31
+ function PrometheusTimeSeriesQueryEditor(props) {
32
+ const { onChange , value } = props;
33
+ const { query , datasource } = value;
34
+ const handleQueryChange = (e)=>{
35
+ onChange((0, _immer.default)(value, (draft)=>{
36
+ draft.query = e.target.value;
37
+ }));
38
+ };
39
+ const handleDatasourceChange = (next)=>{
40
+ if ((0, _model.isPrometheusDatasourceSelector)(next)) {
41
+ onChange((0, _immer.default)(value, (draft)=>{
42
+ // If they're using the default, just omit the datasource prop (i.e. set to undefined)
43
+ const nextDatasource = (0, _model.isDefaultPromSelector)(next) ? undefined : next;
44
+ draft.datasource = nextDatasource;
45
+ }));
46
+ return;
47
+ }
48
+ throw new Error('Got unexpected non-Prometheus datasource selector');
49
+ };
50
+ return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
51
+ children: [
52
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
53
+ label: "Query",
54
+ value: query,
55
+ onChange: handleQueryChange,
56
+ margin: "dense"
57
+ }),
58
+ /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.FormControl, {
59
+ margin: "dense",
60
+ fullWidth: false,
61
+ children: [
62
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.InputLabel, {
63
+ id: "prom-datasource-label",
64
+ children: "Prometheus Datasource"
65
+ }),
66
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_pluginSystem.DatasourceSelect, {
67
+ datasourcePluginKind: "PrometheusDatasource",
68
+ value: datasource !== null && datasource !== void 0 ? datasource : _model.DEFAULT_PROM,
69
+ onChange: handleDatasourceChange,
70
+ labelId: "prom-datasource-label",
71
+ label: "Prometheus Datasource"
72
+ })
73
+ ]
74
+ })
75
+ ]
76
+ });
77
+ }
@@ -0,0 +1,54 @@
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
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ Object.defineProperty(exports, "PrometheusDatasource", {
18
+ enumerable: true,
19
+ get: ()=>PrometheusDatasource
20
+ });
21
+ const _model = require("../model");
22
+ /**
23
+ * Creates a PrometheusClient for a specific datasource spec.
24
+ */ const createClient = (spec, options)=>{
25
+ const { direct_url } = spec;
26
+ const { proxyUrl } = options;
27
+ // Use the direct URL if specified, but fallback to the proxyUrl by default if not specified
28
+ const datasourceUrl = direct_url !== null && direct_url !== void 0 ? direct_url : proxyUrl;
29
+ if (datasourceUrl === undefined) {
30
+ throw new Error('No URL specified for Prometheus client. You can use direct_url in the spec to configure it.');
31
+ }
32
+ // Could think about this becoming a class, although it definitely doesn't have to be
33
+ return {
34
+ instantQuery: (params)=>(0, _model.instantQuery)(params, {
35
+ datasourceUrl
36
+ }),
37
+ rangeQuery: (params)=>(0, _model.rangeQuery)(params, {
38
+ datasourceUrl
39
+ }),
40
+ labelNames: (params)=>(0, _model.labelNames)(params, {
41
+ datasourceUrl
42
+ }),
43
+ labelValues: (params)=>(0, _model.labelValues)(params, {
44
+ datasourceUrl
45
+ })
46
+ };
47
+ };
48
+ const PrometheusDatasource = {
49
+ createClient,
50
+ OptionsEditorComponent: ()=>null,
51
+ createInitialOptions: ()=>({
52
+ direct_url: ''
53
+ })
54
+ };
@@ -0,0 +1,76 @@
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
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ function _export(target, all) {
18
+ for(var name in all)Object.defineProperty(target, name, {
19
+ enumerable: true,
20
+ get: all[name]
21
+ });
22
+ }
23
+ _export(exports, {
24
+ PrometheusLabelNamesVariable: ()=>PrometheusLabelNamesVariable,
25
+ PrometheusLabelValuesVariable: ()=>PrometheusLabelValuesVariable
26
+ });
27
+ const _model = require("../model");
28
+ const _jsonspecEditor = require("./JSONSpecEditor");
29
+ /**
30
+ * Takes a list of strings and returns a list of VariableOptions
31
+ */ const stringArrayToVariableOptions = (values)=>{
32
+ if (!values) return [];
33
+ return values.map((value)=>({
34
+ value,
35
+ label: value
36
+ }));
37
+ };
38
+ const PrometheusLabelNamesVariable = {
39
+ getVariableOptions: async (spec, ctx)=>{
40
+ var _datasource;
41
+ const client = await ctx.datasourceStore.getDatasourceClient((_datasource = spec.datasource) !== null && _datasource !== void 0 ? _datasource : _model.DEFAULT_PROM);
42
+ const match = spec.matchers ? spec.matchers.map((m)=>(0, _model.replaceTemplateVariables)(m, ctx.variables)) : undefined;
43
+ const { data: options } = await client.labelNames({
44
+ 'match[]': match
45
+ });
46
+ return {
47
+ data: stringArrayToVariableOptions(options)
48
+ };
49
+ },
50
+ dependsOn: ()=>[],
51
+ OptionsEditorComponent: _jsonspecEditor.JSONSpecEditor,
52
+ createInitialOptions: ()=>({})
53
+ };
54
+ const PrometheusLabelValuesVariable = {
55
+ getVariableOptions: async (spec, ctx)=>{
56
+ const pluginDef = spec;
57
+ var _datasource;
58
+ const client = await ctx.datasourceStore.getDatasourceClient((_datasource = spec.datasource) !== null && _datasource !== void 0 ? _datasource : _model.DEFAULT_PROM);
59
+ const match = pluginDef.matchers ? pluginDef.matchers.map((m)=>(0, _model.replaceTemplateVariables)(m, ctx.variables)) : undefined;
60
+ const { data: options } = await client.labelValues({
61
+ labelName: pluginDef.label_name,
62
+ 'match[]': match
63
+ });
64
+ return {
65
+ data: stringArrayToVariableOptions(options)
66
+ };
67
+ },
68
+ dependsOn: (spec)=>{
69
+ var ref;
70
+ return ((ref = spec.matchers) === null || ref === void 0 ? void 0 : ref.map((m)=>(0, _model.parseTemplateVariables)(m)).flat()) || [];
71
+ },
72
+ OptionsEditorComponent: _jsonspecEditor.JSONSpecEditor,
73
+ createInitialOptions: ()=>({
74
+ label_name: ''
75
+ })
76
+ };
@@ -0,0 +1,82 @@
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
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ Object.defineProperty(exports, "PrometheusTimeSeriesQuery", {
18
+ enumerable: true,
19
+ get: ()=>PrometheusTimeSeriesQuery
20
+ });
21
+ const _dateFns = require("date-fns");
22
+ const _model = require("../model");
23
+ const _prometheusTimeSeriesQueryEditor = require("./PrometheusTimeSeriesQueryEditor");
24
+ const getTimeSeriesData = async (spec, context)=>{
25
+ var ref;
26
+ const minStep = (0, _model.getDurationStringSeconds)(spec.min_step);
27
+ const timeRange = (0, _model.getPrometheusTimeRange)(context.timeRange);
28
+ const step = (0, _model.getRangeStep)(timeRange, minStep, undefined, context.suggestedStepMs);
29
+ // Align the time range so that it's a multiple of the step
30
+ let { start , end } = timeRange;
31
+ const utcOffsetSec = new Date().getTimezoneOffset() * 60;
32
+ const alignedEnd = Math.floor((end + utcOffsetSec) / step) * step - utcOffsetSec;
33
+ const alignedStart = Math.floor((start + utcOffsetSec) / step) * step - utcOffsetSec;
34
+ start = alignedStart;
35
+ end = alignedEnd;
36
+ // Replace template variable placeholders in PromQL query
37
+ let query = spec.query.replace('$__rate_interval', `15s`);
38
+ query = (0, _model.replaceTemplateVariables)(query, context.variableState);
39
+ var _datasource;
40
+ // Get the datasource, using the default Prom Datasource if one isn't specified in the query
41
+ const client = await context.datasourceStore.getDatasourceClient((_datasource = spec.datasource) !== null && _datasource !== void 0 ? _datasource : _model.DEFAULT_PROM);
42
+ // Make the request to Prom
43
+ const response = await client.rangeQuery({
44
+ query,
45
+ start,
46
+ end,
47
+ step
48
+ });
49
+ var ref1;
50
+ // TODO: What about error responses from Prom that have a response body?
51
+ const result = (ref1 = (ref = response.data) === null || ref === void 0 ? void 0 : ref.result) !== null && ref1 !== void 0 ? ref1 : [];
52
+ // Transform response
53
+ const chartData = {
54
+ // Return the time range and step we actually used for the query
55
+ timeRange: {
56
+ start: (0, _dateFns.fromUnixTime)(start),
57
+ end: (0, _dateFns.fromUnixTime)(end)
58
+ },
59
+ stepMs: step * 1000,
60
+ // TODO: Maybe do a proper Iterable implementation that defers some of this
61
+ // processing until its needed
62
+ series: result.map((value)=>{
63
+ const { metric , values } = value;
64
+ // Name the series after the metric labels or if no metric, just use the
65
+ // overall query
66
+ let name = Object.entries(metric).map(([labelName, labelValue])=>`${labelName}="${labelValue}"`).join(', ');
67
+ if (name === '') name = query;
68
+ return {
69
+ name,
70
+ values: values.map(_model.parseValueTuple)
71
+ };
72
+ })
73
+ };
74
+ return chartData;
75
+ };
76
+ const PrometheusTimeSeriesQuery = {
77
+ getTimeSeriesData,
78
+ OptionsEditorComponent: _prometheusTimeSeriesQueryEditor.PrometheusTimeSeriesQueryEditor,
79
+ createInitialOptions: ()=>({
80
+ query: ''
81
+ })
82
+ };
@@ -0,0 +1,43 @@
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
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ Object.defineProperty(exports, "StaticListVariable", {
18
+ enumerable: true,
19
+ get: ()=>StaticListVariable
20
+ });
21
+ const _jsonspecEditor = require("./JSONSpecEditor");
22
+ const StaticListVariable = {
23
+ getVariableOptions: async (spec)=>{
24
+ var ref;
25
+ const values = (ref = spec.values) === null || ref === void 0 ? void 0 : ref.map((v)=>{
26
+ if (typeof v === 'string') {
27
+ return {
28
+ label: v,
29
+ value: v
30
+ };
31
+ }
32
+ return v;
33
+ });
34
+ return {
35
+ data: values
36
+ };
37
+ },
38
+ dependsOn: ()=>[],
39
+ OptionsEditorComponent: _jsonspecEditor.JSONSpecEditor,
40
+ createInitialOptions: ()=>({
41
+ values: []
42
+ })
43
+ };
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  // Copyright 2022 The Perses Authors
3
2
  // Licensed under the Apache License, Version 2.0 (the "License");
4
3
  // you may not use this file except in compliance with the License.
@@ -11,5 +10,8 @@
11
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
11
  // See the License for the specific language governing permissions and
13
12
  // limitations under the License.
14
- Object.defineProperty(exports, "__esModule", { value: true });
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
15
17
  require("@testing-library/jest-dom/extend-expect");
package/dist/index.d.ts CHANGED
@@ -1,3 +1,6 @@
1
- import { PrometheusGraphQuery } from './plugins/graph-query';
2
- export { PrometheusGraphQuery };
1
+ import { PrometheusTimeSeriesQuery } from './plugins/time-series-query';
2
+ import { StaticListVariable } from './plugins/variable';
3
+ import { PrometheusLabelNamesVariable, PrometheusLabelValuesVariable } from './plugins/prometheus-variables';
4
+ import { PrometheusDatasource } from './plugins/prometheus-datasource';
5
+ export { PrometheusTimeSeriesQuery, StaticListVariable, PrometheusLabelNamesVariable, PrometheusLabelValuesVariable, PrometheusDatasource, };
3
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAG7D,OAAO,EAAE,oBAAoB,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAExE,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,4BAA4B,EAAE,6BAA6B,EAAE,MAAM,gCAAgC,CAAC;AAC7G,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAGvE,OAAO,EACL,yBAAyB,EACzB,kBAAkB,EAClB,4BAA4B,EAC5B,6BAA6B,EAC7B,oBAAoB,GACrB,CAAC"}
package/dist/index.js CHANGED
@@ -1 +1,21 @@
1
- import{PrometheusGraphQuery}from"./plugins/graph-query";export{PrometheusGraphQuery};
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 { PrometheusTimeSeriesQuery } from './plugins/time-series-query';
14
+ // @TODO: Move this to a more generic location;
15
+ import { StaticListVariable } from './plugins/variable';
16
+ import { PrometheusLabelNamesVariable, PrometheusLabelValuesVariable } from './plugins/prometheus-variables';
17
+ import { PrometheusDatasource } from './plugins/prometheus-datasource';
18
+ // Export plugins under the same name as the kinds they handle from the plugin.json
19
+ export { PrometheusTimeSeriesQuery, StaticListVariable, PrometheusLabelNamesVariable, PrometheusLabelValuesVariable, PrometheusDatasource };
20
+
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.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 { PrometheusTimeSeriesQuery } from './plugins/time-series-query';\n// @TODO: Move this to a more generic location;\nimport { StaticListVariable } from './plugins/variable';\nimport { PrometheusLabelNamesVariable, PrometheusLabelValuesVariable } from './plugins/prometheus-variables';\nimport { PrometheusDatasource } from './plugins/prometheus-datasource';\n\n// Export plugins under the same name as the kinds they handle from the plugin.json\nexport {\n PrometheusTimeSeriesQuery,\n StaticListVariable,\n PrometheusLabelNamesVariable,\n PrometheusLabelValuesVariable,\n PrometheusDatasource,\n};\n"],"names":["PrometheusTimeSeriesQuery","StaticListVariable","PrometheusLabelNamesVariable","PrometheusLabelValuesVariable","PrometheusDatasource"],"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,yBAAyB,QAAQ,6BAA6B,CAAC;AACxE,+CAA+C;AAC/C,SAASC,kBAAkB,QAAQ,oBAAoB,CAAC;AACxD,SAASC,4BAA4B,EAAEC,6BAA6B,QAAQ,gCAAgC,CAAC;AAC7G,SAASC,oBAAoB,QAAQ,iCAAiC,CAAC;AAEvE,mFAAmF;AACnF,SACEJ,yBAAyB,EACzBC,kBAAkB,EAClBC,4BAA4B,EAC5BC,6BAA6B,EAC7BC,oBAAoB,GACpB"}
@@ -1 +1,15 @@
1
- export{};
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
+ export { };
14
+
15
+ //# sourceMappingURL=api-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/model/api-types.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';\n\n// Just reuse dashboard model's type and re-export\nexport type { DurationString };\n\nexport interface SuccessResponse<T> {\n status: 'success';\n data: T;\n warnings?: string[];\n}\n\nexport interface ErrorResponse<T> {\n status: 'error';\n data?: T;\n errorType: string;\n error: string;\n}\n\nexport type ApiResponse<T> = SuccessResponse<T> | ErrorResponse<T>;\n\nexport type DurationSeconds = number;\n\nexport type UnixTimestampSeconds = number;\n\nexport type ValueTuple = [unixTimeSeconds: UnixTimestampSeconds, sampleValue: string];\n\nexport type Metric = Record<string, string>;\n\nexport interface VectorData {\n resultType: 'vector';\n result: Array<{\n metric: Metric;\n value: ValueTuple;\n }>;\n}\n\nexport interface MatrixData {\n resultType: 'matrix';\n result: Array<{\n metric: Metric;\n values: ValueTuple[];\n }>;\n}\n\nexport interface ScalarData {\n resultType: 'scalar';\n result: ValueTuple;\n}\n\nexport interface InstantQueryRequestParameters {\n query: string;\n time?: UnixTimestampSeconds;\n timeout?: DurationString;\n}\n\nexport type InstantQueryResponse = ApiResponse<MatrixData | VectorData | ScalarData>;\n\nexport interface RangeQueryRequestParameters {\n query: string;\n start: UnixTimestampSeconds;\n end: UnixTimestampSeconds;\n step: DurationSeconds;\n timeout?: DurationString;\n}\n\nexport type RangeQueryResponse = ApiResponse<MatrixData>;\n\nexport interface SeriesRequestParameters {\n 'match[]': string[];\n start: UnixTimestampSeconds;\n end: UnixTimestampSeconds;\n}\n\nexport type SeriesResponse = ApiResponse<Metric[]>;\n\nexport interface LabelNamesRequestParameters {\n start?: UnixTimestampSeconds;\n end?: UnixTimestampSeconds;\n 'match[]'?: string[];\n}\n\nexport type LabelNamesResponse = ApiResponse<string[]>;\n\nexport interface LabelValuesRequestParameters {\n labelName: string;\n start?: UnixTimestampSeconds;\n end?: UnixTimestampSeconds;\n 'match[]'?: string[];\n}\n\nexport type LabelValuesResponse = ApiResponse<string[]>;\n\nexport interface MetricMetadata {\n type: string;\n help: string;\n unit?: string;\n}\n\nexport interface MetricMetadataRequestParameters {\n limit?: number;\n metric?: string;\n}\n\nexport type MetricMetadataResponse = ApiResponse<Record<string, MetricMetadata[]>>;\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,WAuGmF"}
@@ -0,0 +1,8 @@
1
+ export * from './api-types';
2
+ export * from './parse-sample-values';
3
+ export * from './prometheus-client';
4
+ export * from './prometheus-selectors';
5
+ export * from './templating';
6
+ export * from './time';
7
+ export * from './utils';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/model/index.ts"],"names":[],"mappings":"AAaA,cAAc,aAAa,CAAC;AAC5B,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC"}
@@ -0,0 +1,21 @@
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
+ export * from './api-types';
14
+ export * from './parse-sample-values';
15
+ export * from './prometheus-client';
16
+ export * from './prometheus-selectors';
17
+ export * from './templating';
18
+ export * from './time';
19
+ export * from './utils';
20
+
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/model/index.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\nexport * from './api-types';\nexport * from './parse-sample-values';\nexport * from './prometheus-client';\nexport * from './prometheus-selectors';\nexport * from './templating';\nexport * from './time';\nexport * from './utils';\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,aAAa,CAAC;AAC5B,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC"}