@perses-dev/prometheus-plugin 0.32.0 → 0.34.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.
@@ -19,9 +19,8 @@ Object.defineProperty(exports, "useReplaceTemplateString", {
19
19
  get: ()=>useReplaceTemplateString
20
20
  });
21
21
  const _pluginSystem = require("@perses-dev/plugin-system");
22
- const _utils = require("../utils");
23
22
  function useReplaceTemplateString(templateString) {
24
- const templateVariablesInTemplate = (0, _utils.parseTemplateVariables)(templateString || '');
23
+ const templateVariablesInTemplate = (0, _pluginSystem.parseTemplateVariables)(templateString || '');
25
24
  const variables = (0, _pluginSystem.useTemplateVariableValues)(templateVariablesInTemplate);
26
- return (0, _utils.replaceTemplateVariables)(templateString || '', variables);
25
+ return (0, _pluginSystem.replaceTemplateVariables)(templateString || '', variables);
27
26
  }
@@ -18,7 +18,7 @@ Object.defineProperty(exports, "PrometheusTimeSeriesQuery", {
18
18
  enumerable: true,
19
19
  get: ()=>PrometheusTimeSeriesQuery
20
20
  });
21
- const _utils = require("../../utils");
21
+ const _pluginSystem = require("@perses-dev/plugin-system");
22
22
  const _getTimeSeriesData = require("./get-time-series-data");
23
23
  const _prometheusTimeSeriesQueryEditor = require("./PrometheusTimeSeriesQueryEditor");
24
24
  const PrometheusTimeSeriesQuery = {
@@ -29,8 +29,17 @@ const PrometheusTimeSeriesQuery = {
29
29
  datasource: undefined
30
30
  }),
31
31
  dependsOn: (spec)=>{
32
+ // Variables can be used in the query and/or in the legend format string
33
+ const queryVariables = (0, _pluginSystem.parseTemplateVariables)(spec.query);
34
+ const legendVariables = (0, _pluginSystem.parseTemplateVariables)(spec.series_name_format || '');
35
+ const allVariables = [
36
+ ...new Set([
37
+ ...queryVariables,
38
+ ...legendVariables
39
+ ])
40
+ ];
32
41
  return {
33
- variables: (0, _utils.parseTemplateVariables)(spec.query)
42
+ variables: allVariables
34
43
  };
35
44
  }
36
45
  };
@@ -18,6 +18,7 @@ Object.defineProperty(exports, "getTimeSeriesData", {
18
18
  enumerable: true,
19
19
  get: ()=>getTimeSeriesData
20
20
  });
21
+ const _pluginSystem = require("@perses-dev/plugin-system");
21
22
  const _dateFns = require("date-fns");
22
23
  const _model = require("../../model");
23
24
  const _utils = require("../../utils");
