@perses-dev/prometheus-plugin 0.15.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.
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");
@@ -40,7 +40,8 @@ function PrometheusTimeSeriesQueryEditor(props) {
40
40
  }
41
41
  throw new Error('Got unexpected non-Prometheus datasource selector');
42
42
  };
43
- return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
43
+ return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
44
+ spacing: 2,
44
45
  children: [
45
46
  /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
46
47
  fullWidth: true,
@@ -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);
@@ -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,9 +148,10 @@ const PrometheusLabelNamesVariable = {
94
148
  data: stringArrayToVariableOptions(options)
95
149
  };
96
150
  },
97
- dependsOn: ()=>{
151
+ dependsOn: (spec)=>{
152
+ var ref;
98
153
  return {
99
- variables: []
154
+ variables: ((ref = spec.matchers) === null || ref === void 0 ? void 0 : ref.map((m)=>(0, _model.parseTemplateVariables)(m)).flat()) || []
100
155
  };
101
156
  },
102
157
  OptionsEditorComponent: PrometheusLabelNamesVariableEditor,
@@ -110,7 +165,7 @@ const PrometheusLabelValuesVariable = {
110
165
  const match = pluginDef.matchers ? pluginDef.matchers.map((m)=>(0, _model.replaceTemplateVariables)(m, ctx.variables)) : undefined;
111
166
  const timeRange = (0, _model.getPrometheusTimeRange)(ctx.timeRange);
112
167
  const { data: options } = await client.labelValues({
113
- labelName: pluginDef.label_name,
168
+ labelName: (0, _model.replaceTemplateVariables)(pluginDef.label_name, ctx.variables),
114
169
  'match[]': match,
115
170
  ...timeRange
116
171
  });
@@ -121,7 +176,7 @@ const PrometheusLabelValuesVariable = {
121
176
  dependsOn: (spec)=>{
122
177
  var ref;
123
178
  return {
124
- variables: ((ref = spec.matchers) === null || ref === void 0 ? void 0 : ref.map((m)=>(0, _model.parseTemplateVariables)(m)).flat()) || []
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))) || []
125
180
  };
126
181
  },
127
182
  OptionsEditorComponent: PrometheusLabelValuesVariableEditor,
@@ -129,3 +184,33 @@ const PrometheusLabelValuesVariable = {
129
184
  label_name: ''
130
185
  })
131
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
+ };
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"}
@@ -12,7 +12,7 @@
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
18
  import { useQueryState, useFormatState } from './query-editor-model';
@@ -34,7 +34,8 @@ import { useQueryState, useFormatState } from './query-editor-model';
34
34
  }
35
35
  throw new Error('Got unexpected non-Prometheus datasource selector');
36
36
  };
37
- return /*#__PURE__*/ _jsxs(Box, {
37
+ return /*#__PURE__*/ _jsxs(Stack, {
38
+ spacing: 2,
38
39
  children: [
39
40
  /*#__PURE__*/ _jsx(TextField, {
40
41
  fullWidth: true,
@@ -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, 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 <Box>\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 </Box>\n );\n}\n"],"names":["produce","Box","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","fullWidth","label","onBlur","margin","id","datasourcePluginKind","labelId"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0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,CAAC,CAAC;IACvE,CAAC,AAAC;IAEF,qBACE,MAAC1B,GAAG;;0BACF,KAACC,SAAS;gBACR0B,SAAS;gBACTC,KAAK,EAAC,OAAO;gBACbf,KAAK,EAAEE,KAAK;gBACZH,QAAQ,EAAEI,iBAAiB;gBAC3Ba,MAAM,EAAEZ,eAAe;gBACvBa,MAAM,EAAC,OAAO;cACd;0BACF,KAAC7B,SAAS;gBACR0B,SAAS;gBACTC,KAAK,EAAC,oBAAoB;gBAC1Bf,KAAK,EAAEK,MAAM,aAANA,MAAM,cAANA,MAAM,GAAI,EAAE;gBACnBN,QAAQ,EAAEO,kBAAkB;gBAC5BU,MAAM,EAAET,gBAAgB;gBACxBU,MAAM,EAAC,OAAO;cACd;0BACF,MAAC5B,WAAW;gBAAC4B,MAAM,EAAC,OAAO;gBAACH,SAAS,EAAE,KAAK;;kCAG1C,KAACxB,UAAU;wBAAC4B,EAAE,EAAC,uBAAuB;kCAAC,uBAAqB;sBAAa;kCACzE,KAAC3B,gBAAgB;wBACf4B,oBAAoB,EAAC,sBAAsB;wBAC3CnB,KAAK,EAAEC,UAAU,aAAVA,UAAU,cAAVA,UAAU,GAAIT,YAAY;wBACjCO,QAAQ,EAAES,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,QAAQ,sBAAsB,CAAC;AAE3G;;CAEC,GACD,OAAO,SAASC,+BAA+B,CAACC,KAA2C,EAAE;IAC3F,MAAM,EAAEC,QAAQ,CAAA,EAAEC,KAAK,CAAA,EAAE,GAAGF,KAAK,AAAC;IAClC,MAAM,EAAEG,UAAU,CAAA,EAAE,GAAGD,KAAK,AAAC;IAE7B,MAAM,EAAEE,KAAK,CAAA,EAAEC,iBAAiB,CAAA,EAAEC,eAAe,CAAA,EAAE,GAAGT,aAAa,CAACG,KAAK,CAAC,AAAC;IAC3E,MAAM,EAAEO,MAAM,CAAA,EAAEC,kBAAkB,CAAA,EAAEC,gBAAgB,CAAA,EAAE,GAAGX,cAAc,CAACE,KAAK,CAAC,AAAC;IAE/E,MAAMU,sBAAsB,GAAsC,CAACC,IAAI,GAAK;QAC1E,IAAIf,8BAA8B,CAACe,IAAI,CAAC,EAAE;YACxCV,QAAQ,CACNb,OAA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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,CAiEvG,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"}
@@ -14,6 +14,12 @@ import { fromUnixTime } from 'date-fns';
14
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);
@@ -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 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 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 return chartData;\n};\n"],"names":["fromUnixTime","parseValueTuple","getDurationStringSeconds","getPrometheusTimeRange","getRangeStep","replaceTemplateVariables","DEFAULT_PROM","formatSeriesName","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","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;QA8BYC,GAAa;IA7B5B,MAAMC,OAAO,GAAGV,wBAAwB,CAACO,IAAI,CAACI,QAAQ,CAAC,AAAC;IACxD,MAAMC,SAAS,GAAGX,sBAAsB,CAACO,OAAO,CAACI,SAAS,CAAC,AAAC;IAC5D,MAAMC,IAAI,GAAGX,YAAY,CAACU,SAAS,EAAEF,OAAO,EAAEI,SAAS,EAAEN,OAAO,C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"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,GAA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AI,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"}
@@ -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,CAgB5F,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,9 +133,10 @@ export const PrometheusLabelNamesVariable = {
80
133
  data: stringArrayToVariableOptions(options)
81
134
  };
82
135
  },
