@perses-dev/prometheus-plugin 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/dist/cjs/index.js +21 -5
  2. package/dist/cjs/model/api-types.js +5 -3
  3. package/dist/cjs/model/parse-sample-values.js +22 -16
  4. package/dist/cjs/model/prometheus-client.js +52 -66
  5. package/dist/cjs/model/templating.js +14 -10
  6. package/dist/cjs/model/time.js +35 -49
  7. package/dist/cjs/model/utils.js +21 -13
  8. package/dist/cjs/model/utils.test.js +57 -31
  9. package/dist/cjs/plugins/prometheus-datasource.js +26 -0
  10. package/dist/cjs/plugins/prometheus-variables.js +77 -0
  11. package/dist/cjs/plugins/time-series-query.js +87 -0
  12. package/dist/cjs/plugins/variable.js +38 -0
  13. package/dist/cjs/test/setup-tests.js +4 -2
  14. package/dist/index.d.ts +5 -2
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +21 -1
  17. package/dist/index.js.map +1 -0
  18. package/dist/model/api-types.js +15 -1
  19. package/dist/model/api-types.js.map +1 -0
  20. package/dist/model/parse-sample-values.d.ts.map +1 -1
  21. package/dist/model/parse-sample-values.js +44 -1
  22. package/dist/model/parse-sample-values.js.map +1 -0
  23. package/dist/model/prometheus-client.d.ts +14 -10
  24. package/dist/model/prometheus-client.d.ts.map +1 -1
  25. package/dist/model/prometheus-client.js +81 -1
  26. package/dist/model/prometheus-client.js.map +1 -0
  27. package/dist/model/templating.js +21 -1
  28. package/dist/model/templating.js.map +1 -0
  29. package/dist/model/time.d.ts +7 -8
  30. package/dist/model/time.d.ts.map +1 -1
  31. package/dist/model/time.js +49 -1
  32. package/dist/model/time.js.map +1 -0
  33. package/dist/model/utils.d.ts +2 -1
  34. package/dist/model/utils.d.ts.map +1 -1
  35. package/dist/model/utils.js +55 -1
  36. package/dist/model/utils.js.map +1 -0
  37. package/dist/model/utils.test.js +110 -1
  38. package/dist/model/utils.test.js.map +1 -0
  39. package/dist/plugins/prometheus-datasource.d.ts +4 -0
  40. package/dist/plugins/prometheus-datasource.d.ts.map +1 -0
  41. package/dist/plugins/prometheus-datasource.js +20 -0
  42. package/dist/plugins/prometheus-datasource.js.map +1 -0
  43. package/dist/plugins/prometheus-variables.d.ts +14 -0
  44. package/dist/plugins/prometheus-variables.d.ts.map +1 -0
  45. package/dist/plugins/prometheus-variables.js +65 -0
  46. package/dist/plugins/prometheus-variables.js.map +1 -0
  47. package/dist/plugins/time-series-query.d.ts +16 -0
  48. package/dist/plugins/time-series-query.d.ts.map +1 -0
  49. package/dist/plugins/time-series-query.js +83 -0
  50. package/dist/plugins/time-series-query.js.map +1 -0
  51. package/dist/plugins/variable.d.ts +8 -0
  52. package/dist/plugins/variable.d.ts.map +1 -0
  53. package/dist/plugins/variable.js +32 -0
  54. package/dist/plugins/variable.js.map +1 -0
  55. package/dist/test/setup-tests.js +15 -1
  56. package/dist/test/setup-tests.js.map +1 -0
  57. package/package.json +9 -7
  58. package/plugin.json +17 -9
  59. package/dist/cjs/model/datasource.js +0 -36
  60. package/dist/cjs/plugins/graph-query.js +0 -84
  61. package/dist/model/datasource.d.ts +0 -11
  62. package/dist/model/datasource.d.ts.map +0 -1
  63. package/dist/model/datasource.js +0 -1
  64. package/dist/plugins/graph-query.d.ts +0 -14
  65. package/dist/plugins/graph-query.d.ts.map +0 -1
  66. package/dist/plugins/graph-query.js +0 -1
package/dist/cjs/index.js CHANGED
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  // Copyright 2022 The Perses Authors
3
2
  // Licensed under the Apache License, Version 2.0 (the "License");
