@perses-dev/prometheus-plugin 0.7.1 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/dist/cjs/index.js +3 -40
  2. package/dist/cjs/model/templating.js +5 -104
  3. package/dist/cjs/model/utils.js +58 -0
  4. package/dist/cjs/model/utils.test.js +86 -0
  5. package/dist/cjs/plugins/graph-query.js +10 -6
  6. package/dist/cjs/{plugins/interval-variable.js → test/setup-tests.js} +2 -13
  7. package/dist/index.d.ts +2 -2
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +1 -1
  10. package/dist/model/templating.d.ts +1 -20
  11. package/dist/model/templating.d.ts.map +1 -1
  12. package/dist/model/templating.js +1 -1
  13. package/dist/model/utils.d.ts +8 -0
  14. package/dist/model/utils.d.ts.map +1 -0
  15. package/dist/model/utils.js +1 -0
  16. package/dist/model/utils.test.d.ts +2 -0
  17. package/dist/model/utils.test.d.ts.map +1 -0
  18. package/dist/model/utils.test.js +1 -0
  19. package/dist/plugins/graph-query.d.ts +6 -5
  20. package/dist/plugins/graph-query.d.ts.map +1 -1
  21. package/dist/plugins/graph-query.js +1 -1
  22. package/dist/test/setup-tests.d.ts +2 -0
  23. package/dist/test/setup-tests.d.ts.map +1 -0
  24. package/dist/test/setup-tests.js +1 -0
  25. package/package.json +8 -21
  26. package/plugin.json +42 -0
  27. package/dist/cjs/plugins/label-names-variable.js +0 -44
  28. package/dist/cjs/plugins/label-values-variable.js +0 -45
  29. package/dist/plugins/interval-variable.d.ts +0 -18
  30. package/dist/plugins/interval-variable.d.ts.map +0 -1
  31. package/dist/plugins/interval-variable.js +0 -1
  32. package/dist/plugins/label-names-variable.d.ts +0 -14
  33. package/dist/plugins/label-names-variable.d.ts.map +0 -1
  34. package/dist/plugins/label-names-variable.js +0 -1
  35. package/dist/plugins/label-values-variable.d.ts +0 -15
  36. package/dist/plugins/label-values-variable.d.ts.map +0 -1
  37. package/dist/plugins/label-values-variable.js +0 -1
package/dist/cjs/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2021 The Perses Authors
2
+ // Copyright 2022 The Perses Authors
3
3
  // Licensed under the Apache License, Version 2.0 (the "License");
4
4
  // you may not use this file except in compliance with the License.
5
5
  // You may obtain a copy of the License at
@@ -12,43 +12,6 @@
12
12
  // See the License for the specific language governing permissions and
13
13
  // limitations under the License.
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.setup = void 0;
15
+ exports.PrometheusGraphQuery = void 0;
16
16
  const graph_query_1 = require("./plugins/graph-query");
17
- const interval_variable_1 = require("./plugins/interval-variable");
18
- const label_names_variable_1 = require("./plugins/label-names-variable");
19
- const label_values_variable_1 = require("./plugins/label-values-variable");
20
- const setup = (registerPlugin) => {
21
- registerPlugin({
22
- pluginType: 'Variable',
23
- kind: label_names_variable_1.PrometheusLabelNamesKind,
24
- validate: undefined,
25
- plugin: {
26
- useVariableOptions: label_names_variable_1.usePrometheusLabelNames,
27
- },
28
- });
29
- registerPlugin({
30
- pluginType: 'Variable',
31
- kind: label_values_variable_1.PrometheusLabelValuesKind,
32
- validate: undefined,
33
- plugin: {
34
- useVariableOptions: label_values_variable_1.usePrometheusLabelValues,
35
- },
36
- });
37
- registerPlugin({
38
- pluginType: 'Variable',
39
- kind: interval_variable_1.IntervalKind,
40
- validate: undefined,
41
- plugin: {
42
- useVariableOptions: interval_variable_1.useIntervalValues,
43
- },
44
- });
45
- registerPlugin({
46
- pluginType: 'GraphQuery',
47
- kind: graph_query_1.PrometheusGraphQueryKind,
48
- validate: undefined,
49
- plugin: {
50
- useGraphQuery: graph_query_1.usePrometheusGraphQuery,
51
- },
52
- });
53
- };
54
- exports.setup = setup;
17
+ Object.defineProperty(exports, "PrometheusGraphQuery", { enumerable: true, get: function () { return graph_query_1.PrometheusGraphQuery; } });
@@ -12,111 +12,12 @@
12
12
  // See the License for the specific language governing permissions and
13
13
  // limitations under the License.
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.useReplaceTemplateString = exports.useReplaceTemplateStrings = void 0;
16
- const lezer_promql_1 = require("@prometheus-io/lezer-promql");
17
- const core_1 = require("@perses-dev/core");
15
+ exports.useReplaceTemplateString = void 0;
18
16
  const plugin_system_1 = require("@perses-dev/plugin-system");
19
- const REPLACE_IN_NODE_TYPES = new Set([lezer_promql_1.StringLiteral, lezer_promql_1.Duration]);
20
- /**
21
- * Replaces template variable placeholders with variable values from the current
22
- * dashbboard in multiple template strings. Since template strings are often
23
- * used as request parameters, the results are memoized and only recalculated
24
- * if the templateStrings or variable values change.
25
- */
26
- function useReplaceTemplateStrings(templateStrings) {
27
- const { variables } = (0, plugin_system_1.useTemplateVariables)();
28
- // Replace template string placeholders with variable values
29
- return (0, core_1.useMemoized)(() => {
30
- const result = [];
31
- const needsVariableValuesFor = new Set();
32
- for (const templateString of templateStrings !== null && templateStrings !== void 0 ? templateStrings : []) {
33
- const replaced = replaceTemplateVariables(templateString, variables);
34
- result.push(replaced.result);
35
- for (const varName of replaced.needsVariableValuesFor) {
36
- needsVariableValuesFor.add(varName);
37
- }
38
- }
39
- return { result, needsVariableValuesFor };
40
- }, [templateStrings, variables]);
41
- }
42
- exports.useReplaceTemplateStrings = useReplaceTemplateStrings;
43
- /**
44
- * Replaces template variable placeholders with variable values from the current
45
- * dashboard in a single template string. Since template strings are often
46
- * used as request parameters, the results are memoized and only recalculated
47
- * if the templateString or variable values change.
48
- */
17
+ const utils_1 = require("./utils");
49
18
  function useReplaceTemplateString(templateString) {
50
- const { variables } = (0, plugin_system_1.useTemplateVariables)();
51
- // Replace template string placeholders with variable values
52
- return (0, core_1.useMemoized)(() => {
53
- if (templateString === undefined) {
54
- return { result: '', needsVariableValuesFor: new Set() };
55
- }
56
- return replaceTemplateVariables(templateString, variables);
57
- }, [templateString, variables]);
19
+ const templateVariablesInTemplate = (0, utils_1.parseTemplateVariables)(templateString || '');
20
+ const variables = (0, plugin_system_1.useTemplateVariableValues)(templateVariablesInTemplate);
21
+ return (0, utils_1.replaceTemplateVariables)(templateString || '', variables);
58
22
  }
59
23
  exports.useReplaceTemplateString = useReplaceTemplateString;
60
- /**
61
- * Replace template variable placeholders with variable values.
62
- */
63
- function replaceTemplateVariables(templateString, variablesState) {
64
- const needsVariableValuesFor = new Set();
65
- let indexAdjustment = 0;
66
- const tree = lezer_promql_1.parser.parse(templateString);
67
- const cursor = tree.cursor();
68
- do {
69
- // Only replace variables in string literals for now
70
- if (REPLACE_IN_NODE_TYPES.has(cursor.node.type.id))
71
- continue;
72
- let { from, to } = cursor.node;
73
- from += indexAdjustment;
74
- to += indexAdjustment;
75
- let nodeText = templateString.substring(from, to);
76
- nodeText = nodeText.replaceAll(/\$([a-zA-Z0-9_-]+)/g, (match, variableName) => {
77
- const state = variablesState[variableName];
78
- if (state === undefined) {
79
- throw new Error(`Unknown variable '${variableName}'`);
80
- }
81
- const { value, options } = state;
82
- let replacement;
83
- if (Array.isArray(value)) {
84
- let selectedValues = value;
85
- // Is the default ALL value?
86
- if (value.length === 1 && value[0] === core_1.DEFAULT_ALL_VALUE) {
87
- // For the default ALL value, we want to use all options as the
88
- // selected values
89
- if (options === undefined) {
90
- // Wait until options are loaded before we do replacement
91
- needsVariableValuesFor.add(variableName);
92
- return match;
93
- }
94
- selectedValues = options;
95
- }
96
- // TODO: Escape v for regex
97
- replacement = selectedValues.map((v) => v).join('|');
98
- }
99
- else {
100
- replacement = escapeVariableValue(value);
101
- }
102
- return replacement;
103
- });
104
- // Replace the string literal with the new one and since that may change the
105
- // overall length of the string, keep track of an "index adjustment" so we
106
- // can shift positions in the tree accordingly
107
- const oldLength = to - from;
108
- indexAdjustment += nodeText.length - oldLength;
109
- templateString = templateString.substring(0, from) + nodeText + templateString.substring(from + oldLength);
110
- } while (cursor.next());
111
- return {
112
- result: templateString,
113
- needsVariableValuesFor,
114
- };
115
- }
116
- const SINGLE_BACKSLASH = '\\';
117
- const DOUBLE_BACKSLASH = '\\\\';
118
- function escapeVariableValue(value) {
119
- // TODO: What about ["'`]? Do we need to know what kind of quotes the
120
- // string literal is using?
121
- return value.replaceAll(SINGLE_BACKSLASH, DOUBLE_BACKSLASH);
122
- }
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ // Copyright 2022 The Perses Authors
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.parseTemplateVariables = exports.replaceTemplateVariable = exports.replaceTemplateVariables = void 0;
16
+ function replaceTemplateVariables(text, variableState) {
17
+ const variables = (0, exports.parseTemplateVariables)(text);
18
+ let finalText = text;
19
+ variables.forEach((v) => {
20
+ const variable = variableState[v];
21
+ if (variable && (variable === null || variable === void 0 ? void 0 : variable.value)) {
22
+ finalText = replaceTemplateVariable(finalText, v, variable === null || variable === void 0 ? void 0 : variable.value);
23
+ }
24
+ });
25
+ return finalText;
26
+ }
27
+ exports.replaceTemplateVariables = replaceTemplateVariables;
28
+ function replaceTemplateVariable(text, varName, templateVariableValue) {
29
+ const variableTemplate = '$' + varName;
30
+ let replaceString = '';
31
+ if (Array.isArray(templateVariableValue)) {
32
+ replaceString = `(${templateVariableValue.join('|')})`; // regex style
33
+ }
34
+ if (typeof templateVariableValue === 'string') {
35
+ replaceString = templateVariableValue;
36
+ }
37
+ return text.replaceAll(variableTemplate, replaceString);
38
+ }
39
+ exports.replaceTemplateVariable = replaceTemplateVariable;
40
+ const TEMPLATE_VARIABLE_REGEX = /\$(\w+)|\${(\w+)(?:\.([^:^\}]+))?(?::([^\}]+))?}/gm;
41
+ /**
42
+ * Returns a list of template variables
43
+ */
44
+ const parseTemplateVariables = (text) => {
45
+ const regex = TEMPLATE_VARIABLE_REGEX;
46
+ const matches = [];
47
+ let match;
48
+ while ((match = regex.exec(text)) !== null) {
49
+ if (match) {
50
+ if (match && match.length > 1 && match[1]) {
51
+ matches.push(match[1]);
52
+ }
53
+ }
54
+ }
55
+ // return unique matches
56
+ return Array.from(new Set(matches));
57
+ };
58
+ exports.parseTemplateVariables = parseTemplateVariables;
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ // Copyright 2022 The Perses Authors
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const utils_1 = require("./utils");
16
+ describe('parseTemplateVariables()', () => {
17
+ const tests = [
18
+ {
19
+ text: 'hello $var1 world $var2',
20
+ variables: ['var1', 'var2'],
21
+ },
22
+ ];
23
+ tests.forEach(({ text, variables }) => {
24
+ it(`parses ${text}`, () => {
25
+ expect((0, utils_1.parseTemplateVariables)(text)).toEqual(variables);
26
+ });
27
+ });
28
+ });
29
+ describe('replaceTemplateVariable()', () => {
30
+ const tests = [
31
+ {
32
+ text: 'hello $var1',
33
+ varName: 'var1',
34
+ value: 'world',
35
+ expected: 'hello world',
36
+ },
37
+ {
38
+ text: 'hello $var1 $var1',
39
+ varName: 'var1',
40
+ value: 'world',
41
+ expected: 'hello world world',
42
+ },
43
+ {
44
+ text: 'hello $var1',
45
+ varName: 'var1',
46
+ value: ['world', 'w'],
47
+ expected: 'hello (world|w)',
48
+ },
49
+ {
50
+ text: 'hello $var1 $var1',
51
+ varName: 'var1',
52
+ value: ['world', 'w'],
53
+ expected: 'hello (world|w) (world|w)',
54
+ },
55
+ ];
56
+ tests.forEach(({ text, value, varName, expected }) => {
57
+ it(`replaces ${text} ${value}`, () => {
58
+ expect((0, utils_1.replaceTemplateVariable)(text, varName, value)).toEqual(expected);
59
+ });
60
+ });
61
+ });
62
+ describe('replaceTemplateVariables()', () => {
63
+ const tests = [
64
+ {
65
+ text: 'hello $var1 $var2',
66
+ state: {
67
+ var1: { value: 'world', loading: false },
68
+ var2: { value: 'world', loading: false },
69
+ },
70
+ expected: 'hello world world',
71
+ },
72
+ {
73
+ text: 'hello $var1 $var2',
74
+ state: {
75
+ var1: { value: 'world', loading: false },
76
+ var2: { value: ['a', 'b'], loading: false },
77
+ },
78
+ expected: 'hello world (a|b)',
79
+ },
80
+ ];
81
+ tests.forEach(({ text, state, expected }) => {
82
+ it(`replaces ${text} ${JSON.stringify(state)}`, () => {
83
+ expect((0, utils_1.replaceTemplateVariables)(text, state)).toEqual(expected);
84
+ });
85
+ });
86
+ });
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2021 The Perses Authors
2
+ // Copyright 2022 The Perses Authors
3
3
  // Licensed under the Apache License, Version 2.0 (the "License");
4
4
  // you may not use this file except in compliance with the License.
5
5
  // You may obtain a copy of the License at
@@ -12,7 +12,7 @@
12
12
  // See the License for the specific language governing permissions and
13
13
  // limitations under the License.
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.usePrometheusGraphQuery = exports.PrometheusGraphQueryKind = void 0;
15
+ exports.PrometheusGraphQuery = void 0;
16
16
  const core_1 = require("@perses-dev/core");
17
17
  const date_fns_1 = require("date-fns");
18
18
  const react_1 = require("react");
@@ -20,7 +20,6 @@ const parse_sample_values_1 = require("../model/parse-sample-values");
20
20
  const prometheus_client_1 = require("../model/prometheus-client");
21
21
  const templating_1 = require("../model/templating");
22
22
  const time_1 = require("../model/time");
23
- exports.PrometheusGraphQueryKind = 'PrometheusGraphQuery';
24
23
  function usePrometheusGraphQuery(definition, hookOptions) {
25
24
  const minStep = (0, time_1.getDurationStringSeconds)(definition.options.min_step);
26
25
  const timeRange = (0, time_1.useDashboardPrometheusTimeRange)();
@@ -38,7 +37,7 @@ function usePrometheusGraphQuery(definition, hookOptions) {
38
37
  end: alignedEnd,
39
38
  };
40
39
  }, [timeRange, step]);
41
- const { result: query, needsVariableValuesFor } = (0, templating_1.useReplaceTemplateString)(definition.options.query);
40
+ const query = (0, templating_1.useReplaceTemplateString)(definition.options.query.replace('$__rate_interval', `15s`));
42
41
  const request = {
43
42
  query,
44
43
  start,
@@ -46,7 +45,7 @@ function usePrometheusGraphQuery(definition, hookOptions) {
46
45
  step,
47
46
  };
48
47
  const { data: response, isLoading: loading, error, } = (0, prometheus_client_1.useRangeQuery)(request, {
49
- enabled: needsVariableValuesFor.size === 0,
48
+ enabled: true,
50
49
  });
51
50
  const data = (0, react_1.useMemo)(() => {
52
51
  if (response === undefined)
@@ -77,4 +76,9 @@ function usePrometheusGraphQuery(definition, hookOptions) {
77
76
  }, [response, start, end, step, query]);
78
77
  return { data, loading, error: error !== null && error !== void 0 ? error : undefined };
79
78
  }
80
- exports.usePrometheusGraphQuery = usePrometheusGraphQuery;
79
+ /**
80
+ * The core Prometheus GraphQuery plugin for Perses.
81
+ */
82
+ exports.PrometheusGraphQuery = {
83
+ useGraphQuery: usePrometheusGraphQuery,
84
+ };
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2021 The Perses Authors
2
+ // Copyright 2022 The Perses Authors
3
3
  // Licensed under the Apache License, Version 2.0 (the "License");
4
4
  // you may not use this file except in compliance with the License.
5
5
  // You may obtain a copy of the License at
@@ -12,15 +12,4 @@
12
12
  // See the License for the specific language governing permissions and
13
13
  // limitations under the License.
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.useIntervalValues = exports.IntervalKind = void 0;
16
- exports.IntervalKind = 'Inverval';
17
- /**
18
- * Variable plugin for getting a list of variable options from a predefined
19
- * list of duration values.
20
- */
21
- function useIntervalValues(definition) {
22
- // TODO: What about auto?
23
- const { options: { values }, } = definition;
24
- return { loading: false, error: undefined, data: values };
25
- }
26
- exports.useIntervalValues = useIntervalValues;
15
+ require("@testing-library/jest-dom/extend-expect");
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { PluginSetupFunction } from '@perses-dev/plugin-system';
2
- export declare const setup: PluginSetupFunction;
1
+ import { PrometheusGraphQuery } from './plugins/graph-query';
2
+ export { PrometheusGraphQuery };
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAMhE,eAAO,MAAM,KAAK,EAAE,mBAiCnB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAG7D,OAAO,EAAE,oBAAoB,EAAE,CAAC"}
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{PrometheusGraphQueryKind,usePrometheusGraphQuery}from"./plugins/graph-query";import{IntervalKind,useIntervalValues}from"./plugins/interval-variable";import{PrometheusLabelNamesKind,usePrometheusLabelNames}from"./plugins/label-names-variable";import{PrometheusLabelValuesKind,usePrometheusLabelValues}from"./plugins/label-values-variable";export const setup=e=>{e({pluginType:"Variable",kind:PrometheusLabelNamesKind,validate:void 0,plugin:{useVariableOptions:usePrometheusLabelNames}}),e({pluginType:"Variable",kind:PrometheusLabelValuesKind,validate:void 0,plugin:{useVariableOptions:usePrometheusLabelValues}}),e({pluginType:"Variable",kind:IntervalKind,validate:void 0,plugin:{useVariableOptions:useIntervalValues}}),e({pluginType:"GraphQuery",kind:PrometheusGraphQueryKind,validate:void 0,plugin:{useGraphQuery:usePrometheusGraphQuery}})};
1
+ import{PrometheusGraphQuery}from"./plugins/graph-query";export{PrometheusGraphQuery};
@@ -2,24 +2,5 @@
2
2
  * Type alias to indicate what parts of the API support template variables.
3
3
  */
4
4
  export declare type TemplateString = string;
5
- /**
6
- * Replaces template variable placeholders with variable values from the current
7
- * dashbboard in multiple template strings. Since template strings are often
8
- * used as request parameters, the results are memoized and only recalculated
9
- * if the templateStrings or variable values change.
10
- */
11
- export declare function useReplaceTemplateStrings(templateStrings?: TemplateString[]): {
12
- result: string[];
13
- needsVariableValuesFor: Set<string>;
14
- };
15
- /**
16
- * Replaces template variable placeholders with variable values from the current
17
- * dashboard in a single template string. Since template strings are often
18
- * used as request parameters, the results are memoized and only recalculated
19
- * if the templateString or variable values change.
20
- */
21
- export declare function useReplaceTemplateString(templateString?: TemplateString): {
22
- result: string;
23
- needsVariableValuesFor: Set<string>;
24
- };
5
+ export declare function useReplaceTemplateString(templateString?: TemplateString): string;
25
6
  //# sourceMappingURL=templating.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"templating.d.ts","sourceRoot":"","sources":["../../src/model/templating.ts"],"names":[],"mappings":"AAmBA;;GAEG;AACH,oBAAY,cAAc,GAAG,MAAM,CAAC;AAEpC;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,eAAe,CAAC,EAAE,cAAc,EAAE;;;EAkB3E;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,cAAc,CAAC,EAAE,cAAc;;;EAWvE"}
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 +1 @@
1
- import{Duration,parser,StringLiteral}from"@prometheus-io/lezer-promql";import{useMemoized,DEFAULT_ALL_VALUE}from"@perses-dev/core";import{useTemplateVariables}from"@perses-dev/plugin-system";const REPLACE_IN_NODE_TYPES=new Set([StringLiteral,Duration]);export function useReplaceTemplateStrings(e){const{variables:r}=useTemplateVariables();return useMemoized((()=>{const t=[],a=new Set;for(const s of null!=e?e:[]){const e=replaceTemplateVariables(s,r);t.push(e.result);for(const r of e.needsVariableValuesFor)a.add(r)}return{result:t,needsVariableValuesFor:a}}),[e,r])}export function useReplaceTemplateString(e){const{variables:r}=useTemplateVariables();return useMemoized((()=>void 0===e?{result:"",needsVariableValuesFor:new Set}:replaceTemplateVariables(e,r)),[e,r])}function replaceTemplateVariables(e,r){const t=new Set;let a=0;const s=parser.parse(e).cursor();do{if(REPLACE_IN_NODE_TYPES.has(s.node.type.id))continue;let{from:l,to:n}=s.node;l+=a,n+=a;let o=e.substring(l,n);o=o.replaceAll(/\$([a-zA-Z0-9_-]+)/g,((e,a)=>{const s=r[a];if(void 0===s)throw new Error(`Unknown variable '${a}'`);const{value:l,options:n}=s;let o;if(Array.isArray(l)){let r=l;if(1===l.length&&l[0]===DEFAULT_ALL_VALUE){if(void 0===n)return t.add(a),e;r=n}o=r.map((e=>e)).join("|")}else o=escapeVariableValue(l);return o}));const i=n-l;a+=o.length-i,e=e.substring(0,l)+o+e.substring(l+i)}while(s.next());return{result:e,needsVariableValuesFor:t}}const SINGLE_BACKSLASH="\\",DOUBLE_BACKSLASH="\\\\";function escapeVariableValue(e){return e.replaceAll("\\","\\\\")}
1
+ import{useTemplateVariableValues}from"@perses-dev/plugin-system";import{replaceTemplateVariables,parseTemplateVariables}from"./utils";export function useReplaceTemplateString(e){const a=parseTemplateVariables(e||""),l=useTemplateVariableValues(a);return replaceTemplateVariables(e||"",l)}
@@ -0,0 +1,8 @@
1
+ import { VariableStateMap, VariableValue } from '@perses-dev/core';
2
+ export declare function replaceTemplateVariables(text: string, variableState: VariableStateMap): string;
3
+ export declare function replaceTemplateVariable(text: string, varName: string, templateVariableValue: VariableValue): string;
4
+ /**
5
+ * Returns a list of template variables
6
+ */
7
+ export declare const parseTemplateVariables: (text: string) => string[];
8
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/model/utils.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEnE,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;AAID;;GAEG;AACH,eAAO,MAAM,sBAAsB,SAAU,MAAM,aAclD,CAAC"}
@@ -0,0 +1 @@
1
+ export function replaceTemplateVariables(e,r){const l=parseTemplateVariables(e);let a=e;return l.forEach((e=>{const l=r[e];l&&(null==l?void 0:l.value)&&(a=replaceTemplateVariable(a,e,null==l?void 0:l.value))})),a}export function replaceTemplateVariable(e,r,l){const a="$"+r;let t="";return Array.isArray(l)&&(t=`(${l.join("|")})`),"string"==typeof l&&(t=l),e.replaceAll(a,t)}const TEMPLATE_VARIABLE_REGEX=/\$(\w+)|\${(\w+)(?:\.([^:^\}]+))?(?::([^\}]+))?}/gm;export const parseTemplateVariables=e=>{const r=TEMPLATE_VARIABLE_REGEX,l=[];let a;for(;null!==(a=r.exec(e));)a&&a&&a.length>1&&a[1]&&l.push(a[1]);return Array.from(new Set(l))};
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=utils.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.test.d.ts","sourceRoot":"","sources":["../../src/model/utils.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ import{parseTemplateVariables,replaceTemplateVariable,replaceTemplateVariables}from"./utils";describe("parseTemplateVariables()",(()=>{[{text:"hello $var1 world $var2",variables:["var1","var2"]}].forEach((({text:e,variables:a})=>{it(`parses ${e}`,(()=>{expect(parseTemplateVariables(e)).toEqual(a)}))}))})),describe("replaceTemplateVariable()",(()=>{[{text:"hello $var1",varName:"var1",value:"world",expected:"hello world"},{text:"hello $var1 $var1",varName:"var1",value:"world",expected:"hello world world"},{text:"hello $var1",varName:"var1",value:["world","w"],expected:"hello (world|w)"},{text:"hello $var1 $var1",varName:"var1",value:["world","w"],expected:"hello (world|w) (world|w)"}].forEach((({text:e,value:a,varName:l,expected:r})=>{it(`replaces ${e} ${a}`,(()=>{expect(replaceTemplateVariable(e,l,a)).toEqual(r)}))}))})),describe("replaceTemplateVariables()",(()=>{[{text:"hello $var1 $var2",state:{var1:{value:"world",loading:!1},var2:{value:"world",loading:!1}},expected:"hello world world"},{text:"hello $var1 $var2",state:{var1:{value:"world",loading:!1},var2:{value:["a","b"],loading:!1}},expected:"hello world (a|b)"}].forEach((({text:e,state:a,expected:l})=>{it(`replaces ${e} ${JSON.stringify(a)}`,(()=>{expect(replaceTemplateVariables(e,a)).toEqual(l)}))}))}));
@@ -1,13 +1,14 @@
1
1
  import { DurationString, JsonObject } from '@perses-dev/core';
