@perses-dev/prometheus-plugin 0.9.0 → 0.11.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/model/index.js +34 -0
- package/dist/cjs/model/prometheus-client.js +4 -4
- package/dist/cjs/model/prometheus-selectors.js +37 -0
- package/dist/cjs/plugins/JSONSpecEditor.js +54 -0
- package/dist/cjs/plugins/MatcherEditor.js +80 -0
- package/dist/cjs/plugins/PrometheusTimeSeriesQueryEditor.js +78 -0
- package/dist/cjs/plugins/prometheus-datasource.js +28 -0
- package/dist/cjs/plugins/prometheus-variables.js +67 -23
- package/dist/cjs/plugins/time-series-query.js +15 -20
- package/dist/cjs/plugins/types.js +16 -0
- package/dist/cjs/plugins/variable.js +40 -1
- package/dist/model/index.d.ts +8 -0
- package/dist/model/index.d.ts.map +1 -0
- package/dist/model/index.js +21 -0
- package/dist/model/index.js.map +1 -0
- package/dist/model/prometheus-client.d.ts +7 -8
- package/dist/model/prometheus-client.d.ts.map +1 -1
- package/dist/model/prometheus-client.js +4 -4
- package/dist/model/prometheus-client.js.map +1 -1
- package/dist/model/prometheus-selectors.d.ts +22 -0
- package/dist/model/prometheus-selectors.d.ts.map +1 -0
- package/dist/model/prometheus-selectors.js +30 -0
- package/dist/model/prometheus-selectors.js.map +1 -0
- package/dist/plugins/JSONSpecEditor.d.ts +4 -0
- package/dist/plugins/JSONSpecEditor.d.ts.map +1 -0
- package/dist/plugins/JSONSpecEditor.js +48 -0
- package/dist/plugins/JSONSpecEditor.js.map +1 -0
- package/dist/plugins/MatcherEditor.d.ts +6 -0
- package/dist/plugins/MatcherEditor.d.ts.map +1 -0
- package/dist/plugins/MatcherEditor.js +69 -0
- package/dist/plugins/MatcherEditor.js.map +1 -0
- package/dist/plugins/PrometheusTimeSeriesQueryEditor.d.ts +6 -0
- package/dist/plugins/PrometheusTimeSeriesQueryEditor.d.ts.map +1 -0
- package/dist/plugins/PrometheusTimeSeriesQueryEditor.js +67 -0
- package/dist/plugins/PrometheusTimeSeriesQueryEditor.js.map +1 -0
- package/dist/plugins/prometheus-datasource.d.ts +5 -2
- package/dist/plugins/prometheus-datasource.d.ts.map +1 -1
- package/dist/plugins/prometheus-datasource.js +28 -0
- package/dist/plugins/prometheus-datasource.js.map +1 -1
- package/dist/plugins/prometheus-variables.d.ts +1 -10
- package/dist/plugins/prometheus-variables.d.ts.map +1 -1
- package/dist/plugins/prometheus-variables.js +65 -21
- package/dist/plugins/prometheus-variables.js.map +1 -1
- package/dist/plugins/time-series-query.d.ts +2 -4
- package/dist/plugins/time-series-query.d.ts.map +1 -1
- package/dist/plugins/time-series-query.js +10 -15
- package/dist/plugins/time-series-query.js.map +1 -1
- package/dist/plugins/types.d.ts +12 -0
- package/dist/plugins/types.d.ts.map +1 -0
- package/dist/plugins/types.js +15 -0
- package/dist/plugins/types.js.map +1 -0
- package/dist/plugins/variable.d.ts.map +1 -1
- package/dist/plugins/variable.js +40 -1
- package/dist/plugins/variable.js.map +1 -1
- package/package.json +5 -4
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { DatasourceSelector } from '@perses-dev/core';
|
|
2
1
|
import { InstantQueryRequestParameters, InstantQueryResponse, LabelNamesRequestParameters, LabelNamesResponse, LabelValuesRequestParameters, LabelValuesResponse, RangeQueryRequestParameters, RangeQueryResponse } from './api-types';
|
|
3
|
-
export interface
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
export interface PrometheusClient {
|
|
3
|
+
instantQuery(params: InstantQueryRequestParameters): Promise<InstantQueryResponse>;
|
|
4
|
+
rangeQuery(params: RangeQueryRequestParameters): Promise<RangeQueryResponse>;
|
|
5
|
+
labelNames(params: LabelNamesRequestParameters): Promise<LabelNamesResponse>;
|
|
6
|
+
labelValues(params: LabelValuesRequestParameters): Promise<LabelValuesResponse>;
|
|
8
7
|
}
|
|
9
|
-
export interface
|
|
10
|
-
|
|
8
|
+
export interface QueryOptions {
|
|
9
|
+
datasourceUrl: string;
|
|
11
10
|
}
|
|
12
11
|
/**
|
|
13
12
|
* Calls the `/api/v1/query` endpoint to get metrics data.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prometheus-client.d.ts","sourceRoot":"","sources":["../../src/model/prometheus-client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"prometheus-client.d.ts","sourceRoot":"","sources":["../../src/model/prometheus-client.ts"],"names":[],"mappings":"AAcA,OAAO,EACL,6BAA6B,EAC7B,oBAAoB,EACpB,2BAA2B,EAC3B,kBAAkB,EAClB,4BAA4B,EAC5B,mBAAmB,EACnB,2BAA2B,EAC3B,kBAAkB,EACnB,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,gBAAgB;IAC/B,YAAY,CAAC,MAAM,EAAE,6BAA6B,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;IACnF,UAAU,CAAC,MAAM,EAAE,2BAA2B,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAC7E,UAAU,CAAC,MAAM,EAAE,2BAA2B,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAC7E,WAAW,CAAC,MAAM,EAAE,4BAA4B,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;CACjF;AAED,MAAM,WAAW,YAAY;IAC3B,aAAa,EAAE,MAAM,CAAC;CACvB;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"}
|
|
@@ -34,8 +34,8 @@ import { fetchJson } from '@perses-dev/core';
|
|
|
34
34
|
return fetchWithGet(apiURI, searchParams, queryOptions);
|
|
35
35
|
}
|
|
36
36
|
function fetchWithGet(apiURI, params, queryOptions) {
|
|
37
|
-
const {
|
|
38
|
-
let url = `${
|
|
37
|
+
const { datasourceUrl } = queryOptions;
|
|
38
|
+
let url = `${datasourceUrl}${apiURI}`;
|
|
39
39
|
const urlParams = createSearchParams(params).toString();
|
|
40
40
|
if (urlParams !== '') {
|
|
41
41
|
url += `?${urlParams}`;
|
|
@@ -45,8 +45,8 @@ function fetchWithGet(apiURI, params, queryOptions) {
|
|
|
45
45
|
});
|
|
46
46
|
}
|
|
47
47
|
function fetchWithPost(apiURI, params, queryOptions) {
|
|
48
|
-
const {
|
|
49
|
-
const url = `${
|
|
48
|
+
const { datasourceUrl } = queryOptions;
|
|
49
|
+
const url = `${datasourceUrl}${apiURI}`;
|
|
50
50
|
const init = {
|
|
51
51
|
method: 'POST',
|
|
52
52
|
headers: {
|
|
@@ -1 +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 {
|
|
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 { 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 PrometheusClient {\n instantQuery(params: InstantQueryRequestParameters): Promise<InstantQueryResponse>;\n rangeQuery(params: RangeQueryRequestParameters): Promise<RangeQueryResponse>;\n labelNames(params: LabelNamesRequestParameters): Promise<LabelNamesResponse>;\n labelValues(params: LabelValuesRequestParameters): Promise<LabelValuesResponse>;\n}\n\nexport interface QueryOptions {\n datasourceUrl: string;\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 { 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 } = 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","datasourceUrl","url","urlParams","createSearchParams","toString","method","init","headers","body","URLSearchParams","key","value","undefined","append","val"],"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,SAAS,QAAQ,kBAAkB,CAAC;AAuB7C;;CAEC,GACD,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
|
2
|
+
declare const PROM_DATASOURCE_KIND: "PrometheusDatasource";
|
|
3
|
+
/**
|
|
4
|
+
* DatasourceSelector for Prom Datasources.
|
|
5
|
+
*/
|
|
6
|
+
export interface PrometheusDatasourceSelector extends DatasourceSelector {
|
|
7
|
+
kind: typeof PROM_DATASOURCE_KIND;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* A default selector that asks for the default Prom Datasource.
|
|
11
|
+
*/
|
|
12
|
+
export declare const DEFAULT_PROM: PrometheusDatasourceSelector;
|
|
13
|
+
/**
|
|
14
|
+
* Returns true if the provided PrometheusDatasourceSelector is the default one.
|
|
15
|
+
*/
|
|
16
|
+
export declare function isDefaultPromSelector(selector: PrometheusDatasourceSelector): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Type guard to make sure a DatasourceSelector is a Prometheus one.
|
|
19
|
+
*/
|
|
20
|
+
export declare function isPrometheusDatasourceSelector(selector: DatasourceSelector): selector is PrometheusDatasourceSelector;
|
|
21
|
+
export {};
|
|
22
|
+
//# sourceMappingURL=prometheus-selectors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prometheus-selectors.d.ts","sourceRoot":"","sources":["../../src/model/prometheus-selectors.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEtD,QAAA,MAAM,oBAAoB,wBAAkC,CAAC;AAE7D;;GAEG;AACH,MAAM,WAAW,4BAA6B,SAAQ,kBAAkB;IACtE,IAAI,EAAE,OAAO,oBAAoB,CAAC;CACnC;AAED;;GAEG;AACH,eAAO,MAAM,YAAY,EAAE,4BAA6D,CAAC;AAEzF;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,4BAA4B,WAE3E;AAED;;GAEG;AACH,wBAAgB,8BAA8B,CAAC,QAAQ,EAAE,kBAAkB,GAAG,QAAQ,IAAI,4BAA4B,CAErH"}
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
const PROM_DATASOURCE_KIND = 'PrometheusDatasource';
|
|
14
|
+
/**
|
|
15
|
+
* A default selector that asks for the default Prom Datasource.
|
|
16
|
+
*/ export const DEFAULT_PROM = {
|
|
17
|
+
kind: PROM_DATASOURCE_KIND
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Returns true if the provided PrometheusDatasourceSelector is the default one.
|
|
21
|
+
*/ export function isDefaultPromSelector(selector) {
|
|
22
|
+
return selector.name === undefined;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Type guard to make sure a DatasourceSelector is a Prometheus one.
|
|
26
|
+
*/ export function isPrometheusDatasourceSelector(selector) {
|
|
27
|
+
return selector.kind === PROM_DATASOURCE_KIND;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=prometheus-selectors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/model/prometheus-selectors.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 } from '@perses-dev/core';\n\nconst PROM_DATASOURCE_KIND = 'PrometheusDatasource' as const;\n\n/**\n * DatasourceSelector for Prom Datasources.\n */\nexport interface PrometheusDatasourceSelector extends DatasourceSelector {\n kind: typeof PROM_DATASOURCE_KIND;\n}\n\n/**\n * A default selector that asks for the default Prom Datasource.\n */\nexport const DEFAULT_PROM: PrometheusDatasourceSelector = { kind: PROM_DATASOURCE_KIND };\n\n/**\n * Returns true if the provided PrometheusDatasourceSelector is the default one.\n */\nexport function isDefaultPromSelector(selector: PrometheusDatasourceSelector) {\n return selector.name === undefined;\n}\n\n/**\n * Type guard to make sure a DatasourceSelector is a Prometheus one.\n */\nexport function isPrometheusDatasourceSelector(selector: DatasourceSelector): selector is PrometheusDatasourceSelector {\n return selector.kind === PROM_DATASOURCE_KIND;\n}\n"],"names":["PROM_DATASOURCE_KIND","DEFAULT_PROM","kind","isDefaultPromSelector","selector","name","undefined","isPrometheusDatasourceSelector"],"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,MAAMA,oBAAoB,GAAG,sBAAsB,AAAS,AAAC;AAS7D;;CAEC,GACD,OAAO,MAAMC,YAAY,GAAiC;IAAEC,IAAI,EAAEF,oBAAoB;CAAE,CAAC;AAEzF;;CAEC,GACD,OAAO,SAASG,qBAAqB,CAACC,QAAsC,EAAE;IAC5E,OAAOA,QAAQ,CAACC,IAAI,KAAKC,SAAS,CAAC;AACrC,CAAC;AAED;;CAEC,GACD,OAAO,SAASC,8BAA8B,CAACH,QAA4B,EAA4C;IACrH,OAAOA,QAAQ,CAACF,IAAI,KAAKF,oBAAoB,CAAC;AAChD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JSONSpecEditor.d.ts","sourceRoot":"","sources":["../../src/plugins/JSONSpecEditor.tsx"],"names":[],"mappings":";AAeA,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAE/D,wBAAgB,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,kBAAkB,CAAC,CAAC,CAAC,eAgC7D"}
|
|
@@ -0,0 +1,48 @@
|
|
|
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 { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
+
import { useEffect, useRef, useState } from 'react';
|
|
15
|
+
import { TextField } from '@mui/material';
|
|
16
|
+
export function JSONSpecEditor(props) {
|
|
17
|
+
const ref = useRef(null);
|
|
18
|
+
const [value, setValue] = useState(JSON.stringify(props.value, null, 2));
|
|
19
|
+
const [invalidJSON, setInvalidJSON] = useState(false);
|
|
20
|
+
useEffect(()=>{
|
|
21
|
+
setValue(JSON.stringify(props.value, null, 2));
|
|
22
|
+
setInvalidJSON(false);
|
|
23
|
+
}, [
|
|
24
|
+
props.value
|
|
25
|
+
]);
|
|
26
|
+
return /*#__PURE__*/ _jsx(TextField, {
|
|
27
|
+
label: "JSON",
|
|
28
|
+
error: invalidJSON,
|
|
29
|
+
helperText: invalidJSON ? 'Invalid JSON' : '',
|
|
30
|
+
multiline: true,
|
|
31
|
+
inputRef: ref,
|
|
32
|
+
value: value,
|
|
33
|
+
onChange: (event)=>{
|
|
34
|
+
setValue(event.target.value);
|
|
35
|
+
},
|
|
36
|
+
onBlur: ()=>{
|
|
37
|
+
try {
|
|
38
|
+
const json = JSON.parse(value !== null && value !== void 0 ? value : '{}');
|
|
39
|
+
setInvalidJSON(false);
|
|
40
|
+
props.onChange(json);
|
|
41
|
+
} catch (e) {
|
|
42
|
+
setInvalidJSON(true);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
//# sourceMappingURL=JSONSpecEditor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/plugins/JSONSpecEditor.tsx"],"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 { useEffect, useRef, useState } from 'react';\nimport { TextField } from '@mui/material';\nimport { OptionsEditorProps } from '@perses-dev/plugin-system';\n\nexport function JSONSpecEditor<T>(props: OptionsEditorProps<T>) {\n const ref = useRef<HTMLInputElement>(null);\n const [value, setValue] = useState(JSON.stringify(props.value, null, 2));\n const [invalidJSON, setInvalidJSON] = useState(false);\n\n useEffect(() => {\n setValue(JSON.stringify(props.value, null, 2));\n setInvalidJSON(false);\n }, [props.value]);\n\n return (\n <TextField\n label=\"JSON\"\n error={invalidJSON}\n helperText={invalidJSON ? 'Invalid JSON' : ''}\n multiline\n inputRef={ref}\n value={value}\n onChange={(event) => {\n setValue(event.target.value);\n }}\n onBlur={() => {\n try {\n const json = JSON.parse(value ?? '{}');\n setInvalidJSON(false);\n props.onChange(json);\n } catch (e) {\n setInvalidJSON(true);\n }\n }}\n />\n );\n}\n"],"names":["useEffect","useRef","useState","TextField","JSONSpecEditor","props","ref","value","setValue","JSON","stringify","invalidJSON","setInvalidJSON","label","error","helperText","multiline","inputRef","onChange","event","target","onBlur","json","parse","e"],"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;AAAA,SAASA,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO,CAAC;AACpD,SAASC,SAAS,QAAQ,eAAe,CAAC;AAG1C,OAAO,SAASC,cAAc,CAAIC,KAA4B,EAAE;IAC9D,MAAMC,GAAG,GAAGL,MAAM,CAAmB,IAAI,CAAC,AAAC;IAC3C,MAAM,CAACM,KAAK,EAAEC,QAAQ,CAAC,GAAGN,QAAQ,CAACO,IAAI,CAACC,SAAS,CAACL,KAAK,CAACE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,AAAC;IACzE,MAAM,CAACI,WAAW,EAAEC,cAAc,CAAC,GAAGV,QAAQ,CAAC,KAAK,CAAC,AAAC;IAEtDF,SAAS,CAAC,IAAM;QACdQ,QAAQ,CAACC,IAAI,CAACC,SAAS,CAACL,KAAK,CAACE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;QAC/CK,cAAc,CAAC,KAAK,CAAC,CAAC;IACxB,CAAC,EAAE;QAACP,KAAK,CAACE,KAAK;KAAC,CAAC,CAAC;IAElB,qBACE,KAACJ,SAAS;QACRU,KAAK,EAAC,MAAM;QACZC,KAAK,EAAEH,WAAW;QAClBI,UAAU,EAAEJ,WAAW,GAAG,cAAc,GAAG,EAAE;QAC7CK,SAAS;QACTC,QAAQ,EAAEX,GAAG;QACbC,KAAK,EAAEA,KAAK;QACZW,QAAQ,EAAE,CAACC,KAAK,GAAK;YACnBX,QAAQ,CAACW,KAAK,CAACC,MAAM,CAACb,KAAK,CAAC,CAAC;QAC/B,CAAC;QACDc,MAAM,EAAE,IAAM;YACZ,IAAI;gBACF,MAAMC,IAAI,GAAGb,IAAI,CAACc,KAAK,CAAChB,KAAK,aAALA,KAAK,cAALA,KAAK,GAAI,IAAI,CAAC,AAAC;gBACvCK,cAAc,CAAC,KAAK,CAAC,CAAC;gBACtBP,KAAK,CAACa,QAAQ,CAACI,IAAI,CAAC,CAAC;YACvB,EAAE,OAAOE,CAAC,EAAE;gBACVZ,cAAc,CAAC,IAAI,CAAC,CAAC;YACvB,CAAC;QACH,CAAC;MACD,CACF;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MatcherEditor.d.ts","sourceRoot":"","sources":["../../src/plugins/MatcherEditor.tsx"],"names":[],"mappings":";AAiBA,wBAAgB,aAAa,CAAC,KAAK,EAAE;IAAE,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,IAAI,CAAA;CAAE,eA0C1G"}
|
|
@@ -0,0 +1,69 @@
|
|
|
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 { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
|
+
import { useState } from 'react';
|
|
15
|
+
import { Stack, TextField, Button, Box, IconButton } from '@mui/material';
|
|
16
|
+
import TrashIcon from 'mdi-material-ui/TrashCan';
|
|
17
|
+
export function MatcherEditor(props) {
|
|
18
|
+
var _initialMatchers;
|
|
19
|
+
const [matchers, setMatchers] = useState((_initialMatchers = props.initialMatchers) !== null && _initialMatchers !== void 0 ? _initialMatchers : []);
|
|
20
|
+
return /*#__PURE__*/ _jsxs(Stack, {
|
|
21
|
+
spacing: 1,
|
|
22
|
+
children: [
|
|
23
|
+
matchers.map((matcher, index)=>/*#__PURE__*/ _jsxs(Box, {
|
|
24
|
+
display: "flex",
|
|
25
|
+
children: [
|
|
26
|
+
/*#__PURE__*/ _jsx(TextField, {
|
|
27
|
+
onBlur: ()=>{
|
|
28
|
+
props.onChange(matchers);
|
|
29
|
+
},
|
|
30
|
+
label: "Series Selector",
|
|
31
|
+
value: matcher,
|
|
32
|
+
onChange: (e)=>{
|
|
33
|
+
const newMatchers = [
|
|
34
|
+
...matchers
|
|
35
|
+
];
|
|
36
|
+
newMatchers[index] = e.target.value;
|
|
37
|
+
setMatchers(newMatchers);
|
|
38
|
+
}
|
|
39
|
+
}),
|
|
40
|
+
/*#__PURE__*/ _jsx(IconButton, {
|
|
41
|
+
onClick: ()=>{
|
|
42
|
+
const newMatchers = [
|
|
43
|
+
...matchers
|
|
44
|
+
];
|
|
45
|
+
newMatchers.splice(index, 1);
|
|
46
|
+
setMatchers(newMatchers);
|
|
47
|
+
},
|
|
48
|
+
children: /*#__PURE__*/ _jsx(TrashIcon, {})
|
|
49
|
+
})
|
|
50
|
+
]
|
|
51
|
+
}, index)),
|
|
52
|
+
/*#__PURE__*/ _jsx(Box, {
|
|
53
|
+
children: /*#__PURE__*/ _jsx(Button, {
|
|
54
|
+
fullWidth: false,
|
|
55
|
+
variant: "outlined",
|
|
56
|
+
onClick: ()=>{
|
|
57
|
+
setMatchers([
|
|
58
|
+
...matchers,
|
|
59
|
+
''
|
|
60
|
+
]);
|
|
61
|
+
},
|
|
62
|
+
children: "Add Series Selector"
|
|
63
|
+
})
|
|
64
|
+
})
|
|
65
|
+
]
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
//# sourceMappingURL=MatcherEditor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/plugins/MatcherEditor.tsx"],"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 { useState } from 'react';\nimport { Stack, TextField, Button, Box, IconButton } from '@mui/material';\nimport TrashIcon from 'mdi-material-ui/TrashCan';\n\nexport function MatcherEditor(props: { initialMatchers?: string[]; onChange: (matchers: string[]) => void }) {\n const [matchers, setMatchers] = useState<string[]>(props.initialMatchers ?? []);\n return (\n <Stack spacing={1}>\n {matchers.map((matcher, index) => (\n <Box key={index} display=\"flex\">\n <TextField\n onBlur={() => {\n props.onChange(matchers);\n }}\n label=\"Series Selector\"\n value={matcher}\n onChange={(e) => {\n const newMatchers = [...matchers];\n newMatchers[index] = e.target.value;\n setMatchers(newMatchers);\n }}\n />\n <IconButton\n onClick={() => {\n const newMatchers = [...matchers];\n newMatchers.splice(index, 1);\n setMatchers(newMatchers);\n }}\n >\n <TrashIcon />\n </IconButton>\n </Box>\n ))}\n <Box>\n <Button\n fullWidth={false}\n variant=\"outlined\"\n onClick={() => {\n setMatchers([...matchers, '']);\n }}\n >\n Add Series Selector\n </Button>\n </Box>\n </Stack>\n );\n}\n"],"names":["useState","Stack","TextField","Button","Box","IconButton","TrashIcon","MatcherEditor","props","matchers","setMatchers","initialMatchers","spacing","map","matcher","index","display","onBlur","onChange","label","value","e","newMatchers","target","onClick","splice","fullWidth","variant"],"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;AAAA,SAASA,QAAQ,QAAQ,OAAO,CAAC;AACjC,SAASC,KAAK,EAAEC,SAAS,EAAEC,MAAM,EAAEC,GAAG,EAAEC,UAAU,QAAQ,eAAe,CAAC;AAC1E,OAAOC,SAAS,MAAM,0BAA0B,CAAC;AAEjD,OAAO,SAASC,aAAa,CAACC,KAA6E,EAAE;QACxDA,gBAAqB;IAAxE,MAAM,CAACC,QAAQ,EAAEC,WAAW,CAAC,GAAGV,QAAQ,CAAWQ,CAAAA,gBAAqB,GAArBA,KAAK,CAACG,eAAe,cAArBH,gBAAqB,cAArBA,gBAAqB,GAAI,EAAE,CAAC,AAAC;IAChF,qBACE,MAACP,KAAK;QAACW,OAAO,EAAE,CAAC;;YACdH,QAAQ,CAACI,GAAG,CAAC,CAACC,OAAO,EAAEC,KAAK,iBAC3B,MAACX,GAAG;oBAAaY,OAAO,EAAC,MAAM;;sCAC7B,KAACd,SAAS;4BACRe,MAAM,EAAE,IAAM;gCACZT,KAAK,CAACU,QAAQ,CAACT,QAAQ,CAAC,CAAC;4BAC3B,CAAC;4BACDU,KAAK,EAAC,iBAAiB;4BACvBC,KAAK,EAAEN,OAAO;4BACdI,QAAQ,EAAE,CAACG,CAAC,GAAK;gCACf,MAAMC,WAAW,GAAG;uCAAIb,QAAQ;iCAAC,AAAC;gCAClCa,WAAW,CAACP,KAAK,CAAC,GAAGM,CAAC,CAACE,MAAM,CAACH,KAAK,CAAC;gCACpCV,WAAW,CAACY,WAAW,CAAC,CAAC;4BAC3B,CAAC;0BACD;sCACF,KAACjB,UAAU;4BACTmB,OAAO,EAAE,IAAM;gCACb,MAAMF,WAAW,GAAG;uCAAIb,QAAQ;iCAAC,AAAC;gCAClCa,WAAW,CAACG,MAAM,CAACV,KAAK,EAAE,CAAC,CAAC,CAAC;gCAC7BL,WAAW,CAACY,WAAW,CAAC,CAAC;4BAC3B,CAAC;sCAED,cAAA,KAAChB,SAAS,KAAG;0BACF;;mBArBLS,KAAK,CAsBT,AACP,CAAC;0BACF,KAACX,GAAG;0BACF,cAAA,KAACD,MAAM;oBACLuB,SAAS,EAAE,KAAK;oBAChBC,OAAO,EAAC,UAAU;oBAClBH,OAAO,EAAE,IAAM;wBACbd,WAAW,CAAC;+BAAID,QAAQ;4BAAE,EAAE;yBAAC,CAAC,CAAC;oBACjC,CAAC;8BACF,qBAED;kBAAS;cACL;;MACA,CACR;AACJ,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { OptionsEditorProps } from '@perses-dev/plugin-system';
|
|
3
|
+
import { PrometheusTimeSeriesQuerySpec } from './time-series-query';
|
|
4
|
+
export declare type PrometheusTimeSeriesQueryEditorProps = OptionsEditorProps<PrometheusTimeSeriesQuerySpec>;
|
|
5
|
+
export declare function PrometheusTimeSeriesQueryEditor(props: PrometheusTimeSeriesQueryEditorProps): JSX.Element;
|
|
6
|
+
//# sourceMappingURL=PrometheusTimeSeriesQueryEditor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PrometheusTimeSeriesQueryEditor.d.ts","sourceRoot":"","sources":["../../src/plugins/PrometheusTimeSeriesQueryEditor.tsx"],"names":[],"mappings":";AAgBA,OAAO,EAAE,kBAAkB,EAA2C,MAAM,2BAA2B,CAAC;AAExG,OAAO,EAAE,6BAA6B,EAAE,MAAM,qBAAqB,CAAC;AAEpE,oBAAY,oCAAoC,GAAG,kBAAkB,CAAC,6BAA6B,CAAC,CAAC;AAErG,wBAAgB,+BAA+B,CAAC,KAAK,EAAE,oCAAoC,eA4C1F"}
|
|
@@ -0,0 +1,67 @@
|
|
|
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 { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
|
+
import produce from 'immer';
|
|
15
|
+
import { Box, TextField, FormControl, InputLabel } from '@mui/material';
|
|
16
|
+
import { DatasourceSelect } from '@perses-dev/plugin-system';
|
|
17
|
+
import { DEFAULT_PROM, isDefaultPromSelector, isPrometheusDatasourceSelector } from '../model';
|
|
18
|
+
export function PrometheusTimeSeriesQueryEditor(props) {
|
|
19
|
+
const { onChange , value } = props;
|
|
20
|
+
const { query , datasource } = value;
|
|
21
|
+
const handleQueryChange = (e)=>{
|
|
22
|
+
onChange(produce(value, (draft)=>{
|
|
23
|
+
draft.query = e.target.value;
|
|
24
|
+
}));
|
|
25
|
+
};
|
|
26
|
+
const handleDatasourceChange = (next)=>{
|
|
27
|
+
if (isPrometheusDatasourceSelector(next)) {
|
|
28
|
+
onChange(produce(value, (draft)=>{
|
|
29
|
+
// If they're using the default, just omit the datasource prop (i.e. set to undefined)
|
|
30
|
+
const nextDatasource = isDefaultPromSelector(next) ? undefined : next;
|
|
31
|
+
draft.datasource = nextDatasource;
|
|
32
|
+
}));
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
throw new Error('Got unexpected non-Prometheus datasource selector');
|
|
36
|
+
};
|
|
37
|
+
return /*#__PURE__*/ _jsxs(Box, {
|
|
38
|
+
children: [
|
|
39
|
+
/*#__PURE__*/ _jsx(TextField, {
|
|
40
|
+
fullWidth: true,
|
|
41
|
+
label: "Query",
|
|
42
|
+
value: query,
|
|
43
|
+
onChange: handleQueryChange,
|
|
44
|
+
margin: "dense"
|
|
45
|
+
}),
|
|
46
|
+
/*#__PURE__*/ _jsxs(FormControl, {
|
|
47
|
+
margin: "dense",
|
|
48
|
+
fullWidth: false,
|
|
49
|
+
children: [
|
|
50
|
+
/*#__PURE__*/ _jsx(InputLabel, {
|
|
51
|
+
id: "prom-datasource-label",
|
|
52
|
+
children: "Prometheus Datasource"
|
|
53
|
+
}),
|
|
54
|
+
/*#__PURE__*/ _jsx(DatasourceSelect, {
|
|
55
|
+
datasourcePluginKind: "PrometheusDatasource",
|
|
56
|
+
value: datasource !== null && datasource !== void 0 ? datasource : DEFAULT_PROM,
|
|
57
|
+
onChange: handleDatasourceChange,
|
|
58
|
+
labelId: "prom-datasource-label",
|
|
59
|
+
label: "Prometheus Datasource"
|
|
60
|
+
})
|
|
61
|
+
]
|
|
62
|
+
})
|
|
63
|
+
]
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
//# sourceMappingURL=PrometheusTimeSeriesQueryEditor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/plugins/PrometheusTimeSeriesQueryEditor.tsx"],"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 { ChangeEvent } from 'react';\nimport produce from 'immer';\nimport { Box, TextField, FormControl, InputLabel } from '@mui/material';\nimport { OptionsEditorProps, DatasourceSelect, DatasourceSelectProps } from '@perses-dev/plugin-system';\nimport { DEFAULT_PROM, isDefaultPromSelector, isPrometheusDatasourceSelector } from '../model';\nimport { PrometheusTimeSeriesQuerySpec } from './time-series-query';\n\nexport type PrometheusTimeSeriesQueryEditorProps = OptionsEditorProps<PrometheusTimeSeriesQuerySpec>;\n\nexport function PrometheusTimeSeriesQueryEditor(props: PrometheusTimeSeriesQueryEditorProps) {\n const { onChange, value } = props;\n const { query, datasource } = value;\n\n const handleQueryChange = (e: ChangeEvent<HTMLInputElement>) => {\n onChange(\n produce(value, (draft) => {\n draft.query = e.target.value;\n })\n );\n };\n\n const handleDatasourceChange: DatasourceSelectProps['onChange'] = (next) => {\n if (isPrometheusDatasourceSelector(next)) {\n onChange(\n produce(value, (draft) => {\n // If they're using the default, just omit the datasource prop (i.e. set to undefined)\n const nextDatasource = isDefaultPromSelector(next) ? undefined : next;\n draft.datasource = nextDatasource;\n })\n );\n return;\n }\n\n throw new Error('Got unexpected non-Prometheus datasource selector');\n };\n\n return (\n <Box>\n <TextField fullWidth label=\"Query\" value={query} onChange={handleQueryChange} margin=\"dense\" />\n <FormControl margin=\"dense\" fullWidth={false}>\n {/* TODO: How do we ensure unique ID values if there are multiple of these? Can we use React 18 useId and\n maintain 17 compatibility somehow with a polyfill/shim? */}\n <InputLabel id=\"prom-datasource-label\">Prometheus Datasource</InputLabel>\n <DatasourceSelect\n datasourcePluginKind=\"PrometheusDatasource\"\n value={datasource ?? DEFAULT_PROM}\n onChange={handleDatasourceChange}\n labelId=\"prom-datasource-label\"\n label=\"Prometheus Datasource\"\n />\n </FormControl>\n </Box>\n );\n}\n"],"names":["produce","Box","TextField","FormControl","InputLabel","DatasourceSelect","DEFAULT_PROM","isDefaultPromSelector","isPrometheusDatasourceSelector","PrometheusTimeSeriesQueryEditor","props","onChange","value","query","datasource","handleQueryChange","e","draft","target","handleDatasourceChange","next","nextDatasource","undefined","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C;QAED,MAAM,IAAIE,KAAK,CAAC,mDAAmD,CAAC,CAAC;IACvE,CAAC,AAAC;IAEF,qBACE,MAACtB,GAAG;;0BACF,KAACC,SAAS;gBAACsB,SAAS;gBAACC,KAAK,EAAC,OAAO;gBAACb,KAAK,EAAEC,KAAK;gBAAEF,QAAQ,EAAEI,iBAAiB;gBAAEW,MAAM,EAAC,OAAO;cAAG;0BAC/F,MAACvB,WAAW;gBAACuB,MAAM,EAAC,OAAO;gBAACF,SAAS,EAAE,KAAK;;kCAG1C,KAACpB,UAAU;wBAACuB,EAAE,EAAC,uBAAuB;kCAAC,uBAAqB;sBAAa;kCACzE,KAACtB,gBAAgB;wBACfuB,oBAAoB,EAAC,sBAAsB;wBAC3ChB,KAAK,EAAEE,UAAU,aAAVA,UAAU,cAAVA,UAAU,GAAIR,YAAY;wBACjCK,QAAQ,EAAEQ,sBAAsB;wBAChCU,OAAO,EAAC,uBAAuB;wBAC/BJ,KAAK,EAAC,uBAAuB;sBAC7B;;cACU;;MACV,CACN;AACJ,CAAC"}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { DatasourcePlugin } from '@perses-dev/plugin-system';
|
|
2
|
-
import {
|
|
3
|
-
export
|
|
2
|
+
import { PrometheusClient } from '../model';
|
|
3
|
+
export interface PrometheusDatasourceSpec {
|
|
4
|
+
direct_url?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare const PrometheusDatasource: DatasourcePlugin<PrometheusDatasourceSpec, PrometheusClient>;
|
|
4
7
|
//# sourceMappingURL=prometheus-datasource.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prometheus-datasource.d.ts","sourceRoot":"","sources":["../../src/plugins/prometheus-datasource.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,wBAAwB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"prometheus-datasource.d.ts","sourceRoot":"","sources":["../../src/plugins/prometheus-datasource.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAqD,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE/F,MAAM,WAAW,wBAAwB;IACvC,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAwBD,eAAO,MAAM,oBAAoB,EAAE,gBAAgB,CAAC,wBAAwB,EAAE,gBAAgB,CAI7F,CAAC"}
|
|
@@ -10,7 +10,35 @@
|
|
|
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 { instantQuery, rangeQuery, labelNames, labelValues } from '../model';
|
|
14
|
+
/**
|
|
15
|
+
* Creates a PrometheusClient for a specific datasource spec.
|
|
16
|
+
*/ const createClient = (spec, options)=>{
|
|
17
|
+
const { direct_url } = spec;
|
|
18
|
+
const { proxyUrl } = options;
|
|
19
|
+
// Use the direct URL if specified, but fallback to the proxyUrl by default if not specified
|
|
20
|
+
const datasourceUrl = direct_url !== null && direct_url !== void 0 ? direct_url : proxyUrl;
|
|
21
|
+
if (datasourceUrl === undefined) {
|
|
22
|
+
throw new Error('No URL specified for Prometheus client. You can use direct_url in the spec to configure it.');
|
|
23
|
+
}
|
|
24
|
+
// Could think about this becoming a class, although it definitely doesn't have to be
|
|
25
|
+
return {
|
|
26
|
+
instantQuery: (params)=>instantQuery(params, {
|
|
27
|
+
datasourceUrl
|
|
28
|
+
}),
|
|
29
|
+
rangeQuery: (params)=>rangeQuery(params, {
|
|
30
|
+
datasourceUrl
|
|
31
|
+
}),
|
|
32
|
+
labelNames: (params)=>labelNames(params, {
|
|
33
|
+
datasourceUrl
|
|
34
|
+
}),
|
|
35
|
+
labelValues: (params)=>labelValues(params, {
|
|
36
|
+
datasourceUrl
|
|
37
|
+
})
|
|
38
|
+
};
|
|
39
|
+
};
|
|
13
40
|
export const PrometheusDatasource = {
|
|
41
|
+
createClient,
|
|
14
42
|
OptionsEditorComponent: ()=>null,
|
|
15
43
|
createInitialOptions: ()=>({
|
|
16
44
|
direct_url: ''
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/plugins/prometheus-datasource.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { DatasourcePlugin } from '@perses-dev/plugin-system';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/plugins/prometheus-datasource.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { DatasourcePlugin } from '@perses-dev/plugin-system';\nimport { instantQuery, rangeQuery, labelNames, labelValues, PrometheusClient } from '../model';\n\nexport interface PrometheusDatasourceSpec {\n direct_url?: string;\n}\n\n/**\n * Creates a PrometheusClient for a specific datasource spec.\n */\nconst createClient: DatasourcePlugin<PrometheusDatasourceSpec, PrometheusClient>['createClient'] = (spec, options) => {\n const { direct_url } = spec;\n const { proxyUrl } = options;\n\n // Use the direct URL if specified, but fallback to the proxyUrl by default if not specified\n const datasourceUrl = direct_url ?? proxyUrl;\n if (datasourceUrl === undefined) {\n throw new Error('No URL specified for Prometheus client. You can use direct_url in the spec to configure it.');\n }\n\n // Could think about this becoming a class, although it definitely doesn't have to be\n return {\n instantQuery: (params) => instantQuery(params, { datasourceUrl }),\n rangeQuery: (params) => rangeQuery(params, { datasourceUrl }),\n labelNames: (params) => labelNames(params, { datasourceUrl }),\n labelValues: (params) => labelValues(params, { datasourceUrl }),\n };\n};\n\nexport const PrometheusDatasource: DatasourcePlugin<PrometheusDatasourceSpec, PrometheusClient> = {\n createClient,\n OptionsEditorComponent: () => null,\n createInitialOptions: () => ({ direct_url: '' }),\n};\n"],"names":["instantQuery","rangeQuery","labelNames","labelValues","createClient","spec","options","direct_url","proxyUrl","datasourceUrl","undefined","Error","params","PrometheusDatasource","OptionsEditorComponent","createInitialOptions"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAGjC,SAASA,YAAY,EAAEC,UAAU,EAAEC,UAAU,EAAEC,WAAW,QAA0B,UAAU,CAAC;AAM/F;;CAEC,GACD,MAAMC,YAAY,GAAiF,CAACC,IAAI,EAAEC,OAAO,GAAK;IACpH,MAAM,EAAEC,UAAU,CAAA,EAAE,GAAGF,IAAI,AAAC;IAC5B,MAAM,EAAEG,QAAQ,CAAA,EAAE,GAAGF,OAAO,AAAC;IAE7B,4FAA4F;IAC5F,MAAMG,aAAa,GAAGF,UAAU,aAAVA,UAAU,cAAVA,UAAU,GAAIC,QAAQ,AAAC;IAC7C,IAAIC,aAAa,KAAKC,SAAS,EAAE;QAC/B,MAAM,IAAIC,KAAK,CAAC,6FAA6F,CAAC,CAAC;IACjH,CAAC;IAED,qFAAqF;IACrF,OAAO;QACLX,YAAY,EAAE,CAACY,MAAM,GAAKZ,YAAY,CAACY,MAAM,EAAE;gBAAEH,aAAa;aAAE,CAAC;QACjER,UAAU,EAAE,CAACW,MAAM,GAAKX,UAAU,CAACW,MAAM,EAAE;gBAAEH,aAAa;aAAE,CAAC;QAC7DP,UAAU,EAAE,CAACU,MAAM,GAAKV,UAAU,CAACU,MAAM,EAAE;gBAAEH,aAAa;aAAE,CAAC;QAC7DN,WAAW,EAAE,CAACS,MAAM,GAAKT,WAAW,CAACS,MAAM,EAAE;gBAAEH,aAAa;aAAE,CAAC;KAChE,CAAC;AACJ,CAAC,AAAC;AAEF,OAAO,MAAMI,oBAAoB,GAAiE;IAChGT,YAAY;IACZU,sBAAsB,EAAE,IAAM,IAAI;IAClCC,oBAAoB,EAAE,IAAO,CAAA;YAAER,UAAU,EAAE,EAAE;SAAE,CAAA,AAAC;CACjD,CAAC"}
|
|
@@ -1,14 +1,5 @@
|
|
|
1
1
|
import { VariablePlugin } from '@perses-dev/plugin-system';
|
|
2
|
-
import {
|
|
3
|
-
interface PrometheusVariableOptionsBase {
|
|
4
|
-
datasource?: PrometheusDatasourceSelector;
|
|
5
|
-
}
|
|
6
|
-
declare type PrometheusLabelNamesVariableOptions = PrometheusVariableOptionsBase;
|
|
7
|
-
declare type PrometheusLabelValuesVariableOptions = PrometheusVariableOptionsBase & {
|
|
8
|
-
label_name: string;
|
|
9
|
-
matchers?: [string];
|
|
10
|
-
};
|
|
2
|
+
import { PrometheusLabelNamesVariableOptions, PrometheusLabelValuesVariableOptions } from './types';
|
|
11
3
|
export declare const PrometheusLabelNamesVariable: VariablePlugin<PrometheusLabelNamesVariableOptions>;
|
|
12
4
|
export declare const PrometheusLabelValuesVariable: VariablePlugin<PrometheusLabelValuesVariableOptions>;
|
|
13
|
-
export {};
|
|
14
5
|
//# sourceMappingURL=prometheus-variables.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prometheus-variables.d.ts","sourceRoot":"","sources":["../../src/plugins/prometheus-variables.
|
|
1
|
+
{"version":3,"file":"prometheus-variables.d.ts","sourceRoot":"","sources":["../../src/plugins/prometheus-variables.tsx"],"names":[],"mappings":"AAYA,OAAO,EAAE,cAAc,EAAsC,MAAM,2BAA2B,CAAC;AAG/F,OAAO,EAAE,mCAAmC,EAAE,oCAAoC,EAAE,MAAM,SAAS,CAAC;AAgDpG,eAAO,MAAM,4BAA4B,EAAE,cAAc,CAAC,mCAAmC,CAY5F,CAAC;AAEF,eAAO,MAAM,6BAA6B,EAAE,cAAc,CAAC,oCAAoC,CAiB9F,CAAC"}
|