4
3
  // you may not use this file except in compliance with the License.
@@ -11,7 +10,24 @@
11
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
11
  // See the License for the specific language governing permissions and
13
12
  // limitations under the License.
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.PrometheusGraphQuery = void 0;
16
- const graph_query_1 = require("./plugins/graph-query");
17
- Object.defineProperty(exports, "PrometheusGraphQuery", { enumerable: true, get: function () { return graph_query_1.PrometheusGraphQuery; } });
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ function _export(target, all) {
18
+ for(var name in all)Object.defineProperty(target, name, {
19
+ enumerable: true,
20
+ get: all[name]
21
+ });
22
+ }
23
+ _export(exports, {
24
+ PrometheusTimeSeriesQuery: ()=>_timeSeriesQuery.PrometheusTimeSeriesQuery,
25
+ StaticListVariable: ()=>_variable.StaticListVariable,
26
+ PrometheusLabelNamesVariable: ()=>_prometheusVariables.PrometheusLabelNamesVariable,
27
+ PrometheusLabelValuesVariable: ()=>_prometheusVariables.PrometheusLabelValuesVariable,
28
+ PrometheusDatasource: ()=>_prometheusDatasource.PrometheusDatasource
29
+ });
30
+ const _timeSeriesQuery = require("./plugins/time-series-query");
31
+ const _variable = require("./plugins/variable");
32
+ const _prometheusVariables = require("./plugins/prometheus-variables");
33
+ const _prometheusDatasource = require("./plugins/prometheus-datasource");
@@ -1,5 +1,4 @@
1
- "use strict";
2
- // Copyright 2021 The Perses Authors
1
+ // Copyright 2022 The Perses Authors
3
2
  // Licensed under the Apache License, Version 2.0 (the "License");
4
3
  // you may not use this file except in compliance with the License.
5
4
  // You may obtain a copy of the License at
@@ -11,4 +10,7 @@
11
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
11
  // See the License for the specific language governing permissions and
13
12
  // limitations under the License.
14
- Object.defineProperty(exports, "__esModule", { value: true });
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
@@ -1,5 +1,4 @@
1
- "use strict";
2
- // Copyright 2021 The Perses Authors
1
+ // Copyright 2022 The Perses Authors
3
2
  // Licensed under the Apache License, Version 2.0 (the "License");
4
3
  // you may not use this file except in compliance with the License.
5
4
  // You may obtain a copy of the License at
@@ -11,34 +10,41 @@
11
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
11
  // See the License for the specific language governing permissions and
13
12
  // limitations under the License.
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.parseSampleValue = exports.parseValueTuple = void 0;
16
- /**
17
- * Parse a ValueTuple from a PromServer response into the a millisecond-based
18
- * unix time and a numeric sample value.
19
- */
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ function _export(target, all) {
18
+ for(var name in all)Object.defineProperty(target, name, {
19
+ enumerable: true,
20
+ get: all[name]
21
+ });
22
+ }
23
+ _export(exports, {
24
+ parseValueTuple: ()=>parseValueTuple,
25
+ parseSampleValue: ()=>parseSampleValue
26
+ });
20
27
  function parseValueTuple(data) {
21
28
  const [unixTimeSeconds, sampleValue] = data;
22
29
  // Prom returns unix time in seconds, so convert to ms
23
- return [unixTimeSeconds * 1000, parseSampleValue(sampleValue)];
30
+ return [
31
+ unixTimeSeconds * 1000,
32
+ parseSampleValue(sampleValue)
33
+ ];
24
34
  }
