@perses-dev/prometheus-plugin 0.14.0 → 0.16.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 (47) hide show
  1. package/dist/cjs/index.js +1 -0
  2. package/dist/cjs/model/utils.js +6 -1
  3. package/dist/cjs/model/utils.test.js +14 -0
  4. package/dist/cjs/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.js +7 -1
  5. package/dist/cjs/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js +11 -1
  6. package/dist/cjs/plugins/prometheus-time-series-query/get-time-series-data.js +11 -1
  7. package/dist/cjs/plugins/prometheus-time-series-query/query-editor-model.js +35 -3
  8. package/dist/cjs/plugins/prometheus-variables.js +95 -4
  9. package/dist/cjs/plugins/variable.js +5 -1
  10. package/dist/index.d.ts +2 -2
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +2 -2
  13. package/dist/index.js.map +1 -1
  14. package/dist/model/utils.d.ts +5 -0
  15. package/dist/model/utils.d.ts.map +1 -1
  16. package/dist/model/utils.js +7 -0
  17. package/dist/model/utils.js.map +1 -1
  18. package/dist/model/utils.test.js +15 -1
  19. package/dist/model/utils.test.js.map +1 -1
  20. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.d.ts.map +1 -1
  21. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.js +7 -1
  22. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.js.map +1 -1
  23. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.d.ts.map +1 -1
  24. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js +13 -3
  25. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js.map +1 -1
  26. package/dist/plugins/prometheus-time-series-query/get-time-series-data.d.ts.map +1 -1
  27. package/dist/plugins/prometheus-time-series-query/get-time-series-data.js +12 -2
  28. package/dist/plugins/prometheus-time-series-query/get-time-series-data.js.map +1 -1
  29. package/dist/plugins/prometheus-time-series-query/query-editor-model.d.ts +8 -0
  30. package/dist/plugins/prometheus-time-series-query/query-editor-model.d.ts.map +1 -1
  31. package/dist/plugins/prometheus-time-series-query/query-editor-model.js +28 -0
  32. package/dist/plugins/prometheus-time-series-query/query-editor-model.js.map +1 -1
  33. package/dist/plugins/prometheus-time-series-query/time-series-query-model.d.ts +1 -0
  34. package/dist/plugins/prometheus-time-series-query/time-series-query-model.d.ts.map +1 -1
  35. package/dist/plugins/prometheus-time-series-query/time-series-query-model.js.map +1 -1
  36. package/dist/plugins/prometheus-variables.d.ts +2 -1
  37. package/dist/plugins/prometheus-variables.d.ts.map +1 -1
  38. package/dist/plugins/prometheus-variables.js +93 -3
  39. package/dist/plugins/prometheus-variables.js.map +1 -1
  40. package/dist/plugins/types.d.ts +4 -0
  41. package/dist/plugins/types.d.ts.map +1 -1
  42. package/dist/plugins/types.js.map +1 -1
  43. package/dist/plugins/variable.d.ts.map +1 -1
  44. package/dist/plugins/variable.js +5 -1
  45. package/dist/plugins/variable.js.map +1 -1
  46. package/package.json +3 -3
  47. package/plugin.json +8 -0
package/dist/cjs/index.js CHANGED
@@ -25,6 +25,7 @@ _export(exports, {
25
25
  StaticListVariable: ()=>_variable.StaticListVariable,
26
26
  PrometheusLabelNamesVariable: ()=>_prometheusVariables.PrometheusLabelNamesVariable,
27
27
  PrometheusLabelValuesVariable: ()=>_prometheusVariables.PrometheusLabelValuesVariable,
28
+ PrometheusPromQLVariable: ()=>_prometheusVariables.PrometheusPromQLVariable,
28
29
  PrometheusDatasource: ()=>_prometheusDatasource.PrometheusDatasource
29
30
  });
30
31
  const _prometheusTimeSeriesQuery = require("./plugins/prometheus-time-series-query");
@@ -23,7 +23,8 @@ function _export(target, all) {
23
23
  _export(exports, {
24
24
  replaceTemplateVariables: ()=>replaceTemplateVariables,
25
25
  replaceTemplateVariable: ()=>replaceTemplateVariable,
26
- parseTemplateVariables: ()=>parseTemplateVariables
26
+ parseTemplateVariables: ()=>parseTemplateVariables,
27
+ formatSeriesName: ()=>formatSeriesName
27
28
  });
28
29
  function replaceTemplateVariables(text, variableState) {
29
30
  const variables = parseTemplateVariables(text);
@@ -64,3 +65,7 @@ const parseTemplateVariables = (text)=>{
64
65
  // return unique matches
65
66
  return Array.from(new Set(matches));
66
67
  };
68
+ function formatSeriesName(inputFormat, seriesLabels) {
69
+ const resolveLabelsRegex = /\{\{\s*(.+?)\s*\}\}/g;
70
+ return inputFormat.replace(resolveLabelsRegex, (_, g)=>seriesLabels[g] ? seriesLabels[g] : g);
71
+ }
@@ -110,3 +110,17 @@ describe('replaceTemplateVariables()', ()=>{
110
110
  });
111
111
  });
112
112
  });
113
+ describe('formatSeriesName', ()=>{
114
+ it('should resolve label name tokens to label values from query response', ()=>{
115
+ // example from query: node_load15{instance=~\"(demo.do.prometheus.io:9100)\",job='$job'}
116
+ const inputFormat = 'Test {{job}} {{instance}}';
117
+ const metric = {
118
+ __name__: 'node_load15',
119
+ env: 'demo',
120
+ instance: 'demo.do.prometheus.io:9100',
121
+ job: 'node'
122
+ };
123
+ const output = 'Test node demo.do.prometheus.io:9100';
124
+ expect((0, _utils.formatSeriesName)(inputFormat, metric)).toEqual(output);
125
+ });
126
+ });
@@ -18,6 +18,7 @@ Object.defineProperty(exports, "PrometheusTimeSeriesQuery", {
18
18
  enumerable: true,
19
19
  get: ()=>PrometheusTimeSeriesQuery
20
20
  });
21
+ const _model = require("../../model");
21
22
  const _getTimeSeriesData = require("./get-time-series-data");
22
23
  const _prometheusTimeSeriesQueryEditor = require("./PrometheusTimeSeriesQueryEditor");
23
24
  const PrometheusTimeSeriesQuery = {
@@ -26,5 +27,10 @@ const PrometheusTimeSeriesQuery = {
26
27
  createInitialOptions: ()=>({
27
28
  query: '',
28
29
  datasource: undefined
29
- })
30
+ }),
31
+ dependsOn: (spec)=>{
32
+ return {
33
+ variables: (0, _model.parseTemplateVariables)(spec.query)
34
+ };
35
+ }
30
36
  };
@@ -28,6 +28,7 @@ function PrometheusTimeSeriesQueryEditor(props) {
28
28
  const { onChange , value } = props;
29
29
  const { datasource } = value;
30
30
  const { query , handleQueryChange , handleQueryBlur } = (0, _queryEditorModel.useQueryState)(props);
31
+ const { format , handleFormatChange , handleFormatBlur } = (0, _queryEditorModel.useFormatState)(props);
31
32
  const handleDatasourceChange = (next)=>{
32
33
  if ((0, _model.isPrometheusDatasourceSelector)(next)) {
33
34
  onChange((0, _immer.produce)(value, (draft)=>{
@@ -39,7 +40,8 @@ function PrometheusTimeSeriesQueryEditor(props) {
39
40
  }
40
41
  throw new Error('Got unexpected non-Prometheus datasource selector');
41
42
  };
42
- return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
43
+ return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
44
+ spacing: 2,
43
45
  children: [
44
46
  /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
45
47
  fullWidth: true,
@@ -49,6 +51,14 @@ function PrometheusTimeSeriesQueryEditor(props) {
49
51
  onBlur: handleQueryBlur,
50
52
  margin: "dense"
51
53
  }),
54
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
55
+ fullWidth: true,
56
+ label: "Series Name Format",
57
+ value: format !== null && format !== void 0 ? format : '',
58
+ onChange: handleFormatChange,
59
+ onBlur: handleFormatBlur,
60
+ margin: "dense"
61
+ }),
52
62
  /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.FormControl, {
53
63
  margin: "dense",
54
64
  fullWidth: false,
@@ -22,6 +22,12 @@ const _dateFns = require("date-fns");
22
22
  const _model = require("../../model");
23
23
  const getTimeSeriesData = async (spec, context)=>{
24
24
  var ref;
25
+ if (spec.query === undefined || spec.query === null || spec.query === '') {
26
+ // Do not make a request to the backend, instead return an empty TimeSeriesData
27
+ return {
28
+ series: []
29
+ };
30
+ }
25
31
  const minStep = (0, _model.getDurationStringSeconds)(spec.min_step);
26
32
  const timeRange = (0, _model.getPrometheusTimeRange)(context.timeRange);
27
33
  const step = (0, _model.getRangeStep)(timeRange, minStep, undefined, context.suggestedStepMs);
@@ -64,9 +70,13 @@ const getTimeSeriesData = async (spec, context)=>{
64
70
  // overall query
65
71
  let name = Object.entries(metric).map(([labelName, labelValue])=>`${labelName}="${labelValue}"`).join(', ');
66
72
  if (name === '') name = query;
73
+ // query editor allows you to define an optional series_name_format
74
+ // property to customize legend and tooltip display
75
+ const formattedName = spec.series_name_format ? (0, _model.formatSeriesName)(spec.series_name_format, metric) : name;
67
76
  return {
68
77
  name,
69
- values: values.map(_model.parseValueTuple)
78
+ values: values.map(_model.parseValueTuple),
79
+ formattedName
70
80
  };
71
81
  })
72
82
  };
@@ -14,9 +14,15 @@
14
14
  Object.defineProperty(exports, "__esModule", {
15
15
  value: true
16
16
  });
17
- Object.defineProperty(exports, "useQueryState", {
18
- enumerable: true,
19
- get: ()=>useQueryState
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
+ useQueryState: ()=>useQueryState,
25
+ useFormatState: ()=>useFormatState
20
26
  });
21
27
  const _react = require("react");
22
28
  const _immer = require("immer");
@@ -49,3 +55,29 @@ function useQueryState(props) {
49
55
  handleQueryBlur
50
56
  };
51
57
  }
58
+ function useFormatState(props) {
59
+ const { onChange , value } = props;
60
+ // TODO: reusable hook or helper util instead of duplicating from useQueryState
61
+ const [format, setFormat] = (0, _react.useState)(value.series_name_format);
62
+ const [lastSyncedFormat, setLastSyncedFormat] = (0, _react.useState)(value.series_name_format);
63
+ if (value.series_name_format !== lastSyncedFormat) {
64
+ setFormat(value.series_name_format);
65
+ setLastSyncedFormat(value.series_name_format);
66
+ }
67
+ // Update our local state as the user types
68
+ const handleFormatChange = (e)=>{
69
+ setFormat(e.target.value);
70
+ };
71
+ // Propagate changes to the panel preview component when series_name_format TextField is blurred
72
+ const handleFormatBlur = ()=>{
73
+ setLastSyncedFormat(format);
74
+ onChange((0, _immer.produce)(value, (draft)=>{
75
+ draft.series_name_format = format;
76
+ }));
77
+ };
78
+ return {
79
+ format,
80
+ handleFormatChange,
81
+ handleFormatBlur
82
+ };
83
+ }
@@ -22,7 +22,8 @@ function _export(target, all) {
22
22
  }
23
23
  _export(exports, {
24
24
  PrometheusLabelNamesVariable: ()=>PrometheusLabelNamesVariable,
25
- PrometheusLabelValuesVariable: ()=>PrometheusLabelValuesVariable
25
+ PrometheusLabelValuesVariable: ()=>PrometheusLabelValuesVariable,
26
+ PrometheusPromQLVariable: ()=>PrometheusPromQLVariable
26
27
  });
27
28
  const _jsxRuntime = require("react/jsx-runtime");
28
29
  const _material = require("@mui/material");
@@ -71,6 +72,59 @@ function PrometheusLabelNamesVariableEditor(props) {
71
72
  })
72
73
  });
73
74
  }
75
+ function PrometheusPromQLVariableEditor(props) {
76
+ return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
77
+ spacing: 1,
78
+ children: [
79
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
80
+ sx: {
81
+ mb: 1
82
+ },
83
+ label: "PromQL Expression",
84
+ value: props.value.expr,
85
+ onChange: (e)=>{
86
+ props.onChange({
87
+ ...props.value,
88
+ expr: e.target.value
89
+ });
90
+ }
91
+ }),
92
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
93
+ sx: {
94
+ mb: 1
95
+ },
96
+ label: "Label Name",
97
+ value: props.value.label_name,
98
+ onChange: (e)=>{
99
+ props.onChange({
100
+ ...props.value,
101
+ label_name: e.target.value
102
+ });
103
+ }
104
+ })
105
+ ]
106
+ });
107
+ }
108
+ function capturingMatrix(matrix, label_name) {
109
+ const captured = new Set();
110
+ for (const sample of matrix.result){
111
+ const value = sample.metric[label_name];
112
+ if (value !== undefined) {
113
+ captured.add(value);
114
+ }
115
+ }
116
+ return Array.from(captured.values());
117
+ }
118
+ function capturingVector(vector, label_name) {
119
+ const captured = new Set();
120
+ for (const sample of vector.result){
121
+ const value = sample.metric[label_name];
122
+ if (value !== undefined) {
123
+ captured.add(value);
124
+ }
125
+ }
126
+ return Array.from(captured.values());
127
+ }
74
128
  /**
75
129
  * Takes a list of strings and returns a list of VariableOptions
76
130
  */ const stringArrayToVariableOptions = (values)=>{
@@ -94,7 +148,12 @@ const PrometheusLabelNamesVariable = {
94
148
  data: stringArrayToVariableOptions(options)
95
149
  };
96
150
  },
