@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
package/plugin.json
CHANGED
|
@@ -7,35 +7,43 @@
|
|
|
7
7
|
"plugins": [
|
|
8
8
|
{
|
|
9
9
|
"pluginType": "Variable",
|
|
10
|
-
"kind": "
|
|
10
|
+
"kind": "StaticListVariable",
|
|
11
11
|
"display": {
|
|
12
|
-
"name": "
|
|
13
|
-
"description": ""
|
|
12
|
+
"name": "Static List Variable",
|
|
13
|
+
"description": "Static list variables allow you to define an array of values"
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
16
|
{
|
|
17
17
|
"pluginType": "Variable",
|
|
18
|
-
"kind": "
|
|
18
|
+
"kind": "PrometheusLabelValuesVariable",
|
|
19
19
|
"display": {
|
|
20
|
-
"name": "
|
|
20
|
+
"name": "PrometheusLabelValuesVariable",
|
|
21
21
|
"description": ""
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
24
|
{
|
|
25
25
|
"pluginType": "Variable",
|
|
26
|
-
"kind": "
|
|
26
|
+
"kind": "PrometheusLabelNamesVariable",
|
|
27
27
|
"display": {
|
|
28
|
-
"name": "
|
|
28
|
+
"name": "PrometheusLabelNamesVariable",
|
|
29
29
|
"description": ""
|
|
30
30
|
}
|
|
31
31
|
},
|
|
32
32
|
{
|
|
33
|
-
"pluginType": "
|
|
34
|
-
"kind": "
|
|
33
|
+
"pluginType": "TimeSeriesQuery",
|
|
34
|
+
"kind": "PrometheusTimeSeriesQuery",
|
|
35
35
|
"display": {
|
|
36
36
|
"name": "Prometheus Range Query",
|
|
37
37
|
"description": ""
|
|
38
38
|
}
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"pluginType": "Datasource",
|
|
42
|
+
"kind": "PrometheusDatasource",
|
|
43
|
+
"display": {
|
|
44
|
+
"name": "Prometheus Datasource",
|
|
45
|
+
"description": ""
|
|
46
|
+
}
|
|
39
47
|
}
|
|
40
48
|
]
|
|
41
49
|
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright 2021 The Perses Authors
|
|
3
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
// you may not use this file except in compliance with the License.
|
|
5
|
-
// You may obtain a copy of the License at
|
|
6
|
-
//
|
|
7
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
//
|
|
9
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
// See the License for the specific language governing permissions and
|
|
13
|
-
// limitations under the License.
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.usePrometheusConfig = void 0;
|
|
16
|
-
const plugin_system_1 = require("@perses-dev/plugin-system");
|
|
17
|
-
function isPrometheusDatasource(def) {
|
|
18
|
-
return def.kind === 'Prometheus';
|
|
19
|
-
}
|
|
20
|
-
function usePrometheusConfig(selector) {
|
|
21
|
-
const datasources = (0, plugin_system_1.useDatasources)();
|
|
22
|
-
const models = selector === undefined ? [datasources.defaultDatasource] : datasources.getDatasources(selector);
|
|
23
|
-
if (models.length > 1) {
|
|
24
|
-
throw new Error('More than one Datasource found');
|
|
25
|
-
}
|
|
26
|
-
const model = models[0];
|
|
27
|
-
if (model === undefined) {
|
|
28
|
-
throw new Error('Datasource not found');
|
|
29
|
-
}
|
|
30
|
-
const spec = model.spec;
|
|
31
|
-
if (isPrometheusDatasource(spec)) {
|
|
32
|
-
return { ...model, spec };
|
|
33
|
-
}
|
|
34
|
-
throw new Error('Datasource is not a valid Prometheus Datasource');
|
|
35
|
-
}
|
|
36
|
-
exports.usePrometheusConfig = usePrometheusConfig;
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright 2022 The Perses Authors
|
|
3
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
// you may not use this file except in compliance with the License.
|
|
5
|
-
// You may obtain a copy of the License at
|
|
6
|
-
//
|
|
7
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
//
|
|
9
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
// See the License for the specific language governing permissions and
|
|
13
|
-
// limitations under the License.
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.PrometheusGraphQuery = void 0;
|
|
16
|
-
const core_1 = require("@perses-dev/core");
|
|
17
|
-
const date_fns_1 = require("date-fns");
|
|
18
|
-
const react_1 = require("react");
|
|
19
|
-
const parse_sample_values_1 = require("../model/parse-sample-values");
|
|
20
|
-
const prometheus_client_1 = require("../model/prometheus-client");
|
|
21
|
-
const templating_1 = require("../model/templating");
|
|
22
|
-
const time_1 = require("../model/time");
|
|
23
|
-
function usePrometheusGraphQuery(definition, hookOptions) {
|
|
24
|
-
const minStep = (0, time_1.getDurationStringSeconds)(definition.options.min_step);
|
|
25
|
-
const timeRange = (0, time_1.useDashboardPrometheusTimeRange)();
|
|
26
|
-
const step = (0, time_1.usePanelRangeStep)(timeRange, minStep, undefined, hookOptions === null || hookOptions === void 0 ? void 0 : hookOptions.suggestedStepMs);
|
|
27
|
-
// Align the time range so that it's a multiple of the step (TODO: we may
|
|
28
|
-
// ultimately want to return this from the hook so that charts will know what
|
|
29
|
-
// time range was actually used?)
|
|
30
|
-
const { start, end } = (0, core_1.useMemoized)(() => {
|
|
31
|
-
const { start, end } = timeRange;
|
|
32
|
-
const utcOffsetSec = new Date().getTimezoneOffset() * 60;
|
|
33
|
-
const alignedEnd = Math.floor((end + utcOffsetSec) / step) * step - utcOffsetSec;
|
|
34
|
-
const alignedStart = Math.floor((start + utcOffsetSec) / step) * step - utcOffsetSec;
|
|
35
|
-
return {
|
|
36
|
-
start: alignedStart,
|
|
37
|
-
end: alignedEnd,
|
|
38
|
-
};
|
|
39
|
-
}, [timeRange, step]);
|
|
40
|
-
const query = (0, templating_1.useReplaceTemplateString)(definition.options.query.replace('$__rate_interval', `15s`));
|
|
41
|
-
const request = {
|
|
42
|
-
query,
|
|
43
|
-
start,
|
|
44
|
-
end,
|
|
45
|
-
step,
|
|
46
|
-
};
|
|
47
|
-
const { data: response, isLoading: loading, error, } = (0, prometheus_client_1.useRangeQuery)(request, {
|
|
48
|
-
enabled: true,
|
|
49
|
-
});
|
|
50
|
-
const data = (0, react_1.useMemo)(() => {
|
|
51
|
-
if (response === undefined)
|
|
52
|
-
return undefined;
|
|
53
|
-
if (response.status === 'error')
|
|
54
|
-
return undefined;
|
|
55
|
-
// TODO: Maybe do a proper Iterable implementation that defers some of this
|
|
56
|
-
// processing until its needed
|
|
57
|
-
const chartData = {
|
|
58
|
-
timeRange: { start: (0, date_fns_1.fromUnixTime)(start), end: (0, date_fns_1.fromUnixTime)(end) },
|
|
59
|
-
stepMs: step * 1000,
|
|
60
|
-
series: response.data.result.map((value) => {
|
|
61
|
-
const { metric, values } = value;
|
|
62
|
-
// Name the series after the metric labels or if no metric, just use the
|
|
63
|
-
// overall query
|
|
64
|
-
let name = Object.entries(metric)
|
|
65
|
-
.map(([labelName, labelValue]) => `${labelName}="${labelValue}"`)
|
|
66
|
-
.join(', ');
|
|
67
|
-
if (name === '')
|
|
68
|
-
name = query;
|
|
69
|
-
return {
|
|
70
|
-
name,
|
|
71
|
-
values: values.map(parse_sample_values_1.parseValueTuple),
|
|
72
|
-
};
|
|
73
|
-
}),
|
|
74
|
-
};
|
|
75
|
-
return chartData;
|
|
76
|
-
}, [response, start, end, step, query]);
|
|
77
|
-
return { data, loading, error: error !== null && error !== void 0 ? error : undefined };
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* The core Prometheus GraphQuery plugin for Perses.
|
|
81
|
-
*/
|
|
82
|
-
exports.PrometheusGraphQuery = {
|
|
83
|
-
useGraphQuery: usePrometheusGraphQuery,
|
|
84
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { DatasourceSelector, DatasourceSpecDefinition, HTTPConfig } from '@perses-dev/core';
|
|
2
|
-
export interface PrometheusSpecDatasource extends DatasourceSpecDefinition {
|
|
3
|
-
kind: 'Prometheus';
|
|
4
|
-
http: HTTPConfig;
|
|
5
|
-
}
|
|
6
|
-
export declare function usePrometheusConfig(selector?: DatasourceSelector): {
|
|
7
|
-
spec: PrometheusSpecDatasource;
|
|
8
|
-
kind: "GlobalDatasource";
|
|
9
|
-
metadata: import("@perses-dev/core").Metadata;
|
|
10
|
-
};
|
|
11
|
-
//# sourceMappingURL=datasource.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"datasource.d.ts","sourceRoot":"","sources":["../../src/model/datasource.ts"],"names":[],"mappings":"AAaA,OAAO,EAEL,kBAAkB,EAClB,wBAAwB,EACxB,UAAU,EACX,MAAM,kBAAkB,CAAC;AAG1B,MAAM,WAAW,wBAAyB,SAAQ,wBAAwB;IACxE,IAAI,EAAE,YAAY,CAAC;IACnB,IAAI,EAAE,UAAU,CAAC;CAClB;AAMD,wBAAgB,mBAAmB,CAAC,QAAQ,CAAC,EAAE,kBAAkB;;;;EAmBhE"}
|
package/dist/model/datasource.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{useDatasources}from"@perses-dev/plugin-system";function isPrometheusDatasource(e){return"Prometheus"===e.kind}export function usePrometheusConfig(e){const o=useDatasources(),r=void 0===e?[o.defaultDatasource]:o.getDatasources(e);if(r.length>1)throw new Error("More than one Datasource found");const t=r[0];if(void 0===t)throw new Error("Datasource not found");const s=t.spec;if(isPrometheusDatasource(s))return{...t,spec:s};throw new Error("Datasource is not a valid Prometheus Datasource")}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { DurationString, JsonObject } from '@perses-dev/core';
|
|
2
|
-
import { GraphQueryPlugin } from '@perses-dev/plugin-system';
|
|
3
|
-
import { TemplateString } from '../model/templating';
|
|
4
|
-
interface PrometheusGraphQueryOptions extends JsonObject {
|
|
5
|
-
query: TemplateString;
|
|
6
|
-
min_step?: DurationString;
|
|
7
|
-
resolution?: number;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* The core Prometheus GraphQuery plugin for Perses.
|
|
11
|
-
*/
|
|
12
|
-
export declare const PrometheusGraphQuery: GraphQueryPlugin<PrometheusGraphQueryOptions>;
|
|
13
|
-
export {};
|
|
14
|
-
//# sourceMappingURL=graph-query.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"graph-query.d.ts","sourceRoot":"","sources":["../../src/plugins/graph-query.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAE,UAAU,EAAe,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAGL,gBAAgB,EAGjB,MAAM,2BAA2B,CAAC;AAMnC,OAAO,EAAE,cAAc,EAA4B,MAAM,qBAAqB,CAAC;AAG/E,UAAU,2BAA4B,SAAQ,UAAU;IACtD,KAAK,EAAE,cAAc,CAAC;IACtB,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AA2ED;;GAEG;AACH,eAAO,MAAM,oBAAoB,EAAE,gBAAgB,CAAC,2BAA2B,CAE9E,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{useMemoized}from"@perses-dev/core";import{fromUnixTime}from"date-fns";import{useMemo}from"react";import{parseValueTuple}from"../model/parse-sample-values";import{useRangeQuery}from"../model/prometheus-client";import{useReplaceTemplateString}from"../model/templating";import{getDurationStringSeconds,useDashboardPrometheusTimeRange,usePanelRangeStep}from"../model/time";function usePrometheusGraphQuery(e,r){const t=getDurationStringSeconds(e.options.min_step),o=useDashboardPrometheusTimeRange(),s=usePanelRangeStep(o,t,void 0,null==r?void 0:r.suggestedStepMs),{start:a,end:n}=useMemoized((()=>{const{start:e,end:r}=o,t=60*(new Date).getTimezoneOffset(),a=Math.floor((r+t)/s)*s-t;return{start:Math.floor((e+t)/s)*s-t,end:a}}),[o,s]),m=useReplaceTemplateString(e.options.query.replace("$__rate_interval","15s")),u={query:m,start:a,end:n,step:s},{data:i,isLoading:p,error:l}=useRangeQuery(u,{enabled:!0});return{data:useMemo((()=>{if(void 0!==i&&"error"!==i.status)return{timeRange:{start:fromUnixTime(a),end:fromUnixTime(n)},stepMs:1e3*s,series:i.data.result.map((e=>{const{metric:r,values:t}=e;let o=Object.entries(r).map((([e,r])=>`${e}="${r}"`)).join(", ");return""===o&&(o=m),{name:o,values:t.map(parseValueTuple)}}))}}),[i,a,n,s,m]),loading:p,error:null!=l?l:void 0}}export const PrometheusGraphQuery={useGraphQuery:usePrometheusGraphQuery};
|