@perses-dev/prometheus-plugin 0.0.0-snapshot-time-range-height-80d08fc
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/LICENSE +201 -0
- package/dist/cjs/index.js +34 -0
- package/dist/cjs/model/api-types.js +16 -0
- package/dist/cjs/model/index.js +34 -0
- package/dist/cjs/model/parse-sample-values.js +50 -0
- package/dist/cjs/model/prometheus-client.js +87 -0
- package/dist/cjs/model/prometheus-selectors.js +37 -0
- package/dist/cjs/model/templating.js +27 -0
- package/dist/cjs/model/time.js +54 -0
- package/dist/cjs/model/utils.js +69 -0
- package/dist/cjs/model/utils.test.js +126 -0
- package/dist/cjs/plugins/MatcherEditor.js +75 -0
- package/dist/cjs/plugins/prometheus-datasource.js +54 -0
- package/dist/cjs/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.js +36 -0
- package/dist/cjs/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js +81 -0
- package/dist/cjs/plugins/prometheus-time-series-query/get-time-series-data.js +84 -0
- package/dist/cjs/plugins/prometheus-time-series-query/index.js +28 -0
- package/dist/cjs/plugins/prometheus-time-series-query/query-editor-model.js +83 -0
- package/dist/cjs/plugins/prometheus-time-series-query/time-series-query-model.js +16 -0
- package/dist/cjs/plugins/prometheus-variables.js +218 -0
- package/dist/cjs/plugins/types.js +16 -0
- package/dist/cjs/plugins/variable.js +103 -0
- package/dist/cjs/test/setup-tests.js +17 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/model/api-types.d.ts +80 -0
- package/dist/model/api-types.d.ts.map +1 -0
- package/dist/model/api-types.js +15 -0
- package/dist/model/api-types.js.map +1 -0
- package/dist/model/index.d.ts +8 -0
- package/dist/model/index.d.ts.map +1 -0
- package/dist/model/index.js +21 -0
- package/dist/model/index.js.map +1 -0
- package/dist/model/parse-sample-values.d.ts +16 -0
- package/dist/model/parse-sample-values.d.ts.map +1 -0
- package/dist/model/parse-sample-values.js +44 -0
- package/dist/model/parse-sample-values.js.map +1 -0
- package/dist/model/prometheus-client.d.ts +27 -0
- package/dist/model/prometheus-client.d.ts.map +1 -0
- package/dist/model/prometheus-client.js +81 -0
- package/dist/model/prometheus-client.js.map +1 -0
- package/dist/model/prometheus-selectors.d.ts +22 -0
- package/dist/model/prometheus-selectors.d.ts.map +1 -0
- package/dist/model/prometheus-selectors.js +30 -0
- package/dist/model/prometheus-selectors.js.map +1 -0
- package/dist/model/templating.d.ts +6 -0
- package/dist/model/templating.d.ts.map +1 -0
- package/dist/model/templating.js +21 -0
- package/dist/model/templating.js.map +1 -0
- package/dist/model/time.d.ts +24 -0
- package/dist/model/time.d.ts.map +1 -0
- package/dist/model/time.js +49 -0
- package/dist/model/time.js.map +1 -0
- package/dist/model/utils.d.ts +14 -0
- package/dist/model/utils.d.ts.map +1 -0
- package/dist/model/utils.js +60 -0
- package/dist/model/utils.js.map +1 -0
- package/dist/model/utils.test.d.ts +2 -0
- package/dist/model/utils.test.d.ts.map +1 -0
- package/dist/model/utils.test.js +124 -0
- package/dist/model/utils.test.js.map +1 -0
- package/dist/plugins/MatcherEditor.d.ts +8 -0
- package/dist/plugins/MatcherEditor.d.ts.map +1 -0
- package/dist/plugins/MatcherEditor.js +64 -0
- package/dist/plugins/MatcherEditor.js.map +1 -0
- package/dist/plugins/prometheus-datasource.d.ts +7 -0
- package/dist/plugins/prometheus-datasource.d.ts.map +1 -0
- package/dist/plugins/prometheus-datasource.js +48 -0
- package/dist/plugins/prometheus-datasource.js.map +1 -0
- package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.d.ts +7 -0
- package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.d.ts.map +1 -0
- package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.js +32 -0
- package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.js.map +1 -0
- package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.d.ts +7 -0
- package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.d.ts.map +1 -0
- package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js +77 -0
- package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js.map +1 -0
- package/dist/plugins/prometheus-time-series-query/get-time-series-data.d.ts +4 -0
- package/dist/plugins/prometheus-time-series-query/get-time-series-data.d.ts.map +1 -0
- package/dist/plugins/prometheus-time-series-query/get-time-series-data.js +78 -0
- package/dist/plugins/prometheus-time-series-query/get-time-series-data.js.map +1 -0
- package/dist/plugins/prometheus-time-series-query/index.d.ts +2 -0
- package/dist/plugins/prometheus-time-series-query/index.d.ts.map +1 -0
- package/dist/plugins/prometheus-time-series-query/index.js +15 -0
- package/dist/plugins/prometheus-time-series-query/index.js.map +1 -0
- package/dist/plugins/prometheus-time-series-query/query-editor-model.d.ts +24 -0
- package/dist/plugins/prometheus-time-series-query/query-editor-model.d.ts.map +1 -0
- package/dist/plugins/prometheus-time-series-query/query-editor-model.js +78 -0
- package/dist/plugins/prometheus-time-series-query/query-editor-model.js.map +1 -0
- package/dist/plugins/prometheus-time-series-query/time-series-query-model.d.ts +13 -0
- package/dist/plugins/prometheus-time-series-query/time-series-query-model.d.ts.map +1 -0
- package/dist/plugins/prometheus-time-series-query/time-series-query-model.js +15 -0
- package/dist/plugins/prometheus-time-series-query/time-series-query-model.js.map +1 -0
- package/dist/plugins/prometheus-variables.d.ts +6 -0
- package/dist/plugins/prometheus-variables.d.ts.map +1 -0
- package/dist/plugins/prometheus-variables.js +205 -0
- package/dist/plugins/prometheus-variables.js.map +1 -0
- package/dist/plugins/types.d.ts +16 -0
- package/dist/plugins/types.d.ts.map +1 -0
- package/dist/plugins/types.js +15 -0
- package/dist/plugins/types.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 +97 -0
- package/dist/plugins/variable.js.map +1 -0
- package/dist/test/setup-tests.d.ts +2 -0
- package/dist/test/setup-tests.d.ts.map +1 -0
- package/dist/test/setup-tests.js +15 -0
- package/dist/test/setup-tests.js.map +1 -0
- package/package.json +46 -0
- package/plugin.json +58 -0
|
@@ -0,0 +1,126 @@
|
|
|
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
|
+
const _utils = require("./utils");
|
|
18
|
+
describe('parseTemplateVariables()', ()=>{
|
|
19
|
+
const tests = [
|
|
20
|
+
{
|
|
21
|
+
text: 'hello $var1 world $var2',
|
|
22
|
+
variables: [
|
|
23
|
+
'var1',
|
|
24
|
+
'var2'
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
];
|
|
28
|
+
tests.forEach(({ text , variables })=>{
|
|
29
|
+
it(`parses ${text}`, ()=>{
|
|
30
|
+
expect((0, _utils.parseTemplateVariables)(text)).toEqual(variables);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
describe('replaceTemplateVariable()', ()=>{
|
|
35
|
+
const tests = [
|
|
36
|
+
{
|
|
37
|
+
text: 'hello $var1',
|
|
38
|
+
varName: 'var1',
|
|
39
|
+
value: 'world',
|
|
40
|
+
expected: 'hello world'
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
text: 'hello $var1 $var1',
|
|
44
|
+
varName: 'var1',
|
|
45
|
+
value: 'world',
|
|
46
|
+
expected: 'hello world world'
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
text: 'hello $var1',
|
|
50
|
+
varName: 'var1',
|
|
51
|
+
value: [
|
|
52
|
+
'world',
|
|
53
|
+
'w'
|
|
54
|
+
],
|
|
55
|
+
expected: 'hello (world|w)'
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
text: 'hello $var1 $var1',
|
|
59
|
+
varName: 'var1',
|
|
60
|
+
value: [
|
|
61
|
+
'world',
|
|
62
|
+
'w'
|
|
63
|
+
],
|
|
64
|
+
expected: 'hello (world|w) (world|w)'
|
|
65
|
+
}
|
|
66
|
+
];
|
|
67
|
+
tests.forEach(({ text , value , varName , expected })=>{
|
|
68
|
+
it(`replaces ${text} ${value}`, ()=>{
|
|
69
|
+
expect((0, _utils.replaceTemplateVariable)(text, varName, value)).toEqual(expected);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
describe('replaceTemplateVariables()', ()=>{
|
|
74
|
+
const tests = [
|
|
75
|
+
{
|
|
76
|
+
text: 'hello $var1 $var2',
|
|
77
|
+
state: {
|
|
78
|
+
var1: {
|
|
79
|
+
value: 'world',
|
|
80
|
+
loading: false
|
|
81
|
+
},
|
|
82
|
+
var2: {
|
|
83
|
+
value: 'world',
|
|
84
|
+
loading: false
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
expected: 'hello world world'
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
text: 'hello $var1 $var2',
|
|
91
|
+
state: {
|
|
92
|
+
var1: {
|
|
93
|
+
value: 'world',
|
|
94
|
+
loading: false
|
|
95
|
+
},
|
|
96
|
+
var2: {
|
|
97
|
+
value: [
|
|
98
|
+
'a',
|
|
99
|
+
'b'
|
|
100
|
+
],
|
|
101
|
+
loading: false
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
expected: 'hello world (a|b)'
|
|
105
|
+
}
|
|
106
|
+
];
|
|
107
|
+
tests.forEach(({ text , state , expected })=>{
|
|
108
|
+
it(`replaces ${text} ${JSON.stringify(state)}`, ()=>{
|
|
109
|
+
expect((0, _utils.replaceTemplateVariables)(text, state)).toEqual(expected);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
describe('formatSeriesName', ()=>{
|
|
114
|
+
it('should resolve label name tokens to label values from query response', ()=>{
|
|
115
|
+
// example from query: node_load15{instance=~\"(demo.do.prometheus.io:9100)\",job='$job'}
|
|
116
|
+
const inputFormat = 'Test {{job}} {{instance}}';
|
|
117
|
+
const metric = {
|
|
118
|
+
__name__: 'node_load15',
|
|
119
|
+
env: 'demo',
|
|
120
|
+
instance: 'demo.do.prometheus.io:9100',
|
|
121
|
+
job: 'node'
|
|
122
|
+
};
|
|
123
|
+
const output = 'Test node demo.do.prometheus.io:9100';
|
|
124
|
+
expect((0, _utils.formatSeriesName)(inputFormat, metric)).toEqual(output);
|
|
125
|
+
});
|
|
126
|
+
});
|
|
@@ -0,0 +1,75 @@
|
|
|
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, "MatcherEditor", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: ()=>MatcherEditor
|
|
20
|
+
});
|
|
21
|
+
const _jsxRuntime = require("react/jsx-runtime");
|
|
22
|
+
const _material = require("@mui/material");
|
|
23
|
+
const _immer = require("immer");
|
|
24
|
+
const _trashCan = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/TrashCan"));
|
|
25
|
+
function _interopRequireDefault(obj) {
|
|
26
|
+
return obj && obj.__esModule ? obj : {
|
|
27
|
+
default: obj
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function MatcherEditor({ matchers , onChange }) {
|
|
31
|
+
return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
32
|
+
spacing: 1,
|
|
33
|
+
children: [
|
|
34
|
+
matchers.map((matcher, index)=>/*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
|
|
35
|
+
display: "flex",
|
|
36
|
+
children: [
|
|
37
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
|
|
38
|
+
fullWidth: true,
|
|
39
|
+
label: "Series Selector",
|
|
40
|
+
value: matcher,
|
|
41
|
+
onChange: (e)=>{
|
|
42
|
+
const newMatchers = (0, _immer.produce)(matchers, (draft)=>{
|
|
43
|
+
draft[index] = e.target.value;
|
|
44
|
+
});
|
|
45
|
+
onChange(newMatchers);
|
|
46
|
+
}
|
|
47
|
+
}),
|
|
48
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.IconButton, {
|
|
49
|
+
onClick: ()=>{
|
|
50
|
+
const newMatchers = (0, _immer.produce)(matchers, (draft)=>{
|
|
51
|
+
draft.splice(index, 1);
|
|
52
|
+
});
|
|
53
|
+
onChange(newMatchers);
|
|
54
|
+
},
|
|
55
|
+
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_trashCan.default, {})
|
|
56
|
+
})
|
|
57
|
+
]
|
|
58
|
+
}, index)),
|
|
59
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
|
|
60
|
+
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Button, {
|
|
61
|
+
fullWidth: false,
|
|
62
|
+
color: "secondary",
|
|
63
|
+
variant: "outlined",
|
|
64
|
+
onClick: ()=>{
|
|
65
|
+
const newMatchers = (0, _immer.produce)(matchers, (draft)=>{
|
|
66
|
+
draft.push('');
|
|
67
|
+
});
|
|
68
|
+
onChange(newMatchers);
|
|
69
|
+
},
|
|
70
|
+
children: "Add Series Selector"
|
|
71
|
+
})
|
|
72
|
+
})
|
|
73
|
+
]
|
|
74
|
+
});
|
|
75
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
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 _model = require("../model");
|
|
22
|
+
/**
|
|
23
|
+
* Creates a PrometheusClient for a specific datasource spec.
|
|
24
|
+
*/ const createClient = (spec, options)=>{
|
|
25
|
+
const { direct_url } = spec;
|
|
26
|
+
const { proxyUrl } = options;
|
|
27
|
+
// Use the direct URL if specified, but fallback to the proxyUrl by default if not specified
|
|
28
|
+
const datasourceUrl = direct_url !== null && direct_url !== void 0 ? direct_url : proxyUrl;
|
|
29
|
+
if (datasourceUrl === undefined) {
|
|
30
|
+
throw new Error('No URL specified for Prometheus client. You can use direct_url in the spec to configure it.');
|
|
31
|
+
}
|
|
32
|
+
// Could think about this becoming a class, although it definitely doesn't have to be
|
|
33
|
+
return {
|
|
34
|
+
instantQuery: (params)=>(0, _model.instantQuery)(params, {
|
|
35
|
+
datasourceUrl
|
|
36
|
+
}),
|
|
37
|
+
rangeQuery: (params)=>(0, _model.rangeQuery)(params, {
|
|
38
|
+
datasourceUrl
|
|
39
|
+
}),
|
|
40
|
+
labelNames: (params)=>(0, _model.labelNames)(params, {
|
|
41
|
+
datasourceUrl
|
|
42
|
+
}),
|
|
43
|
+
labelValues: (params)=>(0, _model.labelValues)(params, {
|
|
44
|
+
datasourceUrl
|
|
45
|
+
})
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
const PrometheusDatasource = {
|
|
49
|
+
createClient,
|
|
50
|
+
OptionsEditorComponent: ()=>null,
|
|
51
|
+
createInitialOptions: ()=>({
|
|
52
|
+
direct_url: ''
|
|
53
|
+
})
|
|
54
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
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, "PrometheusTimeSeriesQuery", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: ()=>PrometheusTimeSeriesQuery
|
|
20
|
+
});
|
|
21
|
+
const _model = require("../../model");
|
|
22
|
+
const _getTimeSeriesData = require("./get-time-series-data");
|
|
23
|
+
const _prometheusTimeSeriesQueryEditor = require("./PrometheusTimeSeriesQueryEditor");
|
|
24
|
+
const PrometheusTimeSeriesQuery = {
|
|
25
|
+
getTimeSeriesData: _getTimeSeriesData.getTimeSeriesData,
|
|
26
|
+
OptionsEditorComponent: _prometheusTimeSeriesQueryEditor.PrometheusTimeSeriesQueryEditor,
|
|
27
|
+
createInitialOptions: ()=>({
|
|
28
|
+
query: '',
|
|
29
|
+
datasource: undefined
|
|
30
|
+
}),
|
|
31
|
+
dependsOn: (spec)=>{
|
|
32
|
+
return {
|
|
33
|
+
variables: (0, _model.parseTemplateVariables)(spec.query)
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
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, "PrometheusTimeSeriesQueryEditor", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: ()=>PrometheusTimeSeriesQueryEditor
|
|
20
|
+
});
|
|
21
|
+
const _jsxRuntime = require("react/jsx-runtime");
|
|
22
|
+
const _immer = require("immer");
|
|
23
|
+
const _material = require("@mui/material");
|
|
24
|
+
const _pluginSystem = require("@perses-dev/plugin-system");
|
|
25
|
+
const _model = require("../../model");
|
|
26
|
+
const _queryEditorModel = require("./query-editor-model");
|
|
27
|
+
function PrometheusTimeSeriesQueryEditor(props) {
|
|
28
|
+
const { onChange , value } = props;
|
|
29
|
+
const { datasource } = value;
|
|
30
|
+
const { query , handleQueryChange , handleQueryBlur } = (0, _queryEditorModel.useQueryState)(props);
|
|
31
|
+
const { format , handleFormatChange , handleFormatBlur } = (0, _queryEditorModel.useFormatState)(props);
|
|
32
|
+
const handleDatasourceChange = (next)=>{
|
|
33
|
+
if ((0, _model.isPrometheusDatasourceSelector)(next)) {
|
|
34
|
+
onChange((0, _immer.produce)(value, (draft)=>{
|
|
35
|
+
// If they're using the default, just omit the datasource prop (i.e. set to undefined)
|
|
36
|
+
const nextDatasource = (0, _model.isDefaultPromSelector)(next) ? undefined : next;
|
|
37
|
+
draft.datasource = nextDatasource;
|
|
38
|
+
}));
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
throw new Error('Got unexpected non-Prometheus datasource selector');
|
|
42
|
+
};
|
|
43
|
+
return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
44
|
+
spacing: 2,
|
|
45
|
+
children: [
|
|
46
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
|
|
47
|
+
fullWidth: true,
|
|
48
|
+
label: "Query",
|
|
49
|
+
value: query,
|
|
50
|
+
onChange: handleQueryChange,
|
|
51
|
+
onBlur: handleQueryBlur,
|
|
52
|
+
margin: "dense"
|
|
53
|
+
}),
|
|
54
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
|
|
55
|
+
fullWidth: true,
|
|
56
|
+
label: "Series Name Format",
|
|
57
|
+
value: format !== null && format !== void 0 ? format : '',
|
|
58
|
+
onChange: handleFormatChange,
|
|
59
|
+
onBlur: handleFormatBlur,
|
|
60
|
+
margin: "dense"
|
|
61
|
+
}),
|
|
62
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.FormControl, {
|
|
63
|
+
margin: "dense",
|
|
64
|
+
fullWidth: false,
|
|
65
|
+
children: [
|
|
66
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.InputLabel, {
|
|
67
|
+
id: "prom-datasource-label",
|
|
68
|
+
children: "Prometheus Datasource"
|
|
69
|
+
}),
|
|
70
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_pluginSystem.DatasourceSelect, {
|
|
71
|
+
datasourcePluginKind: "PrometheusDatasource",
|
|
72
|
+
value: datasource !== null && datasource !== void 0 ? datasource : _model.DEFAULT_PROM,
|
|
73
|
+
onChange: handleDatasourceChange,
|
|
74
|
+
labelId: "prom-datasource-label",
|
|
75
|
+
label: "Prometheus Datasource"
|
|
76
|
+
})
|
|
77
|
+
]
|
|
78
|
+
})
|
|
79
|
+
]
|
|
80
|
+
});
|
|
81
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
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, "getTimeSeriesData", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: ()=>getTimeSeriesData
|
|
20
|
+
});
|
|
21
|
+
const _dateFns = require("date-fns");
|
|
22
|
+
const _model = require("../../model");
|
|
23
|
+
const getTimeSeriesData = async (spec, context)=>{
|
|
24
|
+
var ref;
|
|
25
|
+
if (spec.query === undefined || spec.query === null || spec.query === '') {
|
|
26
|
+
// Do not make a request to the backend, instead return an empty TimeSeriesData
|
|
27
|
+
return {
|
|
28
|
+
series: []
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
const minStep = (0, _model.getDurationStringSeconds)(spec.min_step);
|
|
32
|
+
const timeRange = (0, _model.getPrometheusTimeRange)(context.timeRange);
|
|
33
|
+
const step = (0, _model.getRangeStep)(timeRange, minStep, undefined, context.suggestedStepMs);
|
|
34
|
+
// Align the time range so that it's a multiple of the step
|
|
35
|
+
let { start , end } = timeRange;
|
|
36
|
+
const utcOffsetSec = new Date().getTimezoneOffset() * 60;
|
|
37
|
+
const alignedEnd = Math.floor((end + utcOffsetSec) / step) * step - utcOffsetSec;
|
|
38
|
+
const alignedStart = Math.floor((start + utcOffsetSec) / step) * step - utcOffsetSec;
|
|
39
|
+
start = alignedStart;
|
|
40
|
+
end = alignedEnd;
|
|
41
|
+
// Replace template variable placeholders in PromQL query
|
|
42
|
+
let query = spec.query.replace('$__rate_interval', `15s`);
|
|
43
|
+
query = (0, _model.replaceTemplateVariables)(query, context.variableState);
|
|
44
|
+
var _datasource;
|
|
45
|
+
// Get the datasource, using the default Prom Datasource if one isn't specified in the query
|
|
46
|
+
const client = await context.datasourceStore.getDatasourceClient((_datasource = spec.datasource) !== null && _datasource !== void 0 ? _datasource : _model.DEFAULT_PROM);
|
|
47
|
+
// Make the request to Prom
|
|
48
|
+
const response = await client.rangeQuery({
|
|
49
|
+
query,
|
|
50
|
+
start,
|
|
51
|
+
end,
|
|
52
|
+
step
|
|
53
|
+
});
|
|
54
|
+
var ref1;
|
|
55
|
+
// TODO: What about error responses from Prom that have a response body?
|
|
56
|
+
const result = (ref1 = (ref = response.data) === null || ref === void 0 ? void 0 : ref.result) !== null && ref1 !== void 0 ? ref1 : [];
|
|
57
|
+
// Transform response
|
|
58
|
+
const chartData = {
|
|
59
|
+
// Return the time range and step we actually used for the query
|
|
60
|
+
timeRange: {
|
|
61
|
+
start: (0, _dateFns.fromUnixTime)(start),
|
|
62
|
+
end: (0, _dateFns.fromUnixTime)(end)
|
|
63
|
+
},
|
|
64
|
+
stepMs: step * 1000,
|
|
65
|
+
// TODO: Maybe do a proper Iterable implementation that defers some of this
|
|
66
|
+
// processing until its needed
|
|
67
|
+
series: result.map((value)=>{
|
|
68
|
+
const { metric , values } = value;
|
|
69
|
+
// Name the series after the metric labels or if no metric, just use the
|
|
70
|
+
// overall query
|
|
71
|
+
let name = Object.entries(metric).map(([labelName, labelValue])=>`${labelName}="${labelValue}"`).join(', ');
|
|
72
|
+
if (name === '') name = query;
|
|
73
|
+
// query editor allows you to define an optional series_name_format
|
|
74
|
+
// property to customize legend and tooltip display
|
|
75
|
+
const formattedName = spec.series_name_format ? (0, _model.formatSeriesName)(spec.series_name_format, metric) : name;
|
|
76
|
+
return {
|
|
77
|
+
name,
|
|
78
|
+
values: values.map(_model.parseValueTuple),
|
|
79
|
+
formattedName
|
|
80
|
+
};
|
|
81
|
+
})
|
|
82
|
+
};
|
|
83
|
+
return chartData;
|
|
84
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
_exportStar(require("./PrometheusTimeSeriesQuery"), 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
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
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
|
+
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
|
+
useQueryState: ()=>useQueryState,
|
|
25
|
+
useFormatState: ()=>useFormatState
|
|
26
|
+
});
|
|
27
|
+
const _react = require("react");
|
|
28
|
+
const _immer = require("immer");
|
|
29
|
+
function useQueryState(props) {
|
|
30
|
+
const { onChange , value } = props;
|
|
31
|
+
// Local copy of the query's value
|
|
32
|
+
const [query, setQuery] = (0, _react.useState)(value.query);
|
|
33
|
+
// This is basically "getDerivedStateFromProps" to make sure if spec's value changes external to this component,
|
|
34
|
+
// we render with the latest value
|
|
35
|
+
const [lastSyncedQuery, setLastSyncedQuery] = (0, _react.useState)(value.query);
|
|
36
|
+
if (value.query !== lastSyncedQuery) {
|
|
37
|
+
setQuery(value.query);
|
|
38
|
+
setLastSyncedQuery(value.query);
|
|
39
|
+
}
|
|
40
|
+
// Update our local state's copy as the user types
|
|
41
|
+
const handleQueryChange = (e)=>{
|
|
42
|
+
setQuery(e.target.value);
|
|
43
|
+
};
|
|
44
|
+
// Propagate changes to the query's value when the input is blurred to avoid constantly re-running queries in the
|
|
45
|
+
// PanelPreview
|
|
46
|
+
const handleQueryBlur = ()=>{
|
|
47
|
+
setLastSyncedQuery(query);
|
|
48
|
+
onChange((0, _immer.produce)(value, (draft)=>{
|
|
49
|
+
draft.query = query;
|
|
50
|
+
}));
|
|
51
|
+
};
|
|
52
|
+
return {
|
|
53
|
+
query,
|
|
54
|
+
handleQueryChange,
|
|
55
|
+
handleQueryBlur
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function useFormatState(props) {
|
|
59
|
+
const { onChange , value } = props;
|
|
60
|
+
// TODO: reusable hook or helper util instead of duplicating from useQueryState
|
|
61
|
+
const [format, setFormat] = (0, _react.useState)(value.series_name_format);
|
|
62
|
+
const [lastSyncedFormat, setLastSyncedFormat] = (0, _react.useState)(value.series_name_format);
|
|
63
|
+
if (value.series_name_format !== lastSyncedFormat) {
|
|
64
|
+
setFormat(value.series_name_format);
|
|
65
|
+
setLastSyncedFormat(value.series_name_format);
|
|
66
|
+
}
|
|
67
|
+
// Update our local state as the user types
|
|
68
|
+
const handleFormatChange = (e)=>{
|
|
69
|
+
setFormat(e.target.value);
|
|
70
|
+
};
|
|
71
|
+
// Propagate changes to the panel preview component when series_name_format TextField is blurred
|
|
72
|
+
const handleFormatBlur = ()=>{
|
|
73
|
+
setLastSyncedFormat(format);
|
|
74
|
+
onChange((0, _immer.produce)(value, (draft)=>{
|
|
75
|
+
draft.series_name_format = format;
|
|
76
|
+
}));
|
|
77
|
+
};
|
|
78
|
+
return {
|
|
79
|
+
format,
|
|
80
|
+
handleFormatChange,
|
|
81
|
+
handleFormatBlur
|
|
82
|
+
};
|
|
83
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
});
|