97
- dependsOn: ()=>[],
151
+ dependsOn: (spec)=>{
152
+ var ref;
153
+ return {
154
+ variables: ((ref = spec.matchers) === null || ref === void 0 ? void 0 : ref.map((m)=>(0, _model.parseTemplateVariables)(m)).flat()) || []
155
+ };
156
+ },
98
157
  OptionsEditorComponent: PrometheusLabelNamesVariableEditor,
99
158
  createInitialOptions: ()=>({})
100
159
  };
@@ -106,7 +165,7 @@ const PrometheusLabelValuesVariable = {
106
165
  const match = pluginDef.matchers ? pluginDef.matchers.map((m)=>(0, _model.replaceTemplateVariables)(m, ctx.variables)) : undefined;
107
166
  const timeRange = (0, _model.getPrometheusTimeRange)(ctx.timeRange);
108
167
  const { data: options } = await client.labelValues({
109
- labelName: pluginDef.label_name,
168
+ labelName: (0, _model.replaceTemplateVariables)(pluginDef.label_name, ctx.variables),
110
169
  'match[]': match,
111
170
  ...timeRange
112
171
  });
@@ -116,10 +175,42 @@ const PrometheusLabelValuesVariable = {
116
175
  },
117
176
  dependsOn: (spec)=>{
118
177
  var ref;
119
- return ((ref = spec.matchers) === null || ref === void 0 ? void 0 : ref.map((m)=>(0, _model.parseTemplateVariables)(m)).flat()) || [];
178
+ return {
179
+ variables: ((ref = spec.matchers) === null || ref === void 0 ? void 0 : ref.map((m)=>(0, _model.parseTemplateVariables)(m)).flat().concat((0, _model.parseTemplateVariables)(spec.label_name))) || []
180
+ };
120
181
  },
121
182
  OptionsEditorComponent: PrometheusLabelValuesVariableEditor,
122
183
  createInitialOptions: ()=>({
123
184
  label_name: ''
124
185
  })
125
186
  };
187
+ const PrometheusPromQLVariable = {
188
+ getVariableOptions: async (spec, ctx)=>{
189
+ var _datasource;
190
+ const client = await ctx.datasourceStore.getDatasourceClient((_datasource = spec.datasource) !== null && _datasource !== void 0 ? _datasource : _model.DEFAULT_PROM);
191
+ // TODO we may want to manage a range query as well.
192
+ const { data: options } = await client.instantQuery({
193
+ query: (0, _model.replaceTemplateVariables)(spec.expr, ctx.variables)
194
+ });
195
+ const labelName = (0, _model.replaceTemplateVariables)(spec.label_name, ctx.variables);
196
+ let values = [];
197
+ if ((options === null || options === void 0 ? void 0 : options.resultType) === 'matrix') {
198
+ values = capturingMatrix(options, labelName);
199
+ } else if ((options === null || options === void 0 ? void 0 : options.resultType) === 'vector') {
200
+ values = capturingVector(options, labelName);
201
+ }
202
+ return {
203
+ data: stringArrayToVariableOptions(values)
204
+ };
205
+ },
206
+ dependsOn: (spec)=>{
207
+ return {
208
+ variables: (0, _model.parseTemplateVariables)(spec.expr).concat((0, _model.parseTemplateVariables)(spec.label_name))
209
+ };
210
+ },
211
+ OptionsEditorComponent: PrometheusPromQLVariableEditor,
212
+ createInitialOptions: ()=>({
213
+ expr: '',
214
+ label_name: ''
215
+ })
216
+ };
@@ -69,7 +69,11 @@ const StaticListVariable = {
69
69
  data: values
70
70
  };
71
71
  },
72
- dependsOn: ()=>[],
72
+ dependsOn: ()=>{
73
+ return {
74
+ variables: []
75
+ };
76
+ },
73
77
  OptionsEditorComponent: StaticListVariableOptionEditor,
74
78
  createInitialOptions: ()=>({
75
79
  values: []
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { PrometheusTimeSeriesQuery } from './plugins/prometheus-time-series-query';
2
2
  import { StaticListVariable } from './plugins/variable';
3
- import { PrometheusLabelNamesVariable, PrometheusLabelValuesVariable } from './plugins/prometheus-variables';
3
+ import { PrometheusLabelNamesVariable, PrometheusLabelValuesVariable, PrometheusPromQLVariable } from './plugins/prometheus-variables';
4
4
  import { PrometheusDatasource } from './plugins/prometheus-datasource';
5
- export { PrometheusTimeSeriesQuery, StaticListVariable, PrometheusLabelNamesVariable, PrometheusLabelValuesVariable, PrometheusDatasource, };
5
+ export { PrometheusTimeSeriesQuery, StaticListVariable, PrometheusLabelNamesVariable, PrometheusLabelValuesVariable, PrometheusPromQLVariable, PrometheusDatasource, };
6
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,yBAAyB,EAAE,MAAM,wCAAwC,CAAC;AAEnF,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"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,yBAAyB,EAAE,MAAM,wCAAwC,CAAC;AAEnF,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EACL,4BAA4B,EAC5B,6BAA6B,EAC7B,wBAAwB,EACzB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAGvE,OAAO,EACL,yBAAyB,EACzB,kBAAkB,EAClB,4BAA4B,EAC5B,6BAA6B,EAC7B,wBAAwB,EACxB,oBAAoB,GACrB,CAAC"}
package/dist/index.js CHANGED
@@ -13,9 +13,9 @@
13
13
  import { PrometheusTimeSeriesQuery } from './plugins/prometheus-time-series-query';
14
14
  // @TODO: Move this to a more generic location;
15
15
  import { StaticListVariable } from './plugins/variable';
16
- import { PrometheusLabelNamesVariable, PrometheusLabelValuesVariable } from './plugins/prometheus-variables';
16
+ import { PrometheusLabelNamesVariable, PrometheusLabelValuesVariable, PrometheusPromQLVariable } from './plugins/prometheus-variables';
17
17
  import { PrometheusDatasource } from './plugins/prometheus-datasource';
18
18
  // Export plugins under the same name as the kinds they handle from the plugin.json
19
- export { PrometheusTimeSeriesQuery, StaticListVariable, PrometheusLabelNamesVariable, PrometheusLabelValuesVariable, PrometheusDatasource };
19
+ export { PrometheusTimeSeriesQuery, StaticListVariable, PrometheusLabelNamesVariable, PrometheusLabelValuesVariable, PrometheusPromQLVariable, PrometheusDatasource };
20
20
 
21
21
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +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/prometheus-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,wCAAwC,CAAC;AACnF,+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
+ {"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/prometheus-time-series-query';\n// @TODO: Move this to a more generic location;\nimport { StaticListVariable } from './plugins/variable';\nimport {\n PrometheusLabelNamesVariable,\n PrometheusLabelValuesVariable,\n PrometheusPromQLVariable,\n} 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 PrometheusPromQLVariable,\n PrometheusDatasource,\n};\n"],"names":["PrometheusTimeSeriesQuery","StaticListVariable","PrometheusLabelNamesVariable","PrometheusLabelValuesVariable","PrometheusPromQLVariable","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,wCAAwC,CAAC;AACnF,+CAA+C;AAC/C,SAASC,kBAAkB,QAAQ,oBAAoB,CAAC;AACxD,SACEC,4BAA4B,EAC5BC,6BAA6B,EAC7BC,wBAAwB,QACnB,gCAAgC,CAAC;AACxC,SAASC,oBAAoB,QAAQ,iCAAiC,CAAC;AAEvE,mFAAmF;AACnF,SACEL,yBAAyB,EACzBC,kBAAkB,EAClBC,4BAA4B,EAC5BC,6BAA6B,EAC7BC,wBAAwB,EACxBC,oBAAoB,GACpB"}
@@ -6,4 +6,9 @@ export declare function replaceTemplateVariable(text: string, varName: string, t
6
6
  * Returns a list of template variables
7
7
  */
8
8
  export declare const parseTemplateVariables: (text: string) => string[];
9
+ /**
10
+ * Types for metric labels, used in series_name_format implementation
11
+ */
12
+ export declare type SeriesLabels = Record<string, string>;
13
+ export declare function formatSeriesName(inputFormat: string, seriesLabels: SeriesLabels): string;
9
14
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/model/utils.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAE7D,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,gBAAgB,GAAG,MAAM,CAW9F;AAED,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,qBAAqB,EAAE,aAAa,UAW1G;AAMD;;GAEG;AACH,eAAO,MAAM,sBAAsB,SAAU,MAAM,aAclD,CAAC"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/model/utils.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAE7D,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,gBAAgB,GAAG,MAAM,CAW9F;AAED,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,qBAAqB,EAAE,aAAa,UAW1G;AAMD;;GAEG;AACH,eAAO,MAAM,sBAAsB,SAAU,MAAM,aAclD,CAAC;AAEF;;GAEG;AACH,oBAAY,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAMlD,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY,GAAG,MAAM,CAGxF"}
@@ -51,5 +51,12 @@ const TEMPLATE_VARIABLE_REGEX = /\$(\w+)|\${(\w+)(?:\.([^:^\}]+))?(?::([^\}]+))?
51
51
  // return unique matches
52
52
  return Array.from(new Set(matches));
53
53
  };
54
+ /*
55
+ * Formatter used for series name display in legends and tooltips
56
+ * Regex replaces label {{ name }} with resolved label value
57
+ */ export function formatSeriesName(inputFormat, seriesLabels) {
58
+ const resolveLabelsRegex = /\{\{\s*(.+?)\s*\}\}/g;
59
+ return inputFormat.replace(resolveLabelsRegex, (_, g)=>seriesLabels[g] ? seriesLabels[g] : g);
60
+ }
54
61
 
