@perses-dev/prometheus-plugin 0.8.1 → 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.
- package/dist/cjs/index.js +21 -5
- package/dist/cjs/model/api-types.js +5 -3
- package/dist/cjs/model/parse-sample-values.js +22 -16
- package/dist/cjs/model/prometheus-client.js +52 -66
- package/dist/cjs/model/templating.js +14 -10
- package/dist/cjs/model/time.js +35 -49
- package/dist/cjs/model/utils.js +21 -13
- package/dist/cjs/model/utils.test.js +57 -31
- package/dist/cjs/plugins/prometheus-datasource.js +26 -0
- package/dist/cjs/plugins/prometheus-variables.js +77 -0
- package/dist/cjs/plugins/time-series-query.js +87 -0
- package/dist/cjs/plugins/variable.js +38 -0
- package/dist/cjs/test/setup-tests.js +4 -2
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21 -1
- package/dist/index.js.map +1 -0
- package/dist/model/api-types.js +15 -1
- package/dist/model/api-types.js.map +1 -0
- package/dist/model/parse-sample-values.d.ts.map +1 -1
- package/dist/model/parse-sample-values.js +44 -1
- package/dist/model/parse-sample-values.js.map +1 -0
- package/dist/model/prometheus-client.d.ts +14 -10
- package/dist/model/prometheus-client.d.ts.map +1 -1
- package/dist/model/prometheus-client.js +81 -1
- package/dist/model/prometheus-client.js.map +1 -0
- package/dist/model/templating.js +21 -1
- package/dist/model/templating.js.map +1 -0
- package/dist/model/time.d.ts +7 -8
- package/dist/model/time.d.ts.map +1 -1
- package/dist/model/time.js +49 -1
- package/dist/model/time.js.map +1 -0
- package/dist/model/utils.d.ts +2 -1
- package/dist/model/utils.d.ts.map +1 -1
- package/dist/model/utils.js +55 -1
- package/dist/model/utils.js.map +1 -0
- package/dist/model/utils.test.js +110 -1
- package/dist/model/utils.test.js.map +1 -0
- package/dist/plugins/prometheus-datasource.d.ts +4 -0
- package/dist/plugins/prometheus-datasource.d.ts.map +1 -0
- package/dist/plugins/prometheus-datasource.js +20 -0
- package/dist/plugins/prometheus-datasource.js.map +1 -0
- package/dist/plugins/prometheus-variables.d.ts +14 -0
- package/dist/plugins/prometheus-variables.d.ts.map +1 -0
- package/dist/plugins/prometheus-variables.js +65 -0
- package/dist/plugins/prometheus-variables.js.map +1 -0
- package/dist/plugins/time-series-query.d.ts +16 -0
- package/dist/plugins/time-series-query.d.ts.map +1 -0
- package/dist/plugins/time-series-query.js +83 -0
- package/dist/plugins/time-series-query.js.map +1 -0
- package/dist/plugins/variable.d.ts +8 -0
- package/dist/plugins/variable.d.ts.map +1 -0
- package/dist/plugins/variable.js +32 -0
- package/dist/plugins/variable.js.map +1 -0
- package/dist/test/setup-tests.js +15 -1
- package/dist/test/setup-tests.js.map +1 -0
- package/package.json +9 -7
- package/plugin.json +17 -9
- package/dist/cjs/model/datasource.js +0 -36
- package/dist/cjs/plugins/graph-query.js +0 -84
- package/dist/model/datasource.d.ts +0 -11
- package/dist/model/datasource.d.ts.map +0 -1
- package/dist/model/datasource.js +0 -1
- package/dist/plugins/graph-query.d.ts +0 -14
- package/dist/plugins/graph-query.d.ts.map +0 -1
- 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
|
-
|
|
15
|
-
exports
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
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
|
-
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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 [
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
|
42
|
+
return fetchWithGet(apiURI, searchParams, queryOptions);
|
|
48
43
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
|
64
|
-
const
|
|
65
|
-
const
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
15
|
-
exports
|
|
16
|
-
|
|
17
|
-
|
|
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,
|
|
20
|
-
const variables = (0,
|
|
21
|
-
return (0,
|
|
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;
|
package/dist/cjs/model/time.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
|
|
64
|
-
const
|
|
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;
|
package/dist/cjs/model/utils.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,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
|
-
|
|
15
|
-
|
|
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 =
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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: [
|
|
21
|
-
|
|
22
|
+
variables: [
|
|
23
|
+
'var1',
|
|
24
|
+
'var2'
|
|
25
|
+
]
|
|
26
|
+
}
|
|
22
27
|
];
|
|
23
|
-
tests.forEach(({ text, variables
|
|
24
|
-
it(`parses ${text}`, ()
|
|
25
|
-
expect((0,
|
|
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: [
|
|
47
|
-
|
|
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: [
|
|
53
|
-
|
|
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,
|
|
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: {
|
|
68
|
-
|
|
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: {
|
|
76
|
-
|
|
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,
|
|
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
|
+
};
|