@perses-dev/prometheus-plugin 0.0.0-snapshot-embed-import-errors-8906900 → 0.0.0-snapshot-datasource-browser-test-28cbb71
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/components/PromQL.js +1 -1
- package/dist/cjs/components/index.js +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/model/api-types.js +1 -1
- package/dist/cjs/model/index.js +1 -2
- package/dist/cjs/model/parse-sample-values.js +1 -1
- package/dist/cjs/model/prometheus-client.js +4 -3
- package/dist/cjs/model/prometheus-selectors.js +1 -1
- package/dist/cjs/model/templating.js +2 -2
- package/dist/cjs/model/time.js +1 -1
- package/dist/cjs/plugins/MatcherEditor.js +1 -1
- package/dist/cjs/plugins/prometheus-datasource.js +15 -8
- package/dist/cjs/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.js +3 -3
- package/dist/cjs/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js +1 -1
- package/dist/cjs/plugins/prometheus-time-series-query/get-time-series-data.js +9 -7
- package/dist/cjs/plugins/prometheus-time-series-query/index.js +1 -1
- package/dist/cjs/plugins/prometheus-time-series-query/query-editor-model.js +1 -1
- package/dist/cjs/plugins/prometheus-time-series-query/time-series-query-model.js +1 -1
- package/dist/cjs/plugins/prometheus-variables.js +10 -9
- package/dist/cjs/plugins/types.js +1 -1
- package/dist/cjs/plugins/variable.js +1 -1
- package/dist/cjs/test/setup-tests.js +1 -1
- package/dist/cjs/utils/index.js +28 -0
- package/dist/cjs/{model → utils}/utils.js +37 -2
- package/dist/cjs/{model → utils}/utils.test.js +47 -1
- package/dist/components/PromQL.js +1 -1
- package/dist/components/PromQL.js.map +1 -1
- package/dist/components/index.js +1 -1
- package/dist/components/index.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/model/api-types.js +1 -1
- package/dist/model/api-types.js.map +1 -1
- package/dist/model/index.d.ts +0 -1
- package/dist/model/index.d.ts.map +1 -1
- package/dist/model/index.js +1 -2
- package/dist/model/index.js.map +1 -1
- package/dist/model/parse-sample-values.js +1 -1
- package/dist/model/parse-sample-values.js.map +1 -1
- package/dist/model/prometheus-client.d.ts +3 -0
- package/dist/model/prometheus-client.d.ts.map +1 -1
- package/dist/model/prometheus-client.js +4 -3
- package/dist/model/prometheus-client.js.map +1 -1
- package/dist/model/prometheus-selectors.js +1 -1
- package/dist/model/prometheus-selectors.js.map +1 -1
- package/dist/model/templating.js +2 -2
- package/dist/model/templating.js.map +1 -1
- package/dist/model/time.js +1 -1
- package/dist/model/time.js.map +1 -1
- package/dist/plugins/MatcherEditor.js +1 -1
- package/dist/plugins/MatcherEditor.js.map +1 -1
- package/dist/plugins/prometheus-datasource.d.ts +2 -0
- package/dist/plugins/prometheus-datasource.d.ts.map +1 -1
- package/dist/plugins/prometheus-datasource.js +15 -8
- package/dist/plugins/prometheus-datasource.js.map +1 -1
- package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.js +2 -2
- package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.js.map +1 -1
- package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js +1 -1
- package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js.map +1 -1
- package/dist/plugins/prometheus-time-series-query/get-time-series-data.d.ts.map +1 -1
- package/dist/plugins/prometheus-time-series-query/get-time-series-data.js +8 -6
- package/dist/plugins/prometheus-time-series-query/get-time-series-data.js.map +1 -1
- package/dist/plugins/prometheus-time-series-query/index.js +1 -1
- package/dist/plugins/prometheus-time-series-query/index.js.map +1 -1
- package/dist/plugins/prometheus-time-series-query/query-editor-model.js +1 -1
- package/dist/plugins/prometheus-time-series-query/query-editor-model.js.map +1 -1
- package/dist/plugins/prometheus-time-series-query/time-series-query-model.js +1 -1
- package/dist/plugins/prometheus-time-series-query/time-series-query-model.js.map +1 -1
- package/dist/plugins/prometheus-variables.d.ts.map +1 -1
- package/dist/plugins/prometheus-variables.js +3 -2
- package/dist/plugins/prometheus-variables.js.map +1 -1
- package/dist/plugins/types.js +1 -1
- package/dist/plugins/types.js.map +1 -1
- package/dist/plugins/variable.js +1 -1
- package/dist/plugins/variable.js.map +1 -1
- package/dist/test/setup-tests.js +1 -1
- package/dist/test/setup-tests.js.map +1 -1
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +15 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/{model → utils}/utils.d.ts +5 -0
- package/dist/{model → utils}/utils.d.ts.map +1 -1
- package/dist/{model → utils}/utils.js +37 -1
- package/dist/utils/utils.js.map +1 -0
- package/dist/{model → utils}/utils.test.d.ts +0 -0
- package/dist/{model → utils}/utils.test.d.ts.map +1 -1
- package/dist/{model → utils}/utils.test.js +48 -2
- package/dist/utils/utils.test.js.map +1 -0
- package/package.json +4 -4
- package/dist/model/utils.js.map +0 -1
- package/dist/model/utils.test.js.map +0 -1
package/dist/cjs/index.js
CHANGED
package/dist/cjs/model/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
2
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
3
|
// you may not use this file except in compliance with the License.
|
|
4
4
|
// You may obtain a copy of the License at
|
|
@@ -20,7 +20,6 @@ _exportStar(require("./prometheus-client"), exports);
|
|
|
20
20
|
_exportStar(require("./prometheus-selectors"), exports);
|
|
21
21
|
_exportStar(require("./templating"), exports);
|
|
22
22
|
_exportStar(require("./time"), exports);
|
|
23
|
-
_exportStar(require("./utils"), exports);
|
|
24
23
|
function _exportStar(from, to) {
|
|
25
24
|
Object.keys(from).forEach(function(k) {
|
|
26
25
|
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
2
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
3
|
// you may not use this file except in compliance with the License.
|
|
4
4
|
// You may obtain a copy of the License at
|
|
@@ -53,12 +53,13 @@ function fetchWithGet(apiURI, params, queryOptions) {
|
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
55
|
function fetchWithPost(apiURI, params, queryOptions) {
|
|
56
|
-
const { datasourceUrl } = queryOptions;
|
|
56
|
+
const { datasourceUrl , headers } = queryOptions;
|
|
57
57
|
const url = `${datasourceUrl}${apiURI}`;
|
|
58
58
|
const init = {
|
|
59
59
|
method: 'POST',
|
|
60
60
|
headers: {
|
|
61
|
-
'Content-Type': 'application/x-www-form-urlencoded'
|
|
61
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
62
|
+
...headers
|
|
62
63
|
},
|
|
63
64
|
body: createSearchParams(params)
|
|
64
65
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
2
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
3
|
// you may not use this file except in compliance with the License.
|
|
4
4
|
// You may obtain a copy of the License at
|
|
@@ -19,7 +19,7 @@ Object.defineProperty(exports, "useReplaceTemplateString", {
|
|
|
19
19
|
get: ()=>useReplaceTemplateString
|
|
20
20
|
});
|
|
21
21
|
const _pluginSystem = require("@perses-dev/plugin-system");
|
|
22
|
-
const _utils = require("
|
|
22
|
+
const _utils = require("../utils");
|
|
23
23
|
function useReplaceTemplateString(templateString) {
|
|
24
24
|
const templateVariablesInTemplate = (0, _utils.parseTemplateVariables)(templateString || '');
|
|
25
25
|
const variables = (0, _pluginSystem.useTemplateVariableValues)(templateVariablesInTemplate);
|
package/dist/cjs/model/time.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
2
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
3
|
// you may not use this file except in compliance with the License.
|
|
4
4
|
// You may obtain a copy of the License at
|
|
@@ -22,31 +22,38 @@ const _model = require("../model");
|
|
|
22
22
|
/**
|
|
23
23
|
* Creates a PrometheusClient for a specific datasource spec.
|
|
24
24
|
*/ const createClient = (spec, options)=>{
|
|
25
|
-
const { direct_url } = spec;
|
|
25
|
+
const { direct_url , headers } = spec;
|
|
26
26
|
const { proxyUrl } = options;
|
|
27
|
+
// const headers = direct_url ? spec.headers : spec.proxy?.spec.headers;
|
|
27
28
|
// Use the direct URL if specified, but fallback to the proxyUrl by default if not specified
|
|
28
29
|
const datasourceUrl = direct_url !== null && direct_url !== void 0 ? direct_url : proxyUrl;
|
|
29
30
|
if (datasourceUrl === undefined) {
|
|
30
31
|
throw new Error('No URL specified for Prometheus client. You can use direct_url in the spec to configure it.');
|
|
31
32
|
}
|
|
32
33
|
// Could think about this becoming a class, although it definitely doesn't have to be
|
|
33
|
-
|
|
34
|
+
const client = {
|
|
34
35
|
options: {
|
|
35
|
-
datasourceUrl
|
|
36
|
+
datasourceUrl,
|
|
37
|
+
headers
|
|
36
38
|
},
|
|
37
39
|
instantQuery: (params)=>(0, _model.instantQuery)(params, {
|
|
38
|
-
datasourceUrl
|
|
40
|
+
datasourceUrl,
|
|
41
|
+
headers
|
|
39
42
|
}),
|
|
40
43
|
rangeQuery: (params)=>(0, _model.rangeQuery)(params, {
|
|
41
|
-
datasourceUrl
|
|
44
|
+
datasourceUrl,
|
|
45
|
+
headers
|
|
42
46
|
}),
|
|
43
47
|
labelNames: (params)=>(0, _model.labelNames)(params, {
|
|
44
|
-
datasourceUrl
|
|
48
|
+
datasourceUrl,
|
|
49
|
+
headers
|
|
45
50
|
}),
|
|
46
51
|
labelValues: (params)=>(0, _model.labelValues)(params, {
|
|
47
|
-
datasourceUrl
|
|
52
|
+
datasourceUrl,
|
|
53
|
+
headers
|
|
48
54
|
})
|
|
49
55
|
};
|
|
56
|
+
return client;
|
|
50
57
|
};
|
|
51
58
|
const PrometheusDatasource = {
|
|
52
59
|
createClient,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
2
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
3
|
// you may not use this file except in compliance with the License.
|
|
4
4
|
// You may obtain a copy of the License at
|
|
@@ -18,7 +18,7 @@ Object.defineProperty(exports, "PrometheusTimeSeriesQuery", {
|
|
|
18
18
|
enumerable: true,
|
|
19
19
|
get: ()=>PrometheusTimeSeriesQuery
|
|
20
20
|
});
|
|
21
|
-
const
|
|
21
|
+
const _utils = require("../../utils");
|
|
22
22
|
const _getTimeSeriesData = require("./get-time-series-data");
|
|
23
23
|
const _prometheusTimeSeriesQueryEditor = require("./PrometheusTimeSeriesQueryEditor");
|
|
24
24
|
const PrometheusTimeSeriesQuery = {
|
|
@@ -30,7 +30,7 @@ const PrometheusTimeSeriesQuery = {
|
|
|
30
30
|
}),
|
|
31
31
|
dependsOn: (spec)=>{
|
|
32
32
|
return {
|
|
33
|
-
variables: (0,
|
|
33
|
+
variables: (0, _utils.parseTemplateVariables)(spec.query)
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
36
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
2
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
3
|
// you may not use this file except in compliance with the License.
|
|
4
4
|
// You may obtain a copy of the License at
|
|
@@ -20,6 +20,7 @@ Object.defineProperty(exports, "getTimeSeriesData", {
|
|
|
20
20
|
});
|
|
21
21
|
const _dateFns = require("date-fns");
|
|
22
22
|
const _model = require("../../model");
|
|
23
|
+
const _utils = require("../../utils");
|
|
23
24
|
const getTimeSeriesData = async (spec, context)=>{
|
|
24
25
|
var ref;
|
|
25
26
|
if (spec.query === undefined || spec.query === null || spec.query === '') {
|
|
@@ -40,7 +41,7 @@ const getTimeSeriesData = async (spec, context)=>{
|
|
|
40
41
|
end = alignedEnd;
|
|
41
42
|
// Replace template variable placeholders in PromQL query
|
|
42
43
|
let query = spec.query.replace('$__rate_interval', `15s`);
|
|
43
|
-
query = (0,
|
|
44
|
+
query = (0, _utils.replaceTemplateVariables)(query, context.variableState);
|
|
44
45
|
var _datasource;
|
|
45
46
|
// Get the datasource, using the default Prom Datasource if one isn't specified in the query
|
|
46
47
|
const client = await context.datasourceStore.getDatasourceClient((_datasource = spec.datasource) !== null && _datasource !== void 0 ? _datasource : _model.DEFAULT_PROM);
|
|
@@ -66,13 +67,14 @@ const getTimeSeriesData = async (spec, context)=>{
|
|
|
66
67
|
// processing until its needed
|
|
67
68
|
series: result.map((value)=>{
|
|
68
69
|
const { metric , values } = value;
|
|
69
|
-
// Name the series after the metric labels or if no metric,
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
// Name the series after the metric labels or if no metric, use the query
|
|
71
|
+
let name = (0, _utils.getUniqueKeyForPrometheusResult)(metric);
|
|
72
|
+
if (name === '') {
|
|
73
|
+
name = query;
|
|
74
|
+
}
|
|
73
75
|
// query editor allows you to define an optional series_name_format
|
|
74
76
|
// property to customize legend and tooltip display
|
|
75
|
-
const formattedName = spec.series_name_format ? (0,
|
|
77
|
+
const formattedName = spec.series_name_format ? (0, _utils.formatSeriesName)(spec.series_name_format, metric) : name;
|
|
76
78
|
return {
|
|
77
79
|
name,
|
|
78
80
|
values: values.map(_model.parseValueTuple),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
2
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
3
|
// you may not use this file except in compliance with the License.
|
|
4
4
|
// You may obtain a copy of the License at
|
|
@@ -28,6 +28,7 @@ _export(exports, {
|
|
|
28
28
|
const _jsxRuntime = require("react/jsx-runtime");
|
|
29
29
|
const _material = require("@mui/material");
|
|
30
30
|
const _model = require("../model");
|
|
31
|
+
const _utils = require("../utils");
|
|
31
32
|
const _matcherEditor = require("./MatcherEditor");
|
|
32
33
|
function PrometheusLabelValuesVariableEditor(props) {
|
|
33
34
|
var _matchers;
|
|
@@ -140,7 +141,7 @@ const PrometheusLabelNamesVariable = {
|
|
|
140
141
|
getVariableOptions: async (spec, ctx)=>{
|
|
141
142
|
var _datasource;
|
|
142
143
|
const client = await ctx.datasourceStore.getDatasourceClient((_datasource = spec.datasource) !== null && _datasource !== void 0 ? _datasource : _model.DEFAULT_PROM);
|
|
143
|
-
const match = spec.matchers ? spec.matchers.map((m)=>(0,
|
|
144
|
+
const match = spec.matchers ? spec.matchers.map((m)=>(0, _utils.replaceTemplateVariables)(m, ctx.variables)) : undefined;
|
|
144
145
|
const timeRange = (0, _model.getPrometheusTimeRange)(ctx.timeRange);
|
|
145
146
|
const { data: options } = await client.labelNames({
|
|
146
147
|
'match[]': match,
|
|
@@ -153,7 +154,7 @@ const PrometheusLabelNamesVariable = {
|
|
|
153
154
|
dependsOn: (spec)=>{
|
|
154
155
|
var ref;
|
|
155
156
|
return {
|
|
156
|
-
variables: ((ref = spec.matchers) === null || ref === void 0 ? void 0 : ref.map((m)=>(0,
|
|
157
|
+
variables: ((ref = spec.matchers) === null || ref === void 0 ? void 0 : ref.map((m)=>(0, _utils.parseTemplateVariables)(m)).flat()) || []
|
|
157
158
|
};
|
|
158
159
|
},
|
|
159
160
|
OptionsEditorComponent: PrometheusLabelNamesVariableEditor,
|
|
@@ -164,10 +165,10 @@ const PrometheusLabelValuesVariable = {
|
|
|
164
165
|
const pluginDef = spec;
|
|
165
166
|
var _datasource;
|
|
166
167
|
const client = await ctx.datasourceStore.getDatasourceClient((_datasource = spec.datasource) !== null && _datasource !== void 0 ? _datasource : _model.DEFAULT_PROM);
|
|
167
|
-
const match = pluginDef.matchers ? pluginDef.matchers.map((m)=>(0,
|
|
168
|
+
const match = pluginDef.matchers ? pluginDef.matchers.map((m)=>(0, _utils.replaceTemplateVariables)(m, ctx.variables)) : undefined;
|
|
168
169
|
const timeRange = (0, _model.getPrometheusTimeRange)(ctx.timeRange);
|
|
169
170
|
const { data: options } = await client.labelValues({
|
|
170
|
-
labelName: (0,
|
|
171
|
+
labelName: (0, _utils.replaceTemplateVariables)(pluginDef.label_name, ctx.variables),
|
|
171
172
|
'match[]': match,
|
|
172
173
|
...timeRange
|
|
173
174
|
});
|
|
@@ -178,7 +179,7 @@ const PrometheusLabelValuesVariable = {
|
|
|
178
179
|
dependsOn: (spec)=>{
|
|
179
180
|
var ref;
|
|
180
181
|
return {
|
|
181
|
-
variables: ((ref = spec.matchers) === null || ref === void 0 ? void 0 : ref.map((m)=>(0,
|
|
182
|
+
variables: ((ref = spec.matchers) === null || ref === void 0 ? void 0 : ref.map((m)=>(0, _utils.parseTemplateVariables)(m)).flat().concat((0, _utils.parseTemplateVariables)(spec.label_name))) || []
|
|
182
183
|
};
|
|
183
184
|
},
|
|
184
185
|
OptionsEditorComponent: PrometheusLabelValuesVariableEditor,
|
|
@@ -192,9 +193,9 @@ const PrometheusPromQLVariable = {
|
|
|
192
193
|
const client = await ctx.datasourceStore.getDatasourceClient((_datasource = spec.datasource) !== null && _datasource !== void 0 ? _datasource : _model.DEFAULT_PROM);
|
|
193
194
|
// TODO we may want to manage a range query as well.
|
|
194
195
|
const { data: options } = await client.instantQuery({
|
|
195
|
-
query: (0,
|
|
196
|
+
query: (0, _utils.replaceTemplateVariables)(spec.expr, ctx.variables)
|
|
196
197
|
});
|
|
197
|
-
const labelName = (0,
|
|
198
|
+
const labelName = (0, _utils.replaceTemplateVariables)(spec.label_name, ctx.variables);
|
|
198
199
|
let values = [];
|
|
199
200
|
if ((options === null || options === void 0 ? void 0 : options.resultType) === 'matrix') {
|
|
200
201
|
values = capturingMatrix(options, labelName);
|
|
@@ -207,7 +208,7 @@ const PrometheusPromQLVariable = {
|
|
|
207
208
|
},
|
|
208
209
|
dependsOn: (spec)=>{
|
|
209
210
|
return {
|
|
210
|
-
variables: (0,
|
|
211
|
+
variables: (0, _utils.parseTemplateVariables)(spec.expr).concat((0, _utils.parseTemplateVariables)(spec.label_name))
|
|
211
212
|
};
|
|
212
213
|
},
|
|
213
214
|
OptionsEditorComponent: PrometheusPromQLVariableEditor,
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Copyright 2023 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
|
+
_exportStar(require("./utils"), exports);
|
|
18
|
+
function _exportStar(from, to) {
|
|
19
|
+
Object.keys(from).forEach(function(k) {
|
|
20
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function() {
|
|
23
|
+
return from[k];
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
return from;
|
|
28
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
2
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
3
|
// you may not use this file except in compliance with the License.
|
|
4
4
|
// You may obtain a copy of the License at
|
|
@@ -24,7 +24,8 @@ _export(exports, {
|
|
|
24
24
|
replaceTemplateVariables: ()=>replaceTemplateVariables,
|
|
25
25
|
replaceTemplateVariable: ()=>replaceTemplateVariable,
|
|
26
26
|
parseTemplateVariables: ()=>parseTemplateVariables,
|
|
27
|
-
formatSeriesName: ()=>formatSeriesName
|
|
27
|
+
formatSeriesName: ()=>formatSeriesName,
|
|
28
|
+
getUniqueKeyForPrometheusResult: ()=>getUniqueKeyForPrometheusResult
|
|
28
29
|
});
|
|
29
30
|
function replaceTemplateVariables(text, variableState) {
|
|
30
31
|
const variables = parseTemplateVariables(text);
|
|
@@ -67,3 +68,37 @@ function formatSeriesName(inputFormat, seriesLabels) {
|
|
|
67
68
|
const resolveLabelsRegex = /\{\{\s*(.+?)\s*\}\}/g;
|
|
68
69
|
return inputFormat.replace(resolveLabelsRegex, (_, g)=>seriesLabels[g] ? seriesLabels[g] : g);
|
|
69
70
|
}
|
|
71
|
+
/*
|
|
72
|
+
* Stringifies object of labels into valid PromQL for querying metric by label
|
|
73
|
+
*/ function stringifyPrometheusMetricLabels(labels, removeExprWrap) {
|
|
74
|
+
const labelStrings = [];
|
|
75
|
+
Object.keys(labels).sort().forEach((labelName)=>{
|
|
76
|
+
const labelValue = labels[labelName];
|
|
77
|
+
if (labelValue !== undefined) {
|
|
78
|
+
if (removeExprWrap) {
|
|
79
|
+
labelStrings.push(`"${labelName}":"${labelValue}"`);
|
|
80
|
+
} else {
|
|
81
|
+
labelStrings.push(`${labelName}="${labelValue}"`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
return `{${labelStrings.join(',')}}`;
|
|
86
|
+
}
|
|
87
|
+
function getUniqueKeyForPrometheusResult(metricLabels, { removeExprWrap } = {}) {
|
|
88
|
+
const metricNameKey = '__name__';
|
|
89
|
+
if (metricLabels) {
|
|
90
|
+
if (Object.prototype.hasOwnProperty.call(metricLabels, metricNameKey)) {
|
|
91
|
+
const stringifiedLabels = stringifyPrometheusMetricLabels({
|
|
92
|
+
...metricLabels,
|
|
93
|
+
[metricNameKey]: undefined
|
|
94
|
+
}, removeExprWrap);
|
|
95
|
+
if (removeExprWrap === true) {
|
|
96
|
+
return `${stringifiedLabels}`;
|
|
97
|
+
} else {
|
|
98
|
+
return `${metricLabels[metricNameKey]}${stringifiedLabels}`;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return stringifyPrometheusMetricLabels(metricLabels, removeExprWrap);
|
|
102
|
+
}
|
|
103
|
+
return '';
|
|
104
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
2
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
3
|
// you may not use this file except in compliance with the License.
|
|
4
4
|
// You may obtain a copy of the License at
|
|
@@ -124,3 +124,49 @@ describe('formatSeriesName', ()=>{
|
|
|
124
124
|
expect((0, _utils.formatSeriesName)(inputFormat, metric)).toEqual(output);
|
|
125
125
|
});
|
|
126
126
|
});
|
|
127
|
+
describe('getUniqueKeyForPrometheusResult', ()=>{
|
|
128
|
+
let labels = {};
|
|
129
|
+
beforeEach(()=>{
|
|
130
|
+
labels = {};
|
|
131
|
+
});
|
|
132
|
+
it('should be a formatted prometheus string', ()=>{
|
|
133
|
+
labels = {
|
|
134
|
+
['foo']: 'bar'
|
|
135
|
+
};
|
|
136
|
+
const result = (0, _utils.getUniqueKeyForPrometheusResult)(labels);
|
|
137
|
+
expect(result).toEqual('{foo="bar"}');
|
|
138
|
+
});
|
|
139
|
+
it('should be formatted with "', ()=>{
|
|
140
|
+
labels = {
|
|
141
|
+
['foo']: 'bar'
|
|
142
|
+
};
|
|
143
|
+
const result = (0, _utils.getUniqueKeyForPrometheusResult)(labels, {
|
|
144
|
+
removeExprWrap: true
|
|
145
|
+
});
|
|
146
|
+
expect(result).toEqual('{"foo":"bar"}');
|
|
147
|
+
});
|
|
148
|
+
it('should be formatted with __name__ removed', ()=>{
|
|
149
|
+
labels = {
|
|
150
|
+
__name__: 'node_memory_Buffers_bytes',
|
|
151
|
+
env: 'demo',
|
|
152
|
+
instance: 'demo.do.prometheus.io:9100',
|
|
153
|
+
job: 'node'
|
|
154
|
+
};
|
|
155
|
+
const result = (0, _utils.getUniqueKeyForPrometheusResult)(labels, {
|
|
156
|
+
removeExprWrap: true
|
|
157
|
+
});
|
|
158
|
+
expect(result).toEqual('{"env":"demo","instance":"demo.do.prometheus.io:9100","job":"node"}');
|
|
159
|
+
});
|
|
160
|
+
it('should return a valid query to filter by label', ()=>{
|
|
161
|
+
labels = {
|
|
162
|
+
__name__: 'node_memory_Buffers_bytes',
|
|
163
|
+
env: 'demo',
|
|
164
|
+
instance: 'demo.do.prometheus.io:9100',
|
|
165
|
+
job: 'node'
|
|
166
|
+
};
|
|
167
|
+
const result = (0, _utils.getUniqueKeyForPrometheusResult)(labels, {
|
|
168
|
+
removeExprWrap: false
|
|
169
|
+
});
|
|
170
|
+
expect(result).toEqual('node_memory_Buffers_bytes{env="demo",instance="demo.do.prometheus.io:9100",job="node"}');
|
|
171
|
+
});
|
|
172
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/PromQL.tsx"],"sourcesContent":["// Copyright
|
|
1
|
+
{"version":3,"sources":["../../src/components/PromQL.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport CodeMirror, { ReactCodeMirrorProps } from '@uiw/react-codemirror';\nimport { PromQLExtension, CompleteConfiguration } from '@prometheus-io/codemirror-promql';\nimport { EditorView } from '@codemirror/view';\nimport { useTheme } from '@mui/material';\nimport { useMemo } from 'react';\n\nexport type PromQLEditorProps = { completeConfig: CompleteConfiguration } & Omit<\n ReactCodeMirrorProps,\n 'theme' | 'extensions'\n>;\n\nexport function PromQLEditor({ completeConfig, ...rest }: PromQLEditorProps) {\n const theme = useTheme();\n const isDarkMode = theme.palette.mode === 'dark';\n\n const promQLExtension = useMemo(() => {\n return new PromQLExtension().activateLinter(false).setComplete(completeConfig).asExtension();\n }, [completeConfig]);\n\n return (\n <CodeMirror\n {...rest}\n style={{ border: `1px solid ${theme.palette.divider}` }}\n theme={isDarkMode ? 'dark' : 'light'}\n basicSetup={{\n highlightActiveLine: false,\n highlightActiveLineGutter: false,\n foldGutter: false,\n }}\n extensions={[EditorView.lineWrapping, promQLExtension]}\n />\n );\n}\n"],"names":["CodeMirror","PromQLExtension","EditorView","useTheme","useMemo","PromQLEditor","completeConfig","rest","theme","isDarkMode","palette","mode","promQLExtension","activateLinter","setComplete","asExtension","style","border","divider","basicSetup","highlightActiveLine","highlightActiveLineGutter","foldGutter","extensions","lineWrapping"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,OAAOA,UAAU,MAAgC,uBAAuB,CAAC;AACzE,SAASC,eAAe,QAA+B,kCAAkC,CAAC;AAC1F,SAASC,UAAU,QAAQ,kBAAkB,CAAC;AAC9C,SAASC,QAAQ,QAAQ,eAAe,CAAC;AACzC,SAASC,OAAO,QAAQ,OAAO,CAAC;AAOhC,OAAO,SAASC,YAAY,CAAC,EAAEC,cAAc,CAAA,EAAE,GAAGC,IAAI,EAAqB,EAAE;IAC3E,MAAMC,KAAK,GAAGL,QAAQ,EAAE,AAAC;IACzB,MAAMM,UAAU,GAAGD,KAAK,CAACE,OAAO,CAACC,IAAI,KAAK,MAAM,AAAC;IAEjD,MAAMC,eAAe,GAAGR,OAAO,CAAC,IAAM;QACpC,OAAO,IAAIH,eAAe,EAAE,CAACY,cAAc,CAAC,KAAK,CAAC,CAACC,WAAW,CAACR,cAAc,CAAC,CAACS,WAAW,EAAE,CAAC;IAC/F,CAAC,EAAE;QAACT,cAAc;KAAC,CAAC,AAAC;IAErB,qBACE,KAACN,UAAU;QACR,GAAGO,IAAI;QACRS,KAAK,EAAE;YAAEC,MAAM,EAAE,CAAC,UAAU,EAAET,KAAK,CAACE,OAAO,CAACQ,OAAO,CAAC,CAAC;SAAE;QACvDV,KAAK,EAAEC,UAAU,GAAG,MAAM,GAAG,OAAO;QACpCU,UAAU,EAAE;YACVC,mBAAmB,EAAE,KAAK;YAC1BC,yBAAyB,EAAE,KAAK;YAChCC,UAAU,EAAE,KAAK;SAClB;QACDC,UAAU,EAAE;YAACrB,UAAU,CAACsB,YAAY;YAAEZ,eAAe;SAAC;MACtD,CACF;AACJ,CAAC"}
|
package/dist/components/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/index.ts"],"sourcesContent":["// Copyright
|
|
1
|
+
{"version":3,"sources":["../../src/components/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './PromQL';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,UAAU,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["// Copyright
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { PrometheusTimeSeriesQuery } from './plugins/prometheus-time-series-query';\n// @TODO: Move this to a more generic location;\nimport { StaticListVariable } from './plugins/variable';\nimport {\n PrometheusLabelNamesVariable,\n PrometheusLabelValuesVariable,\n PrometheusPromQLVariable,\n} from './plugins/prometheus-variables';\nimport { PrometheusDatasource } from './plugins/prometheus-datasource';\n\n// Export plugins under the same name as the kinds they handle from the plugin.json\nexport {\n PrometheusTimeSeriesQuery,\n StaticListVariable,\n PrometheusLabelNamesVariable,\n PrometheusLabelValuesVariable,\n PrometheusPromQLVariable,\n PrometheusDatasource,\n};\n"],"names":["PrometheusTimeSeriesQuery","StaticListVariable","PrometheusLabelNamesVariable","PrometheusLabelValuesVariable","PrometheusPromQLVariable","PrometheusDatasource"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,yBAAyB,QAAQ,wCAAwC,CAAC;AACnF,+CAA+C;AAC/C,SAASC,kBAAkB,QAAQ,oBAAoB,CAAC;AACxD,SACEC,4BAA4B,EAC5BC,6BAA6B,EAC7BC,wBAAwB,QACnB,gCAAgC,CAAC;AACxC,SAASC,oBAAoB,QAAQ,iCAAiC,CAAC;AAEvE,mFAAmF;AACnF,SACEL,yBAAyB,EACzBC,kBAAkB,EAClBC,4BAA4B,EAC5BC,6BAA6B,EAC7BC,wBAAwB,EACxBC,oBAAoB,GACpB"}
|
package/dist/model/api-types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/model/api-types.ts"],"sourcesContent":["// Copyright
|
|
1
|
+
{"version":3,"sources":["../../src/model/api-types.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { DurationString } from '@perses-dev/core';\n\n// Just reuse dashboard model's type and re-export\nexport type { DurationString };\n\nexport interface SuccessResponse<T> {\n status: 'success';\n data: T;\n warnings?: string[];\n}\n\nexport interface ErrorResponse<T> {\n status: 'error';\n data?: T;\n errorType: string;\n error: string;\n}\n\nexport type ApiResponse<T> = SuccessResponse<T> | ErrorResponse<T>;\n\nexport type DurationSeconds = number;\n\nexport type UnixTimestampSeconds = number;\n\nexport type ValueTuple = [unixTimeSeconds: UnixTimestampSeconds, sampleValue: string];\n\nexport type Metric = Record<string, string>;\n\nexport interface VectorData {\n resultType: 'vector';\n result: Array<{\n metric: Metric;\n value: ValueTuple;\n }>;\n}\n\nexport interface MatrixData {\n resultType: 'matrix';\n result: Array<{\n metric: Metric;\n values: ValueTuple[];\n }>;\n}\n\nexport interface ScalarData {\n resultType: 'scalar';\n result: ValueTuple;\n}\n\nexport interface InstantQueryRequestParameters {\n query: string;\n time?: UnixTimestampSeconds;\n timeout?: DurationString;\n}\n\nexport type InstantQueryResponse = ApiResponse<MatrixData | VectorData | ScalarData>;\n\nexport interface RangeQueryRequestParameters {\n query: string;\n start: UnixTimestampSeconds;\n end: UnixTimestampSeconds;\n step: DurationSeconds;\n timeout?: DurationString;\n}\n\nexport type RangeQueryResponse = ApiResponse<MatrixData>;\n\nexport interface SeriesRequestParameters {\n 'match[]': string[];\n start: UnixTimestampSeconds;\n end: UnixTimestampSeconds;\n}\n\nexport type SeriesResponse = ApiResponse<Metric[]>;\n\nexport interface LabelNamesRequestParameters {\n start?: UnixTimestampSeconds;\n end?: UnixTimestampSeconds;\n 'match[]'?: string[];\n}\n\nexport type LabelNamesResponse = ApiResponse<string[]>;\n\nexport interface LabelValuesRequestParameters {\n labelName: string;\n start?: UnixTimestampSeconds;\n end?: UnixTimestampSeconds;\n 'match[]'?: string[];\n}\n\nexport type LabelValuesResponse = ApiResponse<string[]>;\n\nexport interface MetricMetadata {\n type: string;\n help: string;\n unit?: string;\n}\n\nexport interface MetricMetadataRequestParameters {\n limit?: number;\n metric?: string;\n}\n\nexport type MetricMetadataResponse = ApiResponse<Record<string, MetricMetadata[]>>;\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,WAuGmF"}
|
package/dist/model/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/model/index.ts"],"names":[],"mappings":"AAaA,cAAc,aAAa,CAAC;AAC5B,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/model/index.ts"],"names":[],"mappings":"AAaA,cAAc,aAAa,CAAC;AAC5B,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC"}
|
package/dist/model/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
2
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
3
|
// you may not use this file except in compliance with the License.
|
|
4
4
|
// You may obtain a copy of the License at
|
|
@@ -16,6 +16,5 @@ export * from './prometheus-client';
|
|
|
16
16
|
export * from './prometheus-selectors';
|
|
17
17
|
export * from './templating';
|
|
18
18
|
export * from './time';
|
|
19
|
-
export * from './utils';
|
|
20
19
|
|
|
21
20
|
//# sourceMappingURL=index.js.map
|
package/dist/model/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/model/index.ts"],"sourcesContent":["// Copyright
|
|
1
|
+
{"version":3,"sources":["../../src/model/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './api-types';\nexport * from './parse-sample-values';\nexport * from './prometheus-client';\nexport * from './prometheus-selectors';\nexport * from './templating';\nexport * from './time';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,aAAa,CAAC;AAC5B,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC"}
|