@perses-dev/prometheus-plugin 0.47.1 → 0.48.0-rc0
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 +1 -2
- package/dist/cjs/model/prometheus-client.js +14 -0
- package/dist/cjs/plugins/prometheus-datasource.js +8 -0
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/dist/model/api-types.d.ts +5 -2
- package/dist/model/api-types.d.ts.map +1 -1
- package/dist/model/api-types.js.map +1 -1
- package/dist/model/prometheus-client.d.ts +11 -1
- package/dist/model/prometheus-client.d.ts.map +1 -1
- package/dist/model/prometheus-client.js +12 -0
- package/dist/model/prometheus-client.js.map +1 -1
- package/dist/plugins/prometheus-datasource.d.ts.map +1 -1
- package/dist/plugins/prometheus-datasource.js +9 -1
- package/dist/plugins/prometheus-datasource.js.map +1 -1
- package/package.json +4 -4
package/dist/cjs/index.js
CHANGED
|
@@ -44,8 +44,7 @@ const _prometheustimeseriesquery = require("./plugins/prometheus-time-series-que
|
|
|
44
44
|
const _variable = require("./plugins/variable");
|
|
45
45
|
const _prometheusvariables = require("./plugins/prometheus-variables");
|
|
46
46
|
const _prometheusdatasource = require("./plugins/prometheus-datasource");
|
|
47
|
-
_export_star(require("./model
|
|
48
|
-
_export_star(require("./model/api-types"), exports);
|
|
47
|
+
_export_star(require("./model"), exports);
|
|
49
48
|
_export_star(require("./plugins/types"), exports);
|
|
50
49
|
function _export_star(from, to) {
|
|
51
50
|
Object.keys(from).forEach(function(k) {
|
|
@@ -36,8 +36,14 @@ _export(exports, {
|
|
|
36
36
|
labelValues: function() {
|
|
37
37
|
return labelValues;
|
|
38
38
|
},
|
|
39
|
+
metricMetadata: function() {
|
|
40
|
+
return metricMetadata;
|
|
41
|
+
},
|
|
39
42
|
rangeQuery: function() {
|
|
40
43
|
return rangeQuery;
|
|
44
|
+
},
|
|
45
|
+
series: function() {
|
|
46
|
+
return series;
|
|
41
47
|
}
|
|
42
48
|
});
|
|
43
49
|
const _core = require("@perses-dev/core");
|
|
@@ -77,6 +83,14 @@ function labelValues(params, queryOptions) {
|
|
|
77
83
|
const apiURI = `/api/v1/label/${encodeURIComponent(labelName)}/values`;
|
|
78
84
|
return fetchWithGet(apiURI, searchParams, queryOptions);
|
|
79
85
|
}
|
|
86
|
+
function metricMetadata(params, queryOptions) {
|
|
87
|
+
const apiURI = `/api/v1/metadata`;
|
|
88
|
+
return fetchWithGet(apiURI, params, queryOptions);
|
|
89
|
+
}
|
|
90
|
+
function series(params, queryOptions) {
|
|
91
|
+
const apiURI = `/api/v1/series`;
|
|
92
|
+
return fetchWithPost(apiURI, params, queryOptions);
|
|
93
|
+
}
|
|
80
94
|
function fetchWithGet(apiURI, params, queryOptions) {
|
|
81
95
|
const { datasourceUrl } = queryOptions;
|
|
82
96
|
let url = `${datasourceUrl}${apiURI}`;
|
|
@@ -57,6 +57,14 @@ const _PrometheusDatasourceEditor = require("./PrometheusDatasourceEditor");
|
|
|
57
57
|
labelValues: (params, headers)=>(0, _model.labelValues)(params, {
|
|
58
58
|
datasourceUrl,
|
|
59
59
|
headers: headers !== null && headers !== void 0 ? headers : specHeaders
|
|
60
|
+
}),
|
|
61
|
+
metricMetadata: (params, headers)=>(0, _model.metricMetadata)(params, {
|
|
62
|
+
datasourceUrl,
|
|
63
|
+
headers: headers !== null && headers !== void 0 ? headers : specHeaders
|
|
64
|
+
}),
|
|
65
|
+
series: (params, headers)=>(0, _model.series)(params, {
|
|
66
|
+
datasourceUrl,
|
|
67
|
+
headers: headers !== null && headers !== void 0 ? headers : specHeaders
|
|
60
68
|
})
|
|
61
69
|
};
|
|
62
70
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,6 @@ import { StaticListVariable } from './plugins/variable';
|
|
|
3
3
|
import { PrometheusLabelNamesVariable, PrometheusLabelValuesVariable, PrometheusPromQLVariable } from './plugins/prometheus-variables';
|
|
4
4
|
import { PrometheusDatasource } from './plugins/prometheus-datasource';
|
|
5
5
|
export { PrometheusTimeSeriesQuery, StaticListVariable, PrometheusLabelNamesVariable, PrometheusLabelValuesVariable, PrometheusPromQLVariable, PrometheusDatasource, };
|
|
6
|
-
export * from './model
|
|
7
|
-
export * from './model/api-types';
|
|
6
|
+
export * from './model';
|
|
8
7
|
export * from './plugins/types';
|
|
9
8
|
//# 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,yBAAyB,EAAE,MAAM,wCAAwC,CAAC;AAEnF,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EACL,4BAA4B,EAC5B,6BAA6B,EAC7B,wBAAwB,EACzB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAGvE,OAAO,EACL,yBAAyB,EACzB,kBAAkB,EAClB,4BAA4B,EAC5B,6BAA6B,EAC7B,wBAAwB,EACxB,oBAAoB,GACrB,CAAC;AAGF,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,yBAAyB,EAAE,MAAM,wCAAwC,CAAC;AAEnF,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EACL,4BAA4B,EAC5B,6BAA6B,EAC7B,wBAAwB,EACzB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAGvE,OAAO,EACL,yBAAyB,EACzB,kBAAkB,EAClB,4BAA4B,EAC5B,6BAA6B,EAC7B,wBAAwB,EACxB,oBAAoB,GACrB,CAAC;AAGF,cAAc,SAAS,CAAC;AAExB,cAAc,iBAAiB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -18,8 +18,7 @@ import { PrometheusDatasource } from './plugins/prometheus-datasource';
|
|
|
18
18
|
// Export plugins under the same name as the kinds they handle from the plugin.json
|
|
19
19
|
export { PrometheusTimeSeriesQuery, StaticListVariable, PrometheusLabelNamesVariable, PrometheusLabelValuesVariable, PrometheusPromQLVariable, PrometheusDatasource };
|
|
20
20
|
// For consumers to leverage in DatasourceStoreProvider onCreate
|
|
21
|
-
export * from './model
|
|
22
|
-
export * from './model/api-types';
|
|
21
|
+
export * from './model';
|
|
23
22
|
export * from './plugins/types';
|
|
24
23
|
|
|
25
24
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { PrometheusTimeSeriesQuery } from './plugins/prometheus-time-series-query';\n// @TODO: Move this to a more generic location;\nimport { StaticListVariable } from './plugins/variable';\nimport {\n PrometheusLabelNamesVariable,\n PrometheusLabelValuesVariable,\n PrometheusPromQLVariable,\n} 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 PrometheusPromQLVariable,\n PrometheusDatasource,\n};\n\n// For consumers to leverage in DatasourceStoreProvider onCreate\nexport * from './model
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { PrometheusTimeSeriesQuery } from './plugins/prometheus-time-series-query';\n// @TODO: Move this to a more generic location;\nimport { StaticListVariable } from './plugins/variable';\nimport {\n PrometheusLabelNamesVariable,\n PrometheusLabelValuesVariable,\n PrometheusPromQLVariable,\n} 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 PrometheusPromQLVariable,\n PrometheusDatasource,\n};\n\n// For consumers to leverage in DatasourceStoreProvider onCreate\nexport * from './model';\n\nexport * from './plugins/types';\n"],"names":["PrometheusTimeSeriesQuery","StaticListVariable","PrometheusLabelNamesVariable","PrometheusLabelValuesVariable","PrometheusPromQLVariable","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,yCAAyC;AACnF,+CAA+C;AAC/C,SAASC,kBAAkB,QAAQ,qBAAqB;AACxD,SACEC,4BAA4B,EAC5BC,6BAA6B,EAC7BC,wBAAwB,QACnB,iCAAiC;AACxC,SAASC,oBAAoB,QAAQ,kCAAkC;AAEvE,mFAAmF;AACnF,SACEL,yBAAyB,EACzBC,kBAAkB,EAClBC,4BAA4B,EAC5BC,6BAA6B,EAC7BC,wBAAwB,EACxBC,oBAAoB,GACpB;AAEF,gEAAgE;AAChE,cAAc,UAAU;AAExB,cAAc,kBAAkB"}
|
|
@@ -51,14 +51,16 @@ export interface RangeQueryRequestParameters {
|
|
|
51
51
|
export type RangeQueryResponse = ApiResponse<MatrixData>;
|
|
52
52
|
export interface SeriesRequestParameters {
|
|
53
53
|
'match[]': string[];
|
|
54
|
-
start
|
|
55
|
-
end
|
|
54
|
+
start?: UnixTimestampSeconds;
|
|
55
|
+
end?: UnixTimestampSeconds;
|
|
56
|
+
limit?: number;
|
|
56
57
|
}
|
|
57
58
|
export type SeriesResponse = ApiResponse<Metric[]>;
|
|
58
59
|
export interface LabelNamesRequestParameters {
|
|
59
60
|
start?: UnixTimestampSeconds;
|
|
60
61
|
end?: UnixTimestampSeconds;
|
|
61
62
|
'match[]'?: string[];
|
|
63
|
+
limit?: number;
|
|
62
64
|
}
|
|
63
65
|
export type LabelNamesResponse = ApiResponse<string[]>;
|
|
64
66
|
export interface LabelValuesRequestParameters {
|
|
@@ -66,6 +68,7 @@ export interface LabelValuesRequestParameters {
|
|
|
66
68
|
start?: UnixTimestampSeconds;
|
|
67
69
|
end?: UnixTimestampSeconds;
|
|
68
70
|
'match[]'?: string[];
|
|
71
|
+
limit?: number;
|
|
69
72
|
}
|
|
70
73
|
export type LabelValuesResponse = ApiResponse<string[]>;
|
|
71
74
|
export interface MetricMetadata {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-types.d.ts","sourceRoot":"","sources":["../../src/model/api-types.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAGlD,YAAY,EAAE,cAAc,EAAE,CAAC;AAE/B,MAAM,WAAW,eAAe,CAAC,CAAC;IAChC,MAAM,EAAE,SAAS,CAAC;IAClB,IAAI,EAAE,CAAC,CAAC;IACR,WAAW,CAAC,EA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AAoB,CAAC;IAC7B,GAAG,CAAC,EAAE,oBAAoB,CAAC;IAC3B,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,MAAM,kBAAkB,GAAG,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC;AAEvD,MAAM,WAAW,4BAA4B;IAC3C,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,oBAAoB,CAAC;IAC7B,GAAG,CAAC,EAAE,oBAAoB,CAAC;IAC3B,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,MAAM,mBAAmB,GAAG,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC;AAExD,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,+BAA+B;IAC9C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,MAAM,sBAAsB,GAAG,WAAW,CAAC,MAAM,CAAC,MAAM,EAAE,cAAc,EAAE,CAAC,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/model/api-types.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { 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 rawResponse?: Response;\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
|
|
1
|
+
{"version":3,"sources":["../../src/model/api-types.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { 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 rawResponse?: Response;\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 limit?: number;\n}\n\nexport type SeriesResponse = ApiResponse<Metric[]>;\n\nexport interface LabelNamesRequestParameters {\n start?: UnixTimestampSeconds;\n end?: UnixTimestampSeconds;\n 'match[]'?: string[];\n limit?: number;\n}\n\nexport type LabelNamesResponse = ApiResponse<string[]>;\n\nexport interface LabelValuesRequestParameters {\n labelName: string;\n start?: UnixTimestampSeconds;\n end?: UnixTimestampSeconds;\n 'match[]'?: string[];\n limit?: number;\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;AA6GjC,WAAmF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { RequestHeaders } from '@perses-dev/core';
|
|
2
2
|
import { DatasourceClient } from '@perses-dev/plugin-system';
|
|
3
|
-
import { InstantQueryRequestParameters, InstantQueryResponse, LabelNamesRequestParameters, LabelNamesResponse, LabelValuesRequestParameters, LabelValuesResponse, RangeQueryRequestParameters, RangeQueryResponse } from './api-types';
|
|
3
|
+
import { InstantQueryRequestParameters, InstantQueryResponse, LabelNamesRequestParameters, LabelNamesResponse, LabelValuesRequestParameters, LabelValuesResponse, MetricMetadataRequestParameters, MetricMetadataResponse, RangeQueryRequestParameters, RangeQueryResponse, SeriesRequestParameters, SeriesResponse } from './api-types';
|
|
4
4
|
interface PrometheusClientOptions {
|
|
5
5
|
datasourceUrl: string;
|
|
6
6
|
headers?: RequestHeaders;
|
|
@@ -11,6 +11,8 @@ export interface PrometheusClient extends DatasourceClient {
|
|
|
11
11
|
rangeQuery(params: RangeQueryRequestParameters, headers?: RequestHeaders): Promise<RangeQueryResponse>;
|
|
12
12
|
labelNames(params: LabelNamesRequestParameters, headers?: RequestHeaders): Promise<LabelNamesResponse>;
|
|
13
13
|
labelValues(params: LabelValuesRequestParameters, headers?: RequestHeaders): Promise<LabelValuesResponse>;
|
|
14
|
+
metricMetadata(params: MetricMetadataRequestParameters, headers?: RequestHeaders): Promise<MetricMetadataResponse>;
|
|
15
|
+
series(params: SeriesRequestParameters, headers?: RequestHeaders): Promise<SeriesResponse>;
|
|
14
16
|
}
|
|
15
17
|
export interface QueryOptions {
|
|
16
18
|
datasourceUrl: string;
|
|
@@ -42,6 +44,14 @@ export declare function labelNames(params: LabelNamesRequestParameters, queryOpt
|
|
|
42
44
|
* Calls the `/api/v1/label/{labelName}/values` endpoint to get a list of values for a label.
|
|
43
45
|
*/
|
|
44
46
|
export declare function labelValues(params: LabelValuesRequestParameters, queryOptions: QueryOptions): Promise<LabelValuesResponse>;
|
|
47
|
+
/**
|
|
48
|
+
* Calls the `/api/v1/label/{labelName}/values` endpoint to get a list of values for a label.
|
|
49
|
+
*/
|
|
50
|
+
export declare function metricMetadata(params: MetricMetadataRequestParameters, queryOptions: QueryOptions): Promise<MetricMetadataResponse>;
|
|
51
|
+
/**
|
|
52
|
+
* Calls the `/api/v1/series` endpoint to finding series by label matchers.
|
|
53
|
+
*/
|
|
54
|
+
export declare function series(params: SeriesRequestParameters, queryOptions: QueryOptions): Promise<SeriesResponse>;
|
|
45
55
|
/**
|
|
46
56
|
* Fetch JSON and parse warnings for query inspector
|
|
47
57
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prometheus-client.d.ts","sourceRoot":"","sources":["../../src/model/prometheus-client.ts"],"names":[],"mappings":"AAaA,OAAO,EAAoB,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EACL,6BAA6B,EAC7B,oBAAoB,EACpB,2BAA2B,EAC3B,kBAAkB,EAClB,4BAA4B,EAC5B,mBAAmB,EACnB,2BAA2B,EAC3B,kBAAkB,
|
|
1
|
+
{"version":3,"file":"prometheus-client.d.ts","sourceRoot":"","sources":["../../src/model/prometheus-client.ts"],"names":[],"mappings":"AAaA,OAAO,EAAoB,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EACL,6BAA6B,EAC7B,oBAAoB,EACpB,2BAA2B,EAC3B,kBAAkB,EAClB,4BAA4B,EAC5B,mBAAmB,EACnB,+BAA+B,EAC/B,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E,YAAY;;GAEzF;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,2BAA2B,EAAE,YAAY,EAAE,YAAY;;GAEzF;AAED;;GAEG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,4BAA4B,EACpC,YAAY,EAAE,YAAY,GACzB,OAAO,CAAC,mBAAmB,CAAC,CAa9B;AAED;;GAEG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,+BAA+B,EACvC,YAAY,EAAE,YAAY,GACzB,OAAO,CAAC,sBAAsB,CAAC,CAGjC;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,uBAAuB,EAAE,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC,cAAc,CAAC,CAG3G;AA+DD;;GAEG;AACH,wBAAsB,YAAY,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,MAAM,CAAC,KAAK,CAAC;;GAI7E"}
|
|
@@ -57,6 +57,18 @@ import { fetch, fetchJson } from '@perses-dev/core';
|
|
|
57
57
|
const apiURI = `/api/v1/label/${encodeURIComponent(labelName)}/values`;
|
|
58
58
|
return fetchWithGet(apiURI, searchParams, queryOptions);
|
|
59
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Calls the `/api/v1/label/{labelName}/values` endpoint to get a list of values for a label.
|
|
62
|
+
*/ export function metricMetadata(params, queryOptions) {
|
|
63
|
+
const apiURI = `/api/v1/metadata`;
|
|
64
|
+
return fetchWithGet(apiURI, params, queryOptions);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Calls the `/api/v1/series` endpoint to finding series by label matchers.
|
|
68
|
+
*/ export function series(params, queryOptions) {
|
|
69
|
+
const apiURI = `/api/v1/series`;
|
|
70
|
+
return fetchWithPost(apiURI, params, queryOptions);
|
|
71
|
+
}
|
|
60
72
|
function fetchWithGet(apiURI, params, queryOptions) {
|
|
61
73
|
const { datasourceUrl } = queryOptions;
|
|
62
74
|
let url = `${datasourceUrl}${apiURI}`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/model/prometheus-client.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { fetch, fetchJson, RequestHeaders } from '@perses-dev/core';\nimport { DatasourceClient } from '@perses-dev/plugin-system';\nimport {\n InstantQueryRequestParameters,\n InstantQueryResponse,\n LabelNamesRequestParameters,\n LabelNamesResponse,\n LabelValuesRequestParameters,\n LabelValuesResponse,\n RangeQueryRequestParameters,\n RangeQueryResponse,\n SuccessResponse,\n} from './api-types';\n\ninterface PrometheusClientOptions {\n datasourceUrl: string;\n headers?: RequestHeaders;\n}\n\nexport interface PrometheusClient extends DatasourceClient {\n options: PrometheusClientOptions;\n instantQuery(params: InstantQueryRequestParameters, headers?: RequestHeaders): Promise<InstantQueryResponse>;\n rangeQuery(params: RangeQueryRequestParameters, headers?: RequestHeaders): Promise<RangeQueryResponse>;\n labelNames(params: LabelNamesRequestParameters, headers?: RequestHeaders): Promise<LabelNamesResponse>;\n labelValues(params: LabelValuesRequestParameters, headers?: RequestHeaders): Promise<LabelValuesResponse>;\n}\n\nexport interface QueryOptions {\n datasourceUrl: string;\n headers?: RequestHeaders;\n}\n\n/**\n * Calls the `/-/healthy` endpoint to check if the datasource is healthy.\n */\nexport function healthCheck(queryOptions: QueryOptions) {\n return async () => {\n const url = `${queryOptions.datasourceUrl}/-/healthy`;\n\n try {\n const resp = await fetch(url, { headers: queryOptions.headers });\n return resp.status === 200;\n } catch {\n return false;\n }\n };\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(\n params: LabelValuesRequestParameters,\n queryOptions: QueryOptions\n): Promise<LabelValuesResponse> {\n const { labelName, ...searchParams } = params;\n\n // In case label name is empty, we'll receive a 404, so we can replace it by an empty list, which is less confusing.\n // Note that an empty list is the prometheus result if the label does not exist.\n if (labelName.length === 0) {\n return new Promise((resolve) => {\n resolve({ data: [] as string[] } as SuccessResponse<string[]>);\n });\n }\n\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 { datasourceUrl } = 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 { datasourceUrl, headers } = queryOptions;\n\n const url = `${datasourceUrl}${apiURI}`;\n const init = {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/x-www-form-urlencoded',\n ...headers,\n },\n body: createSearchParams(params),\n };\n return fetchResults<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\n/**\n * Fetch JSON and parse warnings for query inspector\n */\nexport async function fetchResults<T>(...args: Parameters<typeof global.fetch>) {\n const response = await fetch(...args);\n const json: T = await response.json();\n return { ...json, rawResponse: response };\n}\n"],"names":["fetch","fetchJson","healthCheck","queryOptions","url","datasourceUrl","resp","headers","status","instantQuery","params","fetchWithPost","rangeQuery","labelNames","labelValues","labelName","searchParams","length","Promise","resolve","data","apiURI","encodeURIComponent","fetchWithGet","urlParams","createSearchParams","toString","method","init","body","fetchResults","URLSearchParams","key","value","undefined","append","val","args","response","json","rawResponse"],"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,KAAK,EAAEC,SAAS,QAAwB,mBAAmB;
|
|
1
|
+
{"version":3,"sources":["../../src/model/prometheus-client.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { fetch, fetchJson, RequestHeaders } from '@perses-dev/core';\nimport { DatasourceClient } from '@perses-dev/plugin-system';\nimport {\n InstantQueryRequestParameters,\n InstantQueryResponse,\n LabelNamesRequestParameters,\n LabelNamesResponse,\n LabelValuesRequestParameters,\n LabelValuesResponse,\n MetricMetadataRequestParameters,\n MetricMetadataResponse,\n RangeQueryRequestParameters,\n RangeQueryResponse,\n SeriesRequestParameters,\n SeriesResponse,\n SuccessResponse,\n} from './api-types';\n\ninterface PrometheusClientOptions {\n datasourceUrl: string;\n headers?: RequestHeaders;\n}\n\nexport interface PrometheusClient extends DatasourceClient {\n options: PrometheusClientOptions;\n instantQuery(params: InstantQueryRequestParameters, headers?: RequestHeaders): Promise<InstantQueryResponse>;\n rangeQuery(params: RangeQueryRequestParameters, headers?: RequestHeaders): Promise<RangeQueryResponse>;\n labelNames(params: LabelNamesRequestParameters, headers?: RequestHeaders): Promise<LabelNamesResponse>;\n labelValues(params: LabelValuesRequestParameters, headers?: RequestHeaders): Promise<LabelValuesResponse>;\n metricMetadata(params: MetricMetadataRequestParameters, headers?: RequestHeaders): Promise<MetricMetadataResponse>;\n series(params: SeriesRequestParameters, headers?: RequestHeaders): Promise<SeriesResponse>;\n}\n\nexport interface QueryOptions {\n datasourceUrl: string;\n headers?: RequestHeaders;\n}\n\n/**\n * Calls the `/-/healthy` endpoint to check if the datasource is healthy.\n */\nexport function healthCheck(queryOptions: QueryOptions) {\n return async () => {\n const url = `${queryOptions.datasourceUrl}/-/healthy`;\n\n try {\n const resp = await fetch(url, { headers: queryOptions.headers });\n return resp.status === 200;\n } catch {\n return false;\n }\n };\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(\n params: LabelValuesRequestParameters,\n queryOptions: QueryOptions\n): Promise<LabelValuesResponse> {\n const { labelName, ...searchParams } = params;\n\n // In case label name is empty, we'll receive a 404, so we can replace it by an empty list, which is less confusing.\n // Note that an empty list is the prometheus result if the label does not exist.\n if (labelName.length === 0) {\n return new Promise((resolve) => {\n resolve({ data: [] as string[] } as SuccessResponse<string[]>);\n });\n }\n\n const apiURI = `/api/v1/label/${encodeURIComponent(labelName)}/values`;\n return fetchWithGet<typeof searchParams, LabelValuesResponse>(apiURI, searchParams, 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 metricMetadata(\n params: MetricMetadataRequestParameters,\n queryOptions: QueryOptions\n): Promise<MetricMetadataResponse> {\n const apiURI = `/api/v1/metadata`;\n return fetchWithGet<MetricMetadataRequestParameters, MetricMetadataResponse>(apiURI, params, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/series` endpoint to finding series by label matchers.\n */\nexport function series(params: SeriesRequestParameters, queryOptions: QueryOptions): Promise<SeriesResponse> {\n const apiURI = `/api/v1/series`;\n return fetchWithPost<SeriesRequestParameters, SeriesResponse>(apiURI, params, queryOptions);\n}\n\nfunction fetchWithGet<T extends RequestParams<T>, TResponse>(apiURI: string, params: T, queryOptions: QueryOptions) {\n const { datasourceUrl } = 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 { datasourceUrl, headers } = queryOptions;\n\n const url = `${datasourceUrl}${apiURI}`;\n const init = {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/x-www-form-urlencoded',\n ...headers,\n },\n body: createSearchParams(params),\n };\n return fetchResults<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\n/**\n * Fetch JSON and parse warnings for query inspector\n */\nexport async function fetchResults<T>(...args: Parameters<typeof global.fetch>) {\n const response = await fetch(...args);\n const json: T = await response.json();\n return { ...json, rawResponse: response };\n}\n"],"names":["fetch","fetchJson","healthCheck","queryOptions","url","datasourceUrl","resp","headers","status","instantQuery","params","fetchWithPost","rangeQuery","labelNames","labelValues","labelName","searchParams","length","Promise","resolve","data","apiURI","encodeURIComponent","fetchWithGet","metricMetadata","series","urlParams","createSearchParams","toString","method","init","body","fetchResults","URLSearchParams","key","value","undefined","append","val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M,CAACH,KAAKC,MAAMP,QAAQ;YACvC;QACF;QAEA,KAAK,MAAMU,OAAOH,MAAO;YACvBnB,aAAaqB,MAAM,CAACH,KAAKI;QAC3B;IACF;IACA,OAAOtB;AACT;AAEA;;CAEC,GACD,OAAO,eAAegB,aAAgB,GAAGO,IAAqC;IAC5E,MAAMC,WAAW,MAAMxC,SAASuC;IAChC,MAAME,OAAU,MAAMD,SAASC,IAAI;IACnC,OAAO;QAAE,GAAGA,IAAI;QAAEC,aAAaF;IAAS;AAC1C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prometheus-datasource.d.ts","sourceRoot":"","sources":["../../src/plugins/prometheus-datasource.tsx"],"names":[],"mappings":"AAcA,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,
|
|
1
|
+
{"version":3,"file":"prometheus-datasource.d.ts","sourceRoot":"","sources":["../../src/plugins/prometheus-datasource.tsx"],"names":[],"mappings":"AAcA,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAML,gBAAgB,EAGjB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAgFnD,eAAO,MAAM,oBAAoB,EAAE,gBAAgB,CAAC,wBAAwB,EAAE,gBAAgB,CAK7F,CAAC"}
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
|
-
import { healthCheck, instantQuery, rangeQuery, labelNames, labelValues } from '../model';
|
|
13
|
+
import { healthCheck, instantQuery, rangeQuery, labelNames, labelValues, metricMetadata, series } from '../model';
|
|
14
14
|
import { PrometheusDatasourceEditor } from './PrometheusDatasourceEditor';
|
|
15
15
|
/**
|
|
16
16
|
* Creates a PrometheusClient for a specific datasource spec.
|
|
@@ -47,6 +47,14 @@ import { PrometheusDatasourceEditor } from './PrometheusDatasourceEditor';
|
|
|
47
47
|
labelValues: (params, headers)=>labelValues(params, {
|
|
48
48
|
datasourceUrl,
|
|
49
49
|
headers: headers !== null && headers !== void 0 ? headers : specHeaders
|
|
50
|
+
}),
|
|
51
|
+
metricMetadata: (params, headers)=>metricMetadata(params, {
|
|
52
|
+
datasourceUrl,
|
|
53
|
+
headers: headers !== null && headers !== void 0 ? headers : specHeaders
|
|
54
|
+
}),
|
|
55
|
+
series: (params, headers)=>series(params, {
|
|
56
|
+
datasourceUrl,
|
|
57
|
+
headers: headers !== null && headers !== void 0 ? headers : specHeaders
|
|
50
58
|
})
|
|
51
59
|
};
|
|
52
60
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/plugins/prometheus-datasource.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { BuiltinVariableDefinition } from '@perses-dev/core';\nimport { DatasourcePlugin } from '@perses-dev/plugin-system';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/plugins/prometheus-datasource.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { BuiltinVariableDefinition } from '@perses-dev/core';\nimport { DatasourcePlugin } from '@perses-dev/plugin-system';\nimport {\n healthCheck,\n instantQuery,\n rangeQuery,\n labelNames,\n labelValues,\n PrometheusClient,\n metricMetadata,\n series,\n} from '../model';\nimport { PrometheusDatasourceSpec } from './types';\nimport { PrometheusDatasourceEditor } from './PrometheusDatasourceEditor';\n\n/**\n * Creates a PrometheusClient for a specific datasource spec.\n */\nconst createClient: DatasourcePlugin<PrometheusDatasourceSpec, PrometheusClient>['createClient'] = (spec, options) => {\n const { directUrl, proxy } = spec;\n const { proxyUrl } = options;\n\n // Use the direct URL if specified, but fallback to the proxyUrl by default if not specified\n const datasourceUrl = directUrl ?? proxyUrl;\n if (datasourceUrl === undefined) {\n throw new Error('No URL specified for Prometheus client. You can use directUrl in the spec to configure it.');\n }\n\n const specHeaders = proxy?.spec.headers;\n\n // Could think about this becoming a class, although it definitely doesn't have to be\n return {\n options: {\n datasourceUrl,\n },\n healthCheck: healthCheck({ datasourceUrl, headers: specHeaders }),\n instantQuery: (params, headers) => instantQuery(params, { datasourceUrl, headers: headers ?? specHeaders }),\n rangeQuery: (params, headers) => rangeQuery(params, { datasourceUrl, headers: headers ?? specHeaders }),\n labelNames: (params, headers) => labelNames(params, { datasourceUrl, headers: headers ?? specHeaders }),\n labelValues: (params, headers) => labelValues(params, { datasourceUrl, headers: headers ?? specHeaders }),\n metricMetadata: (params, headers) => metricMetadata(params, { datasourceUrl, headers: headers ?? specHeaders }),\n series: (params, headers) => series(params, { datasourceUrl, headers: headers ?? specHeaders }),\n };\n};\n\nconst getBuiltinVariableDefinitions: () => BuiltinVariableDefinition[] = () => {\n return [\n {\n kind: 'BuiltinVariable',\n spec: {\n name: '__interval',\n value: () => '$__interval', // will be overriden when time series query is called\n source: 'Prometheus',\n display: {\n name: '__interval',\n description:\n 'Interval that can be used to group by time in queries. When there are more data points than can be shown on a graph then queries can be made more efficient by grouping by a larger interval.',\n hidden: true,\n },\n },\n },\n {\n kind: 'BuiltinVariable',\n spec: {\n name: '__interval_ms',\n value: () => '$__interval_ms', // will be overriden when time series query is called\n source: 'Prometheus',\n display: {\n name: '__interval_ms',\n description:\n 'Interval in millisecond that can be used to group by time in queries. When there are more data points than can be shown on a graph then queries can be made more efficient by grouping by a larger interval.',\n hidden: true,\n },\n },\n },\n {\n kind: 'BuiltinVariable',\n spec: {\n name: '__rate_interval',\n value: () => '$__rate_interval', // will be overriden when time series query is called\n source: 'Prometheus',\n display: {\n name: '__rate_interval',\n description:\n \"Interval at least four times the value of the scrape interval. It avoids problems specific to Prometheus when using 'rate' and 'increase' functions.\",\n hidden: true,\n },\n },\n },\n ] as BuiltinVariableDefinition[];\n};\n\nexport const PrometheusDatasource: DatasourcePlugin<PrometheusDatasourceSpec, PrometheusClient> = {\n createClient,\n getBuiltinVariableDefinitions,\n OptionsEditorComponent: PrometheusDatasourceEditor,\n createInitialOptions: () => ({ directUrl: '' }),\n};\n"],"names":["healthCheck","instantQuery","rangeQuery","labelNames","labelValues","metricMetadata","series","PrometheusDatasourceEditor","createClient","spec","options","directUrl","proxy","proxyUrl","datasourceUrl","undefined","Error","specHeaders","headers","params","getBuiltinVariableDefinitions","kind","name","value","source","display","description","hidden","PrometheusDatasource","OptionsEditorComponent","createInitialOptions"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC,SACEA,WAAW,EACXC,YAAY,EACZC,UAAU,EACVC,UAAU,EACVC,WAAW,EAEXC,cAAc,EACdC,MAAM,QACD,WAAW;AAElB,SAASC,0BAA0B,QAAQ,+BAA+B;AAE1E;;CAEC,GACD,MAAMC,eAA6F,CAACC,MAAMC;IACxG,MAAM,EAAEC,SAAS,EAAEC,KAAK,EAAE,GAAGH;IAC7B,MAAM,EAAEI,QAAQ,EAAE,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;gBACV;YACF;QACF;QACA;YACEN,MAAM;YACNZ,MAAM;gBACJa,MAAM;gBACNC,OAAO,IAAM;gBACbC,QAAQ;gBACRC,SAAS;oBACPH,MAAM;oBACNI,aACE;oBACFC,QAAQ;gBACV;YACF;QACF;KACD;AACH;AAEA,OAAO,MAAMC,uBAAqF;IAChGpB;IACAY;IACAS,wBAAwBtB;IACxBuB,sBAAsB,IAAO,CAAA;YAAEnB,WAAW;QAAG,CAAA;AAC/C,EAAE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@perses-dev/prometheus-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.48.0-rc0",
|
|
4
4
|
"description": "Prometheus plugin for Perses",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://github.com/perses/perses/blob/main/README.md",
|
|
@@ -31,9 +31,9 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@lezer/highlight": "^1.0.0",
|
|
33
33
|
"@lezer/lr": "^1.2.0",
|
|
34
|
-
"@perses-dev/components": "0.
|
|
35
|
-
"@perses-dev/core": "0.
|
|
36
|
-
"@perses-dev/plugin-system": "0.
|
|
34
|
+
"@perses-dev/components": "0.48.0-rc0",
|
|
35
|
+
"@perses-dev/core": "0.48.0-rc0",
|
|
36
|
+
"@perses-dev/plugin-system": "0.48.0-rc0",
|
|
37
37
|
"@prometheus-io/codemirror-promql": "^0.43.0",
|
|
38
38
|
"@uiw/react-codemirror": "^4.19.1",
|
|
39
39
|
"date-fns": "^2.28.0",
|