@@ -41,7 +42,12 @@ const getTimeSeriesData = async (spec, context)=>{
41
42
  end = alignedEnd;
42
43
  // Replace template variable placeholders in PromQL query
43
44
  let query = spec.query.replace('$__rate_interval', `15s`);
44
- query = (0, _utils.replaceTemplateVariables)(query, context.variableState);
45
+ query = (0, _pluginSystem.replaceTemplateVariables)(query, context.variableState);
46
+ let seriesNameFormat = spec.series_name_format;
47
+ // if series name format is defined, replace template variable placeholders in series name format
48
+ if (seriesNameFormat) {
49
+ seriesNameFormat = (0, _pluginSystem.replaceTemplateVariables)(seriesNameFormat, context.variableState);
50
+ }
45
51
  var _datasource;
46
52
  // Get the datasource, using the default Prom Datasource if one isn't specified in the query
47
53
  const client = await context.datasourceStore.getDatasourceClient((_datasource = spec.datasource) !== null && _datasource !== void 0 ? _datasource : _model.DEFAULT_PROM);
@@ -80,7 +86,7 @@ const getTimeSeriesData = async (spec, context)=>{
80
86
  series: result.map((value)=>{
81
87
  const { metric , values } = value;
82
88
  // Account for series_name_format from query editor when determining name to show in legend, tooltip, etc.
83
- const { name , formattedName } = (0, _utils.getFormattedPrometheusSeriesName)(query, metric, spec.series_name_format);
89
+ const { name , formattedName } = (0, _utils.getFormattedPrometheusSeriesName)(query, metric, seriesNameFormat);
84
90
  return {
85
91
  name,
86
92
  values: values.map(_model.parseValueTuple),
@@ -30,7 +30,6 @@ const _pluginSystem = require("@perses-dev/plugin-system");
30
30
  const _material = require("@mui/material");
31
31
  const _immer = require("immer");
32
32
  const _model = require("../model");
33
- const _utils = require("../utils");
34
33
  const _components = require("../components");
35
34
  const _matcherEditor = require("./MatcherEditor");
36
35
  function PrometheusLabelValuesVariableEditor(props) {
@@ -232,7 +231,7 @@ const PrometheusLabelNamesVariable = {
232
231
  getVariableOptions: async (spec, ctx)=>{
233
232
  var _datasource;
234
233
  const client = await ctx.datasourceStore.getDatasourceClient((_datasource = spec.datasource) !== null && _datasource !== void 0 ? _datasource : _model.DEFAULT_PROM);
235
- const match = spec.matchers ? spec.matchers.map((m)=>(0, _utils.replaceTemplateVariables)(m, ctx.variables)) : undefined;
234
+ const match = spec.matchers ? spec.matchers.map((m)=>(0, _pluginSystem.replaceTemplateVariables)(m, ctx.variables)) : undefined;
236
235
  const timeRange = (0, _model.getPrometheusTimeRange)(ctx.timeRange);
237
236
  const { data: options } = await client.labelNames({
238
237
  'match[]': match,
@@ -245,7 +244,7 @@ const PrometheusLabelNamesVariable = {
245
244
  dependsOn: (spec)=>{
246
245
  var ref;
247
246
  return {
248
- variables: ((ref = spec.matchers) === null || ref === void 0 ? void 0 : ref.map((m)=>(0, _utils.parseTemplateVariables)(m)).flat()) || []
247
+ variables: ((ref = spec.matchers) === null || ref === void 0 ? void 0 : ref.map((m)=>(0, _pluginSystem.parseTemplateVariables)(m)).flat()) || []
249
248
  };
250
249
  },
251
250
  OptionsEditorComponent: PrometheusLabelNamesVariableEditor,
@@ -256,10 +255,10 @@ const PrometheusLabelValuesVariable = {
256
255
  const pluginDef = spec;
257
256
  var _datasource;
258
257
  const client = await ctx.datasourceStore.getDatasourceClient((_datasource = spec.datasource) !== null && _datasource !== void 0 ? _datasource : _model.DEFAULT_PROM);
259
- const match = pluginDef.matchers ? pluginDef.matchers.map((m)=>(0, _utils.replaceTemplateVariables)(m, ctx.variables)) : undefined;
258
+ const match = pluginDef.matchers ? pluginDef.matchers.map((m)=>(0, _pluginSystem.replaceTemplateVariables)(m, ctx.variables)) : undefined;
260
259
  const timeRange = (0, _model.getPrometheusTimeRange)(ctx.timeRange);
261
260
  const { data: options } = await client.labelValues({
262
- labelName: (0, _utils.replaceTemplateVariables)(pluginDef.label_name, ctx.variables),
261
+ labelName: (0, _pluginSystem.replaceTemplateVariables)(pluginDef.label_name, ctx.variables),
263
262
  'match[]': match,
264
263
  ...timeRange
265
264
  });
@@ -270,7 +269,7 @@ const PrometheusLabelValuesVariable = {
270
269
  dependsOn: (spec)=>{
271
270
  var ref;
272
271
  return {
273
- variables: ((ref = spec.matchers) === null || ref === void 0 ? void 0 : ref.map((m)=>(0, _utils.parseTemplateVariables)(m)).flat().concat((0, _utils.parseTemplateVariables)(spec.label_name))) || []
272
+ variables: ((ref = spec.matchers) === null || ref === void 0 ? void 0 : ref.map((m)=>(0, _pluginSystem.parseTemplateVariables)(m)).flat().concat((0, _pluginSystem.parseTemplateVariables)(spec.label_name))) || []
274
273
  };
275
274
  },
276
275
  OptionsEditorComponent: PrometheusLabelValuesVariableEditor,
@@ -284,9 +283,9 @@ const PrometheusPromQLVariable = {
284
283
  const client = await ctx.datasourceStore.getDatasourceClient((_datasource = spec.datasource) !== null && _datasource !== void 0 ? _datasource : _model.DEFAULT_PROM);
285
284
  // TODO we may want to manage a range query as well.
286
285
  const { data: options } = await client.instantQuery({
287
- query: (0, _utils.replaceTemplateVariables)(spec.expr, ctx.variables)
286
+ query: (0, _pluginSystem.replaceTemplateVariables)(spec.expr, ctx.variables)
288
287
  });
289
- const labelName = (0, _utils.replaceTemplateVariables)(spec.label_name, ctx.variables);
288
+ const labelName = (0, _pluginSystem.replaceTemplateVariables)(spec.label_name, ctx.variables);
290
289
  let values = [];
291
290
  if ((options === null || options === void 0 ? void 0 : options.resultType) === 'matrix') {
292
291
  values = capturingMatrix(options, labelName);
@@ -299,7 +298,7 @@ const PrometheusPromQLVariable = {
299
298
  },
300
299
  dependsOn: (spec)=>{
301
300
  return {
302
- variables: (0, _utils.parseTemplateVariables)(spec.expr).concat((0, _utils.parseTemplateVariables)(spec.label_name))
301
+ variables: (0, _pluginSystem.parseTemplateVariables)(spec.expr).concat((0, _pluginSystem.parseTemplateVariables)(spec.label_name))
303
302
  };
304
303
  },
305
304
  OptionsEditorComponent: PrometheusPromQLVariableEditor,
@@ -21,51 +21,11 @@ function _export(target, all) {
21
21
  });
22
22
  }
23
23
  _export(exports, {
24
- replaceTemplateVariables: ()=>replaceTemplateVariables,
25
- replaceTemplateVariable: ()=>replaceTemplateVariable,
26
- parseTemplateVariables: ()=>parseTemplateVariables,
27
24
  formatSeriesName: ()=>formatSeriesName,
28
25
  getUniqueKeyForPrometheusResult: ()=>getUniqueKeyForPrometheusResult,
29
26
  getFormattedPrometheusSeriesName: ()=>getFormattedPrometheusSeriesName
30
27
  });
31
28
  const _core = require("@perses-dev/core");
32
- function replaceTemplateVariables(text, variableState) {
33
- const variables = parseTemplateVariables(text);
34
- let finalText = text;
35
- variables.forEach((v)=>{
36
- const variable = variableState[v];
37
- if (variable && (variable === null || variable === void 0 ? void 0 : variable.value)) {
38
- finalText = replaceTemplateVariable(finalText, v, variable === null || variable === void 0 ? void 0 : variable.value);
39
- }
40
- });
41
- return finalText;
42
- }
43
- function replaceTemplateVariable(text, varName, templateVariableValue) {
44
- const variableTemplate = '$' + varName;
45
- let replaceString = '';
46
- if (Array.isArray(templateVariableValue)) {
47
- replaceString = `(${templateVariableValue.join('|')})`; // regex style
48
- }
49
- if (typeof templateVariableValue === 'string') {
50
- replaceString = templateVariableValue;
51
- }
52
- return text.replaceAll(variableTemplate, replaceString);
53
- }
54
- // TODO: Fix this lint error
55
- // eslint-disable-next-line no-useless-escape
56
- const TEMPLATE_VARIABLE_REGEX = /\$(\w+)|\${(\w+)(?:\.([^:^\}]+))?(?::([^\}]+))?}/gm;
57
- const parseTemplateVariables = (text)=>{
58
- const regex = TEMPLATE_VARIABLE_REGEX;
59
- const matches = new Set();
60
- let match;
61
- while((match = regex.exec(text)) !== null){
62
- if (match && match.length > 1 && match[1]) {
63
- matches.add(match[1]);
64
- }
65
- }
66
- // return unique matches
67
- return Array.from(matches.values());
68
- };
69
29
  function formatSeriesName(inputFormat, seriesLabels) {
70
30
  const resolveLabelsRegex = /\{\{\s*(.+?)\s*\}\}/g;
71
31
  return inputFormat.replace(resolveLabelsRegex, (_match, token)=>{
@@ -1 +1 @@
1
- {"version":3,"file":"templating.d.ts","sourceRoot":"","sources":["../../src/model/templating.ts"],"names":[],"mappings":"AAgBA;;GAEG;AACH,oBAAY,cAAc,GAAG,MAAM,CAAC;AAEpC,wBAAgB,wBAAwB,CAAC,cAAc,CAAC,EAAE,cAAc,UAIvE"}
1
+ {"version":3,"file":"templating.d.ts","sourceRoot":"","sources":["../../src/model/templating.ts"],"names":[],"mappings":"AAeA;;GAEG;AACH,oBAAY,cAAc,GAAG,MAAM,CAAC;AAEpC,wBAAgB,wBAAwB,CAAC,cAAc,CAAC,EAAE,cAAc,UAIvE"}
@@ -10,8 +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 { useTemplateVariableValues } from '@perses-dev/plugin-system';
14
- import { replaceTemplateVariables, parseTemplateVariables } from '../utils';
13
+ import { useTemplateVariableValues, replaceTemplateVariables, parseTemplateVariables } from '@perses-dev/plugin-system';
15
14
  export function useReplaceTemplateString(templateString) {
16
15
  const templateVariablesInTemplate = parseTemplateVariables(templateString || '');
17
16
  const variables = useTemplateVariableValues(templateVariablesInTemplate);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/model/templating.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { useTemplateVariableValues } from '@perses-dev/plugin-system';\nimport { replaceTemplateVariables, parseTemplateVariables } from '../utils';\n\n/**\n * Type alias to indicate what parts of the API support template variables.\n */\nexport type TemplateString = string;\n\nexport function useReplaceTemplateString(templateString?: TemplateString) {\n const templateVariablesInTemplate = parseTemplateVariables(templateString || '');\n const variables = useTemplateVariableValues(templateVariablesInTemplate);\n return replaceTemplateVariables(templateString || '', variables);\n}\n"],"names":["useTemplateVariableValues","replaceTemplateVariables","parseTemplateVariables","useReplaceTemplateString","templateString","templateVariablesInTemplate","variables"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,yBAAyB,QAAQ,2BAA2B,CAAC;AACtE,SAASC,wBAAwB,EAAEC,sBAAsB,QAAQ,UAAU,CAAC;AAO5E,OAAO,SAASC,wBAAwB,CAACC,cAA+B,EAAE;IACxE,MAAMC,2BAA2B,GAAGH,sBAAsB,CAACE,cAAc,IAAI,EAAE,CAAC,AAAC;IACjF,MAAME,SAAS,GAAGN,yBAAyB,CAACK,2BAA2B,CAAC,AAAC;IACzE,OAAOJ,wBAAwB,CAACG,cAAc,IAAI,EAAE,EAAEE,SAAS,CAAC,CAAC;AACnE,CAAC"}
1
+ {"version":3,"sources":["../../src/model/templating.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { useTemplateVariableValues, replaceTemplateVariables, parseTemplateVariables } from '@perses-dev/plugin-system';\n\n/**\n * Type alias to indicate what parts of the API support template variables.\n */\nexport type TemplateString = string;\n\nexport function useReplaceTemplateString(templateString?: TemplateString) {\n const templateVariablesInTemplate = parseTemplateVariables(templateString || '');\n const variables = useTemplateVariableValues(templateVariablesInTemplate);\n return replaceTemplateVariables(templateString || '', variables);\n}\n"],"names":["useTemplateVariableValues","replaceTemplateVariables","parseTemplateVariables","useReplaceTemplateString","templateString","templateVariablesInTemplate","variables"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,yBAAyB,EAAEC,wBAAwB,EAAEC,sBAAsB,QAAQ,2BAA2B,CAAC;AAOxH,OAAO,SAASC,wBAAwB,CAACC,cAA+B,EAAE;IACxE,MAAMC,2BAA2B,GAAGH,sBAAsB,CAACE,cAAc,IAAI,EAAE,CAAC,AAAC;IACjF,MAAME,SAAS,GAAGN,yBAAyB,CAACK,2BAA2B,CAAC,AAAC;IACzE,OAAOJ,wBAAwB,CAACG,cAAc,IAAI,EAAE,EAAEE,SAAS,CAAC,CAAC;AACnE,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;AAIlE,OAAO,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAE1E;;GAEG;AACH,eAAO,MAAM,yBAAyB,EAAE,qBAAqB,CAAC,6BAA6B,CAY1F,CAAC"}
1
+ {"version":3,"file":"PrometheusTimeSeriesQuery.d.ts","sourceRoot":"","sources":["../../../src/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,qBAAqB,EAA0B,MAAM,2BAA2B,CAAC;AAG1F,OAAO,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAE1E;;GAEG;AACH,eAAO,MAAM,yBAAyB,EAAE,qBAAqB,CAAC,6BAA6B,CAgB1F,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 } from '../../utils';
13
+ import { parseTemplateVariables } from '@perses-dev/plugin-system';
14
14
  import { getTimeSeriesData } from './get-time-series-data';
15
15
  import { PrometheusTimeSeriesQueryEditor } from './PrometheusTimeSeriesQueryEditor';
16
16
  /**
@@ -23,8 +23,17 @@ import { PrometheusTimeSeriesQueryEditor } from './PrometheusTimeSeriesQueryEdit
23
23
  datasource: undefined
24
24
  }),
25
25
  dependsOn: (spec)=>{
26
+ // Variables can be used in the query and/or in the legend format string
27
+ const queryVariables = parseTemplateVariables(spec.query);
28
+ const legendVariables = parseTemplateVariables(spec.series_name_format || '');
29
+ const allVariables = [
30
+ ...new Set([
31
+ ...queryVariables,
32
+ ...legendVariables
33
+ ])
34
+ ];
26
35
  return {
27
- variables: parseTemplateVariables(spec.query)
36
+ variables: allVariables
28
37
  };
29
38
  }
30
39
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { TimeSeriesQueryPlugin } from '@perses-dev/plugin-system';\nimport { parseTemplateVariables } from '../../utils';\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
+ {"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { TimeSeriesQueryPlugin, parseTemplateVariables } from '@perses-dev/plugin-system';\nimport { getTimeSeriesData } from './get-time-series-data';\nimport { PrometheusTimeSeriesQueryEditor } from './PrometheusTimeSeriesQueryEditor';\nimport { PrometheusTimeSeriesQuerySpec } from './time-series-query-model';\n\n/**\n * The core Prometheus TimeSeriesQuery plugin for Perses.\n */\nexport const PrometheusTimeSeriesQuery: TimeSeriesQueryPlugin<PrometheusTimeSeriesQuerySpec> = {\n getTimeSeriesData,\n OptionsEditorComponent: PrometheusTimeSeriesQueryEditor,\n createInitialOptions: () => ({\n query: '',\n datasource: undefined,\n }),\n dependsOn: (spec) => {\n // Variables can be used in the query and/or in the legend format string\n const queryVariables = parseTemplateVariables(spec.query);\n const legendVariables = parseTemplateVariables(spec.series_name_format || '');\n const allVariables = [...new Set([...queryVariables, ...legendVariables])];\n return {\n variables: allVariables,\n };\n },\n};\n"],"names":["parseTemplateVariables","getTimeSeriesData","PrometheusTimeSeriesQueryEditor","PrometheusTimeSeriesQuery","OptionsEditorComponent","createInitialOptions","query","datasource","undefined","dependsOn","spec","queryVariables","legendVariables","series_name_format","allVariables","Set","variables"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAAgCA,sBAAsB,QAAQ,2BAA2B,CAAC;AAC1F,SAASC,iBAAiB,QAAQ,wBAAwB,CAAC;AAC3D,SAASC,+BAA+B,QAAQ,mCAAmC,CAAC;AAGpF;;CAEC,GACD,OAAO,MAAMC,yBAAyB,GAAyD;IAC7FF,iBAAiB;IACjBG,sBAAsB,EAAEF,+BAA+B;IACvDG,oBAAoB,EAAE,IAAO,CAAA;YAC3BC,KAAK,EAAE,EAAE;YACTC,UAAU,EAAEC,SAAS;SACtB,CAAA,AAAC;IACFC,SAAS,EAAE,CAACC,IAAI,GAAK;QACnB,wEAAwE;QACxE,MAAMC,cAAc,GAAGX,sBAAsB,CAACU,IAAI,CAACJ,KAAK,CAAC,AAAC;QAC1D,MAAMM,eAAe,GAAGZ,sBAAsB,CAACU,IAAI,CAACG,kBAAkB,IAAI,EAAE,CAAC,AAAC;QAC9E,MAAMC,YAAY,GAAG;eAAI,IAAIC,GAAG,CAAC;mBAAIJ,cAAc;mBAAKC,eAAe;aAAC,CAAC;SAAC,AAAC;QAC3E,OAAO;YACLI,SAAS,EAAEF,YAAY;SACxB,CAAC;IACJ,CAAC;CACF,CAAC"}
@@ -1 +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":"AAcA,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAWlE,OAAO,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAE1E,eAAO,MAAM,iBAAiB,EAAE,qBAAqB,CAAC,6BAA6B,CAAC,CAAC,mBAAmB,CA8EvG,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":"AAcA,OAAO,EAAE,qBAAqB,EAA4B,MAAM,2BAA2B,CAAC;AAW5F,OAAO,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAE1E,eAAO,MAAM,iBAAiB,EAAE,qBAAqB,CAAC,6BAA6B,CAAC,CAAC,mBAAmB,CAoFvG,CAAC"}
@@ -10,9 +10,10 @@
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 { replaceTemplateVariables } from '@perses-dev/plugin-system';
13
14
  import { fromUnixTime } from 'date-fns';
14
15
  import { parseValueTuple, getDurationStringSeconds, getPrometheusTimeRange, getRangeStep, DEFAULT_PROM } from '../../model';
15
- import { getFormattedPrometheusSeriesName, replaceTemplateVariables } from '../../utils';
16
+ import { getFormattedPrometheusSeriesName } from '../../utils';
16
17
  export const getTimeSeriesData = async (spec, context)=>{
17
18
  var ref;
18
19
  if (spec.query === undefined || spec.query === null || spec.query === '') {
@@ -34,6 +35,11 @@ export const getTimeSeriesData = async (spec, context)=>{
34
35
  // Replace template variable placeholders in PromQL query
35
36
  let query = spec.query.replace('$__rate_interval', `15s`);
36
37
  query = replaceTemplateVariables(query, context.variableState);
38
+ let seriesNameFormat = spec.series_name_format;
39
+ // if series name format is defined, replace template variable placeholders in series name format
40
+ if (seriesNameFormat) {
41
+ seriesNameFormat = replaceTemplateVariables(seriesNameFormat, context.variableState);
42
+ }
37
43
  var _datasource;
38
44
  // Get the datasource, using the default Prom Datasource if one isn't specified in the query
39
45
  const client = await context.datasourceStore.getDatasourceClient((_datasource = spec.datasource) !== null && _datasource !== void 0 ? _datasource : DEFAULT_PROM);
@@ -72,7 +78,7 @@ export const getTimeSeriesData = async (spec, context)=>{
72
78
  series: result.map((value)=>{
73
79
  const { metric , values } = value;
74
80
  // Account for series_name_format from query editor when determining name to show in legend, tooltip, etc.
75
- const { name , formattedName } = getFormattedPrometheusSeriesName(query, metric, spec.series_name_format);
81
+ const { name , formattedName } = getFormattedPrometheusSeriesName(query, metric, seriesNameFormat);
76
82
  return {
77
83
  name,
78
84
  values: values.map(parseValueTuple),
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/get-time-series-data.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Notice, TimeSeriesData } from '@perses-dev/core';\nimport { TimeSeriesQueryPlugin } from '@perses-dev/plugin-system';\nimport { fromUnixTime } from 'date-fns';\nimport {\n parseValueTuple,\n PrometheusClient,\n getDurationStringSeconds,\n getPrometheusTimeRange,\n getRangeStep,\n DEFAULT_PROM,\n} from '../../model';\nimport { getFormattedPrometheusSeriesName, replaceTemplateVariables } from '../../utils';\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 // Custom display for response header warnings, configurable error responses display coming next\n const notices: Notice[] = [];\n if (response.status === 'success') {\n const warnings = response.warnings ?? [];\n const warningMessage = warnings[0] ?? '';\n if (warningMessage !== '') {\n notices.push({\n type: 'warning',\n message: warningMessage,\n });\n }\n }\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 series: result.map((value) => {\n const { metric, values } = value;\n\n // Account for series_name_format from query editor when determining name to show in legend, tooltip, etc.\n const { name, formattedName } = getFormattedPrometheusSeriesName(query, metric, spec.series_name_format);\n\n return {\n name,\n values: values.map(parseValueTuple),\n formattedName,\n labels: metric,\n };\n }),\n metadata: {\n notices,\n },\n };\n\n return chartData;\n};\n"],"names":["fromUnixTime","parseValueTuple","getDurationStringSeconds","getPrometheusTimeRange","getRangeStep","DEFAULT_PROM","getFormattedPrometheusSeriesName","replaceTemplateVariables","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","notices","status","warnings","warningMessage","push","type","message","chartData","stepMs","map","value","metric","values","name","formattedName","series_name_format","labels","metadata"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC,SAASA,YAAY,QAAQ,UAAU,CAAC;AACxC,SACEC,eAAe,EAEfC,wBAAwB,EACxBC,sBAAsB,EACtBC,YAAY,EACZC,YAAY,QACP,aAAa,CAAC;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ED,qBAAqB;IACrB,MAAMI,SAAS,GAAmB;QAChC,gEAAgE;QAChE5B,SAAS,EAAE;YAAEG,KAAK,EAAEpB,YAAY,CAACoB,KAAK,CAAC;YAAEC,GAAG,EAAErB,YAAY,CAACqB,GAAG,CAAC;SAAE;QACjEyB,MAAM,EAAE5B,IAAI,GAAG,IAAI;QAEnBJ,MAAM,EAAEsB,MAAM,CAACW,GAAG,CAAC,CAACC,KAAK,GAAK;YAC5B,MAAM,EAAEC,MAAM,CAAA,EAAEC,MAAM,CAAA,EAAE,GAAGF,KAAK,AAAC;YAEjC,0GAA0G;YAC1G,MAAM,EAAEG,IAAI,CAAA,EAAEC,aAAa,CAAA,EAAE,GAAG9C,gCAAgC,CAACM,KAAK,EAAEqC,MAAM,EAAExC,IAAI,CAAC4C,kBAAkB,CAAC,AAAC;YAEzG,OAAO;gBACLF,IAAI;gBACJD,MAAM,EAAEA,MAAM,CAACH,GAAG,CAAC9C,eAAe,CAAC;gBACnCmD,aAAa;gBACbE,MAAM,EAAEL,MAAM;aACf,CAAC;QACJ,CAAC,CAAC;QACFM,QAAQ,EAAE;YACRjB,OAAO;SACR;KACF,AAAC;IAEF,OAAOO,SAAS,CAAC;AACnB,CAAC,CAAC"}
1
+ {"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/get-time-series-data.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Notice, TimeSeriesData } from '@perses-dev/core';\nimport { TimeSeriesQueryPlugin, replaceTemplateVariables } from '@perses-dev/plugin-system';\nimport { fromUnixTime } from 'date-fns';\nimport {\n parseValueTuple,\n PrometheusClient,\n getDurationStringSeconds,\n getPrometheusTimeRange,\n getRangeStep,\n DEFAULT_PROM,\n} from '../../model';\nimport { getFormattedPrometheusSeriesName } from '../../utils';\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 let seriesNameFormat = spec.series_name_format;\n // if series name format is defined, replace template variable placeholders in series name format\n if (seriesNameFormat) {\n seriesNameFormat = replaceTemplateVariables(seriesNameFormat, context.variableState);\n }\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 // Custom display for response header warnings, configurable error responses display coming next\n const notices: Notice[] = [];\n if (response.status === 'success') {\n const warnings = response.warnings ?? [];\n const warningMessage = warnings[0] ?? '';\n if (warningMessage !== '') {\n notices.push({\n type: 'warning',\n message: warningMessage,\n });\n }\n }\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 series: result.map((value) => {\n const { metric, values } = value;\n\n // Account for series_name_format from query editor when determining name to show in legend, tooltip, etc.\n const { name, formattedName } = getFormattedPrometheusSeriesName(query, metric, seriesNameFormat);\n\n return {\n name,\n values: values.map(parseValueTuple),\n formattedName,\n labels: metric,\n };\n }),\n metadata: {\n notices,\n },\n };\n\n return chartData;\n};\n"],"names":["replaceTemplateVariables","fromUnixTime","parseValueTuple","getDurationStringSeconds","getPrometheusTimeRange","getRangeStep","DEFAULT_PROM","getFormattedPrometheusSeriesName","getTimeSeriesData","spec","context","response","query","undefined","series","minStep","min_step","timeRange","step","suggestedStepMs","start","end","utcOffsetSec","Date","getTimezoneOffset","alignedEnd","Math","floor","alignedStart","replace","variableState","seriesNameFormat","series_name_format","client","datasourceStore","getDatasourceClient","datasource","rangeQuery","result","data","notices","status","warnings","warningMessage","push","type","message","chartData","stepMs","map","value","metric","values","name","formattedName","labels","metadata"],"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,SAAgCA,wBAAwB,QAAQ,2BAA2B,CAAC;AAC5F,SAASC,YAAY,QAAQ,UAAU,CAAC;AACxC,SACEC,eAAe,EAEfC,wBAAwB,EACxBC,sBAAsB,EACtBC,YAAY,EACZC,YAAY,QACP,aAAa,CAAC;AACrB,SAASC,gCAAgC,QAAQ,aAAa,CAAC;AAG/D,OAAO,MAAMC,iBAAiB,GAA8E,OAC1GC,IAAI,EACJC,OAAO,GACJ;QAyCYC,GAAa;IAxC5B,IAAIF,IAAI,CAACG,KAAK,KAAKC,SAAS,IAAIJ,IAAI,CAACG,KAAK,KAA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IACrB,MAAMI,SAAS,GAAmB;QAChC,gEAAgE;QAChE9B,SAAS,EAAE;YAAEG,KAAK,EAAEnB,YAAY,CAACmB,KAAK,CAAC;YAAEC,GAAG,EAAEpB,YAAY,CAACoB,GAAG,CAAC;SAAE;QACjE2B,MAAM,EAAE9B,IAAI,GAAG,IAAI;QAEnBJ,MAAM,EAAEwB,MAAM,CAACW,GAAG,CAAC,CAACC,KAAK,GAAK;YAC5B,MAAM,EAAEC,MAAM,CAAA,EAAEC,MAAM,CAAA,EAAE,GAAGF,KAAK,AAAC;YAEjC,0GAA0G;YAC1G,MAAM,EAAEG,IAAI,CAAA,EAAEC,aAAa,CAAA,EAAE,GAAG/C,gCAAgC,CAACK,KAAK,EAAEuC,MAAM,EAAEpB,gBAAgB,CAAC,AAAC;YAElG,OAAO;gBACLsB,IAAI;gBACJD,MAAM,EAAEA,MAAM,CAACH,GAAG,CAAC/C,eAAe,CAAC;gBACnCoD,aAAa;gBACbC,MAAM,EAAEJ,MAAM;aACf,CAAC;QACJ,CAAC,CAAC;QACFK,QAAQ,EAAE;YACRhB,OAAO;SACR;KACF,AAAC;IAEF,OAAOO,SAAS,CAAC;AACnB,CAAC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"prometheus-variables.d.ts","sourceRoot":"","sources":["../../src/plugins/prometheus-variables.tsx"],"names":[],"mappings":"AAYA,OAAO,EAML,cAAc,EACf,MAAM,2BAA2B,CAAC;AAenC,OAAO,EACL,mCAAmC,EACnC,oCAAoC,EACpC,+BAA+B,EAChC,MAAM,SAAS,CAAC;AAmLjB,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"}
1
+ {"version":3,"file":"prometheus-variables.d.ts","sourceRoot":"","sources":["../../src/plugins/prometheus-variables.tsx"],"names":[],"mappings":"AAYA,OAAO,EAML,cAAc,EAGf,MAAM,2BAA2B,CAAC;AAcnC,OAAO,EACL,mCAAmC,EACnC,oCAAoC,EACpC,+BAA+B,EAChC,MAAM,SAAS,CAAC;AAmLjB,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"}
@@ -11,11 +11,10 @@
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
13
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
- import { DatasourceSelect, useDatasourceClient } from '@perses-dev/plugin-system';
14
+ import { DatasourceSelect, useDatasourceClient, parseTemplateVariables, replaceTemplateVariables } from '@perses-dev/plugin-system';
15
15
  import { FormControl, InputLabel, Stack, TextField } from '@mui/material';
16
16
  import { produce } from 'immer';
17
17
  import { DEFAULT_PROM, getPrometheusTimeRange, isDefaultPromSelector, isPrometheusDatasourceSelector, PROM_DATASOURCE_KIND } from '../model';
18
- import { parseTemplateVariables, replaceTemplateVariables } from '../utils';
19
18
  import { PromQLEditor } from '../components';
20
19
  import { MatcherEditor } from './MatcherEditor';
21
20
  function PrometheusLabelValuesVariableEditor(props) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/plugins/prometheus-variables.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\nimport {\n DatasourceSelect,\n DatasourceSelectProps,\n OptionsEditorProps,\n useDatasourceClient,\n VariableOption,\n VariablePlugin,\n} from '@perses-dev/plugin-system';\nimport { FormControl, InputLabel, Stack, TextField } from '@mui/material';\nimport { produce } from 'immer';\nimport {\n DEFAULT_PROM,\n getPrometheusTimeRange,\n isDefaultPromSelector,\n isPrometheusDatasourceSelector,\n MatrixData,\n PROM_DATASOURCE_KIND,\n PrometheusClient,\n VectorData,\n} from '../model';\nimport { parseTemplateVariables, replaceTemplateVariables } from '../utils';\nimport { PromQLEditor } from '../components';\nimport {\n PrometheusLabelNamesVariableOptions,\n PrometheusLabelValuesVariableOptions,\n PrometheusPromQLVariableOptions,\n} from './types';\nimport { MatcherEditor } from './MatcherEditor';\n\nfunction PrometheusLabelValuesVariableEditor(props: OptionsEditorProps<PrometheusLabelValuesVariableOptions>) {\n const { onChange, value } = props;\n const { datasource } = value;\n const selectedDatasource = datasource ?? DEFAULT_PROM;\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 draft.datasource = isDefaultPromSelector(next) ? undefined : next;\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 <FormControl margin=\"dense\">\n <InputLabel id=\"prom-datasource-label\">Prometheus Datasource</InputLabel>\n <DatasourceSelect\n datasourcePluginKind=\"PrometheusDatasource\"\n value={selectedDatasource}\n onChange={handleDatasourceChange}\n labelId=\"prom-datasource-label\"\n label=\"Prometheus Datasource\"\n />\n </FormControl>\n <TextField\n label=\"Label Name\"\n required\n value={props.value.label_name}\n onChange={(e) => {\n props.onChange({ ...props.value, label_name: e.target.value });\n }}\n />\n <MatcherEditor\n matchers={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 const { onChange, value } = props;\n const { datasource } = value;\n const selectedDatasource = datasource ?? DEFAULT_PROM;\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 draft.datasource = isDefaultPromSelector(next) ? undefined : next;\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 <FormControl margin=\"dense\">\n <InputLabel id=\"prom-datasource-label\">Prometheus Datasource</InputLabel>\n <DatasourceSelect\n datasourcePluginKind=\"PrometheusDatasource\"\n value={selectedDatasource}\n onChange={handleDatasourceChange}\n labelId=\"prom-datasource-label\"\n label=\"Prometheus Datasource\"\n />\n </FormControl>\n <MatcherEditor\n matchers={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 const { onChange, value } = props;\n const { datasource } = value;\n const selectedDatasource = datasource ?? DEFAULT_PROM;\n\n const { data: client } = useDatasourceClient<PrometheusClient>(selectedDatasource);\n const promURL = client?.options.datasourceUrl;\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 draft.datasource = isDefaultPromSelector(next) ? undefined : next;\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 <FormControl margin=\"dense\">\n <InputLabel id=\"prom-datasource-label\">Prometheus Datasource</InputLabel>\n <DatasourceSelect\n datasourcePluginKind={PROM_DATASOURCE_KIND}\n value={selectedDatasource}\n onChange={handleDatasourceChange}\n labelId=\"prom-datasource-label\"\n label=\"Prometheus Datasource\"\n />\n </FormControl>\n <PromQLEditor\n completeConfig={{ remote: { url: promURL } }}\n value={value.expr}\n onChange={(query) => {\n props.onChange({ ...props.value, expr: query });\n }}\n width=\"100%\"\n />\n <TextField\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":["DatasourceSelect","useDatasourceClient","FormControl","InputLabel","Stack","TextField","produce","DEFAULT_PROM","getPrometheusTimeRange","isDefaultPromSelector","isPrometheusDatasourceSelector","PROM_DATASOURCE_KIND","parseTemplateVariables","replaceTemplateVariables","PromQLEditor","MatcherEditor","PrometheusLabelValuesVariableEditor","props","onChange","value","datasource","selectedDatasource","handleDatasourceChange","next","draft","undefined","Error","spacing","margin","id","datasourcePluginKind","labelId","label","required","label_name","e","target","matchers","PrometheusLabelNamesVariableEditor","PrometheusPromQLVariableEditor","data","client","promURL","options","datasourceUrl","completeConfig","remote","url","expr","query","width","capturingMatrix","matrix","captured","Set","sample","result","metric","add","Array","from","values","capturingVector","vector","stringArrayToVariableOptions","map","PrometheusLabelNamesVariable","getVariableOptions","spec","ctx","datasourceStore","getDatasourceClient","match","m","variables","timeRange","labelNames","dependsOn","flat","OptionsEditorComponent","createInitialOptions","PrometheusLabelValuesVariable","pluginDef","labelValues","labelName","concat","PrometheusPromQLVariable","instantQuery","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;AAAA,SACEA,gBAAgB,EAGhBC,mBAAmB,QAGd,2BAA2B,CAAC;AACnC,SAASC,WAAW,EAAEC,UAAU,EAAEC,KAAK,EAAEC,SAAS,QAAQ,eAAe,CAAC;AAC1E,SAASC,OAAO,QAAQ,OAAO,CAAC;AAChC,SACEC,YAAY,EACZC,sBAAsB,EACtBC,qBAAqB,EACrBC,8BAA8B,EAE9BC,oBAAoB,QAGf,UAAU,CAAC;AAClB,SAASC,sBAAsB,EAAEC,wBAAwB,QAAQ,UAAU,CAAC;AAC5E,SAASC,YAAY,QAAQ,eAAe,CAAC;AAM7C,SAASC,aAAa,QAAQ,iBAAiB,CAAC;AAEhD,SAASC,mCAAmC,CAACC,KAA+D,EAAE;IAC5G,MAAM,EAAEC,QAAQ,CAAA,EAAEC,KAAK,CAAA,EAAE,GAAGF,KAAK,AAAC;IAClC,MAAM,EAAEG,UAAU,CAAA,EAAE,GAAGD,KAAK,AAAC;IAC7B,MAAME,kBAAkB,GAAGD,UA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B,EAAE,IAAO,CAAA;YAAEhC,IAAI,EAAE,EAAE;YAAEd,UAAU,EAAE,EAAE;SAAE,CAAA,AAAC;CAC3D,CAAC"}
1
+ {"version":3,"sources":["../../src/plugins/prometheus-variables.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\nimport {\n DatasourceSelect,\n DatasourceSelectProps,\n OptionsEditorProps,\n useDatasourceClient,\n VariableOption,\n VariablePlugin,\n parseTemplateVariables,\n replaceTemplateVariables,\n} from '@perses-dev/plugin-system';\nimport { FormControl, InputLabel, Stack, TextField } from '@mui/material';\nimport { produce } from 'immer';\nimport {\n DEFAULT_PROM,\n getPrometheusTimeRange,\n isDefaultPromSelector,\n isPrometheusDatasourceSelector,\n MatrixData,\n PROM_DATASOURCE_KIND,\n PrometheusClient,\n VectorData,\n} from '../model';\nimport { PromQLEditor } from '../components';\nimport {\n PrometheusLabelNamesVariableOptions,\n PrometheusLabelValuesVariableOptions,\n PrometheusPromQLVariableOptions,\n} from './types';\nimport { MatcherEditor } from './MatcherEditor';\n\nfunction PrometheusLabelValuesVariableEditor(props: OptionsEditorProps<PrometheusLabelValuesVariableOptions>) {\n const { onChange, value } = props;\n const { datasource } = value;\n const selectedDatasource = datasource ?? DEFAULT_PROM;\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 draft.datasource = isDefaultPromSelector(next) ? undefined : next;\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 <FormControl margin=\"dense\">\n <InputLabel id=\"prom-datasource-label\">Prometheus Datasource</InputLabel>\n <DatasourceSelect\n datasourcePluginKind=\"PrometheusDatasource\"\n value={selectedDatasource}\n onChange={handleDatasourceChange}\n labelId=\"prom-datasource-label\"\n label=\"Prometheus Datasource\"\n />\n </FormControl>\n <TextField\n label=\"Label Name\"\n required\n value={props.value.label_name}\n onChange={(e) => {\n props.onChange({ ...props.value, label_name: e.target.value });\n }}\n />\n <MatcherEditor\n matchers={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 const { onChange, value } = props;\n const { datasource } = value;\n const selectedDatasource = datasource ?? DEFAULT_PROM;\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 draft.datasource = isDefaultPromSelector(next) ? undefined : next;\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 <FormControl margin=\"dense\">\n <InputLabel id=\"prom-datasource-label\">Prometheus Datasource</InputLabel>\n <DatasourceSelect\n datasourcePluginKind=\"PrometheusDatasource\"\n value={selectedDatasource}\n onChange={handleDatasourceChange}\n labelId=\"prom-datasource-label\"\n label=\"Prometheus Datasource\"\n />\n </FormControl>\n <MatcherEditor\n matchers={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 const { onChange, value } = props;\n const { datasource } = value;\n const selectedDatasource = datasource ?? DEFAULT_PROM;\n\n const { data: client } = useDatasourceClient<PrometheusClient>(selectedDatasource);\n const promURL = client?.options.datasourceUrl;\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 draft.datasource = isDefaultPromSelector(next) ? undefined : next;\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 <FormControl margin=\"dense\">\n <InputLabel id=\"prom-datasource-label\">Prometheus Datasource</InputLabel>\n <DatasourceSelect\n datasourcePluginKind={PROM_DATASOURCE_KIND}\n value={selectedDatasource}\n onChange={handleDatasourceChange}\n labelId=\"prom-datasource-label\"\n label=\"Prometheus Datasource\"\n />\n </FormControl>\n <PromQLEditor\n completeConfig={{ remote: { url: promURL } }}\n value={value.expr}\n onChange={(query) => {\n props.onChange({ ...props.value, expr: query });\n }}\n width=\"100%\"\n />\n <TextField\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":["DatasourceSelect","useDatasourceClient","parseTemplateVariables","replaceTemplateVariables","FormControl","InputLabel","Stack","TextField","produce","DEFAULT_PROM","getPrometheusTimeRange","isDefaultPromSelector","isPrometheusDatasourceSelector","PROM_DATASOURCE_KIND","PromQLEditor","MatcherEditor","PrometheusLabelValuesVariableEditor","props","onChange","value","datasource","selectedDatasource","handleDatasourceChange","next","draft","undefined","Error","spacing","margin","id","datasourcePluginKind","labelId","label","required","label_name","e","target","matchers","PrometheusLabelNamesVariableEditor","PrometheusPromQLVariableEditor","data","client","promURL","options","datasourceUrl","completeConfig","remote","url","expr","query","width","capturingMatrix","matrix","captured","Set","sample","result","metric","add","Array","from","values","capturingVector","vector","stringArrayToVariableOptions","map","PrometheusLabelNamesVariable","getVariableOptions","spec","ctx","datasourceStore","getDatasourceClient","match","m","variables","timeRange","labelNames","dependsOn","flat","OptionsEditorComponent","createInitialOptions","PrometheusLabelValuesVariable","pluginDef","labelValues","labelName","concat","PrometheusPromQLVariable","instantQuery","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;AAAA,SACEA,gBAAgB,EAGhBC,mBAAmB,EAGnBC,sBAAsB,EACtBC,wBAAwB,QACnB,2BAA2B,CAAC;AACnC,SAASC,WAAW,EAAEC,UAAU,EAAEC,KAAK,EAAEC,SAAS,QAAQ,eAAe,CAAC;AAC1E,SAASC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eAAe,CAACnB,OAAO,EAAEyC,SAAS,CAAC,CAAC;QAC/C,CAAC;QAED,OAAO;YACL5C,IAAI,EAAEwB,4BAA4B,CAACH,MAAM,CAAC;SAC3C,CAAC;IACJ,CAAC;IACDgB,SAAS,EAAE,CAACT,IAAI,GAAK;QACnB,OAAO;YAAEM,SAAS,EAAExE,sBAAsB,CAACkE,IAAI,CAACpB,IAAI,CAAC,CAACqC,MAAM,CAACnF,sBAAsB,CAACkE,IAAI,CAAClC,UAAU,CAAC,CAAC;SAAE,CAAC;IAC1G,CAAC;IACD6C,sBAAsB,EAAExC,8BAA8B;IACtDyC,oBAAoB,EAAE,IAAO,CAAA;YAAEhC,IAAI,EAAE,EAAE;YAAEd,UAAU,EAAE,EAAE;SAAE,CAAA,AAAC;CAC3D,CAAC"}
@@ -1,12 +1,4 @@
1
- import { VariableValue } from '@perses-dev/core';
2
- import { VariableStateMap } from '@perses-dev/plugin-system';
3
1
  import { Metric } from '../model/api-types';
4
- export declare function replaceTemplateVariables(text: string, variableState: VariableStateMap): string;
5
- export declare function replaceTemplateVariable(text: string, varName: string, templateVariableValue: VariableValue): string;
6
- /**
7
- * Returns a list of template variables
8
- */
9
- export declare const parseTemplateVariables: (text: string) => string[];
10
2
  /**
11
3
  * Types for metric labels, used in series_name_format implementation
12
4
  */
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils/utils.ts"],"names":[],"mappings":"AAaA,OAAO,EAAiB,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,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,aAYlD,CAAC;AAEF;;GAEG;AACH,oBAAY,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAOlD,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY,GAAG,MAAM,CAMxF;AAyBD,wBAAgB,+BAA+B,CAC7C,YAAY,EAAE;IACZ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CACvB,EACD,EAAE,cAAc,EAAE,GAAE;IAAE,cAAc,CAAC,EAAE,OAAO,CAAA;CAAO,UAqBtD;AAKD,wBAAgB,gCAAgC,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM;;;EAYjG"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils/utils.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C;;GAEG;AACH,oBAAY,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAOlD,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY,GAAG,MAAM,CAMxF;AAyBD,wBAAgB,+BAA+B,CAC7C,YAAY,EAAE;IACZ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CACvB,EACD,EAAE,cAAc,EAAE,GAAE;IAAE,cAAc,CAAC,EAAE,OAAO,CAAA;CAAO,UAqBtD;AAKD,wBAAgB,gCAAgC,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM;;;EAYjG"}
@@ -11,45 +11,6 @@
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
13
  import { isEmptyObject } from '@perses-dev/core';
14
- export function replaceTemplateVariables(text, variableState) {
15
- const variables = parseTemplateVariables(text);
16
- let finalText = text;
17
- variables.forEach((v)=>{
18
- const variable = variableState[v];
19
- if (variable && (variable === null || variable === void 0 ? void 0 : variable.value)) {
20
- finalText = replaceTemplateVariable(finalText, v, variable === null || variable === void 0 ? void 0 : variable.value);
21
- }
22
- });
23
- return finalText;
24
- }
25
- export function replaceTemplateVariable(text, varName, templateVariableValue) {
26
- const variableTemplate = '$' + varName;
27
- let replaceString = '';
28
- if (Array.isArray(templateVariableValue)) {
29
- replaceString = `(${templateVariableValue.join('|')})`; // regex style
30
- }
31
- if (typeof templateVariableValue === 'string') {
32
- replaceString = templateVariableValue;
33
- }
34
- return text.replaceAll(variableTemplate, replaceString);
35
- }
36
- // TODO: Fix this lint error
37
- // eslint-disable-next-line no-useless-escape
38
- const TEMPLATE_VARIABLE_REGEX = /\$(\w+)|\${(\w+)(?:\.([^:^\}]+))?(?::([^\}]+))?}/gm;
39
- /**
40
- * Returns a list of template variables
41
- */ export const parseTemplateVariables = (text)=>{
42
- const regex = TEMPLATE_VARIABLE_REGEX;
43
- const matches = new Set();
44
- let match;
45
- while((match = regex.exec(text)) !== null){
46
- if (match && match.length > 1 && match[1]) {
47
- matches.add(match[1]);
48
- }
49
- }
50
- // return unique matches
51
- return Array.from(matches.values());
52
- };
53
14
  /*
54
15
  * Formatter used for series name display in legends and tooltips.
55
16
  * Regex replaces label {{ name }} with resolved label value.
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/utils.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { isEmptyObject, VariableValue } from '@perses-dev/core';\nimport { VariableStateMap } from '@perses-dev/plugin-system';\nimport { Metric } from '../model/api-types';\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 error\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 = new Set<string>();\n let match;\n\n while ((match = regex.exec(text)) !== null) {\n if (match && match.length > 1 && match[1]) {\n matches.add(match[1]);\n }\n }\n // return unique matches\n return Array.from(matches.values());\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 * If no resolved value, return empty string instead of the token inside double curly braces.\n */\nexport function formatSeriesName(inputFormat: string, seriesLabels: SeriesLabels): string {\n const resolveLabelsRegex = /\\{\\{\\s*(.+?)\\s*\\}\\}/g;\n return inputFormat.replace(resolveLabelsRegex, (_match, token) => {\n const resolvedValue = seriesLabels[token] ?? '';\n return resolvedValue;\n });\n}\n\n/*\n * Stringifies object of labels into valid PromQL for querying metric by label\n */\nfunction stringifyPrometheusMetricLabels(labels: { [key: string]: unknown }, removeExprWrap?: boolean) {\n const labelStrings: string[] = [];\n Object.keys(labels)\n .sort()\n .forEach((labelName) => {\n const labelValue = labels[labelName];\n if (labelValue !== undefined) {\n if (removeExprWrap) {\n labelStrings.push(`\"${labelName}\":\"${labelValue}\"`);\n } else {\n labelStrings.push(`${labelName}=\"${labelValue}\"`);\n }\n }\n });\n return `{${labelStrings.join(',')}}`;\n}\n\n/*\n * Metric labels formattter which checks for __name__ and outputs valid PromQL for series name\n */\nexport function getUniqueKeyForPrometheusResult(\n metricLabels: {\n [key: string]: string;\n },\n { removeExprWrap }: { removeExprWrap?: boolean } = {}\n) {\n const metricNameKey = '__name__';\n if (metricLabels) {\n if (Object.prototype.hasOwnProperty.call(metricLabels, metricNameKey)) {\n const stringifiedLabels = stringifyPrometheusMetricLabels(\n {\n ...metricLabels,\n [metricNameKey]: undefined,\n },\n removeExprWrap\n );\n if (removeExprWrap === true) {\n return `${stringifiedLabels}`;\n } else {\n return `${metricLabels[metricNameKey]}${stringifiedLabels}`;\n }\n }\n return stringifyPrometheusMetricLabels(metricLabels, removeExprWrap);\n }\n return '';\n}\n\n/*\n * Determine human-readable series name to be used in legend and tooltip\n */\nexport function getFormattedPrometheusSeriesName(query: string, metric: Metric, formatter?: string) {\n // Name the series after the metric labels by default.\n // Use the query if no metric or metric labels are empty.\n let name = getUniqueKeyForPrometheusResult(metric);\n if (name === '' || isEmptyObject(metric)) {\n name = query;\n }\n\n // Query editor allows you to define an optional series_name_format property.\n // This controls the regex used to customize legend and tooltip display.\n const formattedName = formatter ? formatSeriesName(formatter, metric) : name;\n return { name, formattedName };\n}\n"],"names":["isEmptyObject","replaceTemplateVariables","text","variableState","variables","parseTemplateVariables","finalText","forEach","v","variable","value","replaceTemplateVariable","varName","templateVariableValue","variableTemplate","replaceString","Array","isArray","join","replaceAll","TEMPLATE_VARIABLE_REGEX","regex","matches","Set","match","exec","length","add","from","values","formatSeriesName","inputFormat","seriesLabels","resolveLabelsRegex","replace","_match","token","resolvedValue","stringifyPrometheusMetricLabels","labels","removeExprWrap","labelStrings","Object","keys","sort","labelName","labelValue","undefined","push","getUniqueKeyForPrometheusResult","metricLabels","metricNameKey","prototype","hasOwnProperty","call","stringifiedLabels","getFormattedPrometheusSeriesName","query","metric","formatter","name","formattedName"],"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,aAAa,QAAuB,kBAAkB,CAAC;AAIhE,OAAO,SAASC,wBAAwB,CAACC,IAAY,EAAEC,aAA+B,EAAU;IAC9F,MAAMC,SAAS,GAAGC,sBAAsB,CAACH,IAAI,CAAC,AAAC;IAC/C,IAAII,SAAS,GAAGJ,IAAI,AAAC;IACrBE,SAAS,CAACG,OAAO,CAAC,CAACC,CAAC,GAAK;QACvB,MAAMC,QAAQ,GAAGN,aAAa,CAACK,CAAC,CAAC,AAAC;QAClC,IAAIC,QAAQ,IAAIA,CAAAA,QAAQ,aAARA,QAAQ,WAAO,GAAfA,KAAAA,CAAe,GAAfA,QAAQ,CAAEC,KAAK,CAAA,EAAE;YAC/BJ,SAAS,GAAGK,uBAAuB,CAACL,SAAS,EAAEE,CAAC,EAAEC,QAAQ,aAARA,QAAQ,WAAO,GAAfA,KAAAA,CAAe,GAAfA,QAAQ,CAAEC,KAAK,CAAC,CAAC;QACrE,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAOJ,SAAS,CAAC;AACnB,CAAC;AAED,OAAO,SAASK,uBAAuB,CAACT,IAAY,EAAEU,OAAe,EAAEC,qBAAoC,EAAE;IAC3G,MAAMC,gBAAgB,GAAG,GAAG,GAAGF,OAAO,AAAC;IACvC,IAAIG,aAAa,GAAG,EAAE,AAAC;IACvB,IAAIC,KAAK,CAACC,OAAO,CAACJ,qB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AAc,KAAK,IAAI,EAAE;gBAC3B,OAAO,CAAC,EAAEe,iBAAiB,CAAC,CAAC,CAAC;YAChC,OAAO;gBACL,OAAO,CAAC,EAAEL,YAAY,CAACC,aAAa,CAAC,CAAC,EAAEI,iBAAiB,CAAC,CAAC,CAAC;YAC9D,CAAC;QACH,CAAC;QACD,OAAOjB,+BAA+B,CAACY,YAAY,EAAEV,cAAc,CAAC,CAAC;IACvE,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC;AAED;;CAEC,GACD,OAAO,SAASgB,gCAAgC,CAACC,KAAa,EAAEC,MAAc,EAAEC,SAAkB,EAAE;IAClG,sDAAsD;IACtD,yDAAyD;IACzD,IAAIC,IAAI,GAAGX,+BAA+B,CAACS,MAAM,CAAC,AAAC;IACnD,IAAIE,IAAI,KAAK,EAAE,IAAI5D,aAAa,CAAC0D,MAAM,CAAC,EAAE;QACxCE,IAAI,GAAGH,KAAK,CAAC;IACf,CAAC;IAED,6EAA6E;IAC7E,wEAAwE;IACxE,MAAMI,aAAa,GAAGF,SAAS,GAAG7B,gBAAgB,CAAC6B,SAAS,EAAED,MAAM,CAAC,GAAGE,IAAI,AAAC;IAC7E,OAAO;QAAEA,IAAI;QAAEC,aAAa;KAAE,CAAC;AACjC,CAAC"}
1
+ {"version":3,"sources":["../../src/utils/utils.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { isEmptyObject } from '@perses-dev/core';\nimport { Metric } from '../model/api-types';\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 * If no resolved value, return empty string instead of the token inside double curly braces.\n */\nexport function formatSeriesName(inputFormat: string, seriesLabels: SeriesLabels): string {\n const resolveLabelsRegex = /\\{\\{\\s*(.+?)\\s*\\}\\}/g;\n return inputFormat.replace(resolveLabelsRegex, (_match, token) => {\n const resolvedValue = seriesLabels[token] ?? '';\n return resolvedValue;\n });\n}\n\n/*\n * Stringifies object of labels into valid PromQL for querying metric by label\n */\nfunction stringifyPrometheusMetricLabels(labels: { [key: string]: unknown }, removeExprWrap?: boolean) {\n const labelStrings: string[] = [];\n Object.keys(labels)\n .sort()\n .forEach((labelName) => {\n const labelValue = labels[labelName];\n if (labelValue !== undefined) {\n if (removeExprWrap) {\n labelStrings.push(`\"${labelName}\":\"${labelValue}\"`);\n } else {\n labelStrings.push(`${labelName}=\"${labelValue}\"`);\n }\n }\n });\n return `{${labelStrings.join(',')}}`;\n}\n\n/*\n * Metric labels formattter which checks for __name__ and outputs valid PromQL for series name\n */\nexport function getUniqueKeyForPrometheusResult(\n metricLabels: {\n [key: string]: string;\n },\n { removeExprWrap }: { removeExprWrap?: boolean } = {}\n) {\n const metricNameKey = '__name__';\n if (metricLabels) {\n if (Object.prototype.hasOwnProperty.call(metricLabels, metricNameKey)) {\n const stringifiedLabels = stringifyPrometheusMetricLabels(\n {\n ...metricLabels,\n [metricNameKey]: undefined,\n },\n removeExprWrap\n );\n if (removeExprWrap === true) {\n return `${stringifiedLabels}`;\n } else {\n return `${metricLabels[metricNameKey]}${stringifiedLabels}`;\n }\n }\n return stringifyPrometheusMetricLabels(metricLabels, removeExprWrap);\n }\n return '';\n}\n\n/*\n * Determine human-readable series name to be used in legend and tooltip\n */\nexport function getFormattedPrometheusSeriesName(query: string, metric: Metric, formatter?: string) {\n // Name the series after the metric labels by default.\n // Use the query if no metric or metric labels are empty.\n let name = getUniqueKeyForPrometheusResult(metric);\n if (name === '' || isEmptyObject(metric)) {\n name = query;\n }\n\n // Query editor allows you to define an optional series_name_format property.\n // This controls the regex used to customize legend and tooltip display.\n const formattedName = formatter ? formatSeriesName(formatter, metric) : name;\n return { name, formattedName };\n}\n"],"names":["isEmptyObject","formatSeriesName","inputFormat","seriesLabels","resolveLabelsRegex","replace","_match","token","resolvedValue","stringifyPrometheusMetricLabels","labels","removeExprWrap","labelStrings","Object","keys","sort","forEach","labelName","labelValue","undefined","push","join","getUniqueKeyForPrometheusResult","metricLabels","metricNameKey","prototype","hasOwnProperty","call","stringifiedLabels","getFormattedPrometheusSeriesName","query","metric","formatter","name","formattedName"],"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,aAAa,QAAQ,kBAAkB,CAAC;AAQjD;;;;CAIC,GACD,OAAO,SAASC,gBAAgB,CAACC,WAAmB,EAAEC,YAA0B,EAAU;IACxF,MAAMC,kBAAkB,yBAAyB,AAAC;IAClD,OAAOF,WAAW,CAACG,OAAO,CAACD,kBAAkB,EAAE,CAACE,MAAM,EAAEC,KAAK,GAAK;YAC1CJ,MAAmB;QAAzC,MAAMK,aAAa,GAAGL,CAAAA,MAAmB,GAAnBA,YAAY,CAACI,KAAK,CAAC,cAAnBJ,MAAmB,cAAnBA,MAAmB,GAAI,EAAE,AAAC;QAChD,OAAOK,aAAa,CAAC;IACvB,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;CAEC,GACD,SAASC,+BAA+B,CAACC,MAAkC,EAAEC,cAAwB,EAAE;IACrG,MAAMC,YAAY,GAAa,EAAE,AAAC;IAClCC,MAAM,CAACC,IAAI,CAACJ,MAAM,CAAC,CAChBK,IAAI,EAAE,CACNC,OAAO,CAAC,CAACC,SAAS,GAAK;QACtB,MAAMC,UAAU,GAAGR,MAAM,CAACO,SAAS,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,EAAEC,SAAkB,EAAE;IAClG,sDAAsD;IACtD,yDAAyD;IACzD,IAAIC,IAAI,GAAGX,+BAA+B,CAACS,MAAM,CAAC,AAAC;IACnD,IAAIE,IAAI,KAAK,EAAE,IAAIjC,aAAa,CAAC+B,MAAM,CAAC,EAAE;QACxCE,IAAI,GAAGH,KAAK,CAAC;IACf,CAAC;IAED,6EAA6E;IAC7E,wEAAwE;IACxE,MAAMI,aAAa,GAAGF,SAAS,GAAG/B,gBAAgB,CAAC+B,SAAS,EAAED,MAAM,CAAC,GAAGE,IAAI,AAAC;IAC7E,OAAO;QAAEA,IAAI;QAAEC,aAAa;KAAE,CAAC;AACjC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@perses-dev/prometheus-plugin",
3
- "version": "0.32.0",
3
+ "version": "0.34.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",
@@ -31,9 +31,9 @@
31
31
  "dependencies": {
32
32
  "@lezer/highlight": "^1.0.0",
33
33
  "@lezer/lr": "^1.2.0",
34
- "@perses-dev/components": "0.32.0",
35
- "@perses-dev/core": "0.32.0",
36
- "@perses-dev/plugin-system": "0.32.0",
34
+ "@perses-dev/components": "0.34.0",
35
+ "@perses-dev/core": "0.34.0",
36
+ "@perses-dev/plugin-system": "0.34.0",
37
37
  "@prometheus-io/codemirror-promql": "^0.43.0",
38
38
  "@uiw/react-codemirror": "^4.19.1",
39
39
  "date-fns": "^2.28.0",
@@ -45,8 +45,5 @@
45
45
  "files": [
46
46
  "dist",
47
47
  "plugin.json"
48
- ],
49
- "typedoc": {
50
- "entryPoint": "./src/index.ts"
51
- }
48
+ ]
52
49
  }