83
- dependsOn: ()=>{
136
+ dependsOn: (spec)=>{
137
+ var ref;
84
138
  return {
85
- variables: []
139
+ variables: ((ref = spec.matchers) === null || ref === void 0 ? void 0 : ref.map((m)=>parseTemplateVariables(m)).flat()) || []
86
140
  };
87
141
  },
88
142
  OptionsEditorComponent: PrometheusLabelNamesVariableEditor,
@@ -96,7 +150,7 @@ export const PrometheusLabelValuesVariable = {
96
150
  const match = pluginDef.matchers ? pluginDef.matchers.map((m)=>replaceTemplateVariables(m, ctx.variables)) : undefined;
97
151
  const timeRange = getPrometheusTimeRange(ctx.timeRange);
98
152
  const { data: options } = await client.labelValues({
99
- labelName: pluginDef.label_name,
153
+ labelName: replaceTemplateVariables(pluginDef.label_name, ctx.variables),
100
154
  'match[]': match,
101
155
  ...timeRange
102
156
  });
@@ -107,7 +161,7 @@ export const PrometheusLabelValuesVariable = {
107
161
  dependsOn: (spec)=>{
108
162
  var ref;
109
163
  return {
110
- variables: ((ref = spec.matchers) === null || ref === void 0 ? void 0 : ref.map((m)=>parseTemplateVariables(m)).flat()) || []
164
+ variables: ((ref = spec.matchers) === null || ref === void 0 ? void 0 : ref.map((m)=>parseTemplateVariables(m)).flat().concat(parseTemplateVariables(spec.label_name))) || []
111
165
  };
112
166
  },
113
167
  OptionsEditorComponent: PrometheusLabelValuesVariableEditor,
@@ -115,5 +169,35 @@ export const PrometheusLabelValuesVariable = {
115
169
  label_name: ''
116
170
  })
117
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
+ };
118
202
 
119
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 return { variables: [] };\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: pluginDef.label_name,\n 'match[]': match,\n ...timeRange,\n });\n return {\n data: stringArrayToVariableOptions(options),\n };\n },\n dependsOn: (spec) => {\n return { variables: 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,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,AAAC;QAEd,MAAMC,SAAS,GAAG/B,sBAAsB,CAACsB,GAAG,CAACS,SAAS,CAAC,AAAC;QAExD,MAAM,EAAEC,IAAI,EAAEC,OAAO,CAAA,EAAE,GAAG,MAAMV,MAAM,CAACiB,WAAW,CAAC;YACjDC,SAAS,EAAEF,SAAS,CAAC9B,UAAU;YAC/B,SAAS,EAAEkB,KAAK;YAChB,GAAGI,SAAS;SACb,CAAC,AAAC;QACH,OAAO;YACLC,IAAI,EAAEhB,4BAA4B,CAACiB,OAAO,CAAC;SAC5C,CAAC;IACJ,CAAC;IACDE,SAAS,EAAE,CAACd,IAAI,GAAK;YACCA,GAAa;QAAjC,OAAO;YAAEQ,SAAS,EAAER,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;SAAE,CAAC;IAC1F,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,EACx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ACH,MAAMY,SAAS,GAAG3D,wBAAwB,CAACuC,IAAI,CAAC3B,UAAU,EAAE4B,GAAG,CAACO,SAAS,CAAC,AAAC;QAC3E,IAAIf,MAAM,GAAa,EAAE,AAAC;QAC1B,IAAIkB,CAAAA,OAAO,aAAPA,OAAO,WAAY,GAAnBA,KAAAA,CAAmB,GAAnBA,OAAO,CAAEc,UAAU,CAAA,KAAK,QAAQ,EAAE;YACpChC,MAAM,GAAGX,eAAe,CAAC6B,OAAO,EAAES,SAAS,CAAC,CAAC;QAC/C,OAAO,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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@perses-dev/prometheus-plugin",
3
- "version": "0.15.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.15.0",
34
- "@perses-dev/plugin-system": "^0.15.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",