55
62
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/model/utils.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 { VariableValue } from '@perses-dev/core';\nimport { VariableStateMap } from '@perses-dev/plugin-system';\n\nexport function replaceTemplateVariables(text: string, variableState: VariableStateMap): string {\n const variables = parseTemplateVariables(text);\n let finalText = text;\n variables.forEach((v) => {\n const variable = variableState[v];\n if (variable && variable?.value) {\n finalText = replaceTemplateVariable(finalText, v, variable?.value);\n }\n });\n\n return finalText;\n}\n\nexport function replaceTemplateVariable(text: string, varName: string, templateVariableValue: VariableValue) {\n const variableTemplate = '$' + varName;\n let replaceString = '';\n if (Array.isArray(templateVariableValue)) {\n replaceString = `(${templateVariableValue.join('|')})`; // regex style\n }\n if (typeof templateVariableValue === 'string') {\n replaceString = templateVariableValue;\n }\n\n return text.replaceAll(variableTemplate, replaceString);\n}\n\n// TODO: Fix this lint eror\n// eslint-disable-next-line no-useless-escape\nconst TEMPLATE_VARIABLE_REGEX = /\\$(\\w+)|\\${(\\w+)(?:\\.([^:^\\}]+))?(?::([^\\}]+))?}/gm;\n\n/**\n * Returns a list of template variables\n */\nexport const parseTemplateVariables = (text: string) => {\n const regex = TEMPLATE_VARIABLE_REGEX;\n const matches = [];\n let match;\n\n while ((match = regex.exec(text)) !== null) {\n if (match) {\n if (match && match.length > 1 && match[1]) {\n matches.push(match[1]);\n }\n }\n }\n // return unique matches\n return Array.from(new Set(matches));\n};\n"],"names":["replaceTemplateVariables","text","variableState","variables","parseTemplateVariables","finalText","forEach","v","variable","value","replaceTemplateVariable","varName","templateVariableValue","variableTemplate","replaceString","Array","isArray","join","replaceAll","TEMPLATE_VARIABLE_REGEX","regex","matches","match","exec","length","push","from","Set"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AAC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uDAAuD,AAAC;AAErF;;CAEC,GACD,OAAO,MAAMf,sBAAsB,GAAG,CAACH,IAAY,GAAK;IACtD,MAAMmB,KAAK,GAAGD,uBAAuB,AAAC;IACtC,MAAME,OAAO,GAAG,EAAE,AAAC;IACnB,IAAIC,KAAK,AAAC;IAEV,MAAO,AAACA,CAAAA,KAAK,GAAGF,KAAK,CAACG,IAAI,CAACtB,IAAI,CAAC,CAAA,KAAM,IAAI,CAAE;QAC1C,IAAIqB,KAAK,EAAE;YACT,IAAIA,KAAK,IAAIA,KAAK,CAACE,MAAM,GAAG,CAAC,IAAIF,KAAK,CAAC,CAAC,CAAC,EAAE;gBACzCD,OAAO,CAACI,IAAI,CAACH,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;YACzB,CAAC;QACH,CAAC;IACH,CAAC;IACD,wBAAwB;IACxB,OAAOP,KAAK,CAACW,IAAI,CAAC,IAAIC,GAAG,CAACN,OAAO,CAAC,CAAC,CAAC;AACtC,CAAC,CAAC"}
1
+ {"version":3,"sources":["../../src/model/utils.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 { VariableValue } from '@perses-dev/core';\nimport { VariableStateMap } from '@perses-dev/plugin-system';\n\nexport function replaceTemplateVariables(text: string, variableState: VariableStateMap): string {\n const variables = parseTemplateVariables(text);\n let finalText = text;\n variables.forEach((v) => {\n const variable = variableState[v];\n if (variable && variable?.value) {\n finalText = replaceTemplateVariable(finalText, v, variable?.value);\n }\n });\n\n return finalText;\n}\n\nexport function replaceTemplateVariable(text: string, varName: string, templateVariableValue: VariableValue) {\n const variableTemplate = '$' + varName;\n let replaceString = '';\n if (Array.isArray(templateVariableValue)) {\n replaceString = `(${templateVariableValue.join('|')})`; // regex style\n }\n if (typeof templateVariableValue === 'string') {\n replaceString = templateVariableValue;\n }\n\n return text.replaceAll(variableTemplate, replaceString);\n}\n\n// TODO: Fix this lint eror\n// eslint-disable-next-line no-useless-escape\nconst TEMPLATE_VARIABLE_REGEX = /\\$(\\w+)|\\${(\\w+)(?:\\.([^:^\\}]+))?(?::([^\\}]+))?}/gm;\n\n/**\n * Returns a list of template variables\n */\nexport const parseTemplateVariables = (text: string) => {\n const regex = TEMPLATE_VARIABLE_REGEX;\n const matches = [];\n let match;\n\n while ((match = regex.exec(text)) !== null) {\n if (match) {\n if (match && match.length > 1 && match[1]) {\n matches.push(match[1]);\n }\n }\n }\n // return unique matches\n return Array.from(new Set(matches));\n};\n\n/**\n * Types for metric labels, used in series_name_format implementation\n */\nexport type SeriesLabels = Record<string, string>;\n\n/*\n * Formatter used for series name display in legends and tooltips\n * Regex replaces label {{ name }} with resolved label value\n */\nexport function formatSeriesName(inputFormat: string, seriesLabels: SeriesLabels): string {\n const resolveLabelsRegex = /\\{\\{\\s*(.+?)\\s*\\}\\}/g;\n return inputFormat.replace(resolveLabelsRegex, (_, g) => (seriesLabels[g] ? seriesLabels[g] : g));\n}\n"],"names":["replaceTemplateVariables","text","variableState","variables","parseTemplateVariables","finalText","forEach","v","variable","value","replaceTemplateVariable","varName","templateVariableValue","variableTemplate","replaceString","Array","isArray","join","replaceAll","TEMPLATE_VARIABLE_REGEX","regex","matches","match","exec","length","push","from","Set","formatSeriesName","inputFormat","seriesLabels","resolveLabelsRegex","replace","_","g"],"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;AAKjC,OAAO,SAASA,wBAAw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AAY,GAAK;IACtD,MAAMmB,KAAK,GAAGD,uBAAuB,AAAC;IACtC,MAAME,OAAO,GAAG,EAAE,AAAC;IACnB,IAAIC,KAAK,AAAC;IAEV,MAAO,AAACA,CAAAA,KAAK,GAAGF,KAAK,CAACG,IAAI,CAACtB,IAAI,CAAC,CAAA,KAAM,IAAI,CAAE;QAC1C,IAAIqB,KAAK,EAAE;YACT,IAAIA,KAAK,IAAIA,KAAK,CAACE,MAAM,GAAG,CAAC,IAAIF,KAAK,CAAC,CAAC,CAAC,EAAE;gBACzCD,OAAO,CAACI,IAAI,CAACH,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;YACzB,CAAC;QACH,CAAC;IACH,CAAC;IACD,wBAAwB;IACxB,OAAOP,KAAK,CAACW,IAAI,CAAC,IAAIC,GAAG,CAACN,OAAO,CAAC,CAAC,CAAC;AACtC,CAAC,CAAC;AAOF;;;CAGC,GACD,OAAO,SAASO,gBAAgB,CAACC,WAAmB,EAAEC,YAA0B,EAAU;IACxF,MAAMC,kBAAkB,yBAAyB,AAAC;IAClD,OAAOF,WAAW,CAACG,OAAO,CAACD,kBAAkB,EAAE,CAACE,CAAC,EAAEC,CAAC,GAAMJ,YAAY,CAACI,CAAC,CAAC,GAAGJ,YAAY,CAACI,CAAC,CAAC,GAAGA,CAAC,AAAC,CAAC,CAAC;AACpG,CAAC"}
@@ -10,7 +10,7 @@
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
- import { parseTemplateVariables, replaceTemplateVariable, replaceTemplateVariables } from './utils';
13
+ import { parseTemplateVariables, replaceTemplateVariable, replaceTemplateVariables, formatSeriesName } from './utils';
14
14
  describe('parseTemplateVariables()', ()=>{
15
15
  const tests = [
16
16
  {
@@ -106,5 +106,19 @@ describe('replaceTemplateVariables()', ()=>{
106
106
  });
107
107
  });
108
108
  });
109
+ describe('formatSeriesName', ()=>{
110
+ it('should resolve label name tokens to label values from query response', ()=>{
111
+ // example from query: node_load15{instance=~\"(demo.do.prometheus.io:9100)\",job='$job'}
112
+ const inputFormat = 'Test {{job}} {{instance}}';
113
+ const metric = {
114
+ __name__: 'node_load15',
115
+ env: 'demo',
116
+ instance: 'demo.do.prometheus.io:9100',
117
+ job: 'node'
118
+ };
119
+ const output = 'Test node demo.do.prometheus.io:9100';
120
+ expect(formatSeriesName(inputFormat, metric)).toEqual(output);
121
+ });
122
+ });
109
123
 
110
124
  //# sourceMappingURL=utils.test.js.map
@@ -1 +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,CAACJ,SAAS,CAAC,CAAC;QAC1D,CAAC,CAAC,CAAC;IACL,CAAC,CA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AI,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"}
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, formatSeriesName } 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\ndescribe('formatSeriesName', () => {\n it('should resolve label name tokens to label values from query response', () => {\n // example from query: node_load15{instance=~\\\"(demo.do.prometheus.io:9100)\\\",job='$job'}\n const inputFormat = 'Test {{job}} {{instance}}';\n\n const metric = {\n __name__: 'node_load15',\n env: 'demo',\n instance: 'demo.do.prometheus.io:9100',\n job: 'node',\n };\n\n const output = 'Test node demo.do.prometheus.io:9100';\n\n expect(formatSeriesName(inputFormat, metric)).toEqual(output);\n });\n});\n"],"names":["parseTemplateVariables","replaceTemplateVariable","replaceTemplateVariables","formatSeriesName","describe","tests","text","variables","forEach","it","expect","toEqual","varName","value","expected","state","var1","loading","var2","JSON","stringify","inputFormat","metric","__name__","env","instance","job","output"],"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,EAAEC,gBAAgB,QAAQ,SAAS,CAAC;AAEtHC,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,CAACV,sBAAsB,CAACM,IAAI,CAAC,CAAC,CAACK,OAAO,CAACJ,SAAS,CAAC,CAAC;QAC1D,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEHH,QAAQ,CAAC,2BAA2B,EAAE,IAAM;IAC1C,MAAMC,KAAK,GAAG;QACZ;YACEC,IAAI,EAAE,aAAa;YACnBM,OAAO,EAAE,MAAM;YACfC,KAAK,EAAE,OAAO;YACdC,QAAQ,EAAE,aAAa;SACxB;QACD;YACER,IAAI,EAAE,mBAAmB;YACzBM,OAAO,EAAE,MAAM;YACfC,KAAK,EAAE,OAAO;YACdC,QAAQ,EAAE,mBAAmB;SAC9B;QACD;YACER,IAAI,EAAE,aAAa;YACnBM,OAAO,EAAE,MAAM;YACfC,KAAK,EAAE;gBAAC,OAAO;gBAAE,G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G,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,CAACR,wBAAwB,CAACI,IAAI,EAAES,KAAK,CAAC,CAAC,CAACJ,OAAO,CAACG,QAAQ,CAAC,CAAC;QAClE,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEHV,QAAQ,CAAC,kBAAkB,EAAE,IAAM;IACjCK,EAAE,CAAC,sEAAsE,EAAE,IAAM;QAC/E,yFAAyF;QACzF,MAAMY,WAAW,GAAG,2BAA2B,AAAC;QAEhD,MAAMC,MAAM,GAAG;YACbC,QAAQ,EAAE,aAAa;YACvBC,GAAG,EAAE,MAAM;YACXC,QAAQ,EAAE,4BAA4B;YACtCC,GAAG,EAAE,MAAM;SACZ,AAAC;QAEF,MAAMC,MAAM,GAAG,sCAAsC,AAAC;QAEtDjB,MAAM,CAACP,gBAAgB,CAACkB,WAAW,EAAEC,MAAM,CAAC,CAAC,CAACX,OAAO,CAACgB,MAAM,CAAC,CAAC;IAChE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"PrometheusTimeSeriesQuery.d.ts","sourceRoot":"","sources":["../../../src/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAGlE,OAAO,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAE1E;;GAEG;AACH,eAAO,MAAM,yBAAyB,EAAE,qBAAqB,CAAC,6BAA6B,CAO1F,CAAC"}
1
+ {"version":3,"file":"PrometheusTimeSeriesQuery.d.ts","sourceRoot":"","sources":["../../../src/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAIlE,OAAO,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAE1E;;GAEG;AACH,eAAO,MAAM,yBAAyB,EAAE,qBAAqB,CAAC,6BAA6B,CAY1F,CAAC"}
@@ -10,6 +10,7 @@
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
+ import { parseTemplateVariables } from '../../model';
13
14
  import { getTimeSeriesData } from './get-time-series-data';
14
15
  import { PrometheusTimeSeriesQueryEditor } from './PrometheusTimeSeriesQueryEditor';
15
16
  /**
@@ -20,7 +21,12 @@ import { PrometheusTimeSeriesQueryEditor } from './PrometheusTimeSeriesQueryEdit
20
21
  createInitialOptions: ()=>({
21
22
  query: '',
22
23
  datasource: undefined
23
- })
24
+ }),
25
+ dependsOn: (spec)=>{
26
+ return {
27
+ variables: parseTemplateVariables(spec.query)
28
+ };
29
+ }
24
30
  };
25
31
 
26
32
  //# sourceMappingURL=PrometheusTimeSeriesQuery.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.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 { TimeSeriesQueryPlugin } 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};\n"],"names":["getTimeSeriesData","PrometheusTimeSeriesQueryEditor","PrometheusTimeSeriesQuery","OptionsEditorComponent","createInitialOptions","query","datasource","undefined"],"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,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;CACH,CAAC"}
1
+ {"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.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 { TimeSeriesQueryPlugin } from '@perses-dev/plugin-system';\nimport { parseTemplateVariables } from '../../model';\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 return {\n variables: parseTemplateVariables(spec.query),\n };\n },\n};\n"],"names":["parseTemplateVariables","getTimeSeriesData","PrometheusTimeSeriesQueryEditor","PrometheusTimeSeriesQuery","OptionsEditorComponent","createInitialOptions","query","datasource","undefined","dependsOn","spec","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;AAGjC,SAASA,sBAAsB,QAAQ,aAAa,CAAC;AACrD,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,OAAO;YACLC,SAAS,EAAEX,sBAAsB,CAACU,IAAI,CAACJ,KAAK,CAAC;SAC9C,CAAC;IACJ,CAAC;CACF,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"PrometheusTimeSeriesQueryEditor.d.ts","sourceRoot":"","sources":["../../../src/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.tsx"],"names":[],"mappings":";AAiBA,OAAO,EAAE,oCAAoC,EAAiB,MAAM,sBAAsB,CAAC;AAE3F;;GAEG;AACH,wBAAgB,+BAA+B,CAAC,KAAK,EAAE,oCAAoC,eA6C1F"}
1
+ {"version":3,"file":"PrometheusTimeSeriesQueryEditor.d.ts","sourceRoot":"","sources":["../../../src/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.tsx"],"names":[],"mappings":";AAiBA,OAAO,EAAE,oCAAoC,EAAiC,MAAM,sBAAsB,CAAC;AAE3G;;GAEG;AACH,wBAAgB,+BAA+B,CAAC,KAAK,EAAE,oCAAoC,eAsD1F"}
@@ -12,16 +12,17 @@
12
12
  // limitations under the License.
13
13
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
14
  import { produce } from 'immer';
15
- import { Box, TextField, FormControl, InputLabel } from '@mui/material';
15
+ import { Stack, TextField, FormControl, InputLabel } from '@mui/material';
16
16
  import { DatasourceSelect } from '@perses-dev/plugin-system';
17
17
  import { DEFAULT_PROM, isDefaultPromSelector, isPrometheusDatasourceSelector } from '../../model';
18
- import { useQueryState } from './query-editor-model';
18
+ import { useQueryState, useFormatState } from './query-editor-model';
19
19
  /**
20
20
  * The options editor component for editing a PrometheusTimeSeriesQuery's spec.
21
21
  */ export function PrometheusTimeSeriesQueryEditor(props) {
22
22
  const { onChange , value } = props;
23
23
  const { datasource } = value;
24
24
  const { query , handleQueryChange , handleQueryBlur } = useQueryState(props);
25
+ const { format , handleFormatChange , handleFormatBlur } = useFormatState(props);
25
26
  const handleDatasourceChange = (next)=>{
26
27
  if (isPrometheusDatasourceSelector(next)) {
27
28
  onChange(produce(value, (draft)=>{
@@ -33,7 +34,8 @@ import { useQueryState } from './query-editor-model';
33
34
  }
34
35
  throw new Error('Got unexpected non-Prometheus datasource selector');
35
36
  };
36
- return /*#__PURE__*/ _jsxs(Box, {
37
+ return /*#__PURE__*/ _jsxs(Stack, {
38
+ spacing: 2,
37
39
  children: [
38
40
  /*#__PURE__*/ _jsx(TextField, {
39
41
  fullWidth: true,
@@ -43,6 +45,14 @@ import { useQueryState } from './query-editor-model';
43
45
  onBlur: handleQueryBlur,
44
46
  margin: "dense"
45
47
  }),
48
+ /*#__PURE__*/ _jsx(TextField, {
49
+ fullWidth: true,
50
+ label: "Series Name Format",
51
+ value: format !== null && format !== void 0 ? format : '',
52
+ onChange: handleFormatChange,
53
+ onBlur: handleFormatBlur,
54
+ margin: "dense"
55
+ }),
46
56
  /*#__PURE__*/ _jsxs(FormControl, {
47
57
  margin: "dense",
48
58
  fullWidth: false,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/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 { produce } from 'immer';\nimport { Box, TextField, FormControl, InputLabel } from '@mui/material';\nimport { DatasourceSelect, DatasourceSelectProps } from '@perses-dev/plugin-system';\nimport { DEFAULT_PROM, isDefaultPromSelector, isPrometheusDatasourceSelector } from '../../model';\nimport { PrometheusTimeSeriesQueryEditorProps, useQueryState } from './query-editor-model';\n\n/**\n * The options editor component for editing a PrometheusTimeSeriesQuery's spec.\n */\nexport function PrometheusTimeSeriesQueryEditor(props: PrometheusTimeSeriesQueryEditorProps) {\n const { onChange, value } = props;\n const { datasource } = value;\n\n const { query, handleQueryChange, handleQueryBlur } = useQueryState(props);\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\n fullWidth\n label=\"Query\"\n value={query}\n onChange={handleQueryChange}\n onBlur={handleQueryBlur}\n margin=\"dense\"\n />\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","useQueryState","PrometheusTimeSeriesQueryEditor","props","onChange","value","datasource","query","handleQueryChange","handleQueryBlur","handleDatasourceChange","next","draft","nextDatasource","undefined","Error","fullWidth","label","onBlur","margin","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;AAAA,SAASA,OAAO,QAAQ,OAAO,CAAC;AAChC,SAASC,GAAG,EAAEC,SAAS,EAAEC,WAAW,EAAEC,UAAU,QAAQ,eAAe,CAAC;AACxE,SAASC,gBAAgB,QAA+B,2BAA2B,CAAC;AACpF,SAASC,YAAY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BAC3ChB,KAAK,EAAEC,UAAU,aAAVA,UAAU,cAAVA,UAAU,GAAIR,YAAY;wBACjCM,QAAQ,EAAEM,sBAAsB;wBAChCY,OAAO,EAAC,uBAAuB;wBAC/BL,KAAK,EAAC,uBAAuB;sBAC7B;;cACU;;MACV,CACN;AACJ,CAAC"}
1
+ {"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/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 { produce } from 'immer';\nimport { Stack, TextField, FormControl, InputLabel } from '@mui/material';\nimport { DatasourceSelect, DatasourceSelectProps } from '@perses-dev/plugin-system';\nimport { DEFAULT_PROM, isDefaultPromSelector, isPrometheusDatasourceSelector } from '../../model';\nimport { PrometheusTimeSeriesQueryEditorProps, useQueryState, useFormatState } from './query-editor-model';\n\n/**\n * The options editor component for editing a PrometheusTimeSeriesQuery's spec.\n */\nexport function PrometheusTimeSeriesQueryEditor(props: PrometheusTimeSeriesQueryEditorProps) {\n const { onChange, value } = props;\n const { datasource } = value;\n\n const { query, handleQueryChange, handleQueryBlur } = useQueryState(props);\n const { format, handleFormatChange, handleFormatBlur } = useFormatState(props);\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 <Stack spacing={2}>\n <TextField\n fullWidth\n label=\"Query\"\n value={query}\n onChange={handleQueryChange}\n onBlur={handleQueryBlur}\n margin=\"dense\"\n />\n <TextField\n fullWidth\n label=\"Series Name Format\"\n value={format ?? ''}\n onChange={handleFormatChange}\n onBlur={handleFormatBlur}\n margin=\"dense\"\n />\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 </Stack>\n );\n}\n"],"names":["produce","Stack","TextField","FormControl","InputLabel","DatasourceSelect","DEFAULT_PROM","isDefaultPromSelector","isPrometheusDatasourceSelector","useQueryState","useFormatState","PrometheusTimeSeriesQueryEditor","props","onChange","value","datasource","query","handleQueryChange","handleQueryBlur","format","handleFormatChange","handleFormatBlur","handleDatasourceChange","next","draft","nextDatasource","undefined","Error","spacing","fullWidth","label","onBlur","margin","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;AAAA,SAASA,OAAO,QAAQ,OAAO,CAAC;AAChC,SAASC,KAAK,EAAEC,SAAS,EAAEC,WAAW,EAAEC,UAAU,QAAQ,eAAe,CAAC;AAC1E,SAASC,gBAAgB,QAA+B,2BAA2B,CAAC;AACpF,SAASC,YAAY,EAAEC,qBAAqB,EAAEC,8BAA8B,QAAQ,aAAa,CAAC;AAClG,SAA+CC,aAAa,EAAEC,cAAc,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I,EAAE;gBACnBN,QAAQ,EAAEO,kBAAkB;gBAC5BW,MAAM,EAAEV,gBAAgB;gBACxBW,MAAM,EAAC,OAAO;cACd;0BACF,MAAC7B,WAAW;gBAAC6B,MAAM,EAAC,OAAO;gBAACH,SAAS,EAAE,KAAK;;kCAG1C,KAACzB,UAAU;wBAAC6B,EAAE,EAAC,uBAAuB;kCAAC,uBAAqB;sBAAa;kCACzE,KAAC5B,gBAAgB;wBACf6B,oBAAoB,EAAC,sBAAsB;wBAC3CpB,KAAK,EAAEC,UAAU,aAAVA,UAAU,cAAVA,UAAU,GAAIT,YAAY;wBACjCO,QAAQ,EAAES,sBAAsB;wBAChCa,OAAO,EAAC,uBAAuB;wBAC/BL,KAAK,EAAC,uBAAuB;sBAC7B;;cACU;;MACR,CACR;AACJ,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"get-time-series-data.d.ts","sourceRoot":"","sources":["../../../src/plugins/prometheus-time-series-query/get-time-series-data.ts"],"names":[],"mappings":"AAaA,OAAO,EAAkB,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAWlF,OAAO,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAE1E,eAAO,MAAM,iBAAiB,EAAE,qBAAqB,CAAC,6BAA6B,CAAC,CAAC,mBAAmB,CA4DvG,CAAC"}
1
+ {"version":3,"file":"get-time-series-data.d.ts","sourceRoot":"","sources":["../../../src/plugins/prometheus-time-series-query/get-time-series-data.ts"],"names":[],"mappings":"AAaA,OAAO,EAAkB,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAYlF,OAAO,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAE1E,eAAO,MAAM,iBAAiB,EAAE,qBAAqB,CAAC,6BAA6B,CAAC,CAAC,mBAAmB,CAuEvG,CAAC"}
@@ -11,9 +11,15 @@
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
13
  import { fromUnixTime } from 'date-fns';
14
- import { parseValueTuple, getDurationStringSeconds, getPrometheusTimeRange, getRangeStep, replaceTemplateVariables, DEFAULT_PROM } from '../../model';
14
+ import { parseValueTuple, getDurationStringSeconds, getPrometheusTimeRange, getRangeStep, replaceTemplateVariables, DEFAULT_PROM, formatSeriesName } from '../../model';
15
15
  export const getTimeSeriesData = async (spec, context)=>{
16
16
  var ref;
17
+ if (spec.query === undefined || spec.query === null || spec.query === '') {
18
+ // Do not make a request to the backend, instead return an empty TimeSeriesData
19
+ return {
20
+ series: []
21
+ };
22
+ }
17
23
  const minStep = getDurationStringSeconds(spec.min_step);
18
24
  const timeRange = getPrometheusTimeRange(context.timeRange);
19
25
  const step = getRangeStep(timeRange, minStep, undefined, context.suggestedStepMs);
@@ -56,9 +62,13 @@ export const getTimeSeriesData = async (spec, context)=>{
56
62
  // overall query
57
63
  let name = Object.entries(metric).map(([labelName, labelValue])=>`${labelName}="${labelValue}"`).join(', ');
58
64
  if (name === '') name = query;
65
+ // query editor allows you to define an optional series_name_format
66
+ // property to customize legend and tooltip display
67
+ const formattedName = spec.series_name_format ? formatSeriesName(spec.series_name_format, metric) : name;
59
68
  return {
60
69
  name,
61
- values: values.map(parseValueTuple)
70
+ values: values.map(parseValueTuple),
71
+ formattedName
62
72
  };
63
73
  })
64
74
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/get-time-series-data.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 { TimeSeriesData, TimeSeriesQueryPlugin } from '@perses-dev/plugin-system';\nimport { fromUnixTime } from 'date-fns';\nimport {\n parseValueTuple,\n PrometheusClient,\n getDurationStringSeconds,\n getPrometheusTimeRange,\n getRangeStep,\n replaceTemplateVariables,\n DEFAULT_PROM,\n} from '../../model';\nimport { PrometheusTimeSeriesQuerySpec } from './time-series-query-model';\n\nexport const 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"],"names":["fromUnixTime","parseValueTuple","getDurationStringSeconds","getPrometheusTimeRange","getRangeStep","replaceTemplateVariables","DEFAULT_PROM","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"],"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,QAAQ,UAAU,CAAC;AACxC,SACEC,eAAe,EAEfC,wBAAwB,EACxBC,sBAAsB,EACtBC,YAAY,EACZC,wBAAwB,EACxBC,YAAY,QACP,aAAa,CAAC;AAGrB,OAAO,MAAMC,iBAAiB,GAA8E,OAC1GC,IAAI,EACJC,OAAO,GACJ;QA8BYC,GAAa;IA7B5B,MAAMC,OAAO,GAAGT,wBAAwB,CAACM,IAAI,CAACI,QAAQ,CAAC,AAAC;IACxD,MAAMC,SAAS,GAAGV,sBAAsB,CAACM,OAAO,CAACI,SAAS,CAAC,AAAC;IAC5D,MAAMC,IAAI,GAAGV,YAAY,CAACS,SAAS,EAAEF,OAAO,EAAEI,SAAS,EAAEN,OAAO,CAACO,eAAe,CAAC,AAAC;IAElF,2DAA2D;IAC3D,IAAI,EAAEC,KAAK,CAAA,EAAEC,GAAG,CAAA,EAAE,GAAGL,SAAS,AAAC;IAC/B,MAAMM,YAAY,GAAG,IAAIC,IAAI,EAAE,CAACC,iBAAiB,EAAE,GAAG,EAAE,AAAC;IAEzD,MAAMC,UAAU,GAAGC,IAAI,CAACC,KAAK,CAAC,AAACN,CAAAA,GAAG,GAAGC,YAAY,CAAA,GAAIL,IAAI,CAAC,GAAGA,IAAI,GAAGK,YAAY,A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AA2E;QAC3E,8BAA8B;QAC9BwB,MAAM,EAAEJ,MAAM,CAACK,GAAG,CAAC,CAACC,KAAK,GAAK;YAC5B,MAAM,EAAEC,MAAM,CAAA,EAAEC,MAAM,CAAA,EAAE,GAAGF,KAAK,AAAC;YAEjC,wEAAwE;YACxE,gBAAgB;YAChB,IAAIG,IAAI,GAAGC,MAAM,CAACC,OAAO,CAACJ,MAAM,CAAC,CAC9BF,GAAG,CAAC,CAAC,CAACO,SAAS,EAAEC,UAAU,CAAC,GAAK,CAAC,EAAED,SAAS,CAAC,EAAE,EAAEC,UAAU,CAAC,CAAC,CAAC,CAAC,CAChEC,IAAI,CAAC,IAAI,CAAC,AAAC;YACd,IAAIL,IAAI,KAAK,EAAE,EAAEA,IAAI,GAAGjB,KAAK,CAAC;YAE9B,OAAO;gBACLiB,IAAI;gBACJD,MAAM,EAAEA,MAAM,CAACH,GAAG,CAACtC,eAAe,CAAC;aACpC,CAAC;QACJ,CAAC,CAAC;KACH,AAAC;IACF,OAAOmC,SAAS,CAAC;AACnB,CAAC,CAAC"}
1
+ {"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/get-time-series-data.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 { TimeSeriesData, TimeSeriesQueryPlugin } from '@perses-dev/plugin-system';\nimport { fromUnixTime } from 'date-fns';\nimport {\n parseValueTuple,\n PrometheusClient,\n getDurationStringSeconds,\n getPrometheusTimeRange,\n getRangeStep,\n replaceTemplateVariables,\n DEFAULT_PROM,\n formatSeriesName,\n} from '../../model';\nimport { PrometheusTimeSeriesQuerySpec } from './time-series-query-model';\n\nexport const getTimeSeriesData: TimeSeriesQueryPlugin<PrometheusTimeSeriesQuerySpec>['getTimeSeriesData'] = async (\n spec,\n context\n) => {\n if (spec.query === undefined || spec.query === null || spec.query === '') {\n // Do not make a request to the backend, instead return an empty TimeSeriesData\n return { series: [] };\n }\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 // query editor allows you to define an optional series_name_format\n // property to customize legend and tooltip display\n const formattedName = spec.series_name_format ? formatSeriesName(spec.series_name_format, metric) : name;\n\n return {\n name,\n values: values.map(parseValueTuple),\n formattedName,\n };\n }),\n };\n\n return chartData;\n};\n"],"names":["fromUnixTime","parseValueTuple","getDurationStringSeconds","getPrometheusTimeRange","getRangeStep","replaceTemplateVariables","DEFAULT_PROM","formatSeriesName","getTimeSeriesData","spec","context","response","query","undefined","series","minStep","min_step","timeRange","step","suggestedStepMs","start","end","utcOffsetSec","Date","getTimezoneOffset","alignedEnd","Math","floor","alignedStart","replace","variableState","client","datasourceStore","getDatasourceClient","datasource","rangeQuery","result","data","chartData","stepMs","map","value","metric","values","name","Object","entries","labelName","labelValue","join","formattedName","series_name_format"],"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,QAAQ,UAAU,CAAC;AACxC,SACEC,eAAe,EAEfC,wBAAwB,EACxBC,sBAAsB,EACtBC,YAAY,EACZC,wBAAwB,EACxBC,YAAY,EACZC,gBAAgB,QACX,aAAa,CAAC;AAGrB,OAAO,MAAMC,iBAAiB,GAA8E,OAC1GC,IAAI,EACJC,OAAO,GACJ;QAmCYC,GAAa;IAlC5B,IAAIF,IAAI,CAACG,KAAK,KAAKC,SAAS,IAAIJ,IAAI,CAACG,KAAK,KAAK,IAAI,IAAIH,IAAI,CAACG,KAAK,KAAK,EAAE,EAAE;QACxE,+EAA+E;QAC/E,OAAO;YAAEE,MAAM,EAAE,EAAE;SAAE,CAAC;IACxB,CAAC;IAED,MAAMC,OAAO,GAAGb,wBAAwB,CAACO,IAAI,CAACO,QAAQ,CAAC,AAAC;IACxD,MAAMC,SAAS,GAAGd,sBAAsB,CAACO,OAAO,CAACO,SAAS,CAAC,AAAC;IAC5D,MAAMC,IAAI,GAAGd,YAAY,CAACa,SAAS,EAAEF,OAAO,EAAEF,SAAS,EAAEH,OAAO,CAACS,eAAe,CAAC,AAAC;IAElF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CAAqB,GAArBA,GAAa,CAAEyB,MAAM,cAArBzB,IAAqB,cAArBA,IAAqB,GAAI,EAAE,AAAC;IAE3C,qBAAqB;IACrB,MAAM2B,SAAS,GAAmB;QAChC,gEAAgE;QAChErB,SAAS,EAAE;YAAEG,KAAK,EAAEpB,YAAY,CAACoB,KAAK,CAAC;YAAEC,GAAG,EAAErB,YAAY,CAACqB,GAAG,CAAC;SAAE;QACjEkB,MAAM,EAAErB,IAAI,GAAG,IAAI;QAEnB,2EAA2E;QAC3E,8BAA8B;QAC9BJ,MAAM,EAAEsB,MAAM,CAACI,GAAG,CAAC,CAACC,KAAK,GAAK;YAC5B,MAAM,EAAEC,MAAM,CAAA,EAAEC,MAAM,CAAA,EAAE,GAAGF,KAAK,AAAC;YAEjC,wEAAwE;YACxE,gBAAgB;YAChB,IAAIG,IAAI,GAAGC,MAAM,CAACC,OAAO,CAACJ,MAAM,CAAC,CAC9BF,GAAG,CAAC,CAAC,CAACO,SAAS,EAAEC,UAAU,CAAC,GAAK,CAAC,EAAED,SAAS,CAAC,EAAE,EAAEC,UAAU,CAAC,CAAC,CAAC,CAAC,CAChEC,IAAI,CAAC,IAAI,CAAC,AAAC;YACd,IAAIL,IAAI,KAAK,EAAE,EAAEA,IAAI,GAAGhC,KAAK,CAAC;YAE9B,mEAAmE;YACnE,mDAAmD;YACnD,MAAMsC,aAAa,GAAGzC,IAAI,CAAC0C,kBAAkB,GAAG5C,gBAAgB,CAACE,IAAI,CAAC0C,kBAAkB,EAAET,MAAM,CAAC,GAAGE,IAAI,AAAC;YAEzG,OAAO;gBACLA,IAAI;gBACJD,MAAM,EAAEA,MAAM,CAACH,GAAG,CAACvC,eAAe,CAAC;gBACnCiD,aAAa;aACd,CAAC;QACJ,CAAC,CAAC;KACH,AAAC;IAEF,OAAOZ,SAAS,CAAC;AACnB,CAAC,CAAC"}
@@ -13,4 +13,12 @@ export declare function useQueryState(props: PrometheusTimeSeriesQueryEditorProp
13
13
  handleQueryChange: import("react").ChangeEventHandler<HTMLTextAreaElement | HTMLInputElement>;
14
14
  handleQueryBlur: import("react").FocusEventHandler<HTMLTextAreaElement | HTMLInputElement>;
15
15
  };
16
+ /**
17
+ * Hook to manage `series_name_format` state to ensure panel preview does not rerender until text input is blurred
18
+ */
19
+ export declare function useFormatState(props: PrometheusTimeSeriesQueryEditorProps): {
20
+ format: string | undefined;
21
+ handleFormatChange: import("react").ChangeEventHandler<HTMLTextAreaElement | HTMLInputElement>;
22
+ handleFormatBlur: import("react").FocusEventHandler<HTMLTextAreaElement | HTMLInputElement>;
23
+ };
16
24
  //# sourceMappingURL=query-editor-model.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"query-editor-model.d.ts","sourceRoot":"","sources":["../../../src/plugins/prometheus-time-series-query/query-editor-model.ts"],"names":[],"mappings":";AAgBA,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAE1E,oBAAY,oCAAoC,GAAG,kBAAkB,CAAC,6BAA6B,CAAC,CAAC;AAErG;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,oCAAoC;;;;EA+BxE"}
1
+ {"version":3,"file":"query-editor-model.d.ts","sourceRoot":"","sources":["../../../src/plugins/prometheus-time-series-query/query-editor-model.ts"],"names":[],"mappings":";AAgBA,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAE1E,oBAAY,oCAAoC,GAAG,kBAAkB,CAAC,6BAA6B,CAAC,CAAC;AAErG;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,oCAAoC;;;;EA+BxE;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,oCAAoC;;;;EA2BzE"}
@@ -46,5 +46,33 @@ import { produce } from 'immer';
46
46
  handleQueryBlur
47
47
  };
48
48
  }
49
+ /**
50
+ * Hook to manage `series_name_format` state to ensure panel preview does not rerender until text input is blurred
51
+ */ export function useFormatState(props) {
52
+ const { onChange , value } = props;
53
+ // TODO: reusable hook or helper util instead of duplicating from useQueryState
54
+ const [format, setFormat] = useState(value.series_name_format);
55
+ const [lastSyncedFormat, setLastSyncedFormat] = useState(value.series_name_format);
56
+ if (value.series_name_format !== lastSyncedFormat) {
57
+ setFormat(value.series_name_format);
58
+ setLastSyncedFormat(value.series_name_format);
59
+ }
60
+ // Update our local state as the user types
61
+ const handleFormatChange = (e)=>{
62
+ setFormat(e.target.value);
63
+ };
64
+ // Propagate changes to the panel preview component when series_name_format TextField is blurred
65
+ const handleFormatBlur = ()=>{
66
+ setLastSyncedFormat(format);
67
+ onChange(produce(value, (draft)=>{
68
+ draft.series_name_format = format;
69
+ }));
70
+ };
71
+ return {
72
+ format,
73
+ handleFormatChange,
74
+ handleFormatBlur
75
+ };
76
+ }
49
77
 
50
78
  //# sourceMappingURL=query-editor-model.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/query-editor-model.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 { useState } from 'react';\nimport { TextFieldProps } from '@mui/material';\nimport { produce } from 'immer';\nimport { OptionsEditorProps } from '@perses-dev/plugin-system';\nimport { PrometheusTimeSeriesQuerySpec } from './time-series-query-model';\n\nexport type PrometheusTimeSeriesQueryEditorProps = OptionsEditorProps<PrometheusTimeSeriesQuerySpec>;\n\n/**\n * A hook for managing the `query` state in PrometheusTimeSeriesQuerySpec. Returns the `query` value, along with\n * `onChange` and `onBlur` event handlers to the input. Keeps a local copy of the user's input and only syncs those\n * changes with the overall spec value once the input is blurred to prevent re-running queries in the panel's preview\n * every time the user types.\n */\nexport function useQueryState(props: PrometheusTimeSeriesQueryEditorProps) {\n const { onChange, value } = props;\n\n // Local copy of the query's value\n const [query, setQuery] = useState(value.query);\n\n // This is basically \"getDerivedStateFromProps\" to make sure if spec's value changes external to this component,\n // we render with the latest value\n const [lastSyncedQuery, setLastSyncedQuery] = useState(value.query);\n if (value.query !== lastSyncedQuery) {\n setQuery(value.query);\n setLastSyncedQuery(value.query);\n }\n\n // Update our local state's copy as the user types\n const handleQueryChange: TextFieldProps['onChange'] = (e) => {\n setQuery(e.target.value);\n };\n\n // Propagate changes to the query's value when the input is blurred to avoid constantly re-running queries in the\n // PanelPreview\n const handleQueryBlur: TextFieldProps['onBlur'] = () => {\n setLastSyncedQuery(query);\n onChange(\n produce(value, (draft) => {\n draft.query = query;\n })\n );\n };\n\n return { query, handleQueryChange, handleQueryBlur };\n}\n"],"names":["useState","produce","useQueryState","props","onChange","value","query","setQuery","lastSyncedQuery","setLastSyncedQuery","handleQueryChange","e","target","handleQueryBlur","draft"],"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,QAAQ,QAAQ,OAAO,CAAC;AAEjC,SAASC,OAAO,QAAQ,OAAO,CAAC;AAMhC;;;;;CAKC,GACD,OAAO,SAASC,aAAa,CAACC,KAA2C,EAAE;IACzE,MAAM,EAAEC,QAAQ,CAAA,EAAEC,KAAK,CAAA,EAAE,GAAGF,KAAK,AAAC;IAElC,kCAAkC;IAClC,MAAM,CAACG,KAAK,EAAEC,QAAQ,CAAC,GAAGP,QAAQ,CAACK,KAAK,CAACC,KAAK,CAAC,AAAC;IAEhD,gHAAgH;IAChH,kCAAkC;IAClC,MAAM,CAACE,eAAe,EAAEC,kBAAkB,CAAC,GAAGT,QAAQ,CAACK,KAAK,CAACC,KAAK,CAAC,AAAC;IACpE,IAAID,KAAK,CAACC,KAAK,KAAKE,eAAe,EAAE;QACnCD,QAAQ,CAACF,KAAK,CAACC,KAAK,CAAC,CAAC;QACtBG,kBAAkB,CAACJ,KAAK,CAACC,KAAK,CAAC,CAAC;IAClC,CAAC;IAED,kDAAkD;IAClD,MAAMI,iBAAiB,GAA+B,CAACC,CAAC,GAAK;QAC3DJ,QAAQ,CAACI,CAAC,CAACC,MAAM,CAACP,KAAK,CAAC,CAAC;IAC3B,CAAC,AAAC;IAEF,iHAAiH;IACjH,eAAe;IACf,MAAMQ,eAAe,GAA6B,IAAM;QACtDJ,kBAAkB,CAACH,KAAK,CAAC,CAAC;QAC1BF,QAAQ,CACNH,OAAO,CAACI,KAAK,EAAE,CAACS,KAAK,GAAK;YACxBA,KAAK,CAACR,KAAK,GAAGA,KAAK,CAAC;QACtB,CAAC,CAAC,CACH,CAAC;IACJ,CAAC,AAAC;IAEF,OAAO;QAAEA,KAAK;QAAEI,iBAAiB;QAAEG,eAAe;KAAE,CAAC;AACvD,CAAC"}
1
+ {"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/query-editor-model.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 { useState } from 'react';\nimport { TextFieldProps } from '@mui/material';\nimport { produce } from 'immer';\nimport { OptionsEditorProps } from '@perses-dev/plugin-system';\nimport { PrometheusTimeSeriesQuerySpec } from './time-series-query-model';\n\nexport type PrometheusTimeSeriesQueryEditorProps = OptionsEditorProps<PrometheusTimeSeriesQuerySpec>;\n\n/**\n * A hook for managing the `query` state in PrometheusTimeSeriesQuerySpec. Returns the `query` value, along with\n * `onChange` and `onBlur` event handlers to the input. Keeps a local copy of the user's input and only syncs those\n * changes with the overall spec value once the input is blurred to prevent re-running queries in the panel's preview\n * every time the user types.\n */\nexport function useQueryState(props: PrometheusTimeSeriesQueryEditorProps) {\n const { onChange, value } = props;\n\n // Local copy of the query's value\n const [query, setQuery] = useState(value.query);\n\n // This is basically \"getDerivedStateFromProps\" to make sure if spec's value changes external to this component,\n // we render with the latest value\n const [lastSyncedQuery, setLastSyncedQuery] = useState(value.query);\n if (value.query !== lastSyncedQuery) {\n setQuery(value.query);\n setLastSyncedQuery(value.query);\n }\n\n // Update our local state's copy as the user types\n const handleQueryChange: TextFieldProps['onChange'] = (e) => {\n setQuery(e.target.value);\n };\n\n // Propagate changes to the query's value when the input is blurred to avoid constantly re-running queries in the\n // PanelPreview\n const handleQueryBlur: TextFieldProps['onBlur'] = () => {\n setLastSyncedQuery(query);\n onChange(\n produce(value, (draft) => {\n draft.query = query;\n })\n );\n };\n\n return { query, handleQueryChange, handleQueryBlur };\n}\n\n/**\n * Hook to manage `series_name_format` state to ensure panel preview does not rerender until text input is blurred\n */\nexport function useFormatState(props: PrometheusTimeSeriesQueryEditorProps) {\n const { onChange, value } = props;\n\n // TODO: reusable hook or helper util instead of duplicating from useQueryState\n const [format, setFormat] = useState(value.series_name_format);\n const [lastSyncedFormat, setLastSyncedFormat] = useState(value.series_name_format);\n if (value.series_name_format !== lastSyncedFormat) {\n setFormat(value.series_name_format);\n setLastSyncedFormat(value.series_name_format);\n }\n\n // Update our local state as the user types\n const handleFormatChange: TextFieldProps['onChange'] = (e) => {\n setFormat(e.target.value);\n };\n\n // Propagate changes to the panel preview component when series_name_format TextField is blurred\n const handleFormatBlur: TextFieldProps['onBlur'] = () => {\n setLastSyncedFormat(format);\n onChange(\n produce(value, (draft) => {\n draft.series_name_format = format;\n })\n );\n };\n\n return { format, handleFormatChange, handleFormatBlur };\n}\n"],"names":["useState","produce","useQueryState","props","onChange","value","query","setQuery","lastSyncedQuery","setLastSyncedQuery","handleQueryChange","e","target","handleQueryBlur","draft","useFormatState","format","setFormat","series_name_format","lastSyncedFormat","setLastSyncedFormat","handleFormatChange","handleFormatBlur"],"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,QAAQ,QAAQ,OAAO,CAAC;AAEjC,SAASC,OAAO,QAAQ,OAAO,CAAC;AAMhC;;;;;CAKC,GACD,OAAO,SAASC,aAAa,CAACC,KAA2C,EAAE;IACzE,MAAM,EAAEC,QAAQ,CAAA,EAAEC,KAAK,CAAA,EAAE,GAAGF,KAAK,AAAC;IAElC,kCAAkC;IAClC,MAAM,CAACG,KAAK,EAAEC,QAAQ,CAAC,GAAGP,QAAQ,CAACK,KAAK,CAACC,KAAK,CAAC,AAAC;IAEhD,gHAAgH;IAChH,kCAAkC;IAClC,MAAM,CAACE,eAAe,EAAEC,kBAAkB,CAAC,GAAGT,QAAQ,CAACK,KAAK,CAACC,KAAK,CAAC,AAAC;IACpE,IAAID,KAAK,CAACC,KAAK,KAAKE,eAAe,EAAE;QACnCD,QAAQ,CAACF,KAAK,CAACC,KAAK,CAAC,CAAC;QACtBG,kBAAkB,CAACJ,KAAK,CAACC,KAAK,CAAC,CAAC;IAClC,CAAC;IAED,kDAAkD;IAClD,MAAMI,iBAAiB,GAA+B,CAACC,CAAC,GAAK;QAC3DJ,QAAQ,CAACI,CAAC,CAACC,MAAM,CAACP,KAAK,CAAC,CAAC;IAC3B,CAAC,AAAC;IAEF,iHAAiH;IACjH,eAAe;IACf,MA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AEA,MAAM;QAAEK,kBAAkB;QAAEC,gBAAgB;KAAE,CAAC;AAC1D,CAAC"}
@@ -5,6 +5,7 @@ import { PrometheusDatasourceSelector, TemplateString } from '../../model';
5
5
  */
6
6
  export interface PrometheusTimeSeriesQuerySpec {
7
7
  query: TemplateString;
8
+ series_name_format?: string;
8
9
  min_step?: DurationString;
9
10
  resolution?: number;
10
11
  datasource?: PrometheusDatasourceSelector;
@@ -1 +1 @@
1
- {"version":3,"file":"time-series-query-model.d.ts","sourceRoot":"","sources":["../../../src/plugins/prometheus-time-series-query/time-series-query-model.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,4BAA4B,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE3E;;GAEG;AACH,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"}
1
+ {"version":3,"file":"time-series-query-model.d.ts","sourceRoot":"","sources":["../../../src/plugins/prometheus-time-series-query/time-series-query-model.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,4BAA4B,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE3E;;GAEG;AACH,MAAM,WAAW,6BAA6B;IAC5C,KAAK,EAAE,cAAc,CAAC;IACtB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,4BAA4B,CAAC;CAC3C"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/time-series-query-model.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 { PrometheusDatasourceSelector, TemplateString } from '../../model';\n\n/**\n * The spec/options for the PrometheusTimeSeriesQuery plugin.\n */\nexport interface PrometheusTimeSeriesQuerySpec {\n query: TemplateString;\n min_step?: DurationString;\n resolution?: number;\n datasource?: PrometheusDatasourceSelector;\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,WAWC"}
1
+ {"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/time-series-query-model.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 { PrometheusDatasourceSelector, TemplateString } from '../../model';\n\n/**\n * The spec/options for the PrometheusTimeSeriesQuery plugin.\n */\nexport interface PrometheusTimeSeriesQuerySpec {\n query: TemplateString;\n series_name_format?: string;\n min_step?: DurationString;\n resolution?: number;\n datasource?: PrometheusDatasourceSelector;\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,WAYC"}
@@ -1,5 +1,6 @@
1
1
  import { VariablePlugin } from '@perses-dev/plugin-system';
2
- import { PrometheusLabelNamesVariableOptions, PrometheusLabelValuesVariableOptions } from './types';
2
+ import { PrometheusLabelNamesVariableOptions, PrometheusLabelValuesVariableOptions, PrometheusPromQLVariableOptions } from './types';
3
3
  export declare const PrometheusLabelNamesVariable: VariablePlugin<PrometheusLabelNamesVariableOptions>;
4
4
  export declare const PrometheusLabelValuesVariable: VariablePlugin<PrometheusLabelValuesVariableOptions>;
5
+ export declare const PrometheusPromQLVariable: VariablePlugin<PrometheusPromQLVariableOptions>;
5
6
  //# sourceMappingURL=prometheus-variables.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"prometheus-variables.d.ts","sourceRoot":"","sources":["../../src/plugins/prometheus-variables.tsx"],"names":[],"mappings":"AAYA,OAAO,EAAE,cAAc,EAAsC,MAAM,2BAA2B,CAAC;AAS/F,OAAO,EAAE,mCAAmC,EAAE,oCAAoC,EAAE,MAAM,SAAS,CAAC;AAgDpG,eAAO,MAAM,4BAA4B,EAAE,cAAc,CAAC,mCAAmC,CAc5F,CAAC;AAEF,eAAO,MAAM,6BAA6B,EAAE,cAAc,CAAC,oCAAoC,CAwB9F,CAAC"}
1
+ {"version":3,"file":"prometheus-variables.d.ts","sourceRoot":"","sources":["../../src/plugins/prometheus-variables.tsx"],"names":[],"mappings":"AAYA,OAAO,EAAE,cAAc,EAAsC,MAAM,2BAA2B,CAAC;AAW/F,OAAO,EACL,mCAAmC,EACnC,oCAAoC,EACpC,+BAA+B,EAChC,MAAM,SAAS,CAAC;AA6FjB,eAAO,MAAM,4BAA4B,EAAE,cAAc,CAAC,mCAAmC,CAgB5F,CAAC;AAEF,eAAO,MAAM,6BAA6B,EAAE,cAAc,CAAC,oCAAoC,CA8B9F,CAAC;AAEF,eAAO,MAAM,wBAAwB,EAAE,cAAc,CAAC,+BAA+B,CAwBpF,CAAC"}
@@ -57,6 +57,59 @@ function PrometheusLabelNamesVariableEditor(props) {
57
57
  })
58
58
  });
59
59
  }
60
+ function PrometheusPromQLVariableEditor(props) {
61
+ return /*#__PURE__*/ _jsxs(Stack, {
62
+ spacing: 1,
63
+ children: [
64
+ /*#__PURE__*/ _jsx(TextField, {
65
+ sx: {
66
+ mb: 1
67
+ },
68
+ label: "PromQL Expression",
69
+ value: props.value.expr,
70
+ onChange: (e)=>{
71
+ props.onChange({
72
+ ...props.value,
73
+ expr: e.target.value
74
+ });
75
+ }
76
+ }),
77
+ /*#__PURE__*/ _jsx(TextField, {
78
+ sx: {
79
+ mb: 1
80
+ },
81
+ label: "Label Name",
82
+ value: props.value.label_name,
83
+ onChange: (e)=>{
84
+ props.onChange({
85
+ ...props.value,
86
+ label_name: e.target.value
87
+ });
88
+ }
89
+ })
90
+ ]
91
+ });
92
+ }
93
+ function capturingMatrix(matrix, label_name) {
94
+ const captured = new Set();
95
+ for (const sample of matrix.result){
96
+ const value = sample.metric[label_name];
97
+ if (value !== undefined) {
98
+ captured.add(value);
99
+ }
100
+ }
101
+ return Array.from(captured.values());
102
+ }
103
+ function capturingVector(vector, label_name) {
104
+ const captured = new Set();
105
+ for (const sample of vector.result){
106
+ const value = sample.metric[label_name];
107
+ if (value !== undefined) {
108
+ captured.add(value);
109
+ }
110
+ }
111
+ return Array.from(captured.values());
112
+ }
60
113
  /**
61
114
  * Takes a list of strings and returns a list of VariableOptions
62
115
  */ const stringArrayToVariableOptions = (values)=>{
@@ -80,7 +133,12 @@ export const PrometheusLabelNamesVariable = {
80
133
  data: stringArrayToVariableOptions(options)
81
134
  };
82
135
  },
83
- dependsOn: ()=>[],
136
+ dependsOn: (spec)=>{
137
+ var ref;
138
+ return {
139
+ variables: ((ref = spec.matchers) === null || ref === void 0 ? void 0 : ref.map((m)=>parseTemplateVariables(m)).flat()) || []
140
+ };
141
+ },
84
142
  OptionsEditorComponent: PrometheusLabelNamesVariableEditor,
85
143
  createInitialOptions: ()=>({})
86
144
  };
@@ -92,7 +150,7 @@ export const PrometheusLabelValuesVariable = {
92
150
  const match = pluginDef.matchers ? pluginDef.matchers.map((m)=>replaceTemplateVariables(m, ctx.variables)) : undefined;
93
151
  const timeRange = getPrometheusTimeRange(ctx.timeRange);
94
152
  const { data: options } = await client.labelValues({
95
- labelName: pluginDef.label_name,
153
+ labelName: replaceTemplateVariables(pluginDef.label_name, ctx.variables),
96
154
  'match[]': match,
97
155
  ...timeRange
98
156
  });
@@ -102,12 +160,44 @@ export const PrometheusLabelValuesVariable = {
102
160
  },
103
161
  dependsOn: (spec)=>{
104
162
  var ref;
105
- return ((ref = spec.matchers) === null || ref === void 0 ? void 0 : ref.map((m)=>parseTemplateVariables(m)).flat()) || [];
163
+ return {
164
+ variables: ((ref = spec.matchers) === null || ref === void 0 ? void 0 : ref.map((m)=>parseTemplateVariables(m)).flat().concat(parseTemplateVariables(spec.label_name))) || []
165
+ };
106
166
  },
107
167
  OptionsEditorComponent: PrometheusLabelValuesVariableEditor,
108
168
  createInitialOptions: ()=>({
109
169
  label_name: ''
110
170
  })
111
171
  };
172
+ export const PrometheusPromQLVariable = {
173
+ getVariableOptions: async (spec, ctx)=>{
174
+ var _datasource;
175
+ const client = await ctx.datasourceStore.getDatasourceClient((_datasource = spec.datasource) !== null && _datasource !== void 0 ? _datasource : DEFAULT_PROM);
176
+ // TODO we may want to manage a range query as well.
177
+ const { data: options } = await client.instantQuery({
178
+ query: replaceTemplateVariables(spec.expr, ctx.variables)
179
+ });
180
+ const labelName = replaceTemplateVariables(spec.label_name, ctx.variables);
181
+ let values = [];
182
+ if ((options === null || options === void 0 ? void 0 : options.resultType) === 'matrix') {
183
+ values = capturingMatrix(options, labelName);
184
+ } else if ((options === null || options === void 0 ? void 0 : options.resultType) === 'vector') {
185
+ values = capturingVector(options, labelName);
186
+ }
187
+ return {
188
+ data: stringArrayToVariableOptions(values)
189
+ };
190
+ },
191
+ dependsOn: (spec)=>{
192
+ return {
193
+ variables: parseTemplateVariables(spec.expr).concat(parseTemplateVariables(spec.label_name))
194
+ };
195
+ },
196
+ OptionsEditorComponent: PrometheusPromQLVariableEditor,
197
+ createInitialOptions: ()=>({
198
+ expr: '',
199
+ label_name: ''
200
+ })
201
+ };
112
202
 
113
203
  //# sourceMappingURL=prometheus-variables.js.map
@@ -1 +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, OptionsEditorProps } from '@perses-dev/plugin-system';\nimport { Stack, TextField } from '@mui/material';\nimport {\n replaceTemplateVariables,\n parseTemplateVariables,\n PrometheusClient,\n DEFAULT_PROM,\n getPrometheusTimeRange,\n} from '../model';\nimport { PrometheusLabelNamesVariableOptions, PrometheusLabelValuesVariableOptions } from './types';\nimport { MatcherEditor } from './MatcherEditor';\n\nfunction PrometheusLabelValuesVariableEditor(props: OptionsEditorProps<PrometheusLabelValuesVariableOptions>) {\n return (\n <Stack spacing={1}>\n <TextField\n sx={{ mb: 1 }}\n label=\"Label Name\"\n value={props.value.label_name}\n onChange={(e) => {\n props.onChange({ ...props.value, label_name: e.target.value });\n }}\n />\n <MatcherEditor\n initialMatchers={props.value.matchers}\n onChange={(e) => {\n props.onChange({ ...props.value, matchers: e });\n }}\n />\n </Stack>\n );\n}\n\nfunction PrometheusLabelNamesVariableEditor(props: OptionsEditorProps<PrometheusLabelNamesVariableOptions>) {\n return (\n <Stack spacing={1}>\n <MatcherEditor\n initialMatchers={props.value.matchers}\n onChange={(e) => {\n props.onChange({ ...props.value, matchers: e });\n }}\n />\n </Stack>\n );\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 timeRange = getPrometheusTimeRange(ctx.timeRange);\n\n const { data: options } = await client.labelNames({ 'match[]': match, ...timeRange });\n return {\n data: stringArrayToVariableOptions(options),\n };\n },\n dependsOn: () => [],\n OptionsEditorComponent: PrometheusLabelNamesVariableEditor,\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\n const timeRange = getPrometheusTimeRange(ctx.timeRange);\n\n const { data: options } = await client.labelValues({\n labelName: pluginDef.label_name,\n 'match[]': match,\n ...timeRange,\n });\n return {\n data: stringArrayToVariableOptions(options),\n };\n },\n dependsOn: (spec) => {\n return spec.matchers?.map((m) => parseTemplateVariables(m)).flat() || [];\n },\n OptionsEditorComponent: PrometheusLabelValuesVariableEditor,\n createInitialOptions: () => ({ label_name: '' }),\n};\n"],"names":["Stack","TextField","replaceTemplateVariables","parseTemplateVariables","DEFAULT_PROM","getPrometheusTimeRange","MatcherEditor","PrometheusLabelValuesVariableEditor","props","spacing","sx","mb","label","value","label_name","onChange","e","target","initialMatchers","matchers","PrometheusLabelNamesVariableEditor","stringArrayToVariableOptions","values","map","PrometheusLabelNamesVariable","getVariableOptions","spec","ctx","client","datasourceStore","getDatasourceClient","datasource","match","m","variables","undefined","timeRange","data","options","labelNames","dependsOn","OptionsEditorComponent","createInitialOptions","PrometheusLabelValuesVariable","pluginDef","labelValues","labelName","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;AACjC;AACA,SAASA,KAAK,EAAEC,SAAS,QAAQ,eAAe,CAAC;AACjD,SACEC,wBAAwB,EACxBC,sBAAsB,EAEtBC,YAAY,EACZC,sBAAsB,QACjB,UAAU,CAAC;AAElB,SAASC,aAAa,QAAQ,iBAAiB,CAAC;AAEhD,SAASC,mCAAmC,CAACC,KAA+D,EAAE;IAC5G,qBACE,MAACR,KAAK;QAACS,OAAO,EAAE,CAAC;;0BACf,KAACR,SAAS;gBACRS,EAAE,EAAE;oBAAEC,EAAE,EAAE,CAAC;iBAAE;gBACbC,KAAK,EAAC,YAAY;gBAClBC,KAAK,EAAEL,KAAK,CAACK,KAAK,CAACC,UAAU;gBAC7BC,QAAQ,EAAE,CAACC,CAAC,GAAK;oBACfR,KAAK,CAACO,QAAQ,CAAC;wBAAE,GAAGP,KAAK,CAACK,KAAK;wBAAEC,UAAU,EAAEE,CAAC,CAACC,MAAM,CAACJ,KAAK;qBAAE,CAAC,CAAC;gBACjE,CAAC;cACD;0BACF,KAACP,aAAa;gBACZY,eAAe,EAAEV,KAAK,CAACK,KAAK,CAACM,QAAQ;gBACrCJ,QAAQ,EAAE,CAACC,CAAC,GAAK;oBAC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4B,CAACiB,OAAO,CAAC;SAC5C,CAAC;IACJ,CAAC;IACDE,SAAS,EAAE,CAACd,IAAI,GAAK;YACZA,GAAa;QAApB,OAAOA,CAAAA,CAAAA,GAAa,GAAbA,IAAI,CAACP,QAAQ,cAAbO,GAAa,WAAK,GAAlBA,KAAAA,CAAkB,GAAlBA,GAAa,CAAEH,GAAG,CAAC,CAACU,CAAC,GAAK9B,sBAAsB,CAAC8B,CAAC,CAAC,CAAC,CAACc,IAAI,EAAE,CAAA,IAAI,EAAE,CAAC;IAC3E,CAAC;IACDN,sBAAsB,EAAElC,mCAAmC;IAC3DmC,oBAAoB,EAAE,IAAO,CAAA;YAAE5B,UAAU,EAAE,EAAE;SAAE,CAAA,AAAC;CACjD,CAAC"}
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, OptionsEditorProps } from '@perses-dev/plugin-system';\nimport { Stack, TextField } from '@mui/material';\nimport {\n replaceTemplateVariables,\n parseTemplateVariables,\n PrometheusClient,\n DEFAULT_PROM,\n getPrometheusTimeRange,\n MatrixData,\n VectorData,\n} from '../model';\nimport {\n PrometheusLabelNamesVariableOptions,\n PrometheusLabelValuesVariableOptions,\n PrometheusPromQLVariableOptions,\n} from './types';\nimport { MatcherEditor } from './MatcherEditor';\n\nfunction PrometheusLabelValuesVariableEditor(props: OptionsEditorProps<PrometheusLabelValuesVariableOptions>) {\n return (\n <Stack spacing={1}>\n <TextField\n sx={{ mb: 1 }}\n label=\"Label Name\"\n value={props.value.label_name}\n onChange={(e) => {\n props.onChange({ ...props.value, label_name: e.target.value });\n }}\n />\n <MatcherEditor\n initialMatchers={props.value.matchers}\n onChange={(e) => {\n props.onChange({ ...props.value, matchers: e });\n }}\n />\n </Stack>\n );\n}\n\nfunction PrometheusLabelNamesVariableEditor(props: OptionsEditorProps<PrometheusLabelNamesVariableOptions>) {\n return (\n <Stack spacing={1}>\n <MatcherEditor\n initialMatchers={props.value.matchers}\n onChange={(e) => {\n props.onChange({ ...props.value, matchers: e });\n }}\n />\n </Stack>\n );\n}\n\nfunction PrometheusPromQLVariableEditor(props: OptionsEditorProps<PrometheusPromQLVariableOptions>) {\n return (\n <Stack spacing={1}>\n <TextField\n sx={{ mb: 1 }}\n label=\"PromQL Expression\"\n value={props.value.expr}\n onChange={(e) => {\n props.onChange({ ...props.value, expr: e.target.value });\n }}\n />\n <TextField\n sx={{ mb: 1 }}\n label=\"Label Name\"\n value={props.value.label_name}\n onChange={(e) => {\n props.onChange({ ...props.value, label_name: e.target.value });\n }}\n />\n </Stack>\n );\n}\n\nfunction capturingMatrix(matrix: MatrixData, label_name: string): string[] {\n const captured = new Set<string>();\n for (const sample of matrix.result) {\n const value = sample.metric[label_name];\n if (value !== undefined) {\n captured.add(value);\n }\n }\n return Array.from(captured.values());\n}\n\nfunction capturingVector(vector: VectorData, label_name: string): string[] {\n const captured = new Set<string>();\n for (const sample of vector.result) {\n const value = sample.metric[label_name];\n if (value !== undefined) {\n captured.add(value);\n }\n }\n return Array.from(captured.values());\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 timeRange = getPrometheusTimeRange(ctx.timeRange);\n\n const { data: options } = await client.labelNames({ 'match[]': match, ...timeRange });\n return {\n data: stringArrayToVariableOptions(options),\n };\n },\n dependsOn: (spec) => {\n return { variables: spec.matchers?.map((m) => parseTemplateVariables(m)).flat() || [] };\n },\n OptionsEditorComponent: PrometheusLabelNamesVariableEditor,\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\n const timeRange = getPrometheusTimeRange(ctx.timeRange);\n\n const { data: options } = await client.labelValues({\n labelName: replaceTemplateVariables(pluginDef.label_name, ctx.variables),\n 'match[]': match,\n ...timeRange,\n });\n return {\n data: stringArrayToVariableOptions(options),\n };\n },\n dependsOn: (spec) => {\n return {\n variables:\n spec.matchers\n ?.map((m) => parseTemplateVariables(m))\n .flat()\n .concat(parseTemplateVariables(spec.label_name)) || [],\n };\n },\n OptionsEditorComponent: PrometheusLabelValuesVariableEditor,\n createInitialOptions: () => ({ label_name: '' }),\n};\n\nexport const PrometheusPromQLVariable: VariablePlugin<PrometheusPromQLVariableOptions> = {\n getVariableOptions: async (spec, ctx) => {\n const client: PrometheusClient = await ctx.datasourceStore.getDatasourceClient(spec.datasource ?? DEFAULT_PROM);\n // TODO we may want to manage a range query as well.\n const { data: options } = await client.instantQuery({\n query: replaceTemplateVariables(spec.expr, ctx.variables),\n });\n const labelName = replaceTemplateVariables(spec.label_name, ctx.variables);\n let values: string[] = [];\n if (options?.resultType === 'matrix') {\n values = capturingMatrix(options, labelName);\n } else if (options?.resultType === 'vector') {\n values = capturingVector(options, labelName);\n }\n\n return {\n data: stringArrayToVariableOptions(values),\n };\n },\n dependsOn: (spec) => {\n return { variables: parseTemplateVariables(spec.expr).concat(parseTemplateVariables(spec.label_name)) };\n },\n OptionsEditorComponent: PrometheusPromQLVariableEditor,\n createInitialOptions: () => ({ expr: '', label_name: '' }),\n};\n"],"names":["Stack","TextField","replaceTemplateVariables","parseTemplateVariables","DEFAULT_PROM","getPrometheusTimeRange","MatcherEditor","PrometheusLabelValuesVariableEditor","props","spacing","sx","mb","label","value","label_name","onChange","e","target","initialMatchers","matchers","PrometheusLabelNamesVariableEditor","PrometheusPromQLVariableEditor","expr","capturingMatrix","matrix","captured","Set","sample","result","metric","undefined","add","Array","from","values","capturingVector","vector","stringArrayToVariableOptions","map","PrometheusLabelNamesVariable","getVariableOptions","spec","ctx","client","datasourceStore","getDatasourceClient","datasource","match","m","variables","timeRange","data","options","labelNames","dependsOn","flat","OptionsEditorComponent","createInitialOptions","PrometheusLabelValuesVariable","pluginDef","labelValues","labelName","concat","PrometheusPromQLVariable","instantQuery","query","resultType"],"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;AACjC;AACA,SAASA,KAAK,EAAEC,SAAS,QAAQ,eAAe,CAAC;AACjD,SACEC,wBAAwB,EACxBC,sBAAsB,EAEtBC,YAAY,EACZC,sBAAsB,QAGjB,UAAU,CAAC;AAMlB,SAASC,aAAa,QAAQ,iBAAiB,CAAC;AAEhD,SAASC,mCAAmC,CAACC,KAA+D,EAAE;IAC5G,qBACE,MAACR,KAAK;QAACS,OAAO,EAAE,CAAC;;0BACf,KAACR,SAAS;gBACRS,EAAE,EAAE;oBAAEC,EAAE,EAAE,CAAC;iBAAE;gBACbC,KAAK,EAAC,YAAY;gBAClBC,KAAK,EAAEL,KAAK,CAACK,KAAK,CAACC,UA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AO,IAAIT,CAAAA,OAAO,aAAPA,OAAO,WAAY,GAAnBA,KAAAA,CAAmB,GAAnBA,OAAO,CAAEc,UAAU,CAAA,KAAK,QAAQ,EAAE;YAC3ChC,MAAM,GAAGC,eAAe,CAACiB,OAAO,EAAES,SAAS,CAAC,CAAC;QAC/C,CAAC;QAED,OAAO;YACLV,IAAI,EAAEd,4BAA4B,CAACH,MAAM,CAAC;SAC3C,CAAC;IACJ,CAAC;IACDoB,SAAS,EAAE,CAACb,IAAI,GAAK;QACnB,OAAO;YAAEQ,SAAS,EAAE9C,sBAAsB,CAACsC,IAAI,CAACnB,IAAI,CAAC,CAACwC,MAAM,CAAC3D,sBAAsB,CAACsC,IAAI,CAAC3B,UAAU,CAAC,CAAC;SAAE,CAAC;IAC1G,CAAC;IACD0C,sBAAsB,EAAEnC,8BAA8B;IACtDoC,oBAAoB,EAAE,IAAO,CAAA;YAAEnC,IAAI,EAAE,EAAE;YAAER,UAAU,EAAE,EAAE;SAAE,CAAA,AAAC;CAC3D,CAAC"}
@@ -9,4 +9,8 @@ export declare type PrometheusLabelValuesVariableOptions = PrometheusVariableOpt
9
9
  label_name: string;
10
10
  matchers?: string[];
11
11
  };
12
+ export declare type PrometheusPromQLVariableOptions = PrometheusVariableOptionsBase & {
13
+ expr: string;
14
+ label_name: string;
15
+ };
12
16
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/plugins/types.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,4BAA4B,EAAE,MAAM,UAAU,CAAC;AAExD,MAAM,WAAW,6BAA6B;IAC5C,UAAU,CAAC,EAAE,4BAA4B,CAAC;CAC3C;AAED,oBAAY,mCAAmC,GAAG,6BAA6B,GAAG;IAChF,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB,CAAC;AAEF,oBAAY,oCAAoC,GAAG,6BAA6B,GAAG;IACjF,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/plugins/types.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,4BAA4B,EAAE,MAAM,UAAU,CAAC;AAExD,MAAM,WAAW,6BAA6B;IAC5C,UAAU,CAAC,EAAE,4BAA4B,CAAC;CAC3C;AAED,oBAAY,mCAAmC,GAAG,6BAA6B,GAAG;IAChF,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB,CAAC;AAEF,oBAAY,oCAAoC,GAAG,6BAA6B,GAAG;IACjF,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB,CAAC;AAEF,oBAAY,+BAA+B,GAAG,6BAA6B,GAAG;IAE5E,IAAI,EAAE,MAAM,CAAC;IAGb,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/plugins/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 { PrometheusDatasourceSelector } from '../model';\n\nexport interface PrometheusVariableOptionsBase {\n datasource?: PrometheusDatasourceSelector;\n}\n\nexport type PrometheusLabelNamesVariableOptions = PrometheusVariableOptionsBase & {\n matchers?: string[];\n};\n\nexport type PrometheusLabelValuesVariableOptions = PrometheusVariableOptionsBase & {\n label_name: string;\n matchers?: 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,WAaE"}
1
+ {"version":3,"sources":["../../src/plugins/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 { PrometheusDatasourceSelector } from '../model';\n\nexport interface PrometheusVariableOptionsBase {\n datasource?: PrometheusDatasourceSelector;\n}\n\nexport type PrometheusLabelNamesVariableOptions = PrometheusVariableOptionsBase & {\n matchers?: string[];\n};\n\nexport type PrometheusLabelValuesVariableOptions = PrometheusVariableOptionsBase & {\n label_name: string;\n matchers?: string[];\n};\n\nexport type PrometheusPromQLVariableOptions = PrometheusVariableOptionsBase & {\n // expr is the PromQL expression.\n expr: string;\n // label_name is the name of the label that will be used after the PromQL query is performed to select the label value.\n // Note: This field is not part of the Prometheus API.\n label_name: 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,WAqBE"}
@@ -1 +1 @@
1
- {"version":3,"file":"variable.d.ts","sourceRoot":"","sources":["../../src/plugins/variable.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAsB,MAAM,2BAA2B,CAAC;AAG/F,aAAK,gBAAgB,GAAG,MAAM,GAAG,cAAc,CAAC;AAEhD,aAAK,yBAAyB,GAAG;IAC/B,MAAM,EAAE,gBAAgB,EAAE,CAAC;CAC5B,CAAC;AAiCF,eAAO,MAAM,kBAAkB,EAAE,cAAc,CAAC,yBAAyB,CAexE,CAAC"}
1
+ {"version":3,"file":"variable.d.ts","sourceRoot":"","sources":["../../src/plugins/variable.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAsB,MAAM,2BAA2B,CAAC;AAG/F,aAAK,gBAAgB,GAAG,MAAM,GAAG,cAAc,CAAC;AAEhD,aAAK,yBAAyB,GAAG;IAC/B,MAAM,EAAE,gBAAgB,EAAE,CAAC;CAC5B,CAAC;AAiCF,eAAO,MAAM,kBAAkB,EAAE,cAAc,CAAC,yBAAyB,CAiBxE,CAAC"}
@@ -61,7 +61,11 @@ export const StaticListVariable = {
61
61
  data: values
62
62
  };
63
63
  },
64
- dependsOn: ()=>[],
64
+ dependsOn: ()=>{
65
+ return {
66
+ variables: []
67
+ };
68
+ },
65
69
  OptionsEditorComponent: StaticListVariableOptionEditor,
66
70
  createInitialOptions: ()=>({
67
71
  values: []
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/plugins/variable.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 { VariablePlugin, VariableOption, OptionsEditorProps } from '@perses-dev/plugin-system';\nimport { Autocomplete, TextField } from '@mui/material';\n\ntype StaticListOption = string | VariableOption;\n\ntype StaticListVariableOptions = {\n values: StaticListOption[];\n};\n\nfunction StaticListVariableOptionEditor(props: OptionsEditorProps<StaticListVariableOptions>) {\n const value = props.value.values.map((v) => {\n if (typeof v === 'string') {\n return v;\n } else {\n return v.value;\n }\n });\n\n const onChange = (__: unknown, value: string[]) => {\n props.onChange({\n values: value.map((v) => {\n return { value: v, label: v };\n }),\n });\n };\n\n return (\n <div>\n <Autocomplete\n multiple\n value={value}\n onChange={onChange}\n options={[]}\n freeSolo\n renderInput={(params) => <TextField {...params} label=\"Values\" placeholder=\"Values\" />}\n />\n </div>\n );\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: StaticListVariableOptionEditor,\n createInitialOptions: () => ({ values: [] }),\n};\n"],"names":["Autocomplete","TextField","StaticListVariableOptionEditor","props","value","values","map","v","onChange","__","label","div","multiple","options","freeSolo","renderInput","params","placeholder","StaticListVariable","getVariableOptions","spec","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;AAEjC;AACA,SAASA,YAAY,EAAEC,SAAS,QAAQ,eAAe,CAAC;AAQxD,SAASC,8BAA8B,CAACC,KAAoD,EAAE;IAC5F,MAAMC,KAAK,GAAGD,KAAK,CAACC,KAAK,CAACC,MAAM,CAACC,GAAG,CAAC,CAACC,CAAC,GAAK;QAC1C,IAAI,OAAOA,CAAC,KAAK,QAAQ,EAAE;YACzB,OAAOA,CAAC,CAAC;QACX,OAAO;YACL,OAAOA,CAAC,CAACH,KAAK,CAAC;QACjB,CAAC;IACH,CAAC,CAAC,AAAC;IAEH,MAAMI,QAAQ,GAAG,CAACC,EAAW,EAAEL,KAAe,GAAK;QACjDD,KAAK,CAACK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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, OptionsEditorProps } from '@perses-dev/plugin-system';\nimport { Autocomplete, TextField } from '@mui/material';\n\ntype StaticListOption = string | VariableOption;\n\ntype StaticListVariableOptions = {\n values: StaticListOption[];\n};\n\nfunction StaticListVariableOptionEditor(props: OptionsEditorProps<StaticListVariableOptions>) {\n const value = props.value.values.map((v) => {\n if (typeof v === 'string') {\n return v;\n } else {\n return v.value;\n }\n });\n\n const onChange = (__: unknown, value: string[]) => {\n props.onChange({\n values: value.map((v) => {\n return { value: v, label: v };\n }),\n });\n };\n\n return (\n <div>\n <Autocomplete\n multiple\n value={value}\n onChange={onChange}\n options={[]}\n freeSolo\n renderInput={(params) => <TextField {...params} label=\"Values\" placeholder=\"Values\" />}\n />\n </div>\n );\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 return { variables: [] };\n },\n OptionsEditorComponent: StaticListVariableOptionEditor,\n createInitialOptions: () => ({ values: [] }),\n};\n"],"names":["Autocomplete","TextField","StaticListVariableOptionEditor","props","value","values","map","v","onChange","__","label","div","multiple","options","freeSolo","renderInput","params","placeholder","StaticListVariable","getVariableOptions","spec","data","dependsOn","variables","OptionsEditorComponent","createInitialOptions"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAA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,GAAG,CAAC,CAACC,CAAC,GAAK;YACrC,IAAI,OAAOA,CAAC,KAAK,QAAQ,EAAE;gBACzB,OAAO;oBAAEG,KAAK,EAAEH,CAAC;oBAAEH,KAAK,EAAEG,CAAC;iBAAE,CAAC;YAChC,CAAC;YACD,OAAOA,CAAC,CAAC;QACX,CAAC,CAAC,AAAC;QACH,OAAO;YACLc,IAAI,EAAEhB,MAAM;SACb,CAAC;IACJ,CAAC;IACDiB,SAAS,EAAE,IAAM;QACf,OAAO;YAAEC,SAAS,EAAE,EAAE;SAAE,CAAC;IAC3B,CAAC;IACDC,sBAAsB,EAAEtB,8BAA8B;IACtDuB,oBAAoB,EAAE,IAAO,CAAA;YAAEpB,MAAM,EAAE,EAAE;SAAE,CAAA,AAAC;CAC7C,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@perses-dev/prometheus-plugin",
3
- "version": "0.14.0",
3
+ "version": "0.16.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",
@@ -30,8 +30,8 @@
30
30
  "dependencies": {
31
31
  "@lezer/highlight": "^1.0.0",
32
32
  "@lezer/lr": "^1.2.0",
33
- "@perses-dev/core": "^0.14.0",
34
- "@perses-dev/plugin-system": "^0.14.0",
33
+ "@perses-dev/core": "^0.16.0",
34
+ "@perses-dev/plugin-system": "^0.16.0",
35
35
  "@prometheus-io/lezer-promql": "^0.37.0",
36
36
  "date-fns": "^2.28.0",
37
37
  "immer": "^9.0.15"
package/plugin.json CHANGED
@@ -29,6 +29,14 @@
29
29
  "description": ""
30
30
  }
31
31
  },
32
+ {
33
+ "pluginType": "Variable",
34
+ "kind": "PrometheusPromQLVariable",
35
+ "display": {
36
+ "name": "PrometheusPromQLVariable",
37
+ "description": ""
38
+ }
39
+ },
32
40
  {
33
41
  "pluginType": "TimeSeriesQuery",
34
42
  "kind": "PrometheusTimeSeriesQuery",