@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,77 @@
|
|
|
1
|
+
// Copyright 2022 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
function _export(target, all) {
|
|
18
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: all[name]
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
_export(exports, {
|
|
24
|
+
PrometheusLabelNamesVariable: ()=>PrometheusLabelNamesVariable,
|
|
25
|
+
PrometheusLabelValuesVariable: ()=>PrometheusLabelValuesVariable
|
|
26
|
+
});
|
|
27
|
+
const _utils = require("../model/utils");
|
|
28
|
+
const _prometheusClient = require("../model/prometheus-client");
|
|
29
|
+
/**
|
|
30
|
+
* Takes a list of strings and returns a list of VariableOptions
|
|
31
|
+
*/ const stringArrayToVariableOptions = (values)=>{
|
|
32
|
+
if (!values) return [];
|
|
33
|
+
return values.map((value)=>({
|
|
34
|
+
value,
|
|
35
|
+
label: value
|
|
36
|
+
}));
|
|
37
|
+
};
|
|
38
|
+
async function getQueryOptions(ctx, spec) {
|
|
39
|
+
var _datasource;
|
|
40
|
+
// Just use the default Prom datatsource if not specified in variable's spec
|
|
41
|
+
const datasourceSelector = (_datasource = spec.datasource) !== null && _datasource !== void 0 ? _datasource : {
|
|
42
|
+
kind: 'PrometheusDatasource'
|
|
43
|
+
};
|
|
44
|
+
const datasource = await ctx.datasourceStore.getDatasource(datasourceSelector);
|
|
45
|
+
const queryOptions = {
|
|
46
|
+
datasource: datasource.plugin.spec
|
|
47
|
+
};
|
|
48
|
+
return queryOptions;
|
|
49
|
+
}
|
|
50
|
+
const PrometheusLabelNamesVariable = {
|
|
51
|
+
getVariableOptions: async (spec, ctx)=>{
|
|
52
|
+
const queryOptions = await getQueryOptions(ctx, spec);
|
|
53
|
+
const { data: options } = await (0, _prometheusClient.labelNames)({}, queryOptions);
|
|
54
|
+
return {
|
|
55
|
+
data: stringArrayToVariableOptions(options)
|
|
56
|
+
};
|
|
57
|
+
},
|
|
58
|
+
dependsOn: ()=>[]
|
|
59
|
+
};
|
|
60
|
+
const PrometheusLabelValuesVariable = {
|
|
61
|
+
getVariableOptions: async (spec, ctx)=>{
|
|
62
|
+
const pluginDef = spec;
|
|
63
|
+
const queryOptions = await getQueryOptions(ctx, spec);
|
|
64
|
+
const match = pluginDef.matchers ? pluginDef.matchers.map((m)=>(0, _utils.replaceTemplateVariables)(m, ctx.variables)) : undefined;
|
|
65
|
+
const { data: options } = await (0, _prometheusClient.labelValues)({
|
|
66
|
+
labelName: pluginDef.label_name,
|
|
67
|
+
'match[]': match
|
|
68
|
+
}, queryOptions);
|
|
69
|
+
return {
|
|
70
|
+
data: stringArrayToVariableOptions(options)
|
|
71
|
+
};
|
|
72
|
+
},
|
|
73
|
+
dependsOn: (spec)=>{
|
|
74
|
+
var ref;
|
|
75
|
+
return ((ref = spec.matchers) === null || ref === void 0 ? void 0 : ref.map((m)=>(0, _utils.parseTemplateVariables)(m)).flat()) || [];
|
|
76
|
+
}
|
|
77
|
+
};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// Copyright 2022 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(exports, "PrometheusTimeSeriesQuery", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: ()=>PrometheusTimeSeriesQuery
|
|
20
|
+
});
|
|
21
|
+
const _dateFns = require("date-fns");
|
|
22
|
+
const _parseSampleValues = require("../model/parse-sample-values");
|
|
23
|
+
const _prometheusClient = require("../model/prometheus-client");
|
|
24
|
+
const _time = require("../model/time");
|
|
25
|
+
const _utils = require("../model/utils");
|
|
26
|
+
const getTimeSeriesData = async (spec, context)=>{
|
|
27
|
+
var ref;
|
|
28
|
+
const minStep = (0, _time.getDurationStringSeconds)(spec.min_step);
|
|
29
|
+
const timeRange = (0, _time.getPrometheusTimeRange)(context.timeRange);
|
|
30
|
+
const step = (0, _time.getRangeStep)(timeRange, minStep, undefined, context.suggestedStepMs);
|
|
31
|
+
// Align the time range so that it's a multiple of the step
|
|
32
|
+
let { start , end } = timeRange;
|
|
33
|
+
const utcOffsetSec = new Date().getTimezoneOffset() * 60;
|
|
34
|
+
const alignedEnd = Math.floor((end + utcOffsetSec) / step) * step - utcOffsetSec;
|
|
35
|
+
const alignedStart = Math.floor((start + utcOffsetSec) / step) * step - utcOffsetSec;
|
|
36
|
+
start = alignedStart;
|
|
37
|
+
end = alignedEnd;
|
|
38
|
+
// Replace template variable placeholders in PromQL query
|
|
39
|
+
let query = spec.query.replace('$__rate_interval', `15s`);
|
|
40
|
+
query = (0, _utils.replaceTemplateVariables)(query, context.variableState);
|
|
41
|
+
var _datasource;
|
|
42
|
+
// Get the datasource, using the default Prom Datasource if one isn't specified in the query
|
|
43
|
+
const datasourceSelector = (_datasource = spec.datasource) !== null && _datasource !== void 0 ? _datasource : {
|
|
44
|
+
kind: 'PrometheusDatasource'
|
|
45
|
+
};
|
|
46
|
+
const datasource = await context.datasourceStore.getDatasource(datasourceSelector);
|
|
47
|
+
const queryOptions = {
|
|
48
|
+
datasource: datasource.plugin.spec
|
|
49
|
+
};
|
|
50
|
+
// Make the request to Prom
|
|
51
|
+
const request = {
|
|
52
|
+
query,
|
|
53
|
+
start,
|
|
54
|
+
end,
|
|
55
|
+
step
|
|
56
|
+
};
|
|
57
|
+
const response = await (0, _prometheusClient.rangeQuery)(request, queryOptions);
|
|
58
|
+
var ref1;
|
|
59
|
+
// TODO: What about error responses from Prom that have a response body?
|
|
60
|
+
const result = (ref1 = (ref = response.data) === null || ref === void 0 ? void 0 : ref.result) !== null && ref1 !== void 0 ? ref1 : [];
|
|
61
|
+
// Transform response
|
|
62
|
+
const chartData = {
|
|
63
|
+
// Return the time range and step we actually used for the query
|
|
64
|
+
timeRange: {
|
|
65
|
+
start: (0, _dateFns.fromUnixTime)(start),
|
|
66
|
+
end: (0, _dateFns.fromUnixTime)(end)
|
|
67
|
+
},
|
|
68
|
+
stepMs: step * 1000,
|
|
69
|
+
// TODO: Maybe do a proper Iterable implementation that defers some of this
|
|
70
|
+
// processing until its needed
|
|
71
|
+
series: result.map((value)=>{
|
|
72
|
+
const { metric , values } = value;
|
|
73
|
+
// Name the series after the metric labels or if no metric, just use the
|
|
74
|
+
// overall query
|
|
75
|
+
let name = Object.entries(metric).map(([labelName, labelValue])=>`${labelName}="${labelValue}"`).join(', ');
|
|
76
|
+
if (name === '') name = query;
|
|
77
|
+
return {
|
|
78
|
+
name,
|
|
79
|
+
values: values.map(_parseSampleValues.parseValueTuple)
|
|
80
|
+
};
|
|
81
|
+
})
|
|
82
|
+
};
|
|
83
|
+
return chartData;
|
|
84
|
+
};
|
|
85
|
+
const PrometheusTimeSeriesQuery = {
|
|
86
|
+
getTimeSeriesData
|
|
87
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// Copyright 2022 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(exports, "StaticListVariable", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: ()=>StaticListVariable
|
|
20
|
+
});
|
|
21
|
+
const StaticListVariable = {
|
|
22
|
+
getVariableOptions: async (spec)=>{
|
|
23
|
+
var ref;
|
|
24
|
+
const values = (ref = spec.values) === null || ref === void 0 ? void 0 : ref.map((v)=>{
|
|
25
|
+
if (typeof v === 'string') {
|
|
26
|
+
return {
|
|
27
|
+
label: v,
|
|
28
|
+
value: v
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
return v;
|
|
32
|
+
});
|
|
33
|
+
return {
|
|
34
|
+
data: values
|
|
35
|
+
};
|
|
36
|
+
},
|
|
37
|
+
dependsOn: ()=>[]
|
|
38
|
+
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
// Copyright 2022 The Perses Authors
|
|
3
2
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
3
|
// you may not use this file except in compliance with the License.
|
|
@@ -11,5 +10,8 @@
|
|
|
11
10
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
11
|
// See the License for the specific language governing permissions and
|
|
13
12
|
// limitations under the License.
|
|
14
|
-
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
15
17
|
require("@testing-library/jest-dom/extend-expect");
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { PrometheusTimeSeriesQuery } from './plugins/time-series-query';
|
|
2
|
+
import { StaticListVariable } from './plugins/variable';
|
|
3
|
+
import { PrometheusLabelNamesVariable, PrometheusLabelValuesVariable } from './plugins/prometheus-variables';
|
|
4
|
+
import { PrometheusDatasource } from './plugins/prometheus-datasource';
|
|
5
|
+
export { PrometheusTimeSeriesQuery, StaticListVariable, PrometheusLabelNamesVariable, PrometheusLabelValuesVariable, PrometheusDatasource, };
|
|
3
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,oBAAoB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAExE,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,4BAA4B,EAAE,6BAA6B,EAAE,MAAM,gCAAgC,CAAC;AAC7G,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAGvE,OAAO,EACL,yBAAyB,EACzB,kBAAkB,EAClB,4BAA4B,EAC5B,6BAA6B,EAC7B,oBAAoB,GACrB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1 +1,21 @@
|
|
|
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 { PrometheusTimeSeriesQuery } from './plugins/time-series-query';
|
|
14
|
+
// @TODO: Move this to a more generic location;
|
|
15
|
+
import { StaticListVariable } from './plugins/variable';
|
|
16
|
+
import { PrometheusLabelNamesVariable, PrometheusLabelValuesVariable } from './plugins/prometheus-variables';
|
|
17
|
+
import { PrometheusDatasource } from './plugins/prometheus-datasource';
|
|
18
|
+
// Export plugins under the same name as the kinds they handle from the plugin.json
|
|
19
|
+
export { PrometheusTimeSeriesQuery, StaticListVariable, PrometheusLabelNamesVariable, PrometheusLabelValuesVariable, PrometheusDatasource };
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.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 { PrometheusTimeSeriesQuery } from './plugins/time-series-query';\n// @TODO: Move this to a more generic location;\nimport { StaticListVariable } from './plugins/variable';\nimport { PrometheusLabelNamesVariable, PrometheusLabelValuesVariable } from './plugins/prometheus-variables';\nimport { PrometheusDatasource } from './plugins/prometheus-datasource';\n\n// Export plugins under the same name as the kinds they handle from the plugin.json\nexport {\n PrometheusTimeSeriesQuery,\n StaticListVariable,\n PrometheusLabelNamesVariable,\n PrometheusLabelValuesVariable,\n PrometheusDatasource,\n};\n"],"names":["PrometheusTimeSeriesQuery","StaticListVariable","PrometheusLabelNamesVariable","PrometheusLabelValuesVariable","PrometheusDatasource"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,yBAAyB,QAAQ,6BAA6B,CAAC;AACxE,+CAA+C;AAC/C,SAASC,kBAAkB,QAAQ,oBAAoB,CAAC;AACxD,SAASC,4BAA4B,EAAEC,6BAA6B,QAAQ,gCAAgC,CAAC;AAC7G,SAASC,oBAAoB,QAAQ,iCAAiC,CAAC;AAEvE,mFAAmF;AACnF,SACEJ,yBAAyB,EACzBC,kBAAkB,EAClBC,4BAA4B,EAC5BC,6BAA6B,EAC7BC,oBAAoB,GACpB"}
|
package/dist/model/api-types.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
|
+
export { };
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=api-types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/model/api-types.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';\n\n// Just reuse dashboard model's type and re-export\nexport type { DurationString };\n\nexport interface SuccessResponse<T> {\n status: 'success';\n data: T;\n warnings?: string[];\n}\n\nexport interface ErrorResponse<T> {\n status: 'error';\n data?: T;\n errorType: string;\n error: string;\n}\n\nexport type ApiResponse<T> = SuccessResponse<T> | ErrorResponse<T>;\n\nexport type DurationSeconds = number;\n\nexport type UnixTimestampSeconds = number;\n\nexport type ValueTuple = [unixTimeSeconds: UnixTimestampSeconds, sampleValue: string];\n\nexport type Metric = Record<string, string>;\n\nexport interface VectorData {\n resultType: 'vector';\n result: Array<{\n metric: Metric;\n value: ValueTuple;\n }>;\n}\n\nexport interface MatrixData {\n resultType: 'matrix';\n result: Array<{\n metric: Metric;\n values: ValueTuple[];\n }>;\n}\n\nexport interface ScalarData {\n resultType: 'scalar';\n result: ValueTuple;\n}\n\nexport interface InstantQueryRequestParameters {\n query: string;\n time?: UnixTimestampSeconds;\n timeout?: DurationString;\n}\n\nexport type InstantQueryResponse = ApiResponse<MatrixData | VectorData | ScalarData>;\n\nexport interface RangeQueryRequestParameters {\n query: string;\n start: UnixTimestampSeconds;\n end: UnixTimestampSeconds;\n step: DurationSeconds;\n timeout?: DurationString;\n}\n\nexport type RangeQueryResponse = ApiResponse<MatrixData>;\n\nexport interface SeriesRequestParameters {\n 'match[]': string[];\n start: UnixTimestampSeconds;\n end: UnixTimestampSeconds;\n}\n\nexport type SeriesResponse = ApiResponse<Metric[]>;\n\nexport interface LabelNamesRequestParameters {\n start?: UnixTimestampSeconds;\n end?: UnixTimestampSeconds;\n 'match[]'?: string[];\n}\n\nexport type LabelNamesResponse = ApiResponse<string[]>;\n\nexport interface LabelValuesRequestParameters {\n labelName: string;\n start?: UnixTimestampSeconds;\n end?: UnixTimestampSeconds;\n 'match[]'?: string[];\n}\n\nexport type LabelValuesResponse = ApiResponse<string[]>;\n\nexport interface MetricMetadata {\n type: string;\n help: string;\n unit?: string;\n}\n\nexport interface MetricMetadataRequestParameters {\n limit?: number;\n metric?: string;\n}\n\nexport type MetricMetadataResponse = ApiResponse<Record<string, MetricMetadata[]>>;\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,WAuGmF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-sample-values.d.ts","sourceRoot":"","sources":["../../src/model/parse-sample-values.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC;;GAEG;AACH,oBAAY,gBAAgB,GAAG,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;AAEnE;;;GAGG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,UAAU,GAAG,gBAAgB,CAKlE;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"parse-sample-values.d.ts","sourceRoot":"","sources":["../../src/model/parse-sample-values.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC;;GAEG;AACH,oBAAY,gBAAgB,GAAG,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;AAEnE;;;GAGG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,UAAU,GAAG,gBAAgB,CAKlE;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,MAAM,CAenE"}
|
|
@@ -1 +1,44 @@
|
|
|
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
|
+
/**
|
|
14
|
+
* Parse a ValueTuple from a PromServer response into the a millisecond-based
|
|
15
|
+
* unix time and a numeric sample value.
|
|
16
|
+
*/ export function parseValueTuple(data) {
|
|
17
|
+
const [unixTimeSeconds, sampleValue] = data;
|
|
18
|
+
// Prom returns unix time in seconds, so convert to ms
|
|
19
|
+
return [
|
|
20
|
+
unixTimeSeconds * 1000,
|
|
21
|
+
parseSampleValue(sampleValue)
|
|
22
|
+
];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Parses a string sample value from Prometheus, usually included as the
|
|
26
|
+
* second member of a ValueTuple.
|
|
27
|
+
*/ export function parseSampleValue(sampleValue) {
|
|
28
|
+
// Account for Prometheus' representation of +/- infinity, otherwise just
|
|
29
|
+
// parse the sample value as a float
|
|
30
|
+
let value;
|
|
31
|
+
switch(sampleValue){
|
|
32
|
+
case '+Inf':
|
|
33
|
+
value = Number.POSITIVE_INFINITY;
|
|
34
|
+
break;
|
|
35
|
+
case '-Inf':
|
|
36
|
+
value = Number.NEGATIVE_INFINITY;
|
|
37
|
+
break;
|
|
38
|
+
default:
|
|
39
|
+
value = parseFloat(sampleValue);
|
|
40
|
+
}
|
|
41
|
+
return value;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
//# sourceMappingURL=parse-sample-values.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/model/parse-sample-values.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 { ValueTuple } from './api-types';\n\n/**\n * ValueTuple from the Prom server, parsed into ms and floating point number\n */\nexport type ParsedValueTuple = [unixTimeMs: number, value: number];\n\n/**\n * Parse a ValueTuple from a PromServer response into the a millisecond-based\n * unix time and a numeric sample value.\n */\nexport function parseValueTuple(data: ValueTuple): ParsedValueTuple {\n const [unixTimeSeconds, sampleValue] = data;\n\n // Prom returns unix time in seconds, so convert to ms\n return [unixTimeSeconds * 1000, parseSampleValue(sampleValue)];\n}\n\n/**\n * Parses a string sample value from Prometheus, usually included as the\n * second member of a ValueTuple.\n */\nexport function parseSampleValue(sampleValue: ValueTuple[1]): number {\n // Account for Prometheus' representation of +/- infinity, otherwise just\n // parse the sample value as a float\n let value: number;\n switch (sampleValue) {\n case '+Inf':\n value = Number.POSITIVE_INFINITY;\n break;\n case '-Inf':\n value = Number.NEGATIVE_INFINITY;\n break;\n default:\n value = parseFloat(sampleValue);\n }\n return value;\n}\n"],"names":["parseValueTuple","data","unixTimeSeconds","sampleValue","parseSampleValue","value","Number","POSITIVE_INFINITY","NEGATIVE_INFINITY","parseFloat"],"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;AASjC;;;CAGC,GACD,OAAO,SAASA,eAAe,CAACC,IAAgB,EAAoB;IAClE,MAAM,CAACC,eAAe,EAAEC,WAAW,CAAC,GAAGF,IAAI,AAAC;IAE5C,sDAAsD;IACtD,OAAO;QAACC,eAAe,GAAG,IAAI;QAAEE,gBAAgB,CAACD,WAAW,CAAC;KAAC,CAAC;AACjE,CAAC;AAED;;;CAGC,GACD,OAAO,SAASC,gBAAgB,CAACD,WAA0B,EAAU;IACnE,yEAAyE;IACzE,oCAAoC;IACpC,IAAIE,KAAK,AAAQ,AAAC;IAClB,OAAQF,WAAW;QACjB,KAAK,MAAM;YACTE,KAAK,GAAGC,MAAM,CAACC,iBAAiB,CAAC;YACjC,MAAM;QACR,KAAK,MAAM;YACTF,KAAK,GAAGC,MAAM,CAACE,iBAAiB,CAAC;YACjC,MAAM;QACR;YACEH,KAAK,GAAGI,UAAU,CAACN,WAAW,CAAC,CAAC;KACnC;IACD,OAAOE,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -1,24 +1,28 @@
|
|
|
1
|
-
import { UseQueryOptions } from 'react-query';
|
|
2
1
|
import { DatasourceSelector } from '@perses-dev/core';
|
|
3
2
|
import { InstantQueryRequestParameters, InstantQueryResponse, LabelNamesRequestParameters, LabelNamesResponse, LabelValuesRequestParameters, LabelValuesResponse, RangeQueryRequestParameters, RangeQueryResponse } from './api-types';
|
|
4
|
-
export
|
|
5
|
-
datasource
|
|
6
|
-
}
|
|
3
|
+
export interface QueryOptions {
|
|
4
|
+
datasource: PrometheusDatasourceSpec;
|
|
5
|
+
}
|
|
6
|
+
export interface PrometheusDatasourceSpec {
|
|
7
|
+
direct_url: string;
|
|
8
|
+
}
|
|
9
|
+
export interface PrometheusDatasourceSelector extends DatasourceSelector {
|
|
10
|
+
kind: 'PrometheusDatasource';
|
|
11
|
+
}
|
|
7
12
|
/**
|
|
8
13
|
* Calls the `/api/v1/query` endpoint to get metrics data.
|
|
9
14
|
*/
|
|
10
|
-
export declare function
|
|
15
|
+
export declare function instantQuery(params: InstantQueryRequestParameters, queryOptions: QueryOptions): Promise<InstantQueryResponse>;
|
|
11
16
|
/**
|
|
12
17
|
* Calls the `/api/v1/query_range` endpoint to get metrics data.
|
|
13
18
|
*/
|
|
14
|
-
export declare function
|
|
19
|
+
export declare function rangeQuery(params: RangeQueryRequestParameters, queryOptions: QueryOptions): Promise<RangeQueryResponse>;
|
|
15
20
|
/**
|
|
16
21
|
* Calls the `/api/v1/labels` endpoint to get a list of label names.
|
|
17
22
|
*/
|
|
18
|
-
export declare function
|
|
23
|
+
export declare function labelNames(params: LabelNamesRequestParameters, queryOptions: QueryOptions): Promise<LabelNamesResponse>;
|
|
19
24
|
/**
|
|
20
|
-
* Calls the `/api/v1/label/{labelName}/values` endpoint to get a list of
|
|
21
|
-
* values for a label.
|
|
25
|
+
* Calls the `/api/v1/label/{labelName}/values` endpoint to get a list of values for a label.
|
|
22
26
|
*/
|
|
23
|
-
export declare function
|
|
27
|
+
export declare function labelValues(params: LabelValuesRequestParameters, queryOptions: QueryOptions): Promise<LabelValuesResponse>;
|
|
24
28
|
//# sourceMappingURL=prometheus-client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prometheus-client.d.ts","sourceRoot":"","sources":["../../src/model/prometheus-client.ts"],"names":[],"mappings":"AAaA,OAAO,
|
|
1
|
+
{"version":3,"file":"prometheus-client.d.ts","sourceRoot":"","sources":["../../src/model/prometheus-client.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,kBAAkB,EAAa,MAAM,kBAAkB,CAAC;AACjE,OAAO,EACL,6BAA6B,EAC7B,oBAAoB,EACpB,2BAA2B,EAC3B,kBAAkB,EAClB,4BAA4B,EAC5B,mBAAmB,EACnB,2BAA2B,EAC3B,kBAAkB,EACnB,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,YAAY;IAC3B,UAAU,EAAE,wBAAwB,CAAC;CACtC;AAED,MAAM,WAAW,wBAAwB;IAEvC,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,4BAA6B,SAAQ,kBAAkB;IACtE,IAAI,EAAE,sBAAsB,CAAC;CAC9B;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,6BAA6B,EAAE,YAAY,EAAE,YAAY,iCAE7F;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,2BAA2B,EAAE,YAAY,EAAE,YAAY,+BAEzF;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,2BAA2B,EAAE,YAAY,EAAE,YAAY,+BAEzF;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,4BAA4B,EAAE,YAAY,EAAE,YAAY,gCAI3F"}
|
|
@@ -1 +1,81 @@
|
|
|
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 { fetchJson } from '@perses-dev/core';
|
|
14
|
+
/**
|
|
15
|
+
* Calls the `/api/v1/query` endpoint to get metrics data.
|
|
16
|
+
*/ export function instantQuery(params, queryOptions) {
|
|
17
|
+
return fetchWithPost('/api/v1/query', params, queryOptions);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Calls the `/api/v1/query_range` endpoint to get metrics data.
|
|
21
|
+
*/ export function rangeQuery(params, queryOptions) {
|
|
22
|
+
return fetchWithPost('/api/v1/query_range', params, queryOptions);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Calls the `/api/v1/labels` endpoint to get a list of label names.
|
|
26
|
+
*/ export function labelNames(params, queryOptions) {
|
|
27
|
+
return fetchWithPost('/api/v1/labels', params, queryOptions);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Calls the `/api/v1/label/{labelName}/values` endpoint to get a list of values for a label.
|
|
31
|
+
*/ export function labelValues(params, queryOptions) {
|
|
32
|
+
const { labelName , ...searchParams } = params;
|
|
33
|
+
const apiURI = `/api/v1/label/${encodeURIComponent(labelName)}/values`;
|
|
34
|
+
return fetchWithGet(apiURI, searchParams, queryOptions);
|
|
35
|
+
}
|
|
36
|
+
function fetchWithGet(apiURI, params, queryOptions) {
|
|
37
|
+
const { datasource: { direct_url: datasourceURL } , } = queryOptions;
|
|
38
|
+
let url = `${datasourceURL}${apiURI}`;
|
|
39
|
+
const urlParams = createSearchParams(params).toString();
|
|
40
|
+
if (urlParams !== '') {
|
|
41
|
+
url += `?${urlParams}`;
|
|
42
|
+
}
|
|
43
|
+
return fetchJson(url, {
|
|
44
|
+
method: 'GET'
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
function fetchWithPost(apiURI, params, queryOptions) {
|
|
48
|
+
const { datasource: { direct_url: datasourceURL } , } = queryOptions;
|
|
49
|
+
const url = `${datasourceURL}${apiURI}`;
|
|
50
|
+
const init = {
|
|
51
|
+
method: 'POST',
|
|
52
|
+
headers: {
|
|
53
|
+
'Content-Type': 'application/x-www-form-urlencoded'
|
|
54
|
+
},
|
|
55
|
+
body: createSearchParams(params)
|
|
56
|
+
};
|
|
57
|
+
return fetchJson(url, init);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Creates URLSearchParams from a request params object.
|
|
61
|
+
*/ function createSearchParams(params) {
|
|
62
|
+
const searchParams = new URLSearchParams();
|
|
63
|
+
for(const key in params){
|
|
64
|
+
const value = params[key];
|
|
65
|
+
if (value === undefined) continue;
|
|
66
|
+
if (typeof value === 'string') {
|
|
67
|
+
searchParams.append(key, value);
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (typeof value === 'number') {
|
|
71
|
+
searchParams.append(key, value.toString());
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
for (const val of value){
|
|
75
|
+
searchParams.append(key, val);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return searchParams;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
//# sourceMappingURL=prometheus-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/model/prometheus-client.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 { DatasourceSelector, fetchJson } from '@perses-dev/core';\nimport {\n InstantQueryRequestParameters,\n InstantQueryResponse,\n LabelNamesRequestParameters,\n LabelNamesResponse,\n LabelValuesRequestParameters,\n LabelValuesResponse,\n RangeQueryRequestParameters,\n RangeQueryResponse,\n} from './api-types';\n\nexport interface QueryOptions {\n datasource: PrometheusDatasourceSpec;\n}\n\nexport interface PrometheusDatasourceSpec {\n // TODO: Make optional for proxy scenario\n direct_url: string;\n}\n\nexport interface PrometheusDatasourceSelector extends DatasourceSelector {\n kind: 'PrometheusDatasource';\n}\n\n/**\n * Calls the `/api/v1/query` endpoint to get metrics data.\n */\nexport function instantQuery(params: InstantQueryRequestParameters, queryOptions: QueryOptions) {\n return fetchWithPost<InstantQueryRequestParameters, InstantQueryResponse>('/api/v1/query', params, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/query_range` endpoint to get metrics data.\n */\nexport function rangeQuery(params: RangeQueryRequestParameters, queryOptions: QueryOptions) {\n return fetchWithPost<RangeQueryRequestParameters, RangeQueryResponse>('/api/v1/query_range', params, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/labels` endpoint to get a list of label names.\n */\nexport function labelNames(params: LabelNamesRequestParameters, queryOptions: QueryOptions) {\n return fetchWithPost<LabelNamesRequestParameters, LabelNamesResponse>('/api/v1/labels', params, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/label/{labelName}/values` endpoint to get a list of values for a label.\n */\nexport function labelValues(params: LabelValuesRequestParameters, queryOptions: QueryOptions) {\n const { labelName, ...searchParams } = params;\n const apiURI = `/api/v1/label/${encodeURIComponent(labelName)}/values`;\n return fetchWithGet<typeof searchParams, LabelValuesResponse>(apiURI, searchParams, queryOptions);\n}\n\nfunction fetchWithGet<T extends RequestParams<T>, TResponse>(apiURI: string, params: T, queryOptions: QueryOptions) {\n const {\n datasource: { direct_url: datasourceURL },\n } = queryOptions;\n\n let url = `${datasourceURL}${apiURI}`;\n const urlParams = createSearchParams(params).toString();\n if (urlParams !== '') {\n url += `?${urlParams}`;\n }\n return fetchJson<TResponse>(url, { method: 'GET' });\n}\n\nfunction fetchWithPost<T extends RequestParams<T>, TResponse>(apiURI: string, params: T, queryOptions: QueryOptions) {\n const {\n datasource: { direct_url: datasourceURL },\n } = queryOptions;\n\n const url = `${datasourceURL}${apiURI}`;\n const init = {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/x-www-form-urlencoded',\n },\n body: createSearchParams(params),\n };\n return fetchJson<TResponse>(url, init);\n}\n\n// Request parameter values we know how to serialize\ntype ParamValue = string | string[] | number | undefined;\n\n// Used to constrain the types that can be passed to createSearchParams to\n// just the ones we know how to serialize\ntype RequestParams<T> = {\n [K in keyof T]: ParamValue;\n};\n\n/**\n * Creates URLSearchParams from a request params object.\n */\nfunction createSearchParams<T extends RequestParams<T>>(params: T) {\n const searchParams = new URLSearchParams();\n for (const key in params) {\n const value: ParamValue = params[key];\n if (value === undefined) continue;\n\n if (typeof value === 'string') {\n searchParams.append(key, value);\n continue;\n }\n\n if (typeof value === 'number') {\n searchParams.append(key, value.toString());\n continue;\n }\n\n for (const val of value) {\n searchParams.append(key, val);\n }\n }\n return searchParams;\n}\n"],"names":["fetchJson","instantQuery","params","queryOptions","fetchWithPost","rangeQuery","labelNames","labelValues","labelName","searchParams","apiURI","encodeURIComponent","fetchWithGet","datasource","direct_url","datasourceURL","url","urlParams","createSearchParams","toString","method","init","headers","body","URLSearchParams","key","value","undefined","append","val"],"mappings":"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"}
|
package/dist/model/templating.js
CHANGED
|
@@ -1 +1,21 @@
|
|
|
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 { useTemplateVariableValues } from '@perses-dev/plugin-system';
|
|
14
|
+
import { replaceTemplateVariables, parseTemplateVariables } from './utils';
|
|
15
|
+
export function useReplaceTemplateString(templateString) {
|
|
16
|
+
const templateVariablesInTemplate = parseTemplateVariables(templateString || '');
|
|
17
|
+
const variables = useTemplateVariableValues(templateVariablesInTemplate);
|
|
18
|
+
return replaceTemplateVariables(templateString || '', variables);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=templating.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/model/templating.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 { useTemplateVariableValues } from '@perses-dev/plugin-system';\nimport { replaceTemplateVariables, parseTemplateVariables } from './utils';\n\n/**\n * Type alias to indicate what parts of the API support template variables.\n */\nexport type TemplateString = string;\n\nexport function useReplaceTemplateString(templateString?: TemplateString) {\n const templateVariablesInTemplate = parseTemplateVariables(templateString || '');\n const variables = useTemplateVariableValues(templateVariablesInTemplate);\n return replaceTemplateVariables(templateString || '', variables);\n}\n"],"names":["useTemplateVariableValues","replaceTemplateVariables","parseTemplateVariables","useReplaceTemplateString","templateString","templateVariablesInTemplate","variables"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,yBAAyB,QAAQ,2BAA2B,CAAC;AACtE,SAASC,wBAAwB,EAAEC,sBAAsB,QAAQ,SAAS,CAAC;AAO3E,OAAO,SAASC,wBAAwB,CAACC,cAA+B,EAAE;IACxE,MAAMC,2BAA2B,GAAGH,sBAAsB,CAACE,cAAc,IAAI,EAAE,CAAC,AAAC;IACjF,MAAME,SAAS,GAAGN,yBAAyB,CAACK,2BAA2B,CAAC,AAAC;IACzE,OAAOJ,wBAAwB,CAACG,cAAc,IAAI,EAAE,EAAEE,SAAS,CAAC,CAAC;AACnE,CAAC"}
|
package/dist/model/time.d.ts
CHANGED
|
@@ -1,23 +1,22 @@
|
|
|
1
|
-
import { DurationString } from '@perses-dev/core';
|
|
1
|
+
import { AbsoluteTimeRange, DurationString } from '@perses-dev/core';
|
|
2
2
|
import { UnixTimestampSeconds } from './api-types';
|
|
3
3
|
export interface PrometheusTimeRange {
|
|
4
4
|
start: UnixTimestampSeconds;
|
|
5
5
|
end: UnixTimestampSeconds;
|
|
6
6
|
}
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* Converts an AbsoluteTimeRange to Prometheus time in Unix time (i.e. in seconds).
|
|
9
9
|
*/
|
|
10
|
-
export declare function
|
|
10
|
+
export declare function getPrometheusTimeRange(timeRange: AbsoluteTimeRange): {
|
|
11
11
|
start: number;
|
|
12
12
|
end: number;
|
|
13
13
|
};
|
|
14
14
|
/**
|
|
15
|
-
* Gets the step to use for a
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* a Prom query.
|
|
15
|
+
* Gets the step to use for a Prom range query. Tries to take into account a suggested step size (probably based on the
|
|
16
|
+
* width of a visualization where the data will be graphed), any minimum step/resolution set by the user, and a "safe"
|
|
17
|
+
* step based on the max data points we want to allow returning from a Prom query.
|
|
19
18
|
*/
|
|
20
|
-
export declare function
|
|
19
|
+
export declare function getRangeStep(timeRange: PrometheusTimeRange, minStepSeconds?: number, resolution?: number, suggestedStepMs?: number): number;
|
|
21
20
|
/**
|
|
22
21
|
* Converts a DurationString to seconds, rounding down.
|
|
23
22
|
*/
|
package/dist/model/time.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time.d.ts","sourceRoot":"","sources":["../../src/model/time.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,
|
|
1
|
+
{"version":3,"file":"time.d.ts","sourceRoot":"","sources":["../../src/model/time.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAuB,MAAM,kBAAkB,CAAC;AAE1F,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,oBAAoB,CAAC;IAC5B,GAAG,EAAE,oBAAoB,CAAC;CAC3B;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,iBAAiB;;;EAMlE;AAMD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,mBAAmB,EAAE,cAAc,SAAK,EAAE,UAAU,SAAI,EAAE,eAAe,SAAI,UAUpH;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,cAAc,CAAC,EAAE,cAAc,sBAMvE"}
|
package/dist/model/time.js
CHANGED
|
@@ -1 +1,49 @@
|
|
|
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 { parseDurationString } from '@perses-dev/core';
|
|
14
|
+
import { milliseconds, getUnixTime } from 'date-fns';
|
|
15
|
+
/**
|
|
16
|
+
* Converts an AbsoluteTimeRange to Prometheus time in Unix time (i.e. in seconds).
|
|
17
|
+
*/ export function getPrometheusTimeRange(timeRange) {
|
|
18
|
+
const { start , end } = timeRange;
|
|
19
|
+
return {
|
|
20
|
+
start: Math.ceil(getUnixTime(start)),
|
|
21
|
+
end: Math.ceil(getUnixTime(end))
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
// Max data points to allow returning from a Prom Query, used to calculate a
|
|
25
|
+
// "safe" step for a range query
|
|
26
|
+
const MAX_PROM_DATA_POINTS = 10000;
|
|
27
|
+
/**
|
|
28
|
+
* Gets the step to use for a Prom range query. Tries to take into account a suggested step size (probably based on the
|
|
29
|
+
* width of a visualization where the data will be graphed), any minimum step/resolution set by the user, and a "safe"
|
|
30
|
+
* step based on the max data points we want to allow returning from a Prom query.
|
|
31
|
+
*/ export function getRangeStep(timeRange, minStepSeconds = 15, resolution = 1, suggestedStepMs = 0) {
|
|
32
|
+
const suggestedStepSeconds = suggestedStepMs / 1000;
|
|
33
|
+
const queryRangeSeconds = timeRange.end - timeRange.start;
|
|
34
|
+
let safeStep = queryRangeSeconds / MAX_PROM_DATA_POINTS;
|
|
35
|
+
if (safeStep > 1) {
|
|
36
|
+
safeStep = Math.ceil(safeStep);
|
|
37
|
+
}
|
|
38
|
+
return Math.max(suggestedStepSeconds * resolution, minStepSeconds, safeStep);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Converts a DurationString to seconds, rounding down.
|
|
42
|
+
*/ export function getDurationStringSeconds(durationString) {
|
|
43
|
+
if (durationString === undefined) return undefined;
|
|
44
|
+
const duration = parseDurationString(durationString);
|
|
45
|
+
const ms = milliseconds(duration);
|
|
46
|
+
return Math.floor(ms / 1000);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
//# sourceMappingURL=time.js.map
|