@perses-dev/prometheus-plugin 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +21 -5
- package/dist/cjs/model/api-types.js +5 -3
- package/dist/cjs/model/parse-sample-values.js +22 -16
- package/dist/cjs/model/prometheus-client.js +52 -66
- package/dist/cjs/model/templating.js +14 -10
- package/dist/cjs/model/time.js +35 -49
- package/dist/cjs/model/utils.js +21 -13
- package/dist/cjs/model/utils.test.js +57 -31
- package/dist/cjs/plugins/prometheus-datasource.js +26 -0
- package/dist/cjs/plugins/prometheus-variables.js +77 -0
- package/dist/cjs/plugins/time-series-query.js +87 -0
- package/dist/cjs/plugins/variable.js +38 -0
- package/dist/cjs/test/setup-tests.js +4 -2
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21 -1
- package/dist/index.js.map +1 -0
- package/dist/model/api-types.js +15 -1
- package/dist/model/api-types.js.map +1 -0
- package/dist/model/parse-sample-values.d.ts.map +1 -1
- package/dist/model/parse-sample-values.js +44 -1
- package/dist/model/parse-sample-values.js.map +1 -0
- package/dist/model/prometheus-client.d.ts +14 -10
- package/dist/model/prometheus-client.d.ts.map +1 -1
- package/dist/model/prometheus-client.js +81 -1
- package/dist/model/prometheus-client.js.map +1 -0
- package/dist/model/templating.js +21 -1
- package/dist/model/templating.js.map +1 -0
- package/dist/model/time.d.ts +7 -8
- package/dist/model/time.d.ts.map +1 -1
- package/dist/model/time.js +49 -1
- package/dist/model/time.js.map +1 -0
- package/dist/model/utils.d.ts +2 -1
- package/dist/model/utils.d.ts.map +1 -1
- package/dist/model/utils.js +55 -1
- package/dist/model/utils.js.map +1 -0
- package/dist/model/utils.test.js +110 -1
- package/dist/model/utils.test.js.map +1 -0
- package/dist/plugins/prometheus-datasource.d.ts +4 -0
- package/dist/plugins/prometheus-datasource.d.ts.map +1 -0
- package/dist/plugins/prometheus-datasource.js +20 -0
- package/dist/plugins/prometheus-datasource.js.map +1 -0
- package/dist/plugins/prometheus-variables.d.ts +14 -0
- package/dist/plugins/prometheus-variables.d.ts.map +1 -0
- package/dist/plugins/prometheus-variables.js +65 -0
- package/dist/plugins/prometheus-variables.js.map +1 -0
- package/dist/plugins/time-series-query.d.ts +16 -0
- package/dist/plugins/time-series-query.d.ts.map +1 -0
- package/dist/plugins/time-series-query.js +83 -0
- package/dist/plugins/time-series-query.js.map +1 -0
- package/dist/plugins/variable.d.ts +8 -0
- package/dist/plugins/variable.d.ts.map +1 -0
- package/dist/plugins/variable.js +32 -0
- package/dist/plugins/variable.js.map +1 -0
- package/dist/test/setup-tests.js +15 -1
- package/dist/test/setup-tests.js.map +1 -0
- package/package.json +9 -7
- package/plugin.json +17 -9
- package/dist/cjs/model/datasource.js +0 -36
- package/dist/cjs/plugins/graph-query.js +0 -84
- package/dist/model/datasource.d.ts +0 -11
- package/dist/model/datasource.d.ts.map +0 -1
- package/dist/model/datasource.js +0 -1
- package/dist/plugins/graph-query.d.ts +0 -14
- package/dist/plugins/graph-query.d.ts.map +0 -1
- package/dist/plugins/graph-query.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/model/time.ts"],"sourcesContent":["// Copyright 2022 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 { AbsoluteTimeRange, DurationString, parseDurationString } from '@perses-dev/core';\nimport { milliseconds, getUnixTime } from 'date-fns';\nimport { UnixTimestampSeconds } from './api-types';\n\nexport interface PrometheusTimeRange {\n start: UnixTimestampSeconds;\n end: UnixTimestampSeconds;\n}\n\n/**\n * Converts an AbsoluteTimeRange to Prometheus time in Unix time (i.e. in seconds).\n */\nexport function getPrometheusTimeRange(timeRange: AbsoluteTimeRange) {\n const { start, end } = timeRange;\n return {\n start: Math.ceil(getUnixTime(start)),\n end: Math.ceil(getUnixTime(end)),\n };\n}\n\n// Max data points to allow returning from a Prom Query, used to calculate a\n// \"safe\" step for a range query\nconst MAX_PROM_DATA_POINTS = 10000;\n\n/**\n * Gets the step to use for a Prom range query. Tries to take into account a suggested step size (probably based on the\n * width of a visualization where the data will be graphed), any minimum step/resolution set by the user, and a \"safe\"\n * step based on the max data points we want to allow returning from a Prom query.\n */\nexport function getRangeStep(timeRange: PrometheusTimeRange, minStepSeconds = 15, resolution = 1, suggestedStepMs = 0) {\n const suggestedStepSeconds = suggestedStepMs / 1000;\n const queryRangeSeconds = timeRange.end - timeRange.start;\n\n let safeStep = queryRangeSeconds / MAX_PROM_DATA_POINTS;\n if (safeStep > 1) {\n safeStep = Math.ceil(safeStep);\n }\n\n return Math.max(suggestedStepSeconds * resolution, minStepSeconds, safeStep);\n}\n\n/**\n * Converts a DurationString to seconds, rounding down.\n */\nexport function getDurationStringSeconds(durationString?: DurationString) {\n if (durationString === undefined) return undefined;\n\n const duration = parseDurationString(durationString);\n const ms = milliseconds(duration);\n return Math.floor(ms / 1000);\n}\n"],"names":["parseDurationString","milliseconds","getUnixTime","getPrometheusTimeRange","timeRange","start","end","Math","ceil","MAX_PROM_DATA_POINTS","getRangeStep","minStepSeconds","resolution","suggestedStepMs","suggestedStepSeconds","queryRangeSeconds","safeStep","max","getDurationStringSeconds","durationString","undefined","duration","ms","floor"],"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,SAA4CA,mBAAmB,QAAQ,kBAAkB,CAAC;AAC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AOd,IAAI,CAACgB,KAAK,CAACD,EAAE,GAAG,IAAI,CAAC,CAAC;AAC/B,CAAC"}
|
package/dist/model/utils.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { VariableValue } from '@perses-dev/core';
|
|
2
|
+
import { VariableStateMap } from '@perses-dev/plugin-system';
|
|
2
3
|
export declare function replaceTemplateVariables(text: string, variableState: VariableStateMap): string;
|
|
3
4
|
export declare function replaceTemplateVariable(text: string, varName: string, templateVariableValue: VariableValue): string;
|
|
4
5
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/model/utils.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/model/utils.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAE7D,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,gBAAgB,GAAG,MAAM,CAW9F;AAED,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,qBAAqB,EAAE,aAAa,UAW1G;AAMD;;GAEG;AACH,eAAO,MAAM,sBAAsB,SAAU,MAAM,aAclD,CAAC"}
|
package/dist/model/utils.js
CHANGED
|
@@ -1 +1,55 @@
|
|
|
1
|
-
|
|
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
|
+
export function replaceTemplateVariables(text, variableState) {
|
|
14
|
+
const variables = parseTemplateVariables(text);
|
|
15
|
+
let finalText = text;
|
|
16
|
+
variables.forEach((v)=>{
|
|
17
|
+
const variable = variableState[v];
|
|
18
|
+
if (variable && (variable === null || variable === void 0 ? void 0 : variable.value)) {
|
|
19
|
+
finalText = replaceTemplateVariable(finalText, v, variable === null || variable === void 0 ? void 0 : variable.value);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
return finalText;
|
|
23
|
+
}
|
|
24
|
+
export function replaceTemplateVariable(text, varName, templateVariableValue) {
|
|
25
|
+
const variableTemplate = '$' + varName;
|
|
26
|
+
let replaceString = '';
|
|
27
|
+
if (Array.isArray(templateVariableValue)) {
|
|
28
|
+
replaceString = `(${templateVariableValue.join('|')})`; // regex style
|
|
29
|
+
}
|
|
30
|
+
if (typeof templateVariableValue === 'string') {
|
|
31
|
+
replaceString = templateVariableValue;
|
|
32
|
+
}
|
|
33
|
+
return text.replaceAll(variableTemplate, replaceString);
|
|
34
|
+
}
|
|
35
|
+
// TODO: Fix this lint eror
|
|
36
|
+
// eslint-disable-next-line no-useless-escape
|
|
37
|
+
const TEMPLATE_VARIABLE_REGEX = /\$(\w+)|\${(\w+)(?:\.([^:^\}]+))?(?::([^\}]+))?}/gm;
|
|
38
|
+
/**
|
|
39
|
+
* Returns a list of template variables
|
|
40
|
+
*/ export const parseTemplateVariables = (text)=>{
|
|
41
|
+
const regex = TEMPLATE_VARIABLE_REGEX;
|
|
42
|
+
const matches = [];
|
|
43
|
+
let match;
|
|
44
|
+
while((match = regex.exec(text)) !== null){
|
|
45
|
+
if (match) {
|
|
46
|
+
if (match && match.length > 1 && match[1]) {
|
|
47
|
+
matches.push(match[1]);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
// return unique matches
|
|
52
|
+
return Array.from(new Set(matches));
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/model/utils.ts"],"sourcesContent":["// Copyright 2022 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 { VariableValue } from '@perses-dev/core';\nimport { VariableStateMap } from '@perses-dev/plugin-system';\n\nexport function replaceTemplateVariables(text: string, variableState: VariableStateMap): string {\n const variables = parseTemplateVariables(text);\n let finalText = text;\n variables.forEach((v) => {\n const variable = variableState[v];\n if (variable && variable?.value) {\n finalText = replaceTemplateVariable(finalText, v, variable?.value);\n }\n });\n\n return finalText;\n}\n\nexport function replaceTemplateVariable(text: string, varName: string, templateVariableValue: VariableValue) {\n const variableTemplate = '$' + varName;\n let replaceString = '';\n if (Array.isArray(templateVariableValue)) {\n replaceString = `(${templateVariableValue.join('|')})`; // regex style\n }\n if (typeof templateVariableValue === 'string') {\n replaceString = templateVariableValue;\n }\n\n return text.replaceAll(variableTemplate, replaceString);\n}\n\n// TODO: Fix this lint eror\n// eslint-disable-next-line no-useless-escape\nconst TEMPLATE_VARIABLE_REGEX = /\\$(\\w+)|\\${(\\w+)(?:\\.([^:^\\}]+))?(?::([^\\}]+))?}/gm;\n\n/**\n * Returns a list of template variables\n */\nexport const parseTemplateVariables = (text: string) => {\n const regex = TEMPLATE_VARIABLE_REGEX;\n const matches = [];\n let match;\n\n while ((match = regex.exec(text)) !== null) {\n if (match) {\n if (match && match.length > 1 && match[1]) {\n matches.push(match[1]);\n }\n }\n }\n // return unique matches\n return Array.from(new Set(matches));\n};\n"],"names":["replaceTemplateVariables","text","variableState","variables","parseTemplateVariables","finalText","forEach","v","variable","value","replaceTemplateVariable","varName","templateVariableValue","variableTemplate","replaceString","Array","isArray","join","replaceAll","TEMPLATE_VARIABLE_REGEX","regex","matches","match","exec","length","push","from","Set"],"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;AAKjC,OAAO,SAASA,wBAAwB,CAACC,IAAY,EAAEC,aAA+B,EAAU;IAC9F,MAAMC,SAAS,GAAGC,sBAAsB,CAACH,IAAI,CAAC,AAAC;IAC/C,IAAII,SAAS,GAAGJ,IAAI,AAAC;IACrBE,SAAS,CAACG,OAAO,CAAC,CAACC,CAAC,GAAK;QACvB,MAAMC,QAAQ,GAAGN,aAAa,CAACK,CAAC,CAAC,AAAC;QAClC,IAAIC,QAAQ,IAAIA,CAAAA,QAAQ,aAARA,QAAQ,WAAO,GAAfA,KAAAA,CAAe,GAAfA,QAAQ,CAAEC,KAAK,CAAA,EAAE;YAC/BJ,SAAS,GAAGK,uBAAuB,CAACL,SAAS,EAAEE,CAAC,EAAEC,QAAQ,aAARA,QAAQ,WAAO,GAAfA,KAAAA,CAAe,GAAfA,QAAQ,CAAEC,KAAK,CAAC,CAAC;QACrE,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAOJ,SAAS,CAAC;AACnB,CAAC;AAED,OAAO,SAASK,uBAAuB,CAACT,IAAY,EAAEU,OAAe,EAAEC,qBAAoC,EAAE;IAC3G,MAAMC,gBAAgB,GAAG,GAAG,GAAGF,OAAO,AAAC;IACvC,IAAIG,aAAa,GAAG,EAAE,AAAC;IACvB,IAAIC,KAAK,CAACC,OAAO,CAACJ,qBAAqB,CAAC,EAAE;QACxCE,aAAa,GAAG,CAAC,CAAC,EAAEF,qBAAqB,CAACK,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,cAAc;IACxE,CAAC;IACD,IAAI,OAAOL,qBAAqB,KAAK,QAAQ,EAAE;QAC7CE,aAAa,GAAGF,qBAAqB,CAAC;IACxC,CAAC;IAED,OAAOX,IAAI,CAACiB,UAAU,CAACL,gBAAgB,EAAEC,aAAa,CAAC,CAAC;AAC1D,CAAC;AAED,2BAA2B;AAC3B,6CAA6C;AAC7C,MAAMK,uBAAuB,uDAAuD,AAAC;AAErF;;CAEC,GACD,OAAO,MAAMf,sBAAsB,GAAG,CAACH,IAAY,GAAK;IACtD,MAAMmB,KAAK,GAAGD,uBAAuB,AAAC;IACtC,MAAME,OAAO,GAAG,EAAE,AAAC;IACnB,IAAIC,KAAK,AAAC;IAEV,MAAO,AAACA,CAAAA,KAAK,GAAGF,KAAK,CAACG,IAAI,CAACtB,IAAI,CAAC,CAAA,KAAM,IAAI,CAAE;QAC1C,IAAIqB,KAAK,EAAE;YACT,IAAIA,KAAK,IAAIA,KAAK,CAACE,MAAM,GAAG,CAAC,IAAIF,KAAK,CAAC,CAAC,CAAC,EAAE;gBACzCD,OAAO,CAACI,IAAI,CAACH,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;YACzB,CAAC;QACH,CAAC;IACH,CAAC;IACD,wBAAwB;IACxB,OAAOP,KAAK,CAACW,IAAI,CAAC,IAAIC,GAAG,CAACN,OAAO,CAAC,CAAC,CAAC;AACtC,CAAC,CAAC"}
|
package/dist/model/utils.test.js
CHANGED
|
@@ -1 +1,110 @@
|
|
|
1
|
-
|
|
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
|
+
import { parseTemplateVariables, replaceTemplateVariable, replaceTemplateVariables } from './utils';
|
|
14
|
+
describe('parseTemplateVariables()', ()=>{
|
|
15
|
+
const tests = [
|
|
16
|
+
{
|
|
17
|
+
text: 'hello $var1 world $var2',
|
|
18
|
+
variables: [
|
|
19
|
+
'var1',
|
|
20
|
+
'var2'
|
|
21
|
+
]
|
|
22
|
+
}
|
|
23
|
+
];
|
|
24
|
+
tests.forEach(({ text , variables })=>{
|
|
25
|
+
it(`parses ${text}`, ()=>{
|
|
26
|
+
expect(parseTemplateVariables(text)).toEqual(variables);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
describe('replaceTemplateVariable()', ()=>{
|
|
31
|
+
const tests = [
|
|
32
|
+
{
|
|
33
|
+
text: 'hello $var1',
|
|
34
|
+
varName: 'var1',
|
|
35
|
+
value: 'world',
|
|
36
|
+
expected: 'hello world'
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
text: 'hello $var1 $var1',
|
|
40
|
+
varName: 'var1',
|
|
41
|
+
value: 'world',
|
|
42
|
+
expected: 'hello world world'
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
text: 'hello $var1',
|
|
46
|
+
varName: 'var1',
|
|
47
|
+
value: [
|
|
48
|
+
'world',
|
|
49
|
+
'w'
|
|
50
|
+
],
|
|
51
|
+
expected: 'hello (world|w)'
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
text: 'hello $var1 $var1',
|
|
55
|
+
varName: 'var1',
|
|
56
|
+
value: [
|
|
57
|
+
'world',
|
|
58
|
+
'w'
|
|
59
|
+
],
|
|
60
|
+
expected: 'hello (world|w) (world|w)'
|
|
61
|
+
}
|
|
62
|
+
];
|
|
63
|
+
tests.forEach(({ text , value , varName , expected })=>{
|
|
64
|
+
it(`replaces ${text} ${value}`, ()=>{
|
|
65
|
+
expect(replaceTemplateVariable(text, varName, value)).toEqual(expected);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
describe('replaceTemplateVariables()', ()=>{
|
|
70
|
+
const tests = [
|
|
71
|
+
{
|
|
72
|
+
text: 'hello $var1 $var2',
|
|
73
|
+
state: {
|
|
74
|
+
var1: {
|
|
75
|
+
value: 'world',
|
|
76
|
+
loading: false
|
|
77
|
+
},
|
|
78
|
+
var2: {
|
|
79
|
+
value: 'world',
|
|
80
|
+
loading: false
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
expected: 'hello world world'
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
text: 'hello $var1 $var2',
|
|
87
|
+
state: {
|
|
88
|
+
var1: {
|
|
89
|
+
value: 'world',
|
|
90
|
+
loading: false
|
|
91
|
+
},
|
|
92
|
+
var2: {
|
|
93
|
+
value: [
|
|
94
|
+
'a',
|
|
95
|
+
'b'
|
|
96
|
+
],
|
|
97
|
+
loading: false
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
expected: 'hello world (a|b)'
|
|
101
|
+
}
|
|
102
|
+
];
|
|
103
|
+
tests.forEach(({ text , state , expected })=>{
|
|
104
|
+
it(`replaces ${text} ${JSON.stringify(state)}`, ()=>{
|
|
105
|
+
expect(replaceTemplateVariables(text, state)).toEqual(expected);
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
//# sourceMappingURL=utils.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/model/utils.test.ts"],"sourcesContent":["// Copyright 2022 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 { parseTemplateVariables, replaceTemplateVariable, replaceTemplateVariables } from './utils';\n\ndescribe('parseTemplateVariables()', () => {\n const tests = [\n {\n text: 'hello $var1 world $var2',\n variables: ['var1', 'var2'],\n },\n ];\n\n tests.forEach(({ text, variables }) => {\n it(`parses ${text}`, () => {\n expect(parseTemplateVariables(text)).toEqual(variables);\n });\n });\n});\n\ndescribe('replaceTemplateVariable()', () => {\n const tests = [\n {\n text: 'hello $var1',\n varName: 'var1',\n value: 'world',\n expected: 'hello world',\n },\n {\n text: 'hello $var1 $var1',\n varName: 'var1',\n value: 'world',\n expected: 'hello world world',\n },\n {\n text: 'hello $var1',\n varName: 'var1',\n value: ['world', 'w'],\n expected: 'hello (world|w)',\n },\n {\n text: 'hello $var1 $var1',\n varName: 'var1',\n value: ['world', 'w'],\n expected: 'hello (world|w) (world|w)',\n },\n ];\n\n tests.forEach(({ text, value, varName, expected }) => {\n it(`replaces ${text} ${value}`, () => {\n expect(replaceTemplateVariable(text, varName, value)).toEqual(expected);\n });\n });\n});\n\ndescribe('replaceTemplateVariables()', () => {\n const tests = [\n {\n text: 'hello $var1 $var2',\n state: {\n var1: { value: 'world', loading: false },\n var2: { value: 'world', loading: false },\n },\n expected: 'hello world world',\n },\n {\n text: 'hello $var1 $var2',\n state: {\n var1: { value: 'world', loading: false },\n var2: { value: ['a', 'b'], loading: false },\n },\n expected: 'hello world (a|b)',\n },\n ];\n\n tests.forEach(({ text, state, expected }) => {\n it(`replaces ${text} ${JSON.stringify(state)}`, () => {\n expect(replaceTemplateVariables(text, state)).toEqual(expected);\n });\n });\n});\n"],"names":["parseTemplateVariables","replaceTemplateVariable","replaceTemplateVariables","describe","tests","text","variables","forEach","it","expect","toEqual","varName","value","expected","state","var1","loading","var2","JSON","stringify"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,sBAAsB,EAAEC,uBAAuB,EAAEC,wBAAwB,QAAQ,SAAS,CAAC;AAEpGC,QAAQ,CAAC,0BAA0B,EAAE,IAAM;IACzC,MAAMC,KAAK,GAAG;QACZ;YACEC,IAAI,EAAE,yBAAyB;YAC/BC,SAAS,EAAE;gBAAC,MAAM;gBAAE,MAAM;aAAC;SAC5B;KACF,AAAC;IAEFF,KAAK,CAACG,OAAO,CAAC,CAAC,EAAEF,IAAI,CAAA,EAAEC,SAAS,CAAA,EAAE,GAAK;QACrCE,EAAE,CAAC,CAAC,OAAO,EAAEH,IAAI,CAAC,CAAC,EAAE,IAAM;YACzBI,MAAM,CAACT,sBAAsB,CAACK,IAAI,CAAC,CAAC,CAACK,OAAO,CAACJ,SAAS,CAAC,CAAC;QAC1D,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEHH,QAAQ,CAAC,2BAA2B,EAAE,IAAM;IAC1C,MAAMC,KAAK,GAAG;QACZ;YACEC,IAAI,EAAE,aAAa;YACnBM,OAAO,EAAE,MAAM;YACfC,KAAK,EAAE,OAAO;YACdC,QAAQ,EAAE,aAAa;SACxB;QACD;YACER,IAAI,EAAE,mBAAmB;YACzBM,OAAO,EAAE,MAAM;YACfC,KAAK,EAAE,OAAO;YACdC,QAAQ,EAAE,mBAAmB;SAC9B;QACD;YACER,IAAI,EAAE,aAAa;YACnBM,OAAO,EAAE,MAAM;YACfC,KAAK,EAAE;gBAAC,OAAO;gBAAE,GAAG;aAAC;YACrBC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AC,EAAEF,IAAI,CAAA,EAAES,KAAK,CAAA,EAAED,QAAQ,CAAA,EAAE,GAAK;QAC3CL,EAAE,CAAC,CAAC,SAAS,EAAEH,IAAI,CAAC,CAAC,EAAEa,IAAI,CAACC,SAAS,CAACL,KAAK,CAAC,CAAC,CAAC,EAAE,IAAM;YACpDL,MAAM,CAACP,wBAAwB,CAACG,IAAI,EAAES,KAAK,CAAC,CAAC,CAACJ,OAAO,CAACG,QAAQ,CAAC,CAAC;QAClE,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { DatasourcePlugin } from '@perses-dev/plugin-system';
|
|
2
|
+
import { PrometheusDatasourceSpec } from '../model/prometheus-client';
|
|
3
|
+
export declare const PrometheusDatasource: DatasourcePlugin<PrometheusDatasourceSpec>;
|
|
4
|
+
//# sourceMappingURL=prometheus-datasource.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prometheus-datasource.d.ts","sourceRoot":"","sources":["../../src/plugins/prometheus-datasource.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAEtE,eAAO,MAAM,oBAAoB,EAAE,gBAAgB,CAAC,wBAAwB,CAG3E,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
export const PrometheusDatasource = {
|
|
14
|
+
OptionsEditorComponent: ()=>null,
|
|
15
|
+
createInitialOptions: ()=>({
|
|
16
|
+
direct_url: ''
|
|
17
|
+
})
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=prometheus-datasource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/plugins/prometheus-datasource.ts"],"sourcesContent":["// Copyright 2022 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 { DatasourcePlugin } from '@perses-dev/plugin-system';\nimport { PrometheusDatasourceSpec } from '../model/prometheus-client';\n\nexport const PrometheusDatasource: DatasourcePlugin<PrometheusDatasourceSpec> = {\n OptionsEditorComponent: () => null,\n createInitialOptions: () => ({ direct_url: '' }),\n};\n"],"names":["PrometheusDatasource","OptionsEditorComponent","createInitialOptions","direct_url"],"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;AAKjC,OAAO,MAAMA,oBAAoB,GAA+C;IAC9EC,sBAAsB,EAAE,IAAM,IAAI;IAClCC,oBAAoB,EAAE,IAAO,CAAA;YAAEC,UAAU,EAAE,EAAE;SAAE,CAAA,AAAC;CACjD,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { VariablePlugin } from '@perses-dev/plugin-system';
|
|
2
|
+
import { PrometheusDatasourceSelector } from '../model/prometheus-client';
|
|
3
|
+
interface PrometheusVariableOptionsBase {
|
|
4
|
+
datasource?: PrometheusDatasourceSelector;
|
|
5
|
+
}
|
|
6
|
+
declare type PrometheusLabelNamesVariableOptions = PrometheusVariableOptionsBase;
|
|
7
|
+
declare type PrometheusLabelValuesVariableOptions = PrometheusVariableOptionsBase & {
|
|
8
|
+
label_name: string;
|
|
9
|
+
matchers?: [string];
|
|
10
|
+
};
|
|
11
|
+
export declare const PrometheusLabelNamesVariable: VariablePlugin<PrometheusLabelNamesVariableOptions>;
|
|
12
|
+
export declare const PrometheusLabelValuesVariable: VariablePlugin<PrometheusLabelValuesVariableOptions>;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=prometheus-variables.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prometheus-variables.d.ts","sourceRoot":"","sources":["../../src/plugins/prometheus-variables.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAA6C,MAAM,2BAA2B,CAAC;AAEtG,OAAO,EAKL,4BAA4B,EAC7B,MAAM,4BAA4B,CAAC;AAEpC,UAAU,6BAA6B;IACrC,UAAU,CAAC,EAAE,4BAA4B,CAAC;CAC3C;AAED,aAAK,mCAAmC,GAAG,6BAA6B,CAAC;AAEzE,aAAK,oCAAoC,GAAG,6BAA6B,GAAG;IAC1E,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC;CACrB,CAAC;AA0BF,eAAO,MAAM,4BAA4B,EAAE,cAAc,CAAC,mCAAmC,CAS5F,CAAC;AAEF,eAAO,MAAM,6BAA6B,EAAE,cAAc,CAAC,oCAAoC,CAe9F,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
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
|
+
import { replaceTemplateVariables, parseTemplateVariables } from '../model/utils';
|
|
14
|
+
import { labelValues, labelNames } from '../model/prometheus-client';
|
|
15
|
+
/**
|
|
16
|
+
* Takes a list of strings and returns a list of VariableOptions
|
|
17
|
+
*/ const stringArrayToVariableOptions = (values)=>{
|
|
18
|
+
if (!values) return [];
|
|
19
|
+
return values.map((value)=>({
|
|
20
|
+
value,
|
|
21
|
+
label: value
|
|
22
|
+
}));
|
|
23
|
+
};
|
|
24
|
+
async function getQueryOptions(ctx, spec) {
|
|
25
|
+
var _datasource;
|
|
26
|
+
// Just use the default Prom datatsource if not specified in variable's spec
|
|
27
|
+
const datasourceSelector = (_datasource = spec.datasource) !== null && _datasource !== void 0 ? _datasource : {
|
|
28
|
+
kind: 'PrometheusDatasource'
|
|
29
|
+
};
|
|
30
|
+
const datasource = await ctx.datasourceStore.getDatasource(datasourceSelector);
|
|
31
|
+
const queryOptions = {
|
|
32
|
+
datasource: datasource.plugin.spec
|
|
33
|
+
};
|
|
34
|
+
return queryOptions;
|
|
35
|
+
}
|
|
36
|
+
export const PrometheusLabelNamesVariable = {
|
|
37
|
+
getVariableOptions: async (spec, ctx)=>{
|
|
38
|
+
const queryOptions = await getQueryOptions(ctx, spec);
|
|
39
|
+
const { data: options } = await labelNames({}, queryOptions);
|
|
40
|
+
return {
|
|
41
|
+
data: stringArrayToVariableOptions(options)
|
|
42
|
+
};
|
|
43
|
+
},
|
|
44
|
+
dependsOn: ()=>[]
|
|
45
|
+
};
|
|
46
|
+
export const PrometheusLabelValuesVariable = {
|
|
47
|
+
getVariableOptions: async (spec, ctx)=>{
|
|
48
|
+
const pluginDef = spec;
|
|
49
|
+
const queryOptions = await getQueryOptions(ctx, spec);
|
|
50
|
+
const match = pluginDef.matchers ? pluginDef.matchers.map((m)=>replaceTemplateVariables(m, ctx.variables)) : undefined;
|
|
51
|
+
const { data: options } = await labelValues({
|
|
52
|
+
labelName: pluginDef.label_name,
|
|
53
|
+
'match[]': match
|
|
54
|
+
}, queryOptions);
|
|
55
|
+
return {
|
|
56
|
+
data: stringArrayToVariableOptions(options)
|
|
57
|
+
};
|
|
58
|
+
},
|
|
59
|
+
dependsOn: (spec)=>{
|
|
60
|
+
var ref;
|
|
61
|
+
return ((ref = spec.matchers) === null || ref === void 0 ? void 0 : ref.map((m)=>parseTemplateVariables(m)).flat()) || [];
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
//# sourceMappingURL=prometheus-variables.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/plugins/prometheus-variables.ts"],"sourcesContent":["// Copyright 2022 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 { VariablePlugin, VariableOption, GetVariableOptionsContext } from '@perses-dev/plugin-system';\nimport { replaceTemplateVariables, parseTemplateVariables } from '../model/utils';\nimport {\n labelValues,\n labelNames,\n PrometheusDatasourceSpec,\n QueryOptions,\n PrometheusDatasourceSelector,\n} from '../model/prometheus-client';\n\ninterface PrometheusVariableOptionsBase {\n datasource?: PrometheusDatasourceSelector;\n}\n\ntype PrometheusLabelNamesVariableOptions = PrometheusVariableOptionsBase;\n\ntype PrometheusLabelValuesVariableOptions = PrometheusVariableOptionsBase & {\n label_name: string;\n matchers?: [string];\n};\n\n/**\n * Takes a list of strings and returns a list of VariableOptions\n */\nconst stringArrayToVariableOptions = (values?: string[]): VariableOption[] => {\n if (!values) return [];\n return values.map((value) => ({\n value,\n label: value,\n }));\n};\n\nasync function getQueryOptions(\n ctx: GetVariableOptionsContext,\n spec: PrometheusVariableOptionsBase\n): Promise<QueryOptions> {\n // Just use the default Prom datatsource if not specified in variable's spec\n const datasourceSelector = spec.datasource ?? { kind: 'PrometheusDatasource' };\n const datasource = await ctx.datasourceStore.getDatasource(datasourceSelector);\n const queryOptions = {\n datasource: datasource.plugin.spec as PrometheusDatasourceSpec,\n };\n return queryOptions;\n}\n\nexport const PrometheusLabelNamesVariable: VariablePlugin<PrometheusLabelNamesVariableOptions> = {\n getVariableOptions: async (spec, ctx) => {\n const queryOptions = await getQueryOptions(ctx, spec);\n const { data: options } = await labelNames({}, queryOptions);\n return {\n data: stringArrayToVariableOptions(options),\n };\n },\n dependsOn: () => [],\n};\n\nexport const PrometheusLabelValuesVariable: VariablePlugin<PrometheusLabelValuesVariableOptions> = {\n getVariableOptions: async (spec, ctx) => {\n const pluginDef = spec;\n const queryOptions = await getQueryOptions(ctx, spec);\n const match = pluginDef.matchers\n ? pluginDef.matchers.map((m) => replaceTemplateVariables(m, ctx.variables))\n : undefined;\n const { data: options } = await labelValues({ labelName: pluginDef.label_name, 'match[]': match }, queryOptions);\n return {\n data: stringArrayToVariableOptions(options),\n };\n },\n dependsOn: (spec) => {\n return spec.matchers?.map((m) => parseTemplateVariables(m)).flat() || [];\n },\n};\n"],"names":["replaceTemplateVariables","parseTemplateVariables","labelValues","labelNames","stringArrayToVariableOptions","values","map","value","label","getQueryOptions","ctx","spec","datasourceSelector","datasource","kind","datasourceStore","getDatasource","queryOptions","plugin","PrometheusLabelNamesVariable","getVariableOptions","data","options","dependsOn","PrometheusLabelValuesVariable","pluginDef","match","matchers","m","variables","undefined","labelName","label_name","flat"],"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,SAASA,wBAAwB,EAAEC,sBAAsB,QAAQ,gBAAgB,CAAC;AAClF,SACEC,WAAW,EACXC,UAAU,QAIL,4BAA4B,CAAC;AAapC;;CAEC,GACD,MAAMC,4BAA4B,GAAG,CAACC,MAAiB,GAAuB;IAC5E,IAAI,CAACA,MAAM,EAAE,OAAO,EAAE,CAAC;IACvB,OAAOA,MAAM,CAACC,GAAG,CAAC,CAACC,KAAK,GAAM,CAAA;YAC5BA,KAAK;YACLC,KAAK,EAAED,KAAK;SACb,CAAA,AAAC,CAAC,CAAC;AACN,CAAC,AAAC;AAEF,eAAeE,eAAe,CAC5BC,GAA8B,EAC9BC,IAAmC,EACZ;QAEIA,WAAe;IAD1C,4EAA4E;IAC5E,MAAMC,kBAAkB,GAAGD,CAAAA,WAAe,GAAfA,IAAI,CAACE,UAAU,cAAfF,WAAe,cAAfA,WAAe,GAAI;QAAEG,IAAI,EAAE,sBAAsB;KAAE,AAAC;IAC/E,MAAMD,UAAU,GAAG,MAAMH,GAAG,CAACK,eAAe,CAACC,aAAa,CAACJ,kBAAkB,CAAC,AAAC;IAC/E,MAAMK,YAAY,GAAG;QACnBJ,UAAU,EAAEA,UAAU,CAACK,MAAM,CAACP,IAAI;KACnC,AAAC;IACF,OAAOM,YAAY,CAAC;AACtB,CAAC;AAED,OAAO,MAAME,4BAA4B,GAAwD;IAC/FC,kBAAkB,EAAE,OAAOT,IAAI,EAAED,GAAG,GAAK;QACvC,MAAMO,YAAY,GAAG,MAAMR,eAAe,CAACC,GAAG,EAAEC,IAAI,CAAC,AAAC;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|
1
|
+
import { DurationString } from '@perses-dev/core';
|
|
2
|
+
import { TimeSeriesQueryPlugin } from '@perses-dev/plugin-system';
|
|
3
|
+
import { PrometheusDatasourceSelector } from '../model/prometheus-client';
|
|
4
|
+
import { TemplateString } from '../model/templating';
|
|
5
|
+
interface PrometheusTimeSeriesQuerySpec {
|
|
6
|
+
query: TemplateString;
|
|
7
|
+
min_step?: DurationString;
|
|
8
|
+
resolution?: number;
|
|
9
|
+
datasource?: PrometheusDatasourceSelector;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* The core Prometheus TimeSeriesQuery plugin for Perses.
|
|
13
|
+
*/
|
|
14
|
+
export declare const PrometheusTimeSeriesQuery: TimeSeriesQueryPlugin<PrometheusTimeSeriesQuerySpec>;
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=time-series-query.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"time-series-query.d.ts","sourceRoot":"","sources":["../../src/plugins/time-series-query.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAkB,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAIlF,OAAO,EAIL,4BAA4B,EAC7B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAIrD,UAAU,6BAA6B;IACrC,KAAK,EAAE,cAAc,CAAC;IACtB,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,4BAA4B,CAAC;CAC3C;AAqED;;GAEG;AACH,eAAO,MAAM,yBAAyB,EAAE,qBAAqB,CAAC,6BAA6B,CAE1F,CAAC"}
|
|
@@ -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
|
+
import { fromUnixTime } from 'date-fns';
|
|
14
|
+
import { parseValueTuple } from '../model/parse-sample-values';
|
|
15
|
+
import { rangeQuery } from '../model/prometheus-client';
|
|
16
|
+
import { getDurationStringSeconds, getPrometheusTimeRange, getRangeStep } from '../model/time';
|
|
17
|
+
import { replaceTemplateVariables } from '../model/utils';
|
|
18
|
+
const getTimeSeriesData = async (spec, context)=>{
|
|
19
|
+
var ref;
|
|
20
|
+
const minStep = getDurationStringSeconds(spec.min_step);
|
|
21
|
+
const timeRange = getPrometheusTimeRange(context.timeRange);
|
|
22
|
+
const step = getRangeStep(timeRange, minStep, undefined, context.suggestedStepMs);
|
|
23
|
+
// Align the time range so that it's a multiple of the step
|
|
24
|
+
let { start , end } = timeRange;
|
|
25
|
+
const utcOffsetSec = new Date().getTimezoneOffset() * 60;
|
|
26
|
+
const alignedEnd = Math.floor((end + utcOffsetSec) / step) * step - utcOffsetSec;
|
|
27
|
+
const alignedStart = Math.floor((start + utcOffsetSec) / step) * step - utcOffsetSec;
|
|
28
|
+
start = alignedStart;
|
|
29
|
+
end = alignedEnd;
|
|
30
|
+
// Replace template variable placeholders in PromQL query
|
|
31
|
+
let query = spec.query.replace('$__rate_interval', `15s`);
|
|
32
|
+
query = replaceTemplateVariables(query, context.variableState);
|
|
33
|
+
var _datasource;
|
|
34
|
+
// Get the datasource, using the default Prom Datasource if one isn't specified in the query
|
|
35
|
+
const datasourceSelector = (_datasource = spec.datasource) !== null && _datasource !== void 0 ? _datasource : {
|
|
36
|
+
kind: 'PrometheusDatasource'
|
|
37
|
+
};
|
|
38
|
+
const datasource = await context.datasourceStore.getDatasource(datasourceSelector);
|
|
39
|
+
const queryOptions = {
|
|
40
|
+
datasource: datasource.plugin.spec
|
|
41
|
+
};
|
|
42
|
+
// Make the request to Prom
|
|
43
|
+
const request = {
|
|
44
|
+
query,
|
|
45
|
+
start,
|
|
46
|
+
end,
|
|
47
|
+
step
|
|
48
|
+
};
|
|
49
|
+
const response = await rangeQuery(request, queryOptions);
|
|
50
|
+
var ref1;
|
|
51
|
+
// TODO: What about error responses from Prom that have a response body?
|
|
52
|
+
const result = (ref1 = (ref = response.data) === null || ref === void 0 ? void 0 : ref.result) !== null && ref1 !== void 0 ? ref1 : [];
|
|
53
|
+
// Transform response
|
|
54
|
+
const chartData = {
|
|
55
|
+
// Return the time range and step we actually used for the query
|
|
56
|
+
timeRange: {
|
|
57
|
+
start: fromUnixTime(start),
|
|
58
|
+
end: fromUnixTime(end)
|
|
59
|
+
},
|
|
60
|
+
stepMs: step * 1000,
|
|
61
|
+
// TODO: Maybe do a proper Iterable implementation that defers some of this
|
|
62
|
+
// processing until its needed
|
|
63
|
+
series: result.map((value)=>{
|
|
64
|
+
const { metric , values } = value;
|
|
65
|
+
// Name the series after the metric labels or if no metric, just use the
|
|
66
|
+
// overall query
|
|
67
|
+
let name = Object.entries(metric).map(([labelName, labelValue])=>`${labelName}="${labelValue}"`).join(', ');
|
|
68
|
+
if (name === '') name = query;
|
|
69
|
+
return {
|
|
70
|
+
name,
|
|
71
|
+
values: values.map(parseValueTuple)
|
|
72
|
+
};
|
|
73
|
+
})
|
|
74
|
+
};
|
|
75
|
+
return chartData;
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* The core Prometheus TimeSeriesQuery plugin for Perses.
|
|
79
|
+
*/ export const PrometheusTimeSeriesQuery = {
|
|
80
|
+
getTimeSeriesData
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
//# sourceMappingURL=time-series-query.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/plugins/time-series-query.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { DurationString } from '@perses-dev/core';\nimport { TimeSeriesData, TimeSeriesQueryPlugin } from '@perses-dev/plugin-system';\nimport { fromUnixTime } from 'date-fns';\nimport { RangeQueryRequestParameters } from '../model/api-types';\nimport { parseValueTuple } from '../model/parse-sample-values';\nimport {\n PrometheusDatasourceSpec,\n QueryOptions,\n rangeQuery,\n PrometheusDatasourceSelector,\n} from '../model/prometheus-client';\nimport { TemplateString } from '../model/templating';\nimport { getDurationStringSeconds, getPrometheusTimeRange, getRangeStep } from '../model/time';\nimport { replaceTemplateVariables } from '../model/utils';\n\ninterface PrometheusTimeSeriesQuerySpec {\n query: TemplateString;\n min_step?: DurationString;\n resolution?: number;\n datasource?: PrometheusDatasourceSelector;\n}\n\nconst getTimeSeriesData: TimeSeriesQueryPlugin<PrometheusTimeSeriesQuerySpec>['getTimeSeriesData'] = async (\n spec,\n context\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 // Get the datasource, using the default Prom Datasource if one isn't specified in the query\n const datasourceSelector = spec.datasource ?? { kind: 'PrometheusDatasource' };\n const datasource = await context.datasourceStore.getDatasource(datasourceSelector);\n const queryOptions: QueryOptions = {\n datasource: datasource.plugin.spec as PrometheusDatasourceSpec,\n };\n\n // Make the request to Prom\n const request: RangeQueryRequestParameters = {\n query,\n start,\n end,\n step,\n };\n const response = await rangeQuery(request, queryOptions);\n\n // TODO: What about error responses from Prom that have a response body?\n const result = response.data?.result ?? [];\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 // TODO: Maybe do a proper Iterable implementation that defers some of this\n // processing until its needed\n series: result.map((value) => {\n const { metric, values } = value;\n\n // Name the series after the metric labels or if no metric, just use the\n // overall query\n let name = Object.entries(metric)\n .map(([labelName, labelValue]) => `${labelName}=\"${labelValue}\"`)\n .join(', ');\n if (name === '') name = query;\n\n return {\n name,\n values: values.map(parseValueTuple),\n };\n }),\n };\n return chartData;\n};\n\n/**\n * The core Prometheus TimeSeriesQuery plugin for Perses.\n */\nexport const PrometheusTimeSeriesQuery: TimeSeriesQueryPlugin<PrometheusTimeSeriesQuerySpec> = {\n getTimeSeriesData,\n};\n"],"names":["fromUnixTime","parseValueTuple","rangeQuery","getDurationStringSeconds","getPrometheusTimeRange","getRangeStep","replaceTemplateVariables","getTimeSeriesData","spec","context","response","minStep","min_step","timeRange","step","undefined","suggestedStepMs","start","end","utcOffsetSec","Date","getTimezoneOffset","alignedEnd","Math","floor","alignedStart","query","replace","variableState","datasourceSelector","datasource","kind","datasourceStore","getDatasource","queryOptions","plugin","request","result","data","chartData","stepMs","series","map","value","metric","values","name","Object","entries","labelName","labelValue","join","PrometheusTimeSeriesQuery"],"mappings":"AAAA,oCAAoC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EnB,2EAA2E;QAC3E,8BAA8B;QAC9B2B,MAAM,EAAEJ,MAAM,CAACK,GAAG,CAAC,CAACC,KAAK,GAAK;YAC5B,MAAM,EAAEC,MAAM,CAAA,EAAEC,MAAM,CAAA,EAAE,GAAGF,KAAK,AAAC;YAEjC,wEAAwE;YACxE,gBAAgB;YAChB,IAAIG,IAAI,GAAGC,MAAM,CAACC,OAAO,CAACJ,MAAM,CAAC,CAC9BF,GAAG,CAAC,CAAC,CAACO,SAAS,EAAEC,UAAU,CAAC,GAAK,CAAC,EAAED,SAAS,CAAC,EAAE,EAAEC,UAAU,CAAC,CAAC,CAAC,CAAC,CAChEC,IAAI,CAAC,IAAI,CAAC,AAAC;YACd,IAAIL,IAAI,KAAK,EAAE,EAAEA,IAAI,GAAGpB,KAAK,CAAC;YAE9B,OAAO;gBACLoB,IAAI;gBACJD,MAAM,EAAEA,MAAM,CAACH,GAAG,CAACzC,eAAe,CAAC;aACpC,CAAC;QACJ,CAAC,CAAC;KACH,AAAC;IACF,OAAOsC,SAAS,CAAC;AACnB,CAAC,AAAC;AAEF;;CAEC,GACD,OAAO,MAAMa,yBAAyB,GAAyD;IAC7F7C,iBAAiB;CAClB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { VariablePlugin, VariableOption } from '@perses-dev/plugin-system';
|
|
2
|
+
declare type StaticListOption = string | VariableOption;
|
|
3
|
+
declare type StaticListVariableOptions = {
|
|
4
|
+
values: StaticListOption[];
|
|
5
|
+
};
|
|
6
|
+
export declare const StaticListVariable: VariablePlugin<StaticListVariableOptions>;
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=variable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"variable.d.ts","sourceRoot":"","sources":["../../src/plugins/variable.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAE3E,aAAK,gBAAgB,GAAG,MAAM,GAAG,cAAc,CAAC;AAEhD,aAAK,yBAAyB,GAAG;IAC/B,MAAM,EAAE,gBAAgB,EAAE,CAAC;CAC5B,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,cAAc,CAAC,yBAAyB,CAaxE,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
export const StaticListVariable = {
|
|
14
|
+
getVariableOptions: async (spec)=>{
|
|
15
|
+
var ref;
|
|
16
|
+
const values = (ref = spec.values) === null || ref === void 0 ? void 0 : ref.map((v)=>{
|
|
17
|
+
if (typeof v === 'string') {
|
|
18
|
+
return {
|
|
19
|
+
label: v,
|
|
20
|
+
value: v
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
return v;
|
|
24
|
+
});
|
|
25
|
+
return {
|
|
26
|
+
data: values
|
|
27
|
+
};
|
|
28
|
+
},
|
|
29
|
+
dependsOn: ()=>[]
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=variable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/plugins/variable.ts"],"sourcesContent":["// Copyright 2022 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 { VariablePlugin, VariableOption } from '@perses-dev/plugin-system';\n\ntype StaticListOption = string | VariableOption;\n\ntype StaticListVariableOptions = {\n values: StaticListOption[];\n};\n\nexport const StaticListVariable: VariablePlugin<StaticListVariableOptions> = {\n getVariableOptions: async (spec) => {\n const values = spec.values?.map((v) => {\n if (typeof v === 'string') {\n return { label: v, value: v };\n }\n return v;\n });\n return {\n data: values,\n };\n },\n dependsOn: () => [],\n};\n"],"names":["StaticListVariable","getVariableOptions","spec","values","map","v","label","value","data","dependsOn"],"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;AAUjC,OAAO,MAAMA,kBAAkB,GAA8C;IAC3EC,kBAAkB,EAAE,OAAOC,IAAI,GAAK;YACnBA,GAAW;QAA1B,MAAMC,MAAM,GAAGD,CAAAA,GAAW,GAAXA,IAAI,CAACC,MAAM,cAAXD,GAAW,WAAK,GAAhBA,KAAAA,CAAgB,GAAhBA,GAAW,CAAEE,GAAG,CAAC,CAACC,CAAC,GAAK;YACrC,IAAI,OAAOA,CAAC,KAAK,QAAQ,EAAE;gBACzB,OAAO;oBAAEC,KAAK,EAAED,CAAC;oBAAEE,KAAK,EAAEF,CAAC;iBAAE,CAAC;YAChC,CAAC;YACD,OAAOA,CAAC,CAAC;QACX,CAAC,CAAC,AAAC;QACH,OAAO;YACLG,IAAI,EAAEL,MAAM;SACb,CAAC;IACJ,CAAC;IACDM,SAAS,EAAE,IAAM,EAAE;CACpB,CAAC"}
|
package/dist/test/setup-tests.js
CHANGED
|
@@ -1 +1,15 @@
|
|
|
1
|
-
|
|
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
|
+
import '@testing-library/jest-dom/extend-expect';
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=setup-tests.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/test/setup-tests.ts"],"sourcesContent":["// Copyright 2022 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 '@testing-library/jest-dom/extend-expect';\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,OAAO,yCAAyC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@perses-dev/prometheus-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.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",
|
|
@@ -16,8 +16,11 @@
|
|
|
16
16
|
"types": "dist/index.d.ts",
|
|
17
17
|
"scripts": {
|
|
18
18
|
"clean": "rimraf dist/",
|
|
19
|
-
"build": "
|
|
20
|
-
"build:cjs": "
|
|
19
|
+
"build": "concurrently \"npm:build:*\"",
|
|
20
|
+
"build:cjs": "swc ./src -d dist/cjs --config-file ../.cjs.swcrc",
|
|
21
|
+
"build:esm": "swc ./src -d dist --config-file ../.swcrc",
|
|
22
|
+
"build:types": "tsc --emitDeclarationOnly --declaration --preserveWatchOutput",
|
|
23
|
+
"start": "concurrently -P \"npm:build:* -- {*}\" -- --watch",
|
|
21
24
|
"test": "TZ=UTC jest",
|
|
22
25
|
"test:watch": "TZ=UTC jest --watch",
|
|
23
26
|
"lint": "eslint src --ext .ts,.tsx",
|
|
@@ -26,14 +29,13 @@
|
|
|
26
29
|
"dependencies": {
|
|
27
30
|
"@lezer/highlight": "^1.0.0",
|
|
28
31
|
"@lezer/lr": "^1.2.0",
|
|
29
|
-
"@perses-dev/core": "^0.
|
|
30
|
-
"@perses-dev/plugin-system": "^0.
|
|
32
|
+
"@perses-dev/core": "^0.9.0",
|
|
33
|
+
"@perses-dev/plugin-system": "^0.9.0",
|
|
31
34
|
"@prometheus-io/lezer-promql": "^0.37.0",
|
|
32
35
|
"date-fns": "^2.28.0"
|
|
33
36
|
},
|
|
34
37
|
"peerDependencies": {
|
|
35
|
-
"react": "^17.0.2 || ^18.0.0"
|
|
36
|
-
"react-query": "^3.34.16"
|
|
38
|
+
"react": "^17.0.2 || ^18.0.0"
|
|
37
39
|
},
|
|
38
40
|
"files": [
|
|
39
41
|
"dist",
|