@perses-dev/prometheus-plugin 0.38.0 → 0.39.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/plugins/PrometheusDatasourceEditor/PrometheusDatasourceEditor.js +392 -0
- package/dist/cjs/plugins/PrometheusDatasourceEditor/index.js +29 -0
- package/dist/cjs/plugins/PrometheusDatasourceEditor/types.js +16 -0
- package/dist/cjs/plugins/prometheus-datasource.js +2 -1
- package/dist/cjs/plugins/prometheus-time-series-query/get-time-series-data.js +2 -1
- package/dist/plugins/PrometheusDatasourceEditor/PrometheusDatasourceEditor.d.ts +9 -0
- package/dist/plugins/PrometheusDatasourceEditor/PrometheusDatasourceEditor.d.ts.map +1 -0
- package/dist/plugins/PrometheusDatasourceEditor/PrometheusDatasourceEditor.js +342 -0
- package/dist/plugins/PrometheusDatasourceEditor/PrometheusDatasourceEditor.js.map +1 -0
- package/dist/plugins/PrometheusDatasourceEditor/index.d.ts +3 -0
- package/dist/plugins/PrometheusDatasourceEditor/index.d.ts.map +1 -0
- package/dist/plugins/PrometheusDatasourceEditor/index.js +16 -0
- package/dist/plugins/PrometheusDatasourceEditor/index.js.map +1 -0
- package/dist/plugins/PrometheusDatasourceEditor/types.d.ts +20 -0
- package/dist/plugins/PrometheusDatasourceEditor/types.d.ts.map +1 -0
- package/dist/plugins/PrometheusDatasourceEditor/types.js +15 -0
- package/dist/plugins/PrometheusDatasourceEditor/types.js.map +1 -0
- package/dist/plugins/prometheus-datasource.d.ts +2 -1
- package/dist/plugins/prometheus-datasource.d.ts.map +1 -1
- package/dist/plugins/prometheus-datasource.js +2 -1
- package/dist/plugins/prometheus-datasource.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 +2 -1
- package/dist/plugins/prometheus-time-series-query/get-time-series-data.js.map +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1,392 @@
|
|
|
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
|
+
Object.defineProperty(exports, "PrometheusDatasourceEditor", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: ()=>PrometheusDatasourceEditor
|
|
20
|
+
});
|
|
21
|
+
const _jsxRuntime = require("react/jsx-runtime");
|
|
22
|
+
const _pluginSystem = require("@perses-dev/plugin-system");
|
|
23
|
+
const _material = require("@mui/material");
|
|
24
|
+
const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
|
|
25
|
+
const _minus = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/Minus"));
|
|
26
|
+
const _plus = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/Plus"));
|
|
27
|
+
function _interopRequireDefault(obj) {
|
|
28
|
+
return obj && obj.__esModule ? obj : {
|
|
29
|
+
default: obj
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
33
|
+
if (typeof WeakMap !== "function") return null;
|
|
34
|
+
var cacheBabelInterop = new WeakMap();
|
|
35
|
+
var cacheNodeInterop = new WeakMap();
|
|
36
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
37
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
38
|
+
})(nodeInterop);
|
|
39
|
+
}
|
|
40
|
+
function _interopRequireWildcard(obj, nodeInterop) {
|
|
41
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
42
|
+
return obj;
|
|
43
|
+
}
|
|
44
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
45
|
+
return {
|
|
46
|
+
default: obj
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
50
|
+
if (cache && cache.has(obj)) {
|
|
51
|
+
return cache.get(obj);
|
|
52
|
+
}
|
|
53
|
+
var newObj = {};
|
|
54
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
55
|
+
for(var key in obj){
|
|
56
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
57
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
58
|
+
if (desc && (desc.get || desc.set)) {
|
|
59
|
+
Object.defineProperty(newObj, key, desc);
|
|
60
|
+
} else {
|
|
61
|
+
newObj[key] = obj[key];
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
newObj.default = obj;
|
|
66
|
+
if (cache) {
|
|
67
|
+
cache.set(obj, newObj);
|
|
68
|
+
}
|
|
69
|
+
return newObj;
|
|
70
|
+
}
|
|
71
|
+
function PrometheusDatasourceEditor(props) {
|
|
72
|
+
var ref, ref1, ref2, ref3;
|
|
73
|
+
const { value , onChange , isReadonly } = props;
|
|
74
|
+
const strDirect = 'Direct access';
|
|
75
|
+
const strProxy = 'Proxy';
|
|
76
|
+
// TODO refactor with useImmer to avoid doing so much destructuring? feasibility & performances to be checked
|
|
77
|
+
// utilitary function used for headers when renaming a property
|
|
78
|
+
// -> TODO it would be cleaner to manipulate headers as a list instead, to avoid doing this.
|
|
79
|
+
// This could be a pure frontend trick, but change in the backend datamodel should also be considered
|
|
80
|
+
const buildNewHeaders = (oldHeaders, oldName, newName)=>{
|
|
81
|
+
if (oldHeaders === undefined) return oldHeaders;
|
|
82
|
+
const keys = Object.keys(oldHeaders);
|
|
83
|
+
const newHeaders = keys.reduce((acc, val)=>{
|
|
84
|
+
if (val === oldName) {
|
|
85
|
+
acc[newName] = oldHeaders[oldName] || '';
|
|
86
|
+
} else {
|
|
87
|
+
acc[val] = oldHeaders[val] || '';
|
|
88
|
+
}
|
|
89
|
+
return acc;
|
|
90
|
+
}, {});
|
|
91
|
+
return {
|
|
92
|
+
...newHeaders
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
const tabs = [
|
|
96
|
+
{
|
|
97
|
+
label: strDirect,
|
|
98
|
+
content: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
|
|
99
|
+
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
|
|
100
|
+
fullWidth: true,
|
|
101
|
+
label: "URL",
|
|
102
|
+
value: value.direct_url || '',
|
|
103
|
+
InputProps: {
|
|
104
|
+
readOnly: isReadonly
|
|
105
|
+
},
|
|
106
|
+
onChange: (e)=>onChange({
|
|
107
|
+
...value,
|
|
108
|
+
direct_url: e.target.value
|
|
109
|
+
})
|
|
110
|
+
})
|
|
111
|
+
})
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
label: strProxy,
|
|
115
|
+
content: /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
116
|
+
children: [
|
|
117
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
|
|
118
|
+
fullWidth: true,
|
|
119
|
+
label: "URL",
|
|
120
|
+
value: ((ref = value.proxy) === null || ref === void 0 ? void 0 : ref.spec.url) || '',
|
|
121
|
+
InputProps: {
|
|
122
|
+
readOnly: isReadonly
|
|
123
|
+
},
|
|
124
|
+
onChange: (e)=>onChange({
|
|
125
|
+
...value,
|
|
126
|
+
...value.proxy && {
|
|
127
|
+
proxy: {
|
|
128
|
+
...value.proxy,
|
|
129
|
+
spec: {
|
|
130
|
+
...value.proxy.spec,
|
|
131
|
+
url: e.target.value
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
})
|
|
136
|
+
}),
|
|
137
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
|
|
138
|
+
py: 2,
|
|
139
|
+
variant: "h4",
|
|
140
|
+
children: "Allowed endpoints"
|
|
141
|
+
}),
|
|
142
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Grid, {
|
|
143
|
+
container: true,
|
|
144
|
+
spacing: 2,
|
|
145
|
+
mb: 2,
|
|
146
|
+
children: ((ref1 = value.proxy) === null || ref1 === void 0 ? void 0 : ref1.spec.allowed_endpoints) && value.proxy.spec.allowed_endpoints.map(({ endpoint_pattern , method }, i)=>{
|
|
147
|
+
return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_react.default.Fragment, {
|
|
148
|
+
children: [
|
|
149
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Grid, {
|
|
150
|
+
item: true,
|
|
151
|
+
xs: 8,
|
|
152
|
+
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
|
|
153
|
+
disabled: true,
|
|
154
|
+
fullWidth: true,
|
|
155
|
+
label: "Endpoint pattern",
|
|
156
|
+
value: endpoint_pattern,
|
|
157
|
+
InputProps: {
|
|
158
|
+
readOnly: isReadonly
|
|
159
|
+
}
|
|
160
|
+
})
|
|
161
|
+
}),
|
|
162
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Grid, {
|
|
163
|
+
item: true,
|
|
164
|
+
xs: 4,
|
|
165
|
+
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
|
|
166
|
+
disabled: true,
|
|
167
|
+
fullWidth: true,
|
|
168
|
+
label: "URL",
|
|
169
|
+
value: method,
|
|
170
|
+
InputProps: {
|
|
171
|
+
readOnly: isReadonly
|
|
172
|
+
}
|
|
173
|
+
})
|
|
174
|
+
})
|
|
175
|
+
]
|
|
176
|
+
}, i);
|
|
177
|
+
})
|
|
178
|
+
}),
|
|
179
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
|
|
180
|
+
pb: 2,
|
|
181
|
+
variant: "h4",
|
|
182
|
+
children: "Request Headers"
|
|
183
|
+
}),
|
|
184
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Grid, {
|
|
185
|
+
container: true,
|
|
186
|
+
spacing: 2,
|
|
187
|
+
mb: 2,
|
|
188
|
+
children: [
|
|
189
|
+
((ref2 = value.proxy) === null || ref2 === void 0 ? void 0 : ref2.spec.headers) !== undefined && Object.keys(value.proxy.spec.headers).map((headerName, i)=>{
|
|
190
|
+
var ref, ref1;
|
|
191
|
+
return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_react.default.Fragment, {
|
|
192
|
+
children: [
|
|
193
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Grid, {
|
|
194
|
+
item: true,
|
|
195
|
+
xs: 4,
|
|
196
|
+
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
|
|
197
|
+
fullWidth: true,
|
|
198
|
+
label: "Header name",
|
|
199
|
+
value: headerName,
|
|
200
|
+
InputProps: {
|
|
201
|
+
readOnly: isReadonly
|
|
202
|
+
},
|
|
203
|
+
onChange: (e)=>onChange({
|
|
204
|
+
...value,
|
|
205
|
+
...value.proxy && {
|
|
206
|
+
proxy: {
|
|
207
|
+
...value.proxy,
|
|
208
|
+
spec: {
|
|
209
|
+
...value.proxy.spec,
|
|
210
|
+
headers: buildNewHeaders(value.proxy.spec.headers, headerName, e.target.value)
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
})
|
|
215
|
+
})
|
|
216
|
+
}),
|
|
217
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Grid, {
|
|
218
|
+
item: true,
|
|
219
|
+
xs: 7,
|
|
220
|
+
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
|
|
221
|
+
fullWidth: true,
|
|
222
|
+
label: "Header value",
|
|
223
|
+
value: (ref1 = (ref = value.proxy) === null || ref === void 0 ? void 0 : ref.spec.headers) === null || ref1 === void 0 ? void 0 : ref1[headerName],
|
|
224
|
+
InputProps: {
|
|
225
|
+
readOnly: isReadonly
|
|
226
|
+
},
|
|
227
|
+
onChange: (e)=>onChange({
|
|
228
|
+
...value,
|
|
229
|
+
...value.proxy && {
|
|
230
|
+
proxy: {
|
|
231
|
+
...value.proxy,
|
|
232
|
+
spec: {
|
|
233
|
+
...value.proxy.spec,
|
|
234
|
+
headers: {
|
|
235
|
+
...value.proxy.spec.headers,
|
|
236
|
+
[headerName]: e.target.value
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
})
|
|
242
|
+
})
|
|
243
|
+
}),
|
|
244
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Grid, {
|
|
245
|
+
item: true,
|
|
246
|
+
xs: 1,
|
|
247
|
+
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.IconButton, {
|
|
248
|
+
disabled: isReadonly,
|
|
249
|
+
onClick: ()=>{
|
|
250
|
+
var ref;
|
|
251
|
+
const newHeaders = {
|
|
252
|
+
...(ref = value.proxy) === null || ref === void 0 ? void 0 : ref.spec.headers
|
|
253
|
+
};
|
|
254
|
+
delete newHeaders[headerName];
|
|
255
|
+
onChange({
|
|
256
|
+
...value,
|
|
257
|
+
...value.proxy && {
|
|
258
|
+
proxy: {
|
|
259
|
+
...value.proxy,
|
|
260
|
+
spec: {
|
|
261
|
+
...value.proxy.spec,
|
|
262
|
+
headers: newHeaders
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
},
|
|
268
|
+
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_minus.default, {})
|
|
269
|
+
})
|
|
270
|
+
})
|
|
271
|
+
]
|
|
272
|
+
}, i);
|
|
273
|
+
}),
|
|
274
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Grid, {
|
|
275
|
+
item: true,
|
|
276
|
+
xs: 12,
|
|
277
|
+
sx: {
|
|
278
|
+
paddingTop: '5px !important'
|
|
279
|
+
},
|
|
280
|
+
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.IconButton, {
|
|
281
|
+
disabled: isReadonly,
|
|
282
|
+
onClick: ()=>onChange({
|
|
283
|
+
...value,
|
|
284
|
+
...value.proxy && {
|
|
285
|
+
proxy: {
|
|
286
|
+
...value.proxy,
|
|
287
|
+
spec: {
|
|
288
|
+
...value.proxy.spec,
|
|
289
|
+
headers: {
|
|
290
|
+
...value.proxy.spec.headers,
|
|
291
|
+
'': ''
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}),
|
|
297
|
+
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_plus.default, {})
|
|
298
|
+
})
|
|
299
|
+
})
|
|
300
|
+
]
|
|
301
|
+
}),
|
|
302
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
|
|
303
|
+
fullWidth: true,
|
|
304
|
+
label: "Secret",
|
|
305
|
+
value: ((ref3 = value.proxy) === null || ref3 === void 0 ? void 0 : ref3.spec.secret) || '',
|
|
306
|
+
InputProps: {
|
|
307
|
+
readOnly: isReadonly
|
|
308
|
+
},
|
|
309
|
+
onChange: (e)=>onChange({
|
|
310
|
+
...value,
|
|
311
|
+
...value.proxy && {
|
|
312
|
+
proxy: {
|
|
313
|
+
...value.proxy,
|
|
314
|
+
spec: {
|
|
315
|
+
...value.proxy.spec,
|
|
316
|
+
secret: e.target.value
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
})
|
|
321
|
+
})
|
|
322
|
+
]
|
|
323
|
+
})
|
|
324
|
+
}
|
|
325
|
+
];
|
|
326
|
+
// Use of findIndex instead of providing hardcoded values to avoid desynchronisatio or
|
|
327
|
+
// bug in case the tabs get eventually swapped in the future.
|
|
328
|
+
const directModeId = tabs.findIndex((tab)=>tab.label == strDirect);
|
|
329
|
+
const proxyModeId = tabs.findIndex((tab)=>tab.label == strProxy);
|
|
330
|
+
// In "update datasource" case, set defaultTab to the mode that this datasource is currently relying on.
|
|
331
|
+
// Otherwise (create datasource), set defaultTab to Direct access.
|
|
332
|
+
const defaultTab = value.proxy ? proxyModeId : directModeId;
|
|
333
|
+
const initialSpecDirect = {
|
|
334
|
+
direct_url: ''
|
|
335
|
+
};
|
|
336
|
+
const initialSpecProxy = {
|
|
337
|
+
proxy: {
|
|
338
|
+
kind: 'HTTPProxy',
|
|
339
|
+
spec: {
|
|
340
|
+
allowed_endpoints: [
|
|
341
|
+
// hardcoded list of allowed endpoints for now since those are enforced by the backend
|
|
342
|
+
{
|
|
343
|
+
endpoint_pattern: '/api/v1/labels',
|
|
344
|
+
method: 'POST'
|
|
345
|
+
},
|
|
346
|
+
{
|
|
347
|
+
endpoint_pattern: '/api/v1/series',
|
|
348
|
+
method: 'POST'
|
|
349
|
+
},
|
|
350
|
+
{
|
|
351
|
+
endpoint_pattern: '/api/v1/metadata',
|
|
352
|
+
method: 'GET'
|
|
353
|
+
},
|
|
354
|
+
{
|
|
355
|
+
endpoint_pattern: '/api/v1/query',
|
|
356
|
+
method: 'POST'
|
|
357
|
+
},
|
|
358
|
+
{
|
|
359
|
+
endpoint_pattern: '/api/v1/query_range',
|
|
360
|
+
method: 'POST'
|
|
361
|
+
},
|
|
362
|
+
{
|
|
363
|
+
endpoint_pattern: '/api/v1/label/([a-zA-Z0-9_-]+)/values',
|
|
364
|
+
method: 'GET'
|
|
365
|
+
}
|
|
366
|
+
],
|
|
367
|
+
url: ''
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
};
|
|
371
|
+
// For better user experience, save previous states in mind for both mode.
|
|
372
|
+
// This avoids losing everything when the user changes their mind back.
|
|
373
|
+
const [previousSpecDirect, setPreviousSpecDirect] = (0, _react.useState)(initialSpecDirect);
|
|
374
|
+
const [previousSpecProxy, setPreviousSpecProxy] = (0, _react.useState)(initialSpecProxy);
|
|
375
|
+
// When changing mode, remove previous mode's config + append default values for the new mode.
|
|
376
|
+
const handleModeChange = (v)=>{
|
|
377
|
+
var ref, ref1;
|
|
378
|
+
if (((ref = tabs[v]) === null || ref === void 0 ? void 0 : ref.label) == strDirect) {
|
|
379
|
+
setPreviousSpecProxy(value);
|
|
380
|
+
onChange(previousSpecDirect);
|
|
381
|
+
} else if (((ref1 = tabs[v]) === null || ref1 === void 0 ? void 0 : ref1.label) == strProxy) {
|
|
382
|
+
setPreviousSpecDirect(value);
|
|
383
|
+
onChange(previousSpecProxy);
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_pluginSystem.OptionsEditorRadios, {
|
|
387
|
+
isReadonly: isReadonly,
|
|
388
|
+
tabs: tabs,
|
|
389
|
+
defaultTab: defaultTab,
|
|
390
|
+
onModeChange: handleModeChange
|
|
391
|
+
});
|
|
392
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
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("./PrometheusDatasourceEditor"), exports);
|
|
18
|
+
_exportStar(require("./types"), exports);
|
|
19
|
+
function _exportStar(from, to) {
|
|
20
|
+
Object.keys(from).forEach(function(k) {
|
|
21
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function() {
|
|
24
|
+
return from[k];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
return from;
|
|
29
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
});
|
|
@@ -19,6 +19,7 @@ Object.defineProperty(exports, "PrometheusDatasource", {
|
|
|
19
19
|
get: ()=>PrometheusDatasource
|
|
20
20
|
});
|
|
21
21
|
const _model = require("../model");
|
|
22
|
+
const _prometheusDatasourceEditor = require("./PrometheusDatasourceEditor");
|
|
22
23
|
/**
|
|
23
24
|
* Creates a PrometheusClient for a specific datasource spec.
|
|
24
25
|
*/ const createClient = (spec, options)=>{
|
|
@@ -54,7 +55,7 @@ const _model = require("../model");
|
|
|
54
55
|
};
|
|
55
56
|
const PrometheusDatasource = {
|
|
56
57
|
createClient,
|
|
57
|
-
OptionsEditorComponent:
|
|
58
|
+
OptionsEditorComponent: _prometheusDatasourceEditor.PrometheusDatasourceEditor,
|
|
58
59
|
createInitialOptions: ()=>({
|
|
59
60
|
direct_url: ''
|
|
60
61
|
})
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { PrometheusDatasourceSpec } from './types';
|
|
3
|
+
export interface PrometheusDatasourceEditorProps {
|
|
4
|
+
value: PrometheusDatasourceSpec;
|
|
5
|
+
onChange: (next: PrometheusDatasourceSpec) => void;
|
|
6
|
+
isReadonly?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare function PrometheusDatasourceEditor(props: PrometheusDatasourceEditorProps): JSX.Element;
|
|
9
|
+
//# sourceMappingURL=PrometheusDatasourceEditor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PrometheusDatasourceEditor.d.ts","sourceRoot":"","sources":["../../../src/plugins/PrometheusDatasourceEditor/PrometheusDatasourceEditor.tsx"],"names":[],"mappings":";AAmBA,OAAO,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAEnD,MAAM,WAAW,+BAA+B;IAC9C,KAAK,EAAE,wBAAwB,CAAC;IAChC,QAAQ,EAAE,CAAC,IAAI,EAAE,wBAAwB,KAAK,IAAI,CAAC;IACnD,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,+BAA+B,eA6ShF"}
|
|
@@ -0,0 +1,342 @@
|
|
|
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
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
14
|
+
import { OptionsEditorRadios } from '@perses-dev/plugin-system';
|
|
15
|
+
import { Grid, IconButton, TextField, Typography } from '@mui/material';
|
|
16
|
+
import React, { useState } from 'react';
|
|
17
|
+
import MinusIcon from 'mdi-material-ui/Minus';
|
|
18
|
+
import PlusIcon from 'mdi-material-ui/Plus';
|
|
19
|
+
export function PrometheusDatasourceEditor(props) {
|
|
20
|
+
var ref, ref1, ref2, ref3;
|
|
21
|
+
const { value , onChange , isReadonly } = props;
|
|
22
|
+
const strDirect = 'Direct access';
|
|
23
|
+
const strProxy = 'Proxy';
|
|
24
|
+
// TODO refactor with useImmer to avoid doing so much destructuring? feasibility & performances to be checked
|
|
25
|
+
// utilitary function used for headers when renaming a property
|
|
26
|
+
// -> TODO it would be cleaner to manipulate headers as a list instead, to avoid doing this.
|
|
27
|
+
// This could be a pure frontend trick, but change in the backend datamodel should also be considered
|
|
28
|
+
const buildNewHeaders = (oldHeaders, oldName, newName)=>{
|
|
29
|
+
if (oldHeaders === undefined) return oldHeaders;
|
|
30
|
+
const keys = Object.keys(oldHeaders);
|
|
31
|
+
const newHeaders = keys.reduce((acc, val)=>{
|
|
32
|
+
if (val === oldName) {
|
|
33
|
+
acc[newName] = oldHeaders[oldName] || '';
|
|
34
|
+
} else {
|
|
35
|
+
acc[val] = oldHeaders[val] || '';
|
|
36
|
+
}
|
|
37
|
+
return acc;
|
|
38
|
+
}, {});
|
|
39
|
+
return {
|
|
40
|
+
...newHeaders
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
const tabs = [
|
|
44
|
+
{
|
|
45
|
+
label: strDirect,
|
|
46
|
+
content: /*#__PURE__*/ _jsx(_Fragment, {
|
|
47
|
+
children: /*#__PURE__*/ _jsx(TextField, {
|
|
48
|
+
fullWidth: true,
|
|
49
|
+
label: "URL",
|
|
50
|
+
value: value.direct_url || '',
|
|
51
|
+
InputProps: {
|
|
52
|
+
readOnly: isReadonly
|
|
53
|
+
},
|
|
54
|
+
onChange: (e)=>onChange({
|
|
55
|
+
...value,
|
|
56
|
+
direct_url: e.target.value
|
|
57
|
+
})
|
|
58
|
+
})
|
|
59
|
+
})
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
label: strProxy,
|
|
63
|
+
content: /*#__PURE__*/ _jsxs(_Fragment, {
|
|
64
|
+
children: [
|
|
65
|
+
/*#__PURE__*/ _jsx(TextField, {
|
|
66
|
+
fullWidth: true,
|
|
67
|
+
label: "URL",
|
|
68
|
+
value: ((ref = value.proxy) === null || ref === void 0 ? void 0 : ref.spec.url) || '',
|
|
69
|
+
InputProps: {
|
|
70
|
+
readOnly: isReadonly
|
|
71
|
+
},
|
|
72
|
+
onChange: (e)=>onChange({
|
|
73
|
+
...value,
|
|
74
|
+
...value.proxy && {
|
|
75
|
+
proxy: {
|
|
76
|
+
...value.proxy,
|
|
77
|
+
spec: {
|
|
78
|
+
...value.proxy.spec,
|
|
79
|
+
url: e.target.value
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
})
|
|
84
|
+
}),
|
|
85
|
+
/*#__PURE__*/ _jsx(Typography, {
|
|
86
|
+
py: 2,
|
|
87
|
+
variant: "h4",
|
|
88
|
+
children: "Allowed endpoints"
|
|
89
|
+
}),
|
|
90
|
+
/*#__PURE__*/ _jsx(Grid, {
|
|
91
|
+
container: true,
|
|
92
|
+
spacing: 2,
|
|
93
|
+
mb: 2,
|
|
94
|
+
children: ((ref1 = value.proxy) === null || ref1 === void 0 ? void 0 : ref1.spec.allowed_endpoints) && value.proxy.spec.allowed_endpoints.map(({ endpoint_pattern , method }, i)=>{
|
|
95
|
+
return /*#__PURE__*/ _jsxs(React.Fragment, {
|
|
96
|
+
children: [
|
|
97
|
+
/*#__PURE__*/ _jsx(Grid, {
|
|
98
|
+
item: true,
|
|
99
|
+
xs: 8,
|
|
100
|
+
children: /*#__PURE__*/ _jsx(TextField, {
|
|
101
|
+
disabled: true,
|
|
102
|
+
fullWidth: true,
|
|
103
|
+
label: "Endpoint pattern",
|
|
104
|
+
value: endpoint_pattern,
|
|
105
|
+
InputProps: {
|
|
106
|
+
readOnly: isReadonly
|
|
107
|
+
}
|
|
108
|
+
})
|
|
109
|
+
}),
|
|
110
|
+
/*#__PURE__*/ _jsx(Grid, {
|
|
111
|
+
item: true,
|
|
112
|
+
xs: 4,
|
|
113
|
+
children: /*#__PURE__*/ _jsx(TextField, {
|
|
114
|
+
disabled: true,
|
|
115
|
+
fullWidth: true,
|
|
116
|
+
label: "URL",
|
|
117
|
+
value: method,
|
|
118
|
+
InputProps: {
|
|
119
|
+
readOnly: isReadonly
|
|
120
|
+
}
|
|
121
|
+
})
|
|
122
|
+
})
|
|
123
|
+
]
|
|
124
|
+
}, i);
|
|
125
|
+
})
|
|
126
|
+
}),
|
|
127
|
+
/*#__PURE__*/ _jsx(Typography, {
|
|
128
|
+
pb: 2,
|
|
129
|
+
variant: "h4",
|
|
130
|
+
children: "Request Headers"
|
|
131
|
+
}),
|
|
132
|
+
/*#__PURE__*/ _jsxs(Grid, {
|
|
133
|
+
container: true,
|
|
134
|
+
spacing: 2,
|
|
135
|
+
mb: 2,
|
|
136
|
+
children: [
|
|
137
|
+
((ref2 = value.proxy) === null || ref2 === void 0 ? void 0 : ref2.spec.headers) !== undefined && Object.keys(value.proxy.spec.headers).map((headerName, i)=>{
|
|
138
|
+
var ref, ref1;
|
|
139
|
+
return /*#__PURE__*/ _jsxs(React.Fragment, {
|
|
140
|
+
children: [
|
|
141
|
+
/*#__PURE__*/ _jsx(Grid, {
|
|
142
|
+
item: true,
|
|
143
|
+
xs: 4,
|
|
144
|
+
children: /*#__PURE__*/ _jsx(TextField, {
|
|
145
|
+
fullWidth: true,
|
|
146
|
+
label: "Header name",
|
|
147
|
+
value: headerName,
|
|
148
|
+
InputProps: {
|
|
149
|
+
readOnly: isReadonly
|
|
150
|
+
},
|
|
151
|
+
onChange: (e)=>onChange({
|
|
152
|
+
...value,
|
|
153
|
+
...value.proxy && {
|
|
154
|
+
proxy: {
|
|
155
|
+
...value.proxy,
|
|
156
|
+
spec: {
|
|
157
|
+
...value.proxy.spec,
|
|
158
|
+
headers: buildNewHeaders(value.proxy.spec.headers, headerName, e.target.value)
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
})
|
|
163
|
+
})
|
|
164
|
+
}),
|
|
165
|
+
/*#__PURE__*/ _jsx(Grid, {
|
|
166
|
+
item: true,
|
|
167
|
+
xs: 7,
|
|
168
|
+
children: /*#__PURE__*/ _jsx(TextField, {
|
|
169
|
+
fullWidth: true,
|
|
170
|
+
label: "Header value",
|
|
171
|
+
value: (ref1 = (ref = value.proxy) === null || ref === void 0 ? void 0 : ref.spec.headers) === null || ref1 === void 0 ? void 0 : ref1[headerName],
|
|
172
|
+
InputProps: {
|
|
173
|
+
readOnly: isReadonly
|
|
174
|
+
},
|
|
175
|
+
onChange: (e)=>onChange({
|
|
176
|
+
...value,
|
|
177
|
+
...value.proxy && {
|
|
178
|
+
proxy: {
|
|
179
|
+
...value.proxy,
|
|
180
|
+
spec: {
|
|
181
|
+
...value.proxy.spec,
|
|
182
|
+
headers: {
|
|
183
|
+
...value.proxy.spec.headers,
|
|
184
|
+
[headerName]: e.target.value
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
})
|
|
190
|
+
})
|
|
191
|
+
}),
|
|
192
|
+
/*#__PURE__*/ _jsx(Grid, {
|
|
193
|
+
item: true,
|
|
194
|
+
xs: 1,
|
|
195
|
+
children: /*#__PURE__*/ _jsx(IconButton, {
|
|
196
|
+
disabled: isReadonly,
|
|
197
|
+
onClick: ()=>{
|
|
198
|
+
var ref;
|
|
199
|
+
const newHeaders = {
|
|
200
|
+
...(ref = value.proxy) === null || ref === void 0 ? void 0 : ref.spec.headers
|
|
201
|
+
};
|
|
202
|
+
delete newHeaders[headerName];
|
|
203
|
+
onChange({
|
|
204
|
+
...value,
|
|
205
|
+
...value.proxy && {
|
|
206
|
+
proxy: {
|
|
207
|
+
...value.proxy,
|
|
208
|
+
spec: {
|
|
209
|
+
...value.proxy.spec,
|
|
210
|
+
headers: newHeaders
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
},
|
|
216
|
+
children: /*#__PURE__*/ _jsx(MinusIcon, {})
|
|
217
|
+
})
|
|
218
|
+
})
|
|
219
|
+
]
|
|
220
|
+
}, i);
|
|
221
|
+
}),
|
|
222
|
+
/*#__PURE__*/ _jsx(Grid, {
|
|
223
|
+
item: true,
|
|
224
|
+
xs: 12,
|
|
225
|
+
sx: {
|
|
226
|
+
paddingTop: '5px !important'
|
|
227
|
+
},
|
|
228
|
+
children: /*#__PURE__*/ _jsx(IconButton, {
|
|
229
|
+
disabled: isReadonly,
|
|
230
|
+
onClick: ()=>onChange({
|
|
231
|
+
...value,
|
|
232
|
+
...value.proxy && {
|
|
233
|
+
proxy: {
|
|
234
|
+
...value.proxy,
|
|
235
|
+
spec: {
|
|
236
|
+
...value.proxy.spec,
|
|
237
|
+
headers: {
|
|
238
|
+
...value.proxy.spec.headers,
|
|
239
|
+
'': ''
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}),
|
|
245
|
+
children: /*#__PURE__*/ _jsx(PlusIcon, {})
|
|
246
|
+
})
|
|
247
|
+
})
|
|
248
|
+
]
|
|
249
|
+
}),
|
|
250
|
+
/*#__PURE__*/ _jsx(TextField, {
|
|
251
|
+
fullWidth: true,
|
|
252
|
+
label: "Secret",
|
|
253
|
+
value: ((ref3 = value.proxy) === null || ref3 === void 0 ? void 0 : ref3.spec.secret) || '',
|
|
254
|
+
InputProps: {
|
|
255
|
+
readOnly: isReadonly
|
|
256
|
+
},
|
|
257
|
+
onChange: (e)=>onChange({
|
|
258
|
+
...value,
|
|
259
|
+
...value.proxy && {
|
|
260
|
+
proxy: {
|
|
261
|
+
...value.proxy,
|
|
262
|
+
spec: {
|
|
263
|
+
...value.proxy.spec,
|
|
264
|
+
secret: e.target.value
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
})
|
|
269
|
+
})
|
|
270
|
+
]
|
|
271
|
+
})
|
|
272
|
+
}
|
|
273
|
+
];
|
|
274
|
+
// Use of findIndex instead of providing hardcoded values to avoid desynchronisatio or
|
|
275
|
+
// bug in case the tabs get eventually swapped in the future.
|
|
276
|
+
const directModeId = tabs.findIndex((tab)=>tab.label == strDirect);
|
|
277
|
+
const proxyModeId = tabs.findIndex((tab)=>tab.label == strProxy);
|
|
278
|
+
// In "update datasource" case, set defaultTab to the mode that this datasource is currently relying on.
|
|
279
|
+
// Otherwise (create datasource), set defaultTab to Direct access.
|
|
280
|
+
const defaultTab = value.proxy ? proxyModeId : directModeId;
|
|
281
|
+
const initialSpecDirect = {
|
|
282
|
+
direct_url: ''
|
|
283
|
+
};
|
|
284
|
+
const initialSpecProxy = {
|
|
285
|
+
proxy: {
|
|
286
|
+
kind: 'HTTPProxy',
|
|
287
|
+
spec: {
|
|
288
|
+
allowed_endpoints: [
|
|
289
|
+
// hardcoded list of allowed endpoints for now since those are enforced by the backend
|
|
290
|
+
{
|
|
291
|
+
endpoint_pattern: '/api/v1/labels',
|
|
292
|
+
method: 'POST'
|
|
293
|
+
},
|
|
294
|
+
{
|
|
295
|
+
endpoint_pattern: '/api/v1/series',
|
|
296
|
+
method: 'POST'
|
|
297
|
+
},
|
|
298
|
+
{
|
|
299
|
+
endpoint_pattern: '/api/v1/metadata',
|
|
300
|
+
method: 'GET'
|
|
301
|
+
},
|
|
302
|
+
{
|
|
303
|
+
endpoint_pattern: '/api/v1/query',
|
|
304
|
+
method: 'POST'
|
|
305
|
+
},
|
|
306
|
+
{
|
|
307
|
+
endpoint_pattern: '/api/v1/query_range',
|
|
308
|
+
method: 'POST'
|
|
309
|
+
},
|
|
310
|
+
{
|
|
311
|
+
endpoint_pattern: '/api/v1/label/([a-zA-Z0-9_-]+)/values',
|
|
312
|
+
method: 'GET'
|
|
313
|
+
}
|
|
314
|
+
],
|
|
315
|
+
url: ''
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
// For better user experience, save previous states in mind for both mode.
|
|
320
|
+
// This avoids losing everything when the user changes their mind back.
|
|
321
|
+
const [previousSpecDirect, setPreviousSpecDirect] = useState(initialSpecDirect);
|
|
322
|
+
const [previousSpecProxy, setPreviousSpecProxy] = useState(initialSpecProxy);
|
|
323
|
+
// When changing mode, remove previous mode's config + append default values for the new mode.
|
|
324
|
+
const handleModeChange = (v)=>{
|
|
325
|
+
var ref, ref1;
|
|
326
|
+
if (((ref = tabs[v]) === null || ref === void 0 ? void 0 : ref.label) == strDirect) {
|
|
327
|
+
setPreviousSpecProxy(value);
|
|
328
|
+
onChange(previousSpecDirect);
|
|
329
|
+
} else if (((ref1 = tabs[v]) === null || ref1 === void 0 ? void 0 : ref1.label) == strProxy) {
|
|
330
|
+
setPreviousSpecDirect(value);
|
|
331
|
+
onChange(previousSpecProxy);
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
return /*#__PURE__*/ _jsx(OptionsEditorRadios, {
|
|
335
|
+
isReadonly: isReadonly,
|
|
336
|
+
tabs: tabs,
|
|
337
|
+
defaultTab: defaultTab,
|
|
338
|
+
onModeChange: handleModeChange
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
//# sourceMappingURL=PrometheusDatasourceEditor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/PrometheusDatasourceEditor/PrometheusDatasourceEditor.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 { RequestHeaders } from '@perses-dev/core';\nimport { OptionsEditorRadios } from '@perses-dev/plugin-system';\nimport { Grid, IconButton, TextField, Typography } from '@mui/material';\nimport React, { useState } from 'react';\nimport MinusIcon from 'mdi-material-ui/Minus';\nimport PlusIcon from 'mdi-material-ui/Plus';\nimport { PrometheusDatasourceSpec } from './types';\n\nexport interface PrometheusDatasourceEditorProps {\n value: PrometheusDatasourceSpec;\n onChange: (next: PrometheusDatasourceSpec) => void;\n isReadonly?: boolean;\n}\n\nexport function PrometheusDatasourceEditor(props: PrometheusDatasourceEditorProps) {\n const { value, onChange, isReadonly } = props;\n const strDirect = 'Direct access';\n const strProxy = 'Proxy';\n\n // TODO refactor with useImmer to avoid doing so much destructuring? feasibility & performances to be checked\n\n // utilitary function used for headers when renaming a property\n // -> TODO it would be cleaner to manipulate headers as a list instead, to avoid doing this.\n // This could be a pure frontend trick, but change in the backend datamodel should also be considered\n const buildNewHeaders = (oldHeaders: RequestHeaders | undefined, oldName: string, newName: string) => {\n if (oldHeaders === undefined) return oldHeaders;\n const keys = Object.keys(oldHeaders);\n const newHeaders = keys.reduce<Record<string, string>>((acc, val) => {\n if (val === oldName) {\n acc[newName] = oldHeaders[oldName] || '';\n } else {\n acc[val] = oldHeaders[val] || '';\n }\n return acc;\n }, {});\n\n return { ...newHeaders };\n };\n\n const tabs = [\n {\n label: strDirect,\n content: (\n <>\n <TextField\n fullWidth\n label=\"URL\"\n value={value.direct_url || ''}\n InputProps={{\n readOnly: isReadonly,\n }}\n onChange={(e) => onChange({ ...value, direct_url: e.target.value })}\n />\n </>\n ),\n },\n {\n label: strProxy,\n content: (\n <>\n <TextField\n fullWidth\n label=\"URL\"\n value={value.proxy?.spec.url || ''}\n InputProps={{\n readOnly: isReadonly,\n }}\n onChange={(e) =>\n onChange({\n ...value,\n ...(value.proxy && {\n proxy: {\n ...value.proxy,\n spec: {\n ...value.proxy.spec,\n url: e.target.value,\n },\n },\n }),\n })\n }\n />\n <Typography py={2} variant=\"h4\">\n Allowed endpoints\n </Typography>\n <Grid container spacing={2} mb={2}>\n {value.proxy?.spec.allowed_endpoints &&\n value.proxy.spec.allowed_endpoints.map(({ endpoint_pattern, method }, i) => {\n return (\n <React.Fragment key={i}>\n <Grid item xs={8}>\n <TextField\n disabled // at the moment the allowed endpoints cannot be modified (enforced by backend)\n fullWidth\n label=\"Endpoint pattern\"\n value={endpoint_pattern}\n InputProps={{\n readOnly: isReadonly,\n }}\n />\n </Grid>\n <Grid item xs={4}>\n <TextField\n disabled // at the moment the allowed endpoints cannot be modified (enforced by backend)\n fullWidth\n label=\"URL\"\n value={method}\n InputProps={{\n readOnly: isReadonly,\n }}\n />\n </Grid>\n </React.Fragment>\n );\n })}\n </Grid>\n <Typography pb={2} variant=\"h4\">\n Request Headers\n </Typography>\n <Grid container spacing={2} mb={2}>\n {value.proxy?.spec.headers !== undefined &&\n Object.keys(value.proxy.spec.headers).map((headerName, i) => {\n return (\n <React.Fragment key={i}>\n <Grid item xs={4}>\n <TextField\n fullWidth\n label=\"Header name\"\n value={headerName}\n InputProps={{\n readOnly: isReadonly,\n }}\n onChange={(e) =>\n onChange({\n ...value,\n ...(value.proxy && {\n proxy: {\n ...value.proxy,\n spec: {\n ...value.proxy.spec,\n headers: buildNewHeaders(value.proxy.spec.headers, headerName, e.target.value),\n },\n },\n }),\n })\n }\n />\n </Grid>\n <Grid item xs={7}>\n <TextField\n fullWidth\n label=\"Header value\"\n value={value.proxy?.spec.headers?.[headerName]}\n InputProps={{\n readOnly: isReadonly,\n }}\n onChange={(e) =>\n onChange({\n ...value,\n ...(value.proxy && {\n proxy: {\n ...value.proxy,\n spec: {\n ...value.proxy.spec,\n headers: { ...value.proxy.spec.headers, [headerName]: e.target.value },\n },\n },\n }),\n })\n }\n />\n </Grid>\n <Grid item xs={1}>\n <IconButton\n disabled={isReadonly}\n onClick={() => {\n const newHeaders = { ...value.proxy?.spec.headers };\n delete newHeaders[headerName];\n onChange({\n ...value,\n ...(value.proxy && {\n proxy: {\n ...value.proxy,\n spec: {\n ...value.proxy.spec,\n headers: newHeaders,\n },\n },\n }),\n });\n }}\n >\n <MinusIcon />\n </IconButton>\n </Grid>\n </React.Fragment>\n );\n })}\n <Grid item xs={12} sx={{ paddingTop: '5px !important' }}>\n <IconButton\n disabled={isReadonly}\n onClick={() =>\n onChange({\n ...value,\n ...(value.proxy && {\n proxy: {\n ...value.proxy,\n spec: {\n ...value.proxy.spec,\n headers: { ...value.proxy.spec.headers, '': '' },\n },\n },\n }),\n })\n }\n >\n <PlusIcon />\n </IconButton>\n </Grid>\n </Grid>\n <TextField\n fullWidth\n label=\"Secret\"\n value={value.proxy?.spec.secret || ''}\n InputProps={{\n readOnly: isReadonly,\n }}\n onChange={(e) =>\n onChange({\n ...value,\n ...(value.proxy && {\n proxy: {\n ...value.proxy,\n spec: {\n ...value.proxy.spec,\n secret: e.target.value,\n },\n },\n }),\n })\n }\n />\n </>\n ),\n },\n ];\n\n // Use of findIndex instead of providing hardcoded values to avoid desynchronisatio or\n // bug in case the tabs get eventually swapped in the future.\n const directModeId = tabs.findIndex((tab) => tab.label == strDirect);\n const proxyModeId = tabs.findIndex((tab) => tab.label == strProxy);\n\n // In \"update datasource\" case, set defaultTab to the mode that this datasource is currently relying on.\n // Otherwise (create datasource), set defaultTab to Direct access.\n const defaultTab = value.proxy ? proxyModeId : directModeId;\n\n const initialSpecDirect: PrometheusDatasourceSpec = {\n direct_url: '',\n };\n\n const initialSpecProxy: PrometheusDatasourceSpec = {\n proxy: {\n kind: 'HTTPProxy',\n spec: {\n allowed_endpoints: [\n // hardcoded list of allowed endpoints for now since those are enforced by the backend\n {\n endpoint_pattern: '/api/v1/labels',\n method: 'POST',\n },\n {\n endpoint_pattern: '/api/v1/series',\n method: 'POST',\n },\n {\n endpoint_pattern: '/api/v1/metadata',\n method: 'GET',\n },\n {\n endpoint_pattern: '/api/v1/query',\n method: 'POST',\n },\n {\n endpoint_pattern: '/api/v1/query_range',\n method: 'POST',\n },\n {\n endpoint_pattern: '/api/v1/label/([a-zA-Z0-9_-]+)/values',\n method: 'GET',\n },\n ],\n url: '',\n },\n },\n };\n\n // For better user experience, save previous states in mind for both mode.\n // This avoids losing everything when the user changes their mind back.\n const [previousSpecDirect, setPreviousSpecDirect] = useState(initialSpecDirect);\n const [previousSpecProxy, setPreviousSpecProxy] = useState(initialSpecProxy);\n\n // When changing mode, remove previous mode's config + append default values for the new mode.\n const handleModeChange = (v: number) => {\n if (tabs[v]?.label == strDirect) {\n setPreviousSpecProxy(value);\n onChange(previousSpecDirect);\n } else if (tabs[v]?.label == strProxy) {\n setPreviousSpecDirect(value);\n onChange(previousSpecProxy);\n }\n };\n\n return (\n <OptionsEditorRadios isReadonly={isReadonly} tabs={tabs} defaultTab={defaultTab} onModeChange={handleModeChange} />\n );\n}\n"],"names":["OptionsEditorRadios","Grid","IconButton","TextField","Typography","React","useState","MinusIcon","PlusIcon","PrometheusDatasourceEditor","props","value","onChange","isReadonly","strDirect","strProxy","buildNewHeaders","oldHeaders","oldName","newName","undefined","keys","Object","newHeaders","reduce","acc","val","tabs","label","content","fullWidth","direct_url","InputProps","readOnly","e","target","proxy","spec","url","py","variant","container","spacing","mb","allowed_endpoints","map","endpoint_pattern","method","i","Fragment","item","xs","disabled","pb","headers","headerName","onClick","sx","paddingTop","secret","directModeId","findIndex","tab","proxyModeId","defaultTab","initialSpecDirect","initialSpecProx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ses 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
|
+
export * from './PrometheusDatasourceEditor';
|
|
14
|
+
export * from './types';
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/PrometheusDatasourceEditor/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 './PrometheusDatasourceEditor';\nexport * from './types';\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,8BAA8B,CAAC;AAC7C,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { RequestHeaders } from '@perses-dev/core';
|
|
2
|
+
export interface PrometheusDatasourceSpec {
|
|
3
|
+
direct_url?: string;
|
|
4
|
+
proxy?: HTTPProxy;
|
|
5
|
+
}
|
|
6
|
+
export interface HTTPProxy {
|
|
7
|
+
kind: 'HTTPProxy';
|
|
8
|
+
spec: HTTPProxySpec;
|
|
9
|
+
}
|
|
10
|
+
export interface HTTPProxySpec {
|
|
11
|
+
url: string;
|
|
12
|
+
allowed_endpoints?: HTTPAllowedEndpoint[];
|
|
13
|
+
headers?: RequestHeaders;
|
|
14
|
+
secret?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface HTTPAllowedEndpoint {
|
|
17
|
+
endpoint_pattern: string;
|
|
18
|
+
method: string;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/plugins/PrometheusDatasourceEditor/types.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAGlD,MAAM,WAAW,wBAAwB;IACvC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,WAAW,CAAC;IAClB,IAAI,EAAE,aAAa,CAAC;CACrB;AACD,MAAM,WAAW,aAAa;IAG5B,GAAG,EAAE,MAAM,CAAC;IAGZ,iBAAiB,CAAC,EAAE,mBAAmB,EAAE,CAAC;IAE1C,OAAO,CAAC,EAAE,cAAc,CAAC;IAGzB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,mBAAmB;IAClC,gBAAgB,EAAE,MAAM,CAAC;IACzB,MAAM,EAAE,MAAM,CAAC;CAChB"}
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
export { };
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/PrometheusDatasourceEditor/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 { RequestHeaders } from '@perses-dev/core';\n\n// TODO unify this one with the other PrometheusDatasourceSpec used for datasource store manipulation\nexport interface PrometheusDatasourceSpec {\n direct_url?: string;\n proxy?: HTTPProxy;\n}\n\nexport interface HTTPProxy {\n kind: 'HTTPProxy';\n spec: HTTPProxySpec;\n}\nexport interface HTTPProxySpec {\n // url is the url of the datasource. It is not the url of the proxy.\n // The Perses server is the proxy, so it needs to know where to redirect the request.\n url: string;\n // allowed_endpoints is a list of tuples of http methods and http endpoints that will be accessible.\n // Leave it empty if you don't want to restrict the access to the datasource.\n allowed_endpoints?: HTTPAllowedEndpoint[];\n // headers can be used to provide additional headers that need to be forwarded when requesting the datasource\n headers?: RequestHeaders;\n // secret is the name of the secret that should be used for the proxy or discovery configuration\n // It will contain any sensitive information such as password, token, certificate.\n secret?: string;\n}\n\nexport interface HTTPAllowedEndpoint {\n endpoint_pattern: string;\n method: string;\n}\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,WA6BC"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { RequestHeaders } from '@perses-dev/core';
|
|
2
2
|
import { DatasourcePlugin } from '@perses-dev/plugin-system';
|
|
3
3
|
import { PrometheusClient } from '../model';
|
|
4
|
+
import { PrometheusDatasourceSpec as PrometheusDatasourceSpecFull } from './PrometheusDatasourceEditor';
|
|
4
5
|
export interface PrometheusDatasourceSpec {
|
|
5
6
|
direct_url?: string;
|
|
6
7
|
headers?: RequestHeaders;
|
|
7
8
|
}
|
|
8
|
-
export declare const PrometheusDatasource: DatasourcePlugin<
|
|
9
|
+
export declare const PrometheusDatasource: DatasourcePlugin<PrometheusDatasourceSpecFull, PrometheusClient>;
|
|
9
10
|
//# sourceMappingURL=prometheus-datasource.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prometheus-datasource.d.ts","sourceRoot":"","sources":["../../src/plugins/prometheus-datasource.
|
|
1
|
+
{"version":3,"file":"prometheus-datasource.d.ts","sourceRoot":"","sources":["../../src/plugins/prometheus-datasource.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAqD,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC/F,OAAO,EAEL,wBAAwB,IAAI,4BAA4B,EACzD,MAAM,8BAA8B,CAAC;AAEtC,MAAM,WAAW,wBAAwB;IACvC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,cAAc,CAAC;CAC1B;AA2BD,eAAO,MAAM,oBAAoB,EAAE,gBAAgB,CAAC,4BAA4B,EAAE,gBAAgB,CAIjG,CAAC"}
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { instantQuery, rangeQuery, labelNames, labelValues } from '../model';
|
|
14
|
+
import { PrometheusDatasourceEditor } from './PrometheusDatasourceEditor';
|
|
14
15
|
/**
|
|
15
16
|
* Creates a PrometheusClient for a specific datasource spec.
|
|
16
17
|
*/ const createClient = (spec, options)=>{
|
|
@@ -46,7 +47,7 @@ import { instantQuery, rangeQuery, labelNames, labelValues } from '../model';
|
|
|
46
47
|
};
|
|
47
48
|
export const PrometheusDatasource = {
|
|
48
49
|
createClient,
|
|
49
|
-
OptionsEditorComponent:
|
|
50
|
+
OptionsEditorComponent: PrometheusDatasourceEditor,
|
|
50
51
|
createInitialOptions: ()=>({
|
|
51
52
|
direct_url: ''
|
|
52
53
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/plugins/prometheus-datasource.
|
|
1
|
+
{"version":3,"sources":["../../src/plugins/prometheus-datasource.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 { RequestHeaders } from '@perses-dev/core';\nimport { DatasourcePlugin } from '@perses-dev/plugin-system';\nimport { instantQuery, rangeQuery, labelNames, labelValues, PrometheusClient } from '../model';\nimport {\n PrometheusDatasourceEditor,\n PrometheusDatasourceSpec as PrometheusDatasourceSpecFull,\n} from './PrometheusDatasourceEditor';\n\nexport interface PrometheusDatasourceSpec {\n direct_url?: string;\n headers?: RequestHeaders;\n}\n\n/**\n * Creates a PrometheusClient for a specific datasource spec.\n */\nconst createClient: DatasourcePlugin<PrometheusDatasourceSpec, PrometheusClient>['createClient'] = (spec, options) => {\n const { direct_url, headers: specHeaders } = spec;\n const { proxyUrl } = options;\n\n // Use the direct URL if specified, but fallback to the proxyUrl by default if not specified\n const datasourceUrl = direct_url ?? proxyUrl;\n if (datasourceUrl === undefined) {\n throw new Error('No URL specified for Prometheus client. You can use direct_url in the spec to configure it.');\n }\n\n // Could think about this becoming a class, although it definitely doesn't have to be\n return {\n options: {\n datasourceUrl,\n },\n instantQuery: (params, headers) => instantQuery(params, { datasourceUrl, headers: headers ?? specHeaders }),\n rangeQuery: (params, headers) => rangeQuery(params, { datasourceUrl, headers: headers ?? specHeaders }),\n labelNames: (params, headers) => labelNames(params, { datasourceUrl, headers: headers ?? specHeaders }),\n labelValues: (params, headers) => labelValues(params, { datasourceUrl, headers: headers ?? specHeaders }),\n };\n};\n\nexport const PrometheusDatasource: DatasourcePlugin<PrometheusDatasourceSpecFull, PrometheusClient> = {\n createClient,\n OptionsEditorComponent: PrometheusDatasourceEditor,\n createInitialOptions: () => ({ direct_url: '' }),\n};\n"],"names":["instantQuery","rangeQuery","labelNames","labelValues","PrometheusDatasourceEditor","createClient","spec","options","direct_url","headers","specHeaders","proxyUrl","datasourceUrl","undefined","Error","params","PrometheusDatasource","OptionsEditorComponent","createInitialOptions"],"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;AAIjC,SAASA,YAAY,EAAEC,UAAU,EAAEC,UAAU,EAAEC,WAAW,QAA0B,UAAU,CAAC;AAC/F,SACEC,0BAA0B,QAErB,8BAA8B,CAAC;AAOtC;;CAEC,G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sBAAsB,EAAEb,0BAA0B;IAClDc,oBAAoB,EAAE,IAAO,CAAA;YAAEV,UAAU,EAAE,EAAE;SAAE,CAAA,AAAC;CACjD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-time-series-data.d.ts","sourceRoot":"","sources":["../../../src/plugins/prometheus-time-series-query/get-time-series-data.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,qBAAqB,EAA4B,MAAM,2BAA2B,CAAC;AAW5F,OAAO,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAE1E,eAAO,MAAM,iBAAiB,EAAE,qBAAqB,CAAC,6BAA6B,CAAC,CAAC,mBAAmB,
|
|
1
|
+
{"version":3,"file":"get-time-series-data.d.ts","sourceRoot":"","sources":["../../../src/plugins/prometheus-time-series-query/get-time-series-data.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,qBAAqB,EAA4B,MAAM,2BAA2B,CAAC;AAW5F,OAAO,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAE1E,eAAO,MAAM,iBAAiB,EAAE,qBAAqB,CAAC,6BAA6B,CAAC,CAAC,mBAAmB,CAqFvG,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/get-time-series-data.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 { Notice, TimeSeriesData } from '@perses-dev/core';\nimport { TimeSeriesQueryPlugin, replaceTemplateVariables } from '@perses-dev/plugin-system';\nimport { fromUnixTime } from 'date-fns';\nimport {\n parseValueTuple,\n PrometheusClient,\n getDurationStringSeconds,\n getPrometheusTimeRange,\n getRangeStep,\n DEFAULT_PROM,\n} from '../../model';\nimport { getFormattedPrometheusSeriesName } from '../../utils';\nimport { PrometheusTimeSeriesQuerySpec } from './time-series-query-model';\n\nexport const getTimeSeriesData: TimeSeriesQueryPlugin<PrometheusTimeSeriesQuerySpec>['getTimeSeriesData'] = async (\n spec,\n context\n) => {\n if (spec.query === undefined || spec.query === null || spec.query === '') {\n // Do not make a request to the backend, instead return an empty TimeSeriesData\n return { series: [] };\n }\n\n const minStep = getDurationStringSeconds(spec.min_step);\n const timeRange = getPrometheusTimeRange(context.timeRange);\n const step = getRangeStep(timeRange, minStep, undefined, context.suggestedStepMs);\n\n // Align the time range so that it's a multiple of the step\n let { start, end } = timeRange;\n const utcOffsetSec = new Date().getTimezoneOffset() * 60;\n\n const alignedEnd = Math.floor((end + utcOffsetSec) / step) * step - utcOffsetSec;\n const alignedStart = Math.floor((start + utcOffsetSec) / step) * step - utcOffsetSec;\n start = alignedStart;\n end = alignedEnd;\n\n // Replace template variable placeholders in PromQL query\n let query = spec.query.replace('$__rate_interval', `15s`);\n query = replaceTemplateVariables(query, context.variableState);\n\n let seriesNameFormat = spec.series_name_format;\n // if series name format is defined, replace template variable placeholders in series name format\n if (seriesNameFormat) {\n seriesNameFormat = replaceTemplateVariables(seriesNameFormat, context.variableState);\n }\n\n // Get the datasource, using the default Prom Datasource if one isn't specified in the query\n const client: PrometheusClient = await context.datasourceStore.getDatasourceClient(spec.datasource ?? DEFAULT_PROM);\n\n // Make the request to Prom\n const response = await client.rangeQuery({\n query,\n start,\n end,\n step,\n });\n\n // TODO: What about error responses from Prom that have a response body?\n const result = response.data?.result ?? [];\n\n // Custom display for response header warnings, configurable error responses display coming next\n const notices: Notice[] = [];\n if (response.status === 'success') {\n const warnings = response.warnings ?? [];\n const warningMessage = warnings[0] ?? '';\n if (warningMessage !== '') {\n notices.push({\n type: 'warning',\n message: warningMessage,\n });\n }\n }\n\n // Transform response\n const chartData: TimeSeriesData = {\n // Return the time range and step we actually used for the query\n timeRange: { start: fromUnixTime(start), end: fromUnixTime(end) },\n stepMs: step * 1000,\n\n series: result.map((value) => {\n const { metric, values } = value;\n\n // Account for series_name_format from query editor when determining name to show in legend, tooltip, etc.\n const { name, formattedName } = getFormattedPrometheusSeriesName(query, metric, seriesNameFormat);\n\n return {\n name,\n values: values.map(parseValueTuple),\n formattedName,\n labels: metric,\n };\n }),\n metadata: {\n notices,\n },\n };\n\n return chartData;\n};\n"],"names":["replaceTemplateVariables","fromUnixTime","parseValueTuple","getDurationStringSeconds","getPrometheusTimeRange","getRangeStep","DEFAULT_PROM","getFormattedPrometheusSeriesName","getTimeSeriesData","spec","context","response","query","undefined","series","minStep","min_step","timeRange","step","suggestedStepMs","start","end","utcOffsetSec","Date","getTimezoneOffset","alignedEnd","Math","floor","alignedStart","replace","variableState","seriesNameFormat","series_name_format","client","datasourceStore","getDatasourceClient","datasource","rangeQuery","result","data","notices","status","warnings","warningMessage","push","type","message","chartData","stepMs","map","value","metric","values","name","formattedName","labels","metadata"],"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;AAGjC,SAAgCA,wBAAwB,QAAQ,2BAA2B,CAAC;AAC5F,SAASC,YAAY,QAAQ,UAAU,CAAC;AACxC,SACEC,eAAe,EAEfC,wBAAwB,EACxBC,sBAAsB,EACtBC,YAAY,EACZC,YAAY,QACP,aAAa,CAAC;AACrB,SAASC,gCAAgC,QAAQ,aAAa,CAAC;AAG/D,OAAO,MAAMC,iBAAiB,GAA8E,OAC1GC,IAAI,EACJC,OAAO,GACJ;QAyCYC,GAAa;IAxC5B,IAAIF,IAAI,CAACG,KAAK,KAAKC,SAAS,IAAIJ,IAAI,CAACG,KAAK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AqB;IACrB,MAAMI,SAAS,GAAmB;QAChC,gEAAgE;QAChE9B,SAAS,EAAE;YAAEG,KAAK,EAAEnB,YAAY,CAACmB,KAAK,CAAC;YAAEC,GAAG,EAAEpB,YAAY,CAACoB,GAAG,CAAC;SAAE;QACjE2B,MAAM,EAAE9B,IAAI,GAAG,IAAI;QAEnBJ,MAAM,EAAEwB,MAAM,CAACW,GAAG,CAAC,CAACC,KAAK,GAAK;YAC5B,MAAM,EAAEC,MAAM,CAAA,EAAEC,MAAM,CAAA,EAAE,GAAGF,KAAK,AAAC;YAEjC,0GAA0G;YAC1G,MAAM,EAAEG,IAAI,CAAA,EAAEC,aAAa,CAAA,EAAE,GAAG/C,gCAAgC,CAACK,KAAK,EAAEuC,MAAM,EAAEpB,gBAAgB,CAAC,AAAC;YAElG,OAAO;gBACLsB,IAAI;gBACJD,MAAM,EAAEA,MAAM,CAACH,GAAG,CAAC/C,eAAe,CAAC;gBACnCoD,aAAa;gBACbC,MAAM,EAAEJ,MAAM;aACf,CAAC;QACJ,CAAC,CAAC;QACFK,QAAQ,EAAE;YACRhB,OAAO;
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/get-time-series-data.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 { Notice, TimeSeriesData } from '@perses-dev/core';\nimport { TimeSeriesQueryPlugin, replaceTemplateVariables } from '@perses-dev/plugin-system';\nimport { fromUnixTime } from 'date-fns';\nimport {\n parseValueTuple,\n PrometheusClient,\n getDurationStringSeconds,\n getPrometheusTimeRange,\n getRangeStep,\n DEFAULT_PROM,\n} from '../../model';\nimport { getFormattedPrometheusSeriesName } from '../../utils';\nimport { PrometheusTimeSeriesQuerySpec } from './time-series-query-model';\n\nexport const getTimeSeriesData: TimeSeriesQueryPlugin<PrometheusTimeSeriesQuerySpec>['getTimeSeriesData'] = async (\n spec,\n context\n) => {\n if (spec.query === undefined || spec.query === null || spec.query === '') {\n // Do not make a request to the backend, instead return an empty TimeSeriesData\n return { series: [] };\n }\n\n const minStep = getDurationStringSeconds(spec.min_step);\n const timeRange = getPrometheusTimeRange(context.timeRange);\n const step = getRangeStep(timeRange, minStep, undefined, context.suggestedStepMs);\n\n // Align the time range so that it's a multiple of the step\n let { start, end } = timeRange;\n const utcOffsetSec = new Date().getTimezoneOffset() * 60;\n\n const alignedEnd = Math.floor((end + utcOffsetSec) / step) * step - utcOffsetSec;\n const alignedStart = Math.floor((start + utcOffsetSec) / step) * step - utcOffsetSec;\n start = alignedStart;\n end = alignedEnd;\n\n // Replace template variable placeholders in PromQL query\n let query = spec.query.replace('$__rate_interval', `15s`);\n query = replaceTemplateVariables(query, context.variableState);\n\n let seriesNameFormat = spec.series_name_format;\n // if series name format is defined, replace template variable placeholders in series name format\n if (seriesNameFormat) {\n seriesNameFormat = replaceTemplateVariables(seriesNameFormat, context.variableState);\n }\n\n // Get the datasource, using the default Prom Datasource if one isn't specified in the query\n const client: PrometheusClient = await context.datasourceStore.getDatasourceClient(spec.datasource ?? DEFAULT_PROM);\n\n // Make the request to Prom\n const response = await client.rangeQuery({\n query,\n start,\n end,\n step,\n });\n\n // TODO: What about error responses from Prom that have a response body?\n const result = response.data?.result ?? [];\n\n // Custom display for response header warnings, configurable error responses display coming next\n const notices: Notice[] = [];\n if (response.status === 'success') {\n const warnings = response.warnings ?? [];\n const warningMessage = warnings[0] ?? '';\n if (warningMessage !== '') {\n notices.push({\n type: 'warning',\n message: warningMessage,\n });\n }\n }\n\n // Transform response\n const chartData: TimeSeriesData = {\n // Return the time range and step we actually used for the query\n timeRange: { start: fromUnixTime(start), end: fromUnixTime(end) },\n stepMs: step * 1000,\n\n series: result.map((value) => {\n const { metric, values } = value;\n\n // Account for series_name_format from query editor when determining name to show in legend, tooltip, etc.\n const { name, formattedName } = getFormattedPrometheusSeriesName(query, metric, seriesNameFormat);\n\n return {\n name,\n values: values.map(parseValueTuple),\n formattedName,\n labels: metric,\n };\n }),\n metadata: {\n notices,\n executedQueryString: query,\n },\n };\n\n return chartData;\n};\n"],"names":["replaceTemplateVariables","fromUnixTime","parseValueTuple","getDurationStringSeconds","getPrometheusTimeRange","getRangeStep","DEFAULT_PROM","getFormattedPrometheusSeriesName","getTimeSeriesData","spec","context","response","query","undefined","series","minStep","min_step","timeRange","step","suggestedStepMs","start","end","utcOffsetSec","Date","getTimezoneOffset","alignedEnd","Math","floor","alignedStart","replace","variableState","seriesNameFormat","series_name_format","client","datasourceStore","getDatasourceClient","datasource","rangeQuery","result","data","notices","status","warnings","warningMessage","push","type","message","chartData","stepMs","map","value","metric","values","name","formattedName","labels","metadata","executedQueryString"],"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;AAGjC,SAAgCA,wBAAwB,QAAQ,2BAA2B,CAAC;AAC5F,SAASC,YAAY,QAAQ,UAAU,CAAC;AACxC,SACEC,eAAe,EAEfC,wBAAwB,EACxBC,sBAAsB,EACtBC,YAAY,EACZC,YAAY,QACP,aAAa,CAAC;AACrB,SAASC,gCAAgC,QAAQ,aAAa,CAAC;AAG/D,OAAO,MAAMC,iBAAiB,GAA8E,OAC1GC,IAAI,EACJC,OAAO,GACJ;QAyCYC,GAAa;IAxC5B,IAAIF,IAAI,CAACG,KAAK,KAAKC,SAAS,IAAIJ,IAAI,CAACG,KAAK,KAAK,IAAI,IAAIH,IAAI,CAACG,KAAK,KAAK,EAAE,EA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,SAAS,EAAE;YAAEG,KAAK,EAAEnB,YAAY,CAACmB,KAAK,CAAC;YAAEC,GAAG,EAAEpB,YAAY,CAACoB,GAAG,CAAC;SAAE;QACjE2B,MAAM,EAAE9B,IAAI,GAAG,IAAI;QAEnBJ,MAAM,EAAEwB,MAAM,CAACW,GAAG,CAAC,CAACC,KAAK,GAAK;YAC5B,MAAM,EAAEC,MAAM,CAAA,EAAEC,MAAM,CAAA,EAAE,GAAGF,KAAK,AAAC;YAEjC,0GAA0G;YAC1G,MAAM,EAAEG,IAAI,CAAA,EAAEC,aAAa,CAAA,EAAE,GAAG/C,gCAAgC,CAACK,KAAK,EAAEuC,MAAM,EAAEpB,gBAAgB,CAAC,AAAC;YAElG,OAAO;gBACLsB,IAAI;gBACJD,MAAM,EAAEA,MAAM,CAACH,GAAG,CAAC/C,eAAe,CAAC;gBACnCoD,aAAa;gBACbC,MAAM,EAAEJ,MAAM;aACf,CAAC;QACJ,CAAC,CAAC;QACFK,QAAQ,EAAE;YACRhB,OAAO;YACPiB,mBAAmB,EAAE7C,KAAK;SAC3B;KACF,AAAC;IAEF,OAAOmC,SAAS,CAAC;AACnB,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@perses-dev/prometheus-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.39.0",
|
|
4
4
|
"description": "Prometheus plugin for Perses",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://github.com/perses/perses/blob/main/README.md",
|
|
@@ -31,9 +31,9 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@lezer/highlight": "^1.0.0",
|
|
33
33
|
"@lezer/lr": "^1.2.0",
|
|
34
|
-
"@perses-dev/components": "0.
|
|
35
|
-
"@perses-dev/core": "0.
|
|
36
|
-
"@perses-dev/plugin-system": "0.
|
|
34
|
+
"@perses-dev/components": "0.39.0",
|
|
35
|
+
"@perses-dev/core": "0.39.0",
|
|
36
|
+
"@perses-dev/plugin-system": "0.39.0",
|
|
37
37
|
"@prometheus-io/codemirror-promql": "^0.43.0",
|
|
38
38
|
"@uiw/react-codemirror": "^4.19.1",
|
|
39
39
|
"date-fns": "^2.28.0",
|