25
- exports.parseValueTuple = parseValueTuple;
26
- /**
27
- * Parses a string sample value from Prometheus, usually included as the
28
- * second member of a ValueTuple.
29
- */
30
35
  function parseSampleValue(sampleValue) {
31
36
  // Account for Prometheus' representation of +/- infinity, otherwise just
32
37
  // parse the sample value as a float
33
38
  let value;
34
- switch (sampleValue) {
39
+ switch(sampleValue){
35
40
  case '+Inf':
36
41
  value = Number.POSITIVE_INFINITY;
42
+ break;
37
43
  case '-Inf':
38
44
  value = Number.NEGATIVE_INFINITY;
45
+ break;
39
46
  default:
40
47
  value = parseFloat(sampleValue);
41
48
  }
42
49
  return value;
43
50
  }
44
- exports.parseSampleValue = parseSampleValue;
@@ -1,5 +1,4 @@
1
- "use strict";
2
- // Copyright 2021 The Perses Authors
1
+ // Copyright 2022 The Perses Authors
3
2
  // Licensed under the Apache License, Version 2.0 (the "License");
4
3
  // you may not use this file except in compliance with the License.
5
4
  // You may obtain a copy of the License at
@@ -11,80 +10,67 @@
11
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
11
  // See the License for the specific language governing permissions and
13
12
  // limitations under the License.
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.useLabelValues = exports.useLabelNames = exports.useRangeQuery = exports.useInstantQuery = void 0;
16
- const react_query_1 = require("react-query");
17
- const core_1 = require("@perses-dev/core");
18
- const datasource_1 = require("./datasource");
19
- /**
20
- * Calls the `/api/v1/query` endpoint to get metrics data.
21
- */
22
- function useInstantQuery(params, queryOptions) {
23
- return useQueryWithPost('/api/v1/query', params, queryOptions);
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ function _export(target, all) {
18
+ for(var name in all)Object.defineProperty(target, name, {
19
+ enumerable: true,
20
+ get: all[name]
21
+ });
24
22
  }
25
- exports.useInstantQuery = useInstantQuery;
26
- /**
27
- * Calls the `/api/v1/query_range` endpoint to get metrics data.
28
- */
29
- function useRangeQuery(params, queryOptions) {
30
- return useQueryWithPost('/api/v1/query_range', params, queryOptions);
23
+ _export(exports, {
24
+ instantQuery: ()=>instantQuery,
25
+ rangeQuery: ()=>rangeQuery,
26
+ labelNames: ()=>labelNames,
27
+ labelValues: ()=>labelValues
28
+ });
29
+ const _core = require("@perses-dev/core");
30
+ function instantQuery(params, queryOptions) {
31
+ return fetchWithPost('/api/v1/query', params, queryOptions);
31
32
  }
32
- exports.useRangeQuery = useRangeQuery;
33
- /**
34
- * Calls the `/api/v1/labels` endpoint to get a list of label names.
35
- */
36
- function useLabelNames(params, queryOptions) {
37
- return useQueryWithPost('/api/v1/labels', params, queryOptions);
33
+ function rangeQuery(params, queryOptions) {
34
+ return fetchWithPost('/api/v1/query_range', params, queryOptions);
38
35
  }
39
- exports.useLabelNames = useLabelNames;
40
- /**
41
- * Calls the `/api/v1/label/{labelName}/values` endpoint to get a list of
42
- * values for a label.
43
- */
44
- function useLabelValues(params, queryOptions) {
45
- const { labelName, ...searchParams } = params;
36
+ function labelNames(params, queryOptions) {
37
+ return fetchWithPost('/api/v1/labels', params, queryOptions);
38
+ }
39
+ function labelValues(params, queryOptions) {
40
+ const { labelName , ...searchParams } = params;
46
41
  const apiURI = `/api/v1/label/${encodeURIComponent(labelName)}/values`;
47
- return useQueryWithGet(apiURI, searchParams, queryOptions);
42
+ return fetchWithGet(apiURI, searchParams, queryOptions);
48
43
  }
49
- exports.useLabelValues = useLabelValues;
50
- function useQueryWithGet(apiURI, params, queryOptions) {
51
- const config = (0, datasource_1.usePrometheusConfig)(queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.datasource);
52
- const datasourceURL = (0, core_1.buildDatasourceURL)(config.metadata.name, config.spec.http);
53
- const key = [datasourceURL, apiURI, params];
54
- return (0, react_query_1.useQuery)(key, () => {
55
- let url = `${datasourceURL}${apiURI}`;
56
- const urlParams = createSearchParams(params).toString();
57
- if (urlParams !== '') {
58
- url += `?${urlParams}`;
59
- }
60
- return (0, core_1.fetchJson)(url, { method: 'GET' });
61
- }, queryOptions);
44
+ function fetchWithGet(apiURI, params, queryOptions) {
45
+ const { datasource: { direct_url: datasourceURL } , } = queryOptions;
46
+ let url = `${datasourceURL}${apiURI}`;
47
+ const urlParams = createSearchParams(params).toString();
48
+ if (urlParams !== '') {
49
+ url += `?${urlParams}`;
50
+ }
51
+ return (0, _core.fetchJson)(url, {
52
+ method: 'GET'
53
+ });
62
54
  }
63
- function useQueryWithPost(apiURI, params, queryOptions) {
64
- const config = (0, datasource_1.usePrometheusConfig)(queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.datasource);
65
- const datasourceURL = (0, core_1.buildDatasourceURL)(config.metadata.name, config.spec.http);
66
- const key = [datasourceURL, apiURI, params];
67
- return (0, react_query_1.useQuery)(key, () => {
68
- const url = `${datasourceURL}${apiURI}`;
69
- const init = {
70
- method: 'POST',
71
- headers: {
72
- 'Content-Type': 'application/x-www-form-urlencoded',
73
- },
74
- body: createSearchParams(params),
75
- };
76
- return (0, core_1.fetchJson)(url, init);
77
- }, queryOptions);
55
+ function fetchWithPost(apiURI, params, queryOptions) {
56
+ const { datasource: { direct_url: datasourceURL } , } = queryOptions;
57
+ const url = `${datasourceURL}${apiURI}`;
58
+ const init = {
59
+ method: 'POST',
60
+ headers: {
61
+ 'Content-Type': 'application/x-www-form-urlencoded'
62
+ },
63
+ body: createSearchParams(params)
64
+ };
65
+ return (0, _core.fetchJson)(url, init);
78
66
  }
79
67
  /**
80
68
  * Creates URLSearchParams from a request params object.
81
- */
82
- function createSearchParams(params) {
69
+ */ function createSearchParams(params) {
83
70
  const searchParams = new URLSearchParams();
84
- for (const key in params) {
71
+ for(const key in params){
85
72
  const value = params[key];
86
- if (value === undefined)
87
- continue;
73
+ if (value === undefined) continue;
88
74
  if (typeof value === 'string') {
89
75
  searchParams.append(key, value);
90
76
  continue;
@@ -93,7 +79,7 @@ function createSearchParams(params) {
93
79
  searchParams.append(key, value.toString());
94
80
  continue;
95
81
  }
96
- for (const val of value) {
82
+ for (const val of value){
97
83
  searchParams.append(key, val);
98
84
  }
99
85
  }
@@ -1,5 +1,4 @@
1
- "use strict";
2
- // Copyright 2021 The Perses Authors
1
+ // Copyright 2022 The Perses Authors
3
2
  // Licensed under the Apache License, Version 2.0 (the "License");
4
3
  // you may not use this file except in compliance with the License.
5
4
  // You may obtain a copy of the License at
@@ -11,13 +10,18 @@
11
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
11
  // See the License for the specific language governing permissions and
13
12
  // limitations under the License.
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.useReplaceTemplateString = void 0;
16
- const plugin_system_1 = require("@perses-dev/plugin-system");
17
- const utils_1 = require("./utils");
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ Object.defineProperty(exports, "useReplaceTemplateString", {
18
+ enumerable: true,
19
+ get: ()=>useReplaceTemplateString
20
+ });
21
+ const _pluginSystem = require("@perses-dev/plugin-system");
22
+ const _utils = require("./utils");
18
23
  function useReplaceTemplateString(templateString) {
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);
24
+ const templateVariablesInTemplate = (0, _utils.parseTemplateVariables)(templateString || '');
25
+ const variables = (0, _pluginSystem.useTemplateVariableValues)(templateVariablesInTemplate);
26
+ return (0, _utils.replaceTemplateVariables)(templateString || '', variables);
22
27
  }
23
- exports.useReplaceTemplateString = useReplaceTemplateString;
@@ -1,5 +1,4 @@
1
- "use strict";
2
- // Copyright 2021 The Perses Authors
1
+ // Copyright 2022 The Perses Authors
3
2
  // Licensed under the Apache License, Version 2.0 (the "License");
4
3
  // you may not use this file except in compliance with the License.
5
4
  // You may obtain a copy of the License at
@@ -11,58 +10,45 @@
11
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
11
  // See the License for the specific language governing permissions and
13
12
  // limitations under the License.
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.getDurationStringSeconds = exports.usePanelRangeStep = exports.useDashboardPrometheusTimeRange = void 0;
16
- const core_1 = require("@perses-dev/core");
17
- const plugin_system_1 = require("@perses-dev/plugin-system");
18
- const date_fns_1 = require("date-fns");
19
- const react_1 = require("react");
20
- /**
21
- * Get the time range for the current dashboard, converted to Prometheus time.
22
- */
23
- function useDashboardPrometheusTimeRange() {
24
- const { timeRange: { start, end }, } = (0, plugin_system_1.useTimeRange)();
25
- // Only recalculate the time range if the value on the dashboard changes
26
- return (0, core_1.useMemoized)(() => {
27
- return {
28
- start: Math.ceil((0, date_fns_1.getUnixTime)(start)),
29
- end: Math.ceil((0, date_fns_1.getUnixTime)(end)),
30
- };
31
- }, [start, end]);
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ function _export(target, all) {
18
+ for(var name in all)Object.defineProperty(target, name, {
19
+ enumerable: true,
20
+ get: all[name]
21
+ });
22
+ }
23
+ _export(exports, {
24
+ getPrometheusTimeRange: ()=>getPrometheusTimeRange,
25
+ getRangeStep: ()=>getRangeStep,
26
+ getDurationStringSeconds: ()=>getDurationStringSeconds
27
+ });
28
+ const _core = require("@perses-dev/core");
29
+ const _dateFns = require("date-fns");
30
+ function getPrometheusTimeRange(timeRange) {
31
+ const { start , end } = timeRange;
32
+ return {
33
+ start: Math.ceil((0, _dateFns.getUnixTime)(start)),
34
+ end: Math.ceil((0, _dateFns.getUnixTime)(end))
35
+ };
32
36
  }
33
- exports.useDashboardPrometheusTimeRange = useDashboardPrometheusTimeRange;
34
37
  // Max data points to allow returning from a Prom Query, used to calculate a
35
38
  // "safe" step for a range query
36
39
  const MAX_PROM_DATA_POINTS = 10000;
37
- /**
38
- * Gets the step to use for a Panel range query. Tries to take into account
39
- * the width of the panel, any minimum step/resolution set by the user, and
40
- * a "safe" step based on the max data points we want to allow returning from
41
- * a Prom query.
42
- */
43
- function usePanelRangeStep(timeRange, minStepSeconds = 15, resolution = 1, suggestedStepMs = 0) {
44
- // Keep track of the latest suggested step so we don't re-run the query if it changes
45
- const latestSuggestedStep = (0, react_1.useRef)(suggestedStepMs * 1000);
46
- latestSuggestedStep.current = suggestedStepMs * 1000;
47
- // Whenever the time range changes, recalculate the appropriate step
48
- return (0, core_1.useMemoized)(() => {
49
- const queryRangeSeconds = timeRange.end - timeRange.start;
50
- let safeStep = queryRangeSeconds / MAX_PROM_DATA_POINTS;
51
- if (safeStep > 1) {
52
- safeStep = Math.ceil(safeStep);
53
- }
54
- return Math.max(latestSuggestedStep.current * resolution, minStepSeconds, safeStep);
55
- }, [timeRange, minStepSeconds, resolution]);
40
+ function getRangeStep(timeRange, minStepSeconds = 15, resolution = 1, suggestedStepMs = 0) {
41
+ const suggestedStepSeconds = suggestedStepMs / 1000;
42
+ const queryRangeSeconds = timeRange.end - timeRange.start;
43
+ let safeStep = queryRangeSeconds / MAX_PROM_DATA_POINTS;
44
+ if (safeStep > 1) {
45
+ safeStep = Math.ceil(safeStep);
46
+ }
47
+ return Math.max(suggestedStepSeconds * resolution, minStepSeconds, safeStep);
56
48
  }
57
- exports.usePanelRangeStep = usePanelRangeStep;
58
- /**
59
- * Converts a DurationString to seconds, rounding down.
60
- */
61
49
  function getDurationStringSeconds(durationString) {
62
- if (durationString === undefined)
63
- return undefined;
64
- const duration = (0, core_1.parseDurationString)(durationString);
65
- const ms = (0, date_fns_1.milliseconds)(duration);
50
+ if (durationString === undefined) return undefined;
51
+ const duration = (0, _core.parseDurationString)(durationString);
52
+ const ms = (0, _dateFns.milliseconds)(duration);
66
53
  return Math.floor(ms / 1000);
67
54
  }
68
- exports.getDurationStringSeconds = getDurationStringSeconds;
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  // Copyright 2022 The Perses Authors
3
2
  // Licensed under the Apache License, Version 2.0 (the "License");
4
3
  // you may not use this file except in compliance with the License.
@@ -11,12 +10,25 @@
11
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
11
  // See the License for the specific language governing permissions and
13
12
  // limitations under the License.
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.parseTemplateVariables = exports.replaceTemplateVariable = exports.replaceTemplateVariables = void 0;
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ function _export(target, all) {
18
+ for(var name in all)Object.defineProperty(target, name, {
19
+ enumerable: true,
20
+ get: all[name]
21
+ });
22
+ }
23
+ _export(exports, {
24
+ replaceTemplateVariables: ()=>replaceTemplateVariables,
25
+ replaceTemplateVariable: ()=>replaceTemplateVariable,
26
+ parseTemplateVariables: ()=>parseTemplateVariables
27
+ });
16
28
  function replaceTemplateVariables(text, variableState) {
17
- const variables = (0, exports.parseTemplateVariables)(text);
29
+ const variables = parseTemplateVariables(text);
18
30
  let finalText = text;
19
- variables.forEach((v) => {
31
+ variables.forEach((v)=>{
20
32
  const variable = variableState[v];
21
33
  if (variable && (variable === null || variable === void 0 ? void 0 : variable.value)) {
22
34
  finalText = replaceTemplateVariable(finalText, v, variable === null || variable === void 0 ? void 0 : variable.value);
@@ -24,7 +36,6 @@ function replaceTemplateVariables(text, variableState) {
24
36
  });
25
37
  return finalText;
26
38
  }
27
- exports.replaceTemplateVariables = replaceTemplateVariables;
28
39
  function replaceTemplateVariable(text, varName, templateVariableValue) {
29
40
  const variableTemplate = '$' + varName;
30
41
  let replaceString = '';
@@ -36,16 +47,14 @@ function replaceTemplateVariable(text, varName, templateVariableValue) {
36
47
  }
37
48
  return text.replaceAll(variableTemplate, replaceString);
38
49
  }
39
- exports.replaceTemplateVariable = replaceTemplateVariable;
50
+ // TODO: Fix this lint eror
51
+ // eslint-disable-next-line no-useless-escape
40
52
  const TEMPLATE_VARIABLE_REGEX = /\$(\w+)|\${(\w+)(?:\.([^:^\}]+))?(?::([^\}]+))?}/gm;
41
- /**
42
- * Returns a list of template variables
43
- */
44
- const parseTemplateVariables = (text) => {
53
+ const parseTemplateVariables = (text)=>{
45
54
  const regex = TEMPLATE_VARIABLE_REGEX;
46
55
  const matches = [];
47
56
  let match;
48
- while ((match = regex.exec(text)) !== null) {
57
+ while((match = regex.exec(text)) !== null){
49
58
  if (match) {
50
59
  if (match && match.length > 1 && match[1]) {
51
60
  matches.push(match[1]);
@@ -55,4 +64,3 @@ const parseTemplateVariables = (text) => {
55
64
  // return unique matches
56
65
  return Array.from(new Set(matches));
57
66
  };
58
- exports.parseTemplateVariables = parseTemplateVariables;
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  // Copyright 2022 The Perses Authors
3
2
  // Licensed under the Apache License, Version 2.0 (the "License");
4
3
  // you may not use this file except in compliance with the License.
@@ -11,76 +10,103 @@
11
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
11
  // See the License for the specific language governing permissions and
13
12
  // limitations under the License.
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const utils_1 = require("./utils");
16
- describe('parseTemplateVariables()', () => {
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ const _utils = require("./utils");
18
+ describe('parseTemplateVariables()', ()=>{
17
19
  const tests = [
18
20
  {
19
21
  text: 'hello $var1 world $var2',
20
- variables: ['var1', 'var2'],
21
- },
22
+ variables: [
23
+ 'var1',
24
+ 'var2'
25
+ ]
26
+ }
22
27
  ];
23
- tests.forEach(({ text, variables }) => {
24
- it(`parses ${text}`, () => {
25
- expect((0, utils_1.parseTemplateVariables)(text)).toEqual(variables);
28
+ tests.forEach(({ text , variables })=>{
29
+ it(`parses ${text}`, ()=>{
30
+ expect((0, _utils.parseTemplateVariables)(text)).toEqual(variables);
26
31
  });
27
32
  });
28
33
  });
29
- describe('replaceTemplateVariable()', () => {
34
+ describe('replaceTemplateVariable()', ()=>{
30
35
  const tests = [
31
36
  {
32
37
  text: 'hello $var1',
33
38
  varName: 'var1',
34
39
  value: 'world',
35
- expected: 'hello world',
40
+ expected: 'hello world'
36
41
  },
37
42
  {
38
43
  text: 'hello $var1 $var1',
39
44
  varName: 'var1',
40
45
  value: 'world',
41
- expected: 'hello world world',
46
+ expected: 'hello world world'
42
47
  },
43
48
  {
44
49
  text: 'hello $var1',
45
50
  varName: 'var1',
46
- value: ['world', 'w'],
47
- expected: 'hello (world|w)',
51
+ value: [
52
+ 'world',
53
+ 'w'
54
+ ],
55
+ expected: 'hello (world|w)'
48
56
  },
49
57
  {
50
58
  text: 'hello $var1 $var1',
51
59
  varName: 'var1',
52
- value: ['world', 'w'],
53
- expected: 'hello (world|w) (world|w)',
54
- },
60
+ value: [
61
+ 'world',
62
+ 'w'
63
+ ],
64
+ expected: 'hello (world|w) (world|w)'
65
+ }
55
66
  ];
56
- tests.forEach(({ text, value, varName, expected }) => {
57
- it(`replaces ${text} ${value}`, () => {
58
- expect((0, utils_1.replaceTemplateVariable)(text, varName, value)).toEqual(expected);
67
+ tests.forEach(({ text , value , varName , expected })=>{
68
+ it(`replaces ${text} ${value}`, ()=>{
69
+ expect((0, _utils.replaceTemplateVariable)(text, varName, value)).toEqual(expected);
59
70
  });
60
71
  });
61
72
  });
62
- describe('replaceTemplateVariables()', () => {
73
+ describe('replaceTemplateVariables()', ()=>{
63
74
  const tests = [
64
75
  {
65
76
  text: 'hello $var1 $var2',
66
77
  state: {
67
- var1: { value: 'world', loading: false },
68
- var2: { value: 'world', loading: false },
78
+ var1: {
79
+ value: 'world',
80
+ loading: false
81
+ },
82
+ var2: {
83
+ value: 'world',
84
+ loading: false
85
+ }
69
86
  },
70
- expected: 'hello world world',
87
+ expected: 'hello world world'
71
88
  },
72
89
  {
73
90
  text: 'hello $var1 $var2',
74
91
  state: {
75
- var1: { value: 'world', loading: false },
76
- var2: { value: ['a', 'b'], loading: false },
92
+ var1: {
93
+ value: 'world',
94
+ loading: false
95
+ },
96
+ var2: {
97
+ value: [
98
+ 'a',
99
+ 'b'
100
+ ],
101
+ loading: false
102
+ }
77
103
  },
78
- expected: 'hello world (a|b)',
79
- },
104
+ expected: 'hello world (a|b)'
105
+ }
80
106
  ];
81
- tests.forEach(({ text, state, expected }) => {
82
- it(`replaces ${text} ${JSON.stringify(state)}`, () => {
83
- expect((0, utils_1.replaceTemplateVariables)(text, state)).toEqual(expected);
107
+ tests.forEach(({ text , state , expected })=>{
108
+ it(`replaces ${text} ${JSON.stringify(state)}`, ()=>{
109
+ expect((0, _utils.replaceTemplateVariables)(text, state)).toEqual(expected);
84
110
  });
85
111
  });
86
112
  });
@@ -0,0 +1,26 @@
1
+ // Copyright 2022 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ Object.defineProperty(exports, "PrometheusDatasource", {
18
+ enumerable: true,
19
+ get: ()=>PrometheusDatasource
20
+ });
21
+ const PrometheusDatasource = {
22
+ OptionsEditorComponent: ()=>null,
23
+ createInitialOptions: ()=>({
24
+ direct_url: ''
25
+ })
26
+ };