2
- import { GraphQueryDefinition, UseGraphQueryHook, UseGraphQueryHookOptions } from '@perses-dev/plugin-system';
2
+ import { GraphQueryPlugin } from '@perses-dev/plugin-system';
3
3
  import { TemplateString } from '../model/templating';
4
- export declare const PrometheusGraphQueryKind: "PrometheusGraphQuery";
5
- declare type PrometheusGraphQuery = GraphQueryDefinition<GraphQueryOptions>;
6
- interface GraphQueryOptions extends JsonObject {
4
+ interface PrometheusGraphQueryOptions extends JsonObject {
7
5
  query: TemplateString;
8
6
  min_step?: DurationString;
9
7
  resolution?: number;
10
8
  }
11
- export declare function usePrometheusGraphQuery(definition: PrometheusGraphQuery, hookOptions?: UseGraphQueryHookOptions): ReturnType<UseGraphQueryHook<GraphQueryOptions>>;
9
+ /**
10
+ * The core Prometheus GraphQuery plugin for Perses.
11
+ */
12
+ export declare const PrometheusGraphQuery: GraphQueryPlugin<PrometheusGraphQueryOptions>;
12
13
  export {};
13
14
  //# sourceMappingURL=graph-query.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"graph-query.d.ts","sourceRoot":"","sources":["../../src/plugins/graph-query.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAE,UAAU,EAAe,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAEL,oBAAoB,EACpB,iBAAiB,EACjB,wBAAwB,EACzB,MAAM,2BAA2B,CAAC;AAMnC,OAAO,EAAE,cAAc,EAA4B,MAAM,qBAAqB,CAAC;AAG/E,eAAO,MAAM,wBAAwB,wBAAkC,CAAC;AAExE,aAAK,oBAAoB,GAAG,oBAAoB,CAAC,iBAAiB,CAAC,CAAC;AAEpE,UAAU,iBAAkB,SAAQ,UAAU;IAC5C,KAAK,EAAE,cAAc,CAAC;IACtB,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,wBAAgB,uBAAuB,CACrC,UAAU,EAAE,oBAAoB,EAChC,WAAW,CAAC,EAAE,wBAAwB,GACrC,UAAU,CAAC,iBAAiB,CAAC,iBAAiB,CAAC,CAAC,CAoElD"}
1
+ {"version":3,"file":"graph-query.d.ts","sourceRoot":"","sources":["../../src/plugins/graph-query.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAE,UAAU,EAAe,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAGL,gBAAgB,EAGjB,MAAM,2BAA2B,CAAC;AAMnC,OAAO,EAAE,cAAc,EAA4B,MAAM,qBAAqB,CAAC;AAG/E,UAAU,2BAA4B,SAAQ,UAAU;IACtD,KAAK,EAAE,cAAc,CAAC;IACtB,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AA2ED;;GAEG;AACH,eAAO,MAAM,oBAAoB,EAAE,gBAAgB,CAAC,2BAA2B,CAE9E,CAAC"}
@@ -1 +1 @@
1
- import{useMemoized}from"@perses-dev/core";import{fromUnixTime}from"date-fns";import{useMemo}from"react";import{parseValueTuple}from"../model/parse-sample-values";import{useRangeQuery}from"../model/prometheus-client";import{useReplaceTemplateString}from"../model/templating";import{getDurationStringSeconds,useDashboardPrometheusTimeRange,usePanelRangeStep}from"../model/time";export const PrometheusGraphQueryKind="PrometheusGraphQuery";export function usePrometheusGraphQuery(e,r){const t=getDurationStringSeconds(e.options.min_step),o=useDashboardPrometheusTimeRange(),s=usePanelRangeStep(o,t,void 0,null==r?void 0:r.suggestedStepMs),{start:a,end:n}=useMemoized((()=>{const{start:e,end:r}=o,t=60*(new Date).getTimezoneOffset(),a=Math.floor((r+t)/s)*s-t;return{start:Math.floor((e+t)/s)*s-t,end:a}}),[o,s]),{result:m,needsVariableValuesFor:i}=useReplaceTemplateString(e.options.query),u={query:m,start:a,end:n,step:s},{data:p,isLoading:l,error:d}=useRangeQuery(u,{enabled:0===i.size});return{data:useMemo((()=>{if(void 0!==p&&"error"!==p.status)return{timeRange:{start:fromUnixTime(a),end:fromUnixTime(n)},stepMs:1e3*s,series:p.data.result.map((e=>{const{metric:r,values:t}=e;let o=Object.entries(r).map((([e,r])=>`${e}="${r}"`)).join(", ");return""===o&&(o=m),{name:o,values:t.map(parseValueTuple)}}))}}),[p,a,n,s,m]),loading:l,error:null!=d?d:void 0}}
1
+ import{useMemoized}from"@perses-dev/core";import{fromUnixTime}from"date-fns";import{useMemo}from"react";import{parseValueTuple}from"../model/parse-sample-values";import{useRangeQuery}from"../model/prometheus-client";import{useReplaceTemplateString}from"../model/templating";import{getDurationStringSeconds,useDashboardPrometheusTimeRange,usePanelRangeStep}from"../model/time";function usePrometheusGraphQuery(e,r){const t=getDurationStringSeconds(e.options.min_step),o=useDashboardPrometheusTimeRange(),s=usePanelRangeStep(o,t,void 0,null==r?void 0:r.suggestedStepMs),{start:a,end:n}=useMemoized((()=>{const{start:e,end:r}=o,t=60*(new Date).getTimezoneOffset(),a=Math.floor((r+t)/s)*s-t;return{start:Math.floor((e+t)/s)*s-t,end:a}}),[o,s]),m=useReplaceTemplateString(e.options.query.replace("$__rate_interval","15s")),u={query:m,start:a,end:n,step:s},{data:i,isLoading:p,error:l}=useRangeQuery(u,{enabled:!0});return{data:useMemo((()=>{if(void 0!==i&&"error"!==i.status)return{timeRange:{start:fromUnixTime(a),end:fromUnixTime(n)},stepMs:1e3*s,series:i.data.result.map((e=>{const{metric:r,values:t}=e;let o=Object.entries(r).map((([e,r])=>`${e}="${r}"`)).join(", ");return""===o&&(o=m),{name:o,values:t.map(parseValueTuple)}}))}}),[i,a,n,s,m]),loading:p,error:null!=l?l:void 0}}export const PrometheusGraphQuery={useGraphQuery:usePrometheusGraphQuery};
@@ -0,0 +1,2 @@
1
+ import '@testing-library/jest-dom/extend-expect';
2
+ //# sourceMappingURL=setup-tests.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setup-tests.d.ts","sourceRoot":"","sources":["../../src/test/setup-tests.ts"],"names":[],"mappings":"AAaA,OAAO,yCAAyC,CAAC"}
@@ -0,0 +1 @@
1
+ import"@testing-library/jest-dom/extend-expect";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@perses-dev/prometheus-plugin",
3
- "version": "0.7.1",
3
+ "version": "0.8.1",
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",
@@ -18,38 +18,25 @@
18
18
  "clean": "rimraf dist/",
19
19
  "build": "tsc --build",
20
20
  "build:cjs": "tsc --project ./tsconfig.cjs.json",
21
- "test": "echo 'no test to run' && exit 0",
21
+ "test": "TZ=UTC jest",
22
+ "test:watch": "TZ=UTC jest --watch",
22
23
  "lint": "eslint src --ext .ts,.tsx",
23
24
  "lint:fix": "eslint --fix src --ext .ts,.tsx"
24
25
  },
25
26
  "dependencies": {
26
27
  "@lezer/highlight": "^1.0.0",
27
28
  "@lezer/lr": "^1.2.0",
28
- "@perses-dev/core": "^0.7.1",
29
- "@perses-dev/plugin-system": "^0.7.1",
29
+ "@perses-dev/core": "^0.8.1",
30
+ "@perses-dev/plugin-system": "^0.8.1",
30
31
  "@prometheus-io/lezer-promql": "^0.37.0",
31
32
  "date-fns": "^2.28.0"
32
33
  },
33
34
  "peerDependencies": {
34
- "react": "^17.0.2",
35
+ "react": "^17.0.2 || ^18.0.0",
35
36
  "react-query": "^3.34.16"
36
37
  },
37
- "perses": {
38
- "kind": "Plugin",
39
- "metadata": {
40
- "name": "Prometheus"
41
- },
42
- "spec": {
43
- "supported_kinds": {
44
- "PrometheusLabelNames": "Variable",
45
- "PrometheusLabelValues": "Variable",
46
- "Interval": "Variable",
47
- "PrometheusGraphQuery": "GraphQuery"
48
- },
49
- "plugin_module_path": "./dist/index.js"
50
- }
51
- },
52
38
  "files": [
53
- "dist"
39
+ "dist",
40
+ "plugin.json"
54
41
  ]
55
42
  }
package/plugin.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "kind": "PluginModule",
3
+ "metadata": {
4
+ "name": "Prometheus"
5
+ },
6
+ "spec": {
7
+ "plugins": [
8
+ {
9
+ "pluginType": "Variable",
10
+ "kind": "PrometheusLabelNames",
11
+ "display": {
12
+ "name": "Prometheus Label Names",
13
+ "description": ""
14
+ }
15
+ },
16
+ {
17
+ "pluginType": "Variable",
18
+ "kind": "PrometheusLabelValues",
19
+ "display": {
20
+ "name": "Prometheus Label Values",
21
+ "description": ""
22
+ }
23
+ },
24
+ {
25
+ "pluginType": "Variable",
26
+ "kind": "Interval",
27
+ "display": {
28
+ "name": "Time Duration",
29
+ "description": ""
30
+ }
31
+ },
32
+ {
33
+ "pluginType": "GraphQuery",
34
+ "kind": "PrometheusGraphQuery",
35
+ "display": {
36
+ "name": "Prometheus Range Query",
37
+ "description": ""
38
+ }
39
+ }
40
+ ]
41
+ }
42
+ }
@@ -1,44 +0,0 @@
1
- "use strict";
2
- // Copyright 2021 The Perses Authors
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- //
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.usePrometheusLabelNames = exports.PrometheusLabelNamesKind = void 0;
16
- const templating_1 = require("../model/templating");
17
- const time_1 = require("../model/time");
18
- const prometheus_client_1 = require("../model/prometheus-client");
19
- exports.PrometheusLabelNamesKind = 'PrometheusLabelNames';
20
- /**
21
- * Get variable option values by running a Prometheus label names query.
22
- */
23
- function usePrometheusLabelNames(definition) {
24
- var _a;
25
- const { start, end } = (0, time_1.useDashboardPrometheusTimeRange)();
26
- const { result: match, needsVariableValuesFor } = (0, templating_1.useReplaceTemplateStrings)(definition.options.match);
27
- // Make the request, pausing any requests that are still waiting on variable
28
- // values to be filled in/selected
29
- const request = {
30
- 'match[]': match,
31
- start,
32
- end,
33
- };
34
- const { data: response, isLoading: loading, error, } = (0, prometheus_client_1.useLabelNames)(request, {
35
- enabled: needsVariableValuesFor.size === 0,
36
- });
37
- const data = (_a = response === null || response === void 0 ? void 0 : response.data) !== null && _a !== void 0 ? _a : [];
38
- return {
39
- data: data,
40
- loading: loading || needsVariableValuesFor.size > 0,
41
- error: error !== null && error !== void 0 ? error : undefined,
42
- };
43
- }
44
- exports.usePrometheusLabelNames = usePrometheusLabelNames;
@@ -1,45 +0,0 @@
1
- "use strict";
2
- // Copyright 2021 The Perses Authors
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- //
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.usePrometheusLabelValues = exports.PrometheusLabelValuesKind = void 0;
16
- const core_1 = require("@perses-dev/core");
17
- const time_1 = require("../model/time");
18
- const templating_1 = require("../model/templating");
19
- const prometheus_client_1 = require("../model/prometheus-client");
20
- exports.PrometheusLabelValuesKind = 'PrometheusLabelValues';
21
- /**
22
- * Get variable option values by running a Prometheus label values query.
23
- */
24
- function usePrometheusLabelValues(definition) {
25
- const { start, end } = (0, time_1.useDashboardPrometheusTimeRange)();
26
- const { result: match, needsVariableValuesFor } = (0, templating_1.useReplaceTemplateStrings)(definition.options.match);
27
- // Make the request, pausing any requests that are still waiting on variable
28
- // values to be filled in/selected
29
- const request = {
30
- labelName: definition.options.label_name,
31
- 'match[]': match,
32
- start,
33
- end,
34
- };
35
- const { data: response, isLoading: loading, error, } = (0, prometheus_client_1.useLabelValues)(request, {
36
- enabled: needsVariableValuesFor.size === 0,
37
- });
38
- const data = (0, core_1.useMemoized)(() => { var _a; return (_a = response === null || response === void 0 ? void 0 : response.data) !== null && _a !== void 0 ? _a : []; }, [response]);
39
- return {
40
- data: data,
41
- loading: loading || needsVariableValuesFor.size > 0,
42
- error: error !== null && error !== void 0 ? error : undefined,
43
- };
44
- }
45
- exports.usePrometheusLabelValues = usePrometheusLabelValues;
@@ -1,18 +0,0 @@
1
- import { JsonObject, DurationString, VariableDefinition } from '@perses-dev/core';
2
- import { UseVariableOptionsHook } from '@perses-dev/plugin-system';
3
- export declare const IntervalKind: "Inverval";
4
- declare type IntervalVariable = VariableDefinition<IntervalOptions>;
5
- interface IntervalOptions extends JsonObject {
6
- values: DurationString[];
7
- auto?: {
8
- step_count: number;
9
- min_interval: DurationString;
10
- };
11
- }
12
- /**
13
- * Variable plugin for getting a list of variable options from a predefined
14
- * list of duration values.
15
- */
16
- export declare function useIntervalValues(definition: IntervalVariable): ReturnType<UseVariableOptionsHook<IntervalOptions>>;
17
- export {};
18
- //# sourceMappingURL=interval-variable.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"interval-variable.d.ts","sourceRoot":"","sources":["../../src/plugins/interval-variable.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAClF,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAEnE,eAAO,MAAM,YAAY,YAAsB,CAAC;AAEhD,aAAK,gBAAgB,GAAG,kBAAkB,CAAC,eAAe,CAAC,CAAC;AAE5D,UAAU,eAAgB,SAAQ,UAAU;IAC1C,MAAM,EAAE,cAAc,EAAE,CAAC;IACzB,IAAI,CAAC,EAAE;QACL,UAAU,EAAE,MAAM,CAAC;QACnB,YAAY,EAAE,cAAc,CAAC;KAC9B,CAAC;CACH;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,gBAAgB,GAAG,UAAU,CAAC,sBAAsB,CAAC,eAAe,CAAC,CAAC,CAMnH"}
@@ -1 +0,0 @@
1
- export const IntervalKind="Inverval";export function useIntervalValues(n){const{options:{values:e}}=n;return{loading:!1,error:void 0,data:e}}
@@ -1,14 +0,0 @@
1
- import { JsonObject, VariableDefinition } from '@perses-dev/core';
2
- import { UseVariableOptionsHook } from '@perses-dev/plugin-system';
3
- import { TemplateString } from '../model/templating';
4
- export declare const PrometheusLabelNamesKind: "PrometheusLabelNames";
5
- declare type PrometheusLabelNames = VariableDefinition<LabelNamesOptions>;
6
- interface LabelNamesOptions extends JsonObject {
7
- match: TemplateString[];
8
- }
9
- /**
10
- * Get variable option values by running a Prometheus label names query.
11
- */
12
- export declare function usePrometheusLabelNames(definition: PrometheusLabelNames): ReturnType<UseVariableOptionsHook<LabelNamesOptions>>;
13
- export {};
14
- //# sourceMappingURL=label-names-variable.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"label-names-variable.d.ts","sourceRoot":"","sources":["../../src/plugins/label-names-variable.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAClE,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,EAAE,cAAc,EAA6B,MAAM,qBAAqB,CAAC;AAKhF,eAAO,MAAM,wBAAwB,wBAAkC,CAAC;AAExE,aAAK,oBAAoB,GAAG,kBAAkB,CAAC,iBAAiB,CAAC,CAAC;AAElE,UAAU,iBAAkB,SAAQ,UAAU;IAC5C,KAAK,EAAE,cAAc,EAAE,CAAC;CACzB;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,UAAU,EAAE,oBAAoB,GAC/B,UAAU,CAAC,sBAAsB,CAAC,iBAAiB,CAAC,CAAC,CAyBvD"}
@@ -1 +0,0 @@
1
- import{useReplaceTemplateStrings}from"../model/templating";import{useDashboardPrometheusTimeRange}from"../model/time";import{useLabelNames}from"../model/prometheus-client";export const PrometheusLabelNamesKind="PrometheusLabelNames";export function usePrometheusLabelNames(e){var a;const{start:t,end:s}=useDashboardPrometheusTimeRange(),{result:o,needsVariableValuesFor:r}=useReplaceTemplateStrings(e.options.match),m={"match[]":o,start:t,end:s},{data:l,isLoading:i,error:n}=useLabelNames(m,{enabled:0===r.size});return{data:null!==(a=null==l?void 0:l.data)&&void 0!==a?a:[],loading:i||r.size>0,error:null!=n?n:void 0}}
@@ -1,15 +0,0 @@
1
- import { JsonObject, VariableDefinition } from '@perses-dev/core';
2
- import { UseVariableOptionsHook } from '@perses-dev/plugin-system';
3
- import { TemplateString } from '../model/templating';
4
- export declare const PrometheusLabelValuesKind: "PrometheusLabelValues";
5
- declare type PrometheusLabelValues = VariableDefinition<LabelValuesOptions>;
6
- interface LabelValuesOptions extends JsonObject {
7
- label_name: string;
8
- match?: TemplateString[];
9
- }
10
- /**
11
- * Get variable option values by running a Prometheus label values query.
12
- */
13
- export declare function usePrometheusLabelValues(definition: PrometheusLabelValues): ReturnType<UseVariableOptionsHook<LabelValuesOptions>>;
14
- export {};
15
- //# sourceMappingURL=label-values-variable.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"label-values-variable.d.ts","sourceRoot":"","sources":["../../src/plugins/label-values-variable.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAAe,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAC/E,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAGnE,OAAO,EAAE,cAAc,EAA6B,MAAM,qBAAqB,CAAC;AAGhF,eAAO,MAAM,yBAAyB,yBAAmC,CAAC;AAE1E,aAAK,qBAAqB,GAAG,kBAAkB,CAAC,kBAAkB,CAAC,CAAC;AAEpE,UAAU,kBAAmB,SAAQ,UAAU;IAC7C,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,cAAc,EAAE,CAAC;CAC1B;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CACtC,UAAU,EAAE,qBAAqB,GAChC,UAAU,CAAC,sBAAsB,CAAC,kBAAkB,CAAC,CAAC,CA0BxD"}
@@ -1 +0,0 @@
1
- import{useMemoized}from"@perses-dev/core";import{useDashboardPrometheusTimeRange}from"../model/time";import{useReplaceTemplateStrings}from"../model/templating";import{useLabelValues}from"../model/prometheus-client";export const PrometheusLabelValuesKind="PrometheusLabelValues";export function usePrometheusLabelValues(e){const{start:a,end:o}=useDashboardPrometheusTimeRange(),{result:r,needsVariableValuesFor:s}=useReplaceTemplateStrings(e.options.match),t={labelName:e.options.label_name,"match[]":r,start:a,end:o},{data:l,isLoading:m,error:u}=useLabelValues(t,{enabled:0===s.size});return{data:useMemoized((()=>{var e;return null!==(e=null==l?void 0:l.data)&&void 0!==e?e:[]}),[l]),loading:m||s.size>0,error:null!=u?u:void 0}}