@perses-dev/prometheus-plugin 0.0.0-snapshot-embed-import-errors-8906900 → 0.0.0-snapshot-datasource-browser-test-28cbb71
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/components/PromQL.js +1 -1
- package/dist/cjs/components/index.js +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/model/api-types.js +1 -1
- package/dist/cjs/model/index.js +1 -2
- package/dist/cjs/model/parse-sample-values.js +1 -1
- package/dist/cjs/model/prometheus-client.js +4 -3
- package/dist/cjs/model/prometheus-selectors.js +1 -1
- package/dist/cjs/model/templating.js +2 -2
- package/dist/cjs/model/time.js +1 -1
- package/dist/cjs/plugins/MatcherEditor.js +1 -1
- package/dist/cjs/plugins/prometheus-datasource.js +15 -8
- package/dist/cjs/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.js +3 -3
- package/dist/cjs/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js +1 -1
- package/dist/cjs/plugins/prometheus-time-series-query/get-time-series-data.js +9 -7
- package/dist/cjs/plugins/prometheus-time-series-query/index.js +1 -1
- package/dist/cjs/plugins/prometheus-time-series-query/query-editor-model.js +1 -1
- package/dist/cjs/plugins/prometheus-time-series-query/time-series-query-model.js +1 -1
- package/dist/cjs/plugins/prometheus-variables.js +10 -9
- package/dist/cjs/plugins/types.js +1 -1
- package/dist/cjs/plugins/variable.js +1 -1
- package/dist/cjs/test/setup-tests.js +1 -1
- package/dist/cjs/utils/index.js +28 -0
- package/dist/cjs/{model → utils}/utils.js +37 -2
- package/dist/cjs/{model → utils}/utils.test.js +47 -1
- package/dist/components/PromQL.js +1 -1
- package/dist/components/PromQL.js.map +1 -1
- package/dist/components/index.js +1 -1
- package/dist/components/index.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/model/api-types.js +1 -1
- package/dist/model/api-types.js.map +1 -1
- package/dist/model/index.d.ts +0 -1
- package/dist/model/index.d.ts.map +1 -1
- package/dist/model/index.js +1 -2
- package/dist/model/index.js.map +1 -1
- package/dist/model/parse-sample-values.js +1 -1
- package/dist/model/parse-sample-values.js.map +1 -1
- package/dist/model/prometheus-client.d.ts +3 -0
- package/dist/model/prometheus-client.d.ts.map +1 -1
- package/dist/model/prometheus-client.js +4 -3
- package/dist/model/prometheus-client.js.map +1 -1
- package/dist/model/prometheus-selectors.js +1 -1
- package/dist/model/prometheus-selectors.js.map +1 -1
- package/dist/model/templating.js +2 -2
- package/dist/model/templating.js.map +1 -1
- package/dist/model/time.js +1 -1
- package/dist/model/time.js.map +1 -1
- package/dist/plugins/MatcherEditor.js +1 -1
- package/dist/plugins/MatcherEditor.js.map +1 -1
- package/dist/plugins/prometheus-datasource.d.ts +2 -0
- package/dist/plugins/prometheus-datasource.d.ts.map +1 -1
- package/dist/plugins/prometheus-datasource.js +15 -8
- package/dist/plugins/prometheus-datasource.js.map +1 -1
- package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.js +2 -2
- package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.js.map +1 -1
- package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js +1 -1
- package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js.map +1 -1
- package/dist/plugins/prometheus-time-series-query/get-time-series-data.d.ts.map +1 -1
- package/dist/plugins/prometheus-time-series-query/get-time-series-data.js +8 -6
- package/dist/plugins/prometheus-time-series-query/get-time-series-data.js.map +1 -1
- package/dist/plugins/prometheus-time-series-query/index.js +1 -1
- package/dist/plugins/prometheus-time-series-query/index.js.map +1 -1
- package/dist/plugins/prometheus-time-series-query/query-editor-model.js +1 -1
- package/dist/plugins/prometheus-time-series-query/query-editor-model.js.map +1 -1
- package/dist/plugins/prometheus-time-series-query/time-series-query-model.js +1 -1
- package/dist/plugins/prometheus-time-series-query/time-series-query-model.js.map +1 -1
- package/dist/plugins/prometheus-variables.d.ts.map +1 -1
- package/dist/plugins/prometheus-variables.js +3 -2
- package/dist/plugins/prometheus-variables.js.map +1 -1
- package/dist/plugins/types.js +1 -1
- package/dist/plugins/types.js.map +1 -1
- package/dist/plugins/variable.js +1 -1
- package/dist/plugins/variable.js.map +1 -1
- package/dist/test/setup-tests.js +1 -1
- package/dist/test/setup-tests.js.map +1 -1
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +15 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/{model → utils}/utils.d.ts +5 -0
- package/dist/{model → utils}/utils.d.ts.map +1 -1
- package/dist/{model → utils}/utils.js +37 -1
- package/dist/utils/utils.js.map +1 -0
- package/dist/{model → utils}/utils.test.d.ts +0 -0
- package/dist/{model → utils}/utils.test.d.ts.map +1 -1
- package/dist/{model → utils}/utils.test.js +48 -2
- package/dist/utils/utils.test.js.map +1 -0
- package/package.json +4 -4
- package/dist/model/utils.js.map +0 -1
- package/dist/model/utils.test.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/model/parse-sample-values.ts"],"sourcesContent":["// Copyright
|
|
1
|
+
{"version":3,"sources":["../../src/model/parse-sample-values.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 { ValueTuple } from './api-types';\n\n/**\n * ValueTuple from the Prom server, parsed into ms and floating point number\n */\nexport type ParsedValueTuple = [unixTimeMs: number, value: number];\n\n/**\n * Parse a ValueTuple from a PromServer response into the a millisecond-based\n * unix time and a numeric sample value.\n */\nexport function parseValueTuple(data: ValueTuple): ParsedValueTuple {\n const [unixTimeSeconds, sampleValue] = data;\n\n // Prom returns unix time in seconds, so convert to ms\n return [unixTimeSeconds * 1000, parseSampleValue(sampleValue)];\n}\n\n/**\n * Parses a string sample value from Prometheus, usually included as the\n * second member of a ValueTuple.\n */\nexport function parseSampleValue(sampleValue: ValueTuple[1]): number {\n // Account for Prometheus' representation of +/- infinity, otherwise just\n // parse the sample value as a float\n let value: number;\n switch (sampleValue) {\n case '+Inf':\n value = Number.POSITIVE_INFINITY;\n break;\n case '-Inf':\n value = Number.NEGATIVE_INFINITY;\n break;\n default:\n value = parseFloat(sampleValue);\n }\n return value;\n}\n"],"names":["parseValueTuple","data","unixTimeSeconds","sampleValue","parseSampleValue","value","Number","POSITIVE_INFINITY","NEGATIVE_INFINITY","parseFloat"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AASjC;;;CAGC,GACD,OAAO,SAASA,eAAe,CAACC,IAAgB,EAAoB;IAClE,MAAM,CAACC,eAAe,EAAEC,WAAW,CAAC,GAAGF,IAAI,AAAC;IAE5C,sDAAsD;IACtD,OAAO;QAACC,eAAe,GAAG,IAAI;QAAEE,gBAAgB,CAACD,WAAW,CAAC;KAAC,CAAC;AACjE,CAAC;AAED;;;CAGC,GACD,OAAO,SAASC,gBAAgB,CAACD,WAA0B,EAAU;IACnE,yEAAyE;IACzE,oCAAoC;IACpC,IAAIE,KAAK,AAAQ,AAAC;IAClB,OAAQF,WAAW;QACjB,KAAK,MAAM;YACTE,KAAK,GAAGC,MAAM,CAACC,iBAAiB,CAAC;YACjC,MAAM;QACR,KAAK,MAAM;YACTF,KAAK,GAAGC,MAAM,CAACE,iBAAiB,CAAC;YACjC,MAAM;QACR;YACEH,KAAK,GAAGI,UAAU,CAACN,WAAW,CAAC,CAAC;KACnC;IACD,OAAOE,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { RequestHeaders } from '@perses-dev/core';
|
|
1
2
|
import { InstantQueryRequestParameters, InstantQueryResponse, LabelNamesRequestParameters, LabelNamesResponse, LabelValuesRequestParameters, LabelValuesResponse, RangeQueryRequestParameters, RangeQueryResponse } from './api-types';
|
|
2
3
|
interface PrometheusClientOptions {
|
|
3
4
|
datasourceUrl: string;
|
|
5
|
+
headers?: RequestHeaders;
|
|
4
6
|
}
|
|
5
7
|
export interface PrometheusClient {
|
|
6
8
|
options: PrometheusClientOptions;
|
|
@@ -11,6 +13,7 @@ export interface PrometheusClient {
|
|
|
11
13
|
}
|
|
12
14
|
export interface QueryOptions {
|
|
13
15
|
datasourceUrl: string;
|
|
16
|
+
headers?: RequestHeaders;
|
|
14
17
|
}
|
|
15
18
|
/**
|
|
16
19
|
* 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":"AAaA,OAAO,EAAa,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EACL,6BAA6B,EAC7B,oBAAoB,EACpB,2BAA2B,EAC3B,kBAAkB,EAClB,4BAA4B,EAC5B,mBAAmB,EACnB,2BAA2B,EAC3B,kBAAkB,EACnB,MAAM,aAAa,CAAC;AAErB,UAAU,uBAAuB;IAC/B,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,cAAc,CAAC;CAC1B;AAED,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,uBAAuB,CAAC;IACjC,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;IACtB,OAAO,CAAC,EAAE,cAAc,CAAC;CAC1B;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,6BAA6B,EAAE,YAAY,EAAE,YAAY,iCAE7F;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,2BAA2B,EAAE,YAAY,EAAE,YAAY,+BAEzF;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,2BAA2B,EAAE,YAAY,EAAE,YAAY,+BAEzF;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,4BAA4B,EAAE,YAAY,EAAE,YAAY,gCAI3F"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
2
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
3
|
// you may not use this file except in compliance with the License.
|
|
4
4
|
// You may obtain a copy of the License at
|
|
@@ -45,12 +45,13 @@ function fetchWithGet(apiURI, params, queryOptions) {
|
|
|
45
45
|
});
|
|
46
46
|
}
|
|
47
47
|
function fetchWithPost(apiURI, params, queryOptions) {
|
|
48
|
-
const { datasourceUrl } = queryOptions;
|
|
48
|
+
const { datasourceUrl , headers } = queryOptions;
|
|
49
49
|
const url = `${datasourceUrl}${apiURI}`;
|
|
50
50
|
const init = {
|
|
51
51
|
method: 'POST',
|
|
52
52
|
headers: {
|
|
53
|
-
'Content-Type': 'application/x-www-form-urlencoded'
|
|
53
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
54
|
+
...headers
|
|
54
55
|
},
|
|
55
56
|
body: createSearchParams(params)
|
|
56
57
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/model/prometheus-client.ts"],"sourcesContent":["// Copyright
|
|
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 { fetchJson, RequestHeaders } 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\ninterface PrometheusClientOptions {\n datasourceUrl: string;\n headers?: RequestHeaders;\n}\n\nexport interface PrometheusClient {\n options: PrometheusClientOptions;\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 headers?: RequestHeaders;\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, headers } = queryOptions;\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 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","headers","init","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,QAAwB,kBAAkB,CAAC;AA8B7D;;CAEC,GACD,OAAO,SAASC,YAAY,CAACC,MAAqC,EAAEC,YAA0B,EAAE;IAC9F,OAAOC,aAAa,CAAsD,eAAe,EAAEF,MAAM,EAAEC,YAAY,CAAC,CAAC;AACnH,CAAC;AAED;;CAEC,GACD,OAAO,SAASE,UAAU,CAACH,MAAmC,EAAEC,YAA0B,EAAE;IAC1F,OAAOC,aAAa,CAAkD,qBAAqB,EAAEF,MAAM,EAAEC,YAAY,CAAC,CAAC;AACrH,CAAC;AAED;;CAEC,GACD,OAAO,SAASG,UAAU,CAACJ,MAAmC,EAAEC,YAA0B,EAAE;IAC1F,OAAOC,aAAa,CAAkD,gBAAgB,EAAEF,MAAM,EAAEC,YAAY,CAAC,CAAC;AAChH,CAAC;AAED;;CAEC,GACD,OAAO,SAASI,WAAW,CAACL,MAAoC,EAAEC,YAA0B,EAAE;IAC5F,MAAM,EAAEK,SAAS,CAAA,EAAE,GAAGC,YAAY,EAAE,GAAGP,MAAM,AAAC;IAC9C,MAAMQ,MAAM,GAAG,CAAC,cAAc,EAAEC,kBAAkB,CAACH,SAAS,C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K,GAAetB,MAAM,CAACqB,GAAG,CAAC,AAAC;QACtC,IAAIC,KAAK,KAAKC,SAAS,EAAE,SAAS;QAElC,IAAI,OAAOD,KAAK,KAAK,QAAQ,EAAE;YAC7Bf,YAAY,CAACiB,MAAM,CAACH,GAAG,EAAEC,KAAK,CAAC,CAAC;YAChC,SAAS;QACX,CAAC;QAED,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;YAC7Bf,YAAY,CAACiB,MAAM,CAACH,GAAG,EAAEC,KAAK,CAACP,QAAQ,EAAE,CAAC,CAAC;YAC3C,SAAS;QACX,CAAC;QAED,KAAK,MAAMU,GAAG,IAAIH,KAAK,CAAE;YACvBf,YAAY,CAACiB,MAAM,CAACH,GAAG,EAAEI,GAAG,CAAC,CAAC;QAChC,CAAC;IACH,CAAC;IACD,OAAOlB,YAAY,CAAC;AACtB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/model/prometheus-selectors.ts"],"sourcesContent":["// Copyright
|
|
1
|
+
{"version":3,"sources":["../../src/model/prometheus-selectors.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 { 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"}
|
package/dist/model/templating.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
2
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
3
|
// you may not use this file except in compliance with the License.
|
|
4
4
|
// You may obtain a copy of the License at
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { useTemplateVariableValues } from '@perses-dev/plugin-system';
|
|
14
|
-
import { replaceTemplateVariables, parseTemplateVariables } from '
|
|
14
|
+
import { replaceTemplateVariables, parseTemplateVariables } from '../utils';
|
|
15
15
|
export function useReplaceTemplateString(templateString) {
|
|
16
16
|
const templateVariablesInTemplate = parseTemplateVariables(templateString || '');
|
|
17
17
|
const variables = useTemplateVariableValues(templateVariablesInTemplate);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/model/templating.ts"],"sourcesContent":["// Copyright
|
|
1
|
+
{"version":3,"sources":["../../src/model/templating.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 { useTemplateVariableValues } from '@perses-dev/plugin-system';\nimport { replaceTemplateVariables, parseTemplateVariables } from '../utils';\n\n/**\n * Type alias to indicate what parts of the API support template variables.\n */\nexport type TemplateString = string;\n\nexport function useReplaceTemplateString(templateString?: TemplateString) {\n const templateVariablesInTemplate = parseTemplateVariables(templateString || '');\n const variables = useTemplateVariableValues(templateVariablesInTemplate);\n return replaceTemplateVariables(templateString || '', variables);\n}\n"],"names":["useTemplateVariableValues","replaceTemplateVariables","parseTemplateVariables","useReplaceTemplateString","templateString","templateVariablesInTemplate","variables"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,yBAAyB,QAAQ,2BAA2B,CAAC;AACtE,SAASC,wBAAwB,EAAEC,sBAAsB,QAAQ,UAAU,CAAC;AAO5E,OAAO,SAASC,wBAAwB,CAACC,cAA+B,EAAE;IACxE,MAAMC,2BAA2B,GAAGH,sBAAsB,CAACE,cAAc,IAAI,EAAE,CAAC,AAAC;IACjF,MAAME,SAAS,GAAGN,yBAAyB,CAACK,2BAA2B,CAAC,AAAC;IACzE,OAAOJ,wBAAwB,CAACG,cAAc,IAAI,EAAE,EAAEE,SAAS,CAAC,CAAC;AACnE,CAAC"}
|
package/dist/model/time.js
CHANGED
package/dist/model/time.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/model/time.ts"],"sourcesContent":["// Copyright
|
|
1
|
+
{"version":3,"sources":["../../src/model/time.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 { AbsoluteTimeRange, DurationString, parseDurationString } from '@perses-dev/core';\nimport { milliseconds, getUnixTime } from 'date-fns';\nimport { UnixTimestampSeconds } from './api-types';\n\nexport interface PrometheusTimeRange {\n start: UnixTimestampSeconds;\n end: UnixTimestampSeconds;\n}\n\n/**\n * Converts an AbsoluteTimeRange to Prometheus time in Unix time (i.e. in seconds).\n */\nexport function getPrometheusTimeRange(timeRange: AbsoluteTimeRange) {\n const { start, end } = timeRange;\n return {\n start: Math.ceil(getUnixTime(start)),\n end: Math.ceil(getUnixTime(end)),\n };\n}\n\n// Max data points to allow returning from a Prom Query, used to calculate a\n// \"safe\" step for a range query\nconst MAX_PROM_DATA_POINTS = 10000;\n\n/**\n * Gets the step to use for a Prom range query. Tries to take into account a suggested step size (probably based on the\n * width of a visualization where the data will be graphed), any minimum step/resolution set by the user, and a \"safe\"\n * step based on the max data points we want to allow returning from a Prom query.\n */\nexport function getRangeStep(timeRange: PrometheusTimeRange, minStepSeconds = 15, resolution = 1, suggestedStepMs = 0) {\n const suggestedStepSeconds = suggestedStepMs / 1000;\n const queryRangeSeconds = timeRange.end - timeRange.start;\n\n let safeStep = queryRangeSeconds / MAX_PROM_DATA_POINTS;\n if (safeStep > 1) {\n safeStep = Math.ceil(safeStep);\n }\n\n return Math.max(suggestedStepSeconds * resolution, minStepSeconds, safeStep);\n}\n\n/**\n * Converts a DurationString to seconds, rounding down.\n */\nexport function getDurationStringSeconds(durationString?: DurationString) {\n if (durationString === undefined) return undefined;\n\n const duration = parseDurationString(durationString);\n const ms = milliseconds(duration);\n return Math.floor(ms / 1000);\n}\n"],"names":["parseDurationString","milliseconds","getUnixTime","getPrometheusTimeRange","timeRange","start","end","Math","ceil","MAX_PROM_DATA_POINTS","getRangeStep","minStepSeconds","resolution","suggestedStepMs","suggestedStepSeconds","queryRangeSeconds","safeStep","max","getDurationStringSeconds","durationString","undefined","duration","ms","floor"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAA4CA,mBAAmB,QAAQ,kBAAkB,CAAC;AAC1F,SAASC,YAAY,EAAEC,WAAW,QAAQ,UAAU,CAAC;AAQrD;;CAEC,GACD,OAAO,SAASC,sBAAsB,CAACC,SAA4B,EAAE;IACnE,MAAM,EAAEC,KAAK,CAAA,EAAEC,GAAG,CAAA,EAAE,GAAGF,SAAS,AAAC;IACjC,OAAO;QACLC,KAAK,EAAEE,IAAI,CAACC,IAAI,CAACN,WAAW,CAACG,KAAK,CAAC,CAAC;QACpCC,GAAG,EAAEC,IAAI,CAACC,IAAI,CAACN,WAAW,CAACI,GAAG,CAAC,CAAC;KACjC,CAAC;AACJ,CAAC;AAED,4EAA4E;AAC5E,gCAAgC;AAChC,MAAMG,oBAAoB,GAAG,KAAK,AAAC;AAEnC;;;;CAIC,GACD,OAAO,SAASC,YAAY,CAACN,SAA8B,EAAEO,cAAc,GAAG,EAAE,EAAEC,UAAU,GAAG,CAAC,EAAEC,eAAe,GAAG,CAAC,EAAE;IACrH,MAAMC,oBAAoB,GAAGD,eAAe,GAAG,IAAI,AAAC;IACpD,MAAME,iBAAiB,GAAGX,SAAS,CAACE,GAAG,GAAGF,SAAS,CAACC,KAAK,AAAC;IAE1D,IAAIW,QAAQ,GAAGD,iBAAiB,GAAGN,oBAAoB,AAAC;IACxD,IAAIO,QAAQ,GAAG,CAAC,EAAE;QAChBA,QAAQ,GAAGT,IAAI,CAACC,IAAI,CAACQ,QAAQ,CAAC,CAAC;IACjC,CAAC;IAED,OAAOT,IAAI,CAACU,GAAG,CAACH,oBAAoB,GAAGF,UAAU,EAAED,cAAc,EAAEK,QAAQ,CAAC,CAAC;AAC/E,CAAC;AAED;;CAEC,GACD,OAAO,SAASE,wBAAwB,CAACC,cAA+B,EAAE;IACxE,IAAIA,cAAc,KAAKC,SAAS,EAAE,OAAOA,SAAS,CAAC;IAEnD,MAAMC,QAAQ,GAAGrB,mBAAmB,CAACmB,cAAc,CAAC,AAAC;IACrD,MAAMG,EAAE,GAAGrB,YAAY,CAACoB,QAAQ,CAAC,AAAC;IAClC,OAAOd,IAAI,CAACgB,KAAK,CAACD,EAAE,GAAG,IAAI,CAAC,CAAC;AAC/B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/plugins/MatcherEditor.tsx"],"sourcesContent":["// Copyright
|
|
1
|
+
{"version":3,"sources":["../../src/plugins/MatcherEditor.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 { Stack, TextField, Button, Box, IconButton } from '@mui/material';\nimport { produce } from 'immer';\nimport TrashIcon from 'mdi-material-ui/TrashCan';\n\ntype MatcherEditorProps = {\n matchers: string[];\n onChange: (matchers: string[]) => void;\n};\n\nexport function MatcherEditor({ matchers, onChange }: MatcherEditorProps) {\n return (\n <Stack spacing={1}>\n {matchers.map((matcher, index) => (\n <Box key={index} display=\"flex\">\n <TextField\n fullWidth\n label=\"Series Selector\"\n value={matcher}\n onChange={(e) => {\n const newMatchers = produce(matchers, (draft) => {\n draft[index] = e.target.value;\n });\n onChange(newMatchers);\n }}\n />\n <IconButton\n onClick={() => {\n const newMatchers = produce(matchers, (draft) => {\n draft.splice(index, 1);\n });\n onChange(newMatchers);\n }}\n >\n <TrashIcon />\n </IconButton>\n </Box>\n ))}\n <Box>\n <Button\n fullWidth={false}\n color=\"secondary\"\n variant=\"outlined\"\n onClick={() => {\n const newMatchers = produce(matchers, (draft) => {\n draft.push('');\n });\n onChange(newMatchers);\n }}\n >\n Add Series Selector\n </Button>\n </Box>\n </Stack>\n );\n}\n"],"names":["Stack","TextField","Button","Box","IconButton","produce","TrashIcon","MatcherEditor","matchers","onChange","spacing","map","matcher","index","display","fullWidth","label","value","e","newMatchers","draft","target","onClick","splice","color","variant","push"],"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,KAAK,EAAEC,SAAS,EAAEC,MAAM,EAAEC,GAAG,EAAEC,UAAU,QAAQ,eA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C/CA,KAAK,CAACM,IAAI,CAAC,EAAE,CAAC,CAAC;wBACjB,CAAC,CAAC,AAAC;wBACHjB,QAAQ,CAACU,WAAW,CAAC,CAAC;oBACxB,CAAC;8BACF,qBAED;kBAAS;cACL;;MACA,CACR;AACJ,CAAC"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { RequestHeaders } from '@perses-dev/core';
|
|
1
2
|
import { DatasourcePlugin } from '@perses-dev/plugin-system';
|
|
2
3
|
import { PrometheusClient } from '../model';
|
|
3
4
|
export interface PrometheusDatasourceSpec {
|
|
4
5
|
direct_url?: string;
|
|
6
|
+
headers?: RequestHeaders;
|
|
5
7
|
}
|
|
6
8
|
export declare const PrometheusDatasource: DatasourcePlugin<PrometheusDatasourceSpec, PrometheusClient>;
|
|
7
9
|
//# 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,EAAqD,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE/F,MAAM,WAAW,wBAAwB;IACvC,UAAU,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"prometheus-datasource.d.ts","sourceRoot":"","sources":["../../src/plugins/prometheus-datasource.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,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;IACpB,OAAO,CAAC,EAAE,cAAc,CAAC;CAC1B;AA+BD,eAAO,MAAM,oBAAoB,EAAE,gBAAgB,CAAC,wBAAwB,EAAE,gBAAgB,CAI7F,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
2
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
3
|
// you may not use this file except in compliance with the License.
|
|
4
4
|
// You may obtain a copy of the License at
|
|
@@ -14,31 +14,38 @@ import { instantQuery, rangeQuery, labelNames, labelValues } from '../model';
|
|
|
14
14
|
/**
|
|
15
15
|
* Creates a PrometheusClient for a specific datasource spec.
|
|
16
16
|
*/ const createClient = (spec, options)=>{
|
|
17
|
-
const { direct_url } = spec;
|
|
17
|
+
const { direct_url , headers } = spec;
|
|
18
18
|
const { proxyUrl } = options;
|
|
19
|
+
// const headers = direct_url ? spec.headers : spec.proxy?.spec.headers;
|
|
19
20
|
// Use the direct URL if specified, but fallback to the proxyUrl by default if not specified
|
|
20
21
|
const datasourceUrl = direct_url !== null && direct_url !== void 0 ? direct_url : proxyUrl;
|
|
21
22
|
if (datasourceUrl === undefined) {
|
|
22
23
|
throw new Error('No URL specified for Prometheus client. You can use direct_url in the spec to configure it.');
|
|
23
24
|
}
|
|
24
25
|
// Could think about this becoming a class, although it definitely doesn't have to be
|
|
25
|
-
|
|
26
|
+
const client = {
|
|
26
27
|
options: {
|
|
27
|
-
datasourceUrl
|
|
28
|
+
datasourceUrl,
|
|
29
|
+
headers
|
|
28
30
|
},
|
|
29
31
|
instantQuery: (params)=>instantQuery(params, {
|
|
30
|
-
datasourceUrl
|
|
32
|
+
datasourceUrl,
|
|
33
|
+
headers
|
|
31
34
|
}),
|
|
32
35
|
rangeQuery: (params)=>rangeQuery(params, {
|
|
33
|
-
datasourceUrl
|
|
36
|
+
datasourceUrl,
|
|
37
|
+
headers
|
|
34
38
|
}),
|
|
35
39
|
labelNames: (params)=>labelNames(params, {
|
|
36
|
-
datasourceUrl
|
|
40
|
+
datasourceUrl,
|
|
41
|
+
headers
|
|
37
42
|
}),
|
|
38
43
|
labelValues: (params)=>labelValues(params, {
|
|
39
|
-
datasourceUrl
|
|
44
|
+
datasourceUrl,
|
|
45
|
+
headers
|
|
40
46
|
})
|
|
41
47
|
};
|
|
48
|
+
return client;
|
|
42
49
|
};
|
|
43
50
|
export const PrometheusDatasource = {
|
|
44
51
|
createClient,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/plugins/prometheus-datasource.ts"],"sourcesContent":["// Copyright
|
|
1
|
+
{"version":3,"sources":["../../src/plugins/prometheus-datasource.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 { RequestHeaders } from '@perses-dev/core';\nimport { DatasourcePlugin } from '@perses-dev/plugin-system';\nimport { instantQuery, rangeQuery, labelNames, labelValues, PrometheusClient } from '../model';\n\nexport interface PrometheusDatasourceSpec {\n direct_url?: string;\n headers?: RequestHeaders;\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, headers } = spec;\n const { proxyUrl } = options;\n\n // const headers = direct_url ? spec.headers : spec.proxy?.spec.headers;\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 const client: PrometheusClient = {\n options: {\n datasourceUrl,\n headers,\n },\n instantQuery: (params) => instantQuery(params, { datasourceUrl, headers }),\n rangeQuery: (params) => rangeQuery(params, { datasourceUrl, headers }),\n labelNames: (params) => labelNames(params, { datasourceUrl, headers }),\n labelValues: (params) => labelValues(params, { datasourceUrl, headers }),\n };\n return client;\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","headers","proxyUrl","datasourceUrl","undefined","Error","client","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;AAIjC,SAASA,YAAY,EAAEC,UAAU,EAAEC,UAAU,EAAEC,WAAW,QAA0B,UAAU,CAAC;AAO/F;;CAEC,GACD,MAAMC,YAAY,GAAiF,CAACC,IAAI,EAAEC,OAAO,GAAK;IACpH,MAAM,EAAEC,UAAU,CAAA,EAAEC,OAAO,CAAA,EAAE,GAAGH,IAAI,AAAC;IACrC,MAAM,EAAEI,QAAQ,CAAA,EAAE,GAAGH,OAAO,AAAC;IAE7B,wEAAwE;IAExE,4FAA4F;IAC5F,MAAMI,aAAa,GAAGH,UAAU,aAAVA,UAAU,cAAVA,UAAU,GAAIE,QAAQ,AAAC;IAC7C,IAAIC,aAAa,KAAKC,SAAS,EAAE;QAC/B,MAAM,IAAIC,KAAK,CAAC,6FAA6F,CAAC,CAAC;IACjH,CAAC;IAED,qFAAqF;IACrF,MAAMC,MAAM,GAAqB;QAC/BP,OAAO,EAAE;YACPI,aAAa;YACbF,OAAO;SACR;QACDR,YAAY,EAAE,CAACc,MAAM,GAAKd,YAAY,CAACc,MAAM,EAAE;gBAAEJ,aAAa;gBAAEF,OAAO;aAAE,CAAC;QAC1EP,UAAU,EAAE,CAACa,MAAM,GAAKb,UAAU,CAACa,MAAM,EAAE;gBAAEJ,aAAa;gBAAEF,OAAO;aAAE,CAAC;QACtEN,UAAU,EAAE,CAACY,MAAM,GAAKZ,UAAU,CAACY,MAAM,EAAE;gBAAEJ,aAAa;gBAAEF,OAAO;aAAE,CAAC;QACtEL,WAAW,EAAE,CAACW,MAAM,GAAKX,WAAW,CAACW,MAAM,EAAE;gBAAEJ,aAAa;gBAAEF,OAAO;aAAE,CAAC;KACzE,AAAC;IACF,OAAOK,MAAM,CAAC;AAChB,CAAC,AAAC;AAEF,OAAO,MAAME,oBAAoB,GAAiE;IAChGX,YAAY;IACZY,sBAAsB,EAAE,IAAM,IAAI;IAClCC,oBAAoB,EAAE,IAAO,CAAA;YAAEV,UAAU,EAAE,EAAE;SAAE,CAAA,AAAC;CACjD,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
2
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
3
|
// you may not use this file except in compliance with the License.
|
|
4
4
|
// You may obtain a copy of the License at
|
|
@@ -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 { parseTemplateVariables } from '../../
|
|
13
|
+
import { parseTemplateVariables } from '../../utils';
|
|
14
14
|
import { getTimeSeriesData } from './get-time-series-data';
|
|
15
15
|
import { PrometheusTimeSeriesQueryEditor } from './PrometheusTimeSeriesQueryEditor';
|
|
16
16
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.ts"],"sourcesContent":["// Copyright
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.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 { TimeSeriesQueryPlugin } from '@perses-dev/plugin-system';\nimport { parseTemplateVariables } from '../../utils';\nimport { getTimeSeriesData } from './get-time-series-data';\nimport { PrometheusTimeSeriesQueryEditor } from './PrometheusTimeSeriesQueryEditor';\nimport { PrometheusTimeSeriesQuerySpec } from './time-series-query-model';\n\n/**\n * The core Prometheus TimeSeriesQuery plugin for Perses.\n */\nexport const PrometheusTimeSeriesQuery: TimeSeriesQueryPlugin<PrometheusTimeSeriesQuerySpec> = {\n getTimeSeriesData,\n OptionsEditorComponent: PrometheusTimeSeriesQueryEditor,\n createInitialOptions: () => ({\n query: '',\n datasource: undefined,\n }),\n dependsOn: (spec) => {\n return {\n variables: parseTemplateVariables(spec.query),\n };\n },\n};\n"],"names":["parseTemplateVariables","getTimeSeriesData","PrometheusTimeSeriesQueryEditor","PrometheusTimeSeriesQuery","OptionsEditorComponent","createInitialOptions","query","datasource","undefined","dependsOn","spec","variables"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAGjC,SAASA,sBAAsB,QAAQ,aAAa,CAAC;AACrD,SAASC,iBAAiB,QAAQ,wBAAwB,CAAC;AAC3D,SAASC,+BAA+B,QAAQ,mCAAmC,CAAC;AAGpF;;CAEC,GACD,OAAO,MAAMC,yBAAyB,GAAyD;IAC7FF,iBAAiB;IACjBG,sBAAsB,EAAEF,+BAA+B;IACvDG,oBAAoB,EAAE,IAAO,CAAA;YAC3BC,KAAK,EAAE,EAAE;YACTC,UAAU,EAAEC,SAAS;SACtB,CAAA,AAAC;IACFC,SAAS,EAAE,CAACC,IAAI,GAAK;QACnB,OAAO;YACLC,SAAS,EAAEX,sBAAsB,CAACU,IAAI,CAACJ,KAAK,CAAC;SAC9C,CAAC;IACJ,CAAC;CACF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.tsx"],"sourcesContent":["// Copyright
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.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 { produce } from 'immer';\nimport { Stack, TextField, FormControl, InputLabel } from '@mui/material';\nimport { DatasourceSelect, DatasourceSelectProps, useDatasourceClient } from '@perses-dev/plugin-system';\nimport { DEFAULT_PROM, isDefaultPromSelector, isPrometheusDatasourceSelector, PrometheusClient } from '../../model';\nimport { PromQLEditor } from '../../components';\nimport { PrometheusTimeSeriesQueryEditorProps, useQueryState, useFormatState } from './query-editor-model';\n\n/**\n * The options editor component for editing a PrometheusTimeSeriesQuery's spec.\n */\nexport function PrometheusTimeSeriesQueryEditor(props: PrometheusTimeSeriesQueryEditorProps) {\n const { onChange, value } = props;\n const { datasource } = value;\n const selectedDatasource = datasource ?? DEFAULT_PROM;\n\n const { data: client } = useDatasourceClient<PrometheusClient>(selectedDatasource);\n const promURL = client?.options.datasourceUrl;\n\n const { query, handleQueryChange, handleQueryBlur } = useQueryState(props);\n const { format, handleFormatChange, handleFormatBlur } = useFormatState(props);\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 <Stack spacing={2}>\n <PromQLEditor\n completeConfig={{ remote: { url: promURL } }}\n value={query}\n onChange={handleQueryChange}\n onBlur={handleQueryBlur}\n />\n <TextField\n fullWidth\n label=\"Series Name Format\"\n value={format ?? ''}\n onChange={(e) => handleFormatChange(e.target.value)}\n onBlur={handleFormatBlur}\n margin=\"dense\"\n />\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={selectedDatasource}\n onChange={handleDatasourceChange}\n labelId=\"prom-datasource-label\"\n label=\"Prometheus Datasource\"\n />\n </FormControl>\n </Stack>\n );\n}\n"],"names":["produce","Stack","TextField","FormControl","InputLabel","DatasourceSelect","useDatasourceClient","DEFAULT_PROM","isDefaultPromSelector","isPrometheusDatasourceSelector","PromQLEditor","useQueryState","useFormatState","PrometheusTimeSeriesQueryEditor","props","onChange","value","datasource","selectedDatasource","data","client","promURL","options","datasourceUrl","query","handleQueryChange","handleQueryBlur","format","handleFormatChange","handleFormatBlur","handleDatasourceChange","next","draft","nextDatasource","undefined","Error","spacing","completeConfig","remote","url","onBlur","fullWidth","label","e","target","margin","id","datasourcePluginKind","labelId"],"mappings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,EAAEe,sBAAsB;wBAChCkB,OAAO,EAAC,uBAAuB;wBAC/BN,KAAK,EAAC,uBAAuB;sBAC7B;;cACU;;MACR,CACR;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-time-series-data.d.ts","sourceRoot":"","sources":["../../../src/plugins/prometheus-time-series-query/get-time-series-data.ts"],"names":[],"mappings":"AAaA,OAAO,EAAkB,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"get-time-series-data.d.ts","sourceRoot":"","sources":["../../../src/plugins/prometheus-time-series-query/get-time-series-data.ts"],"names":[],"mappings":"AAaA,OAAO,EAAkB,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAWlF,OAAO,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAE1E,eAAO,MAAM,iBAAiB,EAAE,qBAAqB,CAAC,6BAA6B,CAAC,CAAC,mBAAmB,CAsEvG,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
2
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
3
|
// you may not use this file except in compliance with the License.
|
|
4
4
|
// You may obtain a copy of the License at
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { fromUnixTime } from 'date-fns';
|
|
14
|
-
import { parseValueTuple, getDurationStringSeconds, getPrometheusTimeRange, getRangeStep,
|
|
14
|
+
import { parseValueTuple, getDurationStringSeconds, getPrometheusTimeRange, getRangeStep, DEFAULT_PROM } from '../../model';
|
|
15
|
+
import { getUniqueKeyForPrometheusResult, replaceTemplateVariables, formatSeriesName } from '../../utils';
|
|
15
16
|
export const getTimeSeriesData = async (spec, context)=>{
|
|
16
17
|
var ref;
|
|
17
18
|
if (spec.query === undefined || spec.query === null || spec.query === '') {
|
|
@@ -58,10 +59,11 @@ export const getTimeSeriesData = async (spec, context)=>{
|
|
|
58
59
|
// processing until its needed
|
|
59
60
|
series: result.map((value)=>{
|
|
60
61
|
const { metric , values } = value;
|
|
61
|
-
// Name the series after the metric labels or if no metric,
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
// Name the series after the metric labels or if no metric, use the query
|
|
63
|
+
let name = getUniqueKeyForPrometheusResult(metric);
|
|
64
|
+
if (name === '') {
|
|
65
|
+
name = query;
|
|
66
|
+
}
|
|
65
67
|
// query editor allows you to define an optional series_name_format
|
|
66
68
|
// property to customize legend and tooltip display
|
|
67
69
|
const formattedName = spec.series_name_format ? formatSeriesName(spec.series_name_format, metric) : name;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/get-time-series-data.ts"],"sourcesContent":["// Copyright
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/get-time-series-data.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 { TimeSeriesData, TimeSeriesQueryPlugin } from '@perses-dev/plugin-system';\nimport { fromUnixTime } from 'date-fns';\nimport {\n parseValueTuple,\n PrometheusClient,\n getDurationStringSeconds,\n getPrometheusTimeRange,\n getRangeStep,\n DEFAULT_PROM,\n} from '../../model';\nimport { getUniqueKeyForPrometheusResult, replaceTemplateVariables, formatSeriesName } from '../../utils';\nimport { PrometheusTimeSeriesQuerySpec } from './time-series-query-model';\n\nexport const getTimeSeriesData: TimeSeriesQueryPlugin<PrometheusTimeSeriesQuerySpec>['getTimeSeriesData'] = async (\n spec,\n context\n) => {\n if (spec.query === undefined || spec.query === null || spec.query === '') {\n // Do not make a request to the backend, instead return an empty TimeSeriesData\n return { series: [] };\n }\n\n const minStep = getDurationStringSeconds(spec.min_step);\n const timeRange = getPrometheusTimeRange(context.timeRange);\n const step = getRangeStep(timeRange, minStep, undefined, context.suggestedStepMs);\n\n // Align the time range so that it's a multiple of the step\n let { start, end } = timeRange;\n const utcOffsetSec = new Date().getTimezoneOffset() * 60;\n\n const alignedEnd = Math.floor((end + utcOffsetSec) / step) * step - utcOffsetSec;\n const alignedStart = Math.floor((start + utcOffsetSec) / step) * step - utcOffsetSec;\n start = alignedStart;\n end = alignedEnd;\n\n // Replace template variable placeholders in PromQL query\n let query = spec.query.replace('$__rate_interval', `15s`);\n query = replaceTemplateVariables(query, context.variableState);\n\n // Get the datasource, using the default Prom Datasource if one isn't specified in the query\n const client: PrometheusClient = await context.datasourceStore.getDatasourceClient(spec.datasource ?? DEFAULT_PROM);\n\n // Make the request to Prom\n const response = await client.rangeQuery({\n query,\n start,\n end,\n step,\n });\n\n // TODO: What about error responses from Prom that have a response body?\n const result = response.data?.result ?? [];\n\n // Transform response\n const chartData: TimeSeriesData = {\n // Return the time range and step we actually used for the query\n timeRange: { start: fromUnixTime(start), end: fromUnixTime(end) },\n stepMs: step * 1000,\n\n // TODO: Maybe do a proper Iterable implementation that defers some of this\n // processing until its needed\n series: result.map((value) => {\n const { metric, values } = value;\n\n // Name the series after the metric labels or if no metric, use the query\n let name = getUniqueKeyForPrometheusResult(metric);\n if (name === '') {\n name = query;\n }\n\n // query editor allows you to define an optional series_name_format\n // property to customize legend and tooltip display\n const formattedName = spec.series_name_format ? formatSeriesName(spec.series_name_format, metric) : name;\n\n return {\n name,\n values: values.map(parseValueTuple),\n formattedName,\n };\n }),\n };\n\n return chartData;\n};\n"],"names":["fromUnixTime","parseValueTuple","getDurationStringSeconds","getPrometheusTimeRange","getRangeStep","DEFAULT_PROM","getUniqueKeyForPrometheusResult","replaceTemplateVariables","formatSeriesName","getTimeSeriesData","spec","context","response","query","undefined","series","minStep","min_step","timeRange","step","suggestedStepMs","start","end","utcOffsetSec","Date","getTimezoneOffset","alignedEnd","Math","floor","alignedStart","replace","variableState","client","datasourceStore","getDatasourceClient","datasource","rangeQuery","result","data","chartData","stepMs","map","value","metric","values","name","formattedName","series_name_format"],"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,QAAQ,UAAU,CAAC;AACxC,SACEC,eAAe,EAEfC,wBAAwB,EACxBC,sBAAsB,EACtBC,YAAY,EACZC,YAAY,QACP,aAAa,CAAC;AACrB,SAASC,+BAA+B,EAAEC,wBAAwB,EAAEC,gBAAgB,QAAQ,aAAa,CAAC;AAG1G,OAAO,MAAMC,iBAAiB,GAA8E,OAC1GC,IAAI,EACJC,OAAO,GACJ;QAmCYC,GAAa;IAlC5B,IAAIF,IAAI,CAACG,KAAK,KAAKC,SAAS,IAAIJ,IAAI,CAACG,KAAK,KAAK,IAAI,IAAIH,IAAI,CAACG,KAAK,KAAK,EAAE,EAAE;QACxE,+EAA+E;QAC/E,OAAO;YAAEE,MAAM,EAAE,EAAE;SAAE,CAAC;IACxB,CAAC;IAED,MAAMC,OAAO,GAAGd,wBAAwB,CAACQ,IAAI,CAACO,QAAQ,CAAC,AAAC;IACxD,MAAMC,SAAS,GAAGf,sBAAsB,CAACQ,OAAO,CAACO,SAAS,CAAC,AAAC;IAC5D,MAAMC,IAAI,GAAGf,YAAY,CAACc,SAAS,EAAEF,OAAO,EAAEF,SAAS,EAAEH,OAAO,CAACS,eAAe,CAAC,AAAC;IAElF,2DAA2D;IAC3D,IAAI,EAAEC,KAAK,CAAA,EAAEC,GAAG,CAAA,EAAE,GAAGJ,SA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AAC;IAE3C,qBAAqB;IACrB,MAAM2B,SAAS,GAAmB;QAChC,gEAAgE;QAChErB,SAAS,EAAE;YAAEG,KAAK,EAAErB,YAAY,CAACqB,KAAK,CAAC;YAAEC,GAAG,EAAEtB,YAAY,CAACsB,GAAG,CAAC;SAAE;QACjEkB,MAAM,EAAErB,IAAI,GAAG,IAAI;QAEnB,2EAA2E;QAC3E,8BAA8B;QAC9BJ,MAAM,EAAEsB,MAAM,CAACI,GAAG,CAAC,CAACC,KAAK,GAAK;YAC5B,MAAM,EAAEC,MAAM,CAAA,EAAEC,MAAM,CAAA,EAAE,GAAGF,KAAK,AAAC;YAEjC,yEAAyE;YACzE,IAAIG,IAAI,GAAGvC,+BAA+B,CAACqC,MAAM,CAAC,AAAC;YACnD,IAAIE,IAAI,KAAK,EAAE,EAAE;gBACfA,IAAI,GAAGhC,KAAK,CAAC;YACf,CAAC;YAED,mEAAmE;YACnE,mDAAmD;YACnD,MAAMiC,aAAa,GAAGpC,IAAI,CAACqC,kBAAkB,GAAGvC,gBAAgB,CAACE,IAAI,CAACqC,kBAAkB,EAAEJ,MAAM,CAAC,GAAGE,IAAI,AAAC;YAEzG,OAAO;gBACLA,IAAI;gBACJD,MAAM,EAAEA,MAAM,CAACH,GAAG,CAACxC,eAAe,CAAC;gBACnC6C,aAAa;aACd,CAAC;QACJ,CAAC,CAAC;KACH,AAAC;IAEF,OAAOP,SAAS,CAAC;AACnB,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/index.ts"],"sourcesContent":["// Copyright
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/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\nexport * from './PrometheusTimeSeriesQuery';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,6BAA6B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/query-editor-model.ts"],"sourcesContent":["// Copyright
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/query-editor-model.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 { useState } from 'react';\nimport { produce } from 'immer';\nimport { OptionsEditorProps } from '@perses-dev/plugin-system';\nimport { PrometheusTimeSeriesQuerySpec } from './time-series-query-model';\n\nexport type PrometheusTimeSeriesQueryEditorProps = OptionsEditorProps<PrometheusTimeSeriesQuerySpec>;\n\n/**\n * A hook for managing the `query` state in PrometheusTimeSeriesQuerySpec. Returns the `query` value, along with\n * `onChange` and `onBlur` event handlers to the input. Keeps a local copy of the user's input and only syncs those\n * changes with the overall spec value once the input is blurred to prevent re-running queries in the panel's preview\n * every time the user types.\n */\nexport function useQueryState(props: PrometheusTimeSeriesQueryEditorProps) {\n const { onChange, value } = props;\n\n // Local copy of the query's value\n const [query, setQuery] = useState(value.query);\n\n // This is basically \"getDerivedStateFromProps\" to make sure if spec's value changes external to this component,\n // we render with the latest value\n const [lastSyncedQuery, setLastSyncedQuery] = useState(value.query);\n if (value.query !== lastSyncedQuery) {\n setQuery(value.query);\n setLastSyncedQuery(value.query);\n }\n\n // Update our local state's copy as the user types\n const handleQueryChange = (e: string) => {\n setQuery(e);\n };\n\n // Propagate changes to the query's value when the input is blurred to avoid constantly re-running queries in the\n // PanelPreview\n const handleQueryBlur = () => {\n setLastSyncedQuery(query);\n onChange(\n produce(value, (draft) => {\n draft.query = query;\n })\n );\n };\n\n return { query, handleQueryChange, handleQueryBlur };\n}\n\n/**\n * Hook to manage `series_name_format` state to ensure panel preview does not rerender until text input is blurred\n */\nexport function useFormatState(props: PrometheusTimeSeriesQueryEditorProps) {\n const { onChange, value } = props;\n\n // TODO: reusable hook or helper util instead of duplicating from useQueryState\n const [format, setFormat] = useState(value.series_name_format);\n const [lastSyncedFormat, setLastSyncedFormat] = useState(value.series_name_format);\n if (value.series_name_format !== lastSyncedFormat) {\n setFormat(value.series_name_format);\n setLastSyncedFormat(value.series_name_format);\n }\n\n // Update our local state as the user types\n const handleFormatChange = (e: string) => {\n setFormat(e);\n };\n\n // Propagate changes to the panel preview component when series_name_format TextField is blurred\n const handleFormatBlur = () => {\n setLastSyncedFormat(format);\n onChange(\n produce(value, (draft) => {\n draft.series_name_format = format;\n })\n );\n };\n\n return { format, handleFormatChange, handleFormatBlur };\n}\n"],"names":["useState","produce","useQueryState","props","onChange","value","query","setQuery","lastSyncedQuery","setLastSyncedQuery","handleQueryChange","e","handleQueryBlur","draft","useFormatState","format","setFormat","series_name_format","lastSyncedFormat","setLastSyncedFormat","handleFormatChange","handleFormatBlur"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAs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,MAAM,CAACY,MAAM,EAAEC,SAAS,CAAC,GAAGhB,QAAQ,CAACK,KAAK,CAACY,kBAAkB,CAAC,AAAC;IAC/D,MAAM,CAACC,gBAAgB,EAAEC,mBAAmB,CAAC,GAAGnB,QAAQ,CAACK,KAAK,CAACY,kBAAkB,CAAC,AAAC;IACnF,IAAIZ,KAAK,CAACY,kBAAkB,KAAKC,gBAAgB,EAAE;QACjDF,SAAS,CAACX,KAAK,CAACY,kBAAkB,CAAC,CAAC;QACpCE,mBAAmB,CAACd,KAAK,CAACY,kBAAkB,CAAC,CAAC;IAChD,CAAC;IAED,2CAA2C;IAC3C,MAAMG,kBAAkB,GAAG,CAACT,CAAS,GAAK;QACxCK,SAAS,CAACL,CAAC,CAAC,CAAC;IACf,CAAC,AAAC;IAEF,gGAAgG;IAChG,MAAMU,gBAAgB,GAAG,IAAM;QAC7BF,mBAAmB,CAACJ,MAAM,CAAC,CAAC;QAC5BX,QAAQ,CACNH,OAAO,CAACI,KAAK,EAAE,CAACQ,KAAK,GAAK;YACxBA,KAAK,CAACI,kBAAkB,GAAGF,MAAM,CAAC;QACpC,CAAC,CAAC,CACH,CAAC;IACJ,CAAC,AAAC;IAEF,OAAO;QAAEA,MAAM;QAAEK,kBAAkB;QAAEC,gBAAgB;KAAE,CAAC;AAC1D,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/time-series-query-model.ts"],"sourcesContent":["// Copyright
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/time-series-query-model.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';\nimport { PrometheusDatasourceSelector, TemplateString } from '../../model';\n\n/**\n * The spec/options for the PrometheusTimeSeriesQuery plugin.\n */\nexport interface PrometheusTimeSeriesQuerySpec {\n query: TemplateString;\n series_name_format?: string;\n min_step?: DurationString;\n resolution?: number;\n datasource?: PrometheusDatasourceSelector;\n}\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,WAYC"}
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;AAI/F,OAAO,EACL,mCAAmC,EACnC,oCAAoC,EACpC,+BAA+B,EAChC,MAAM,SAAS,CAAC;AA6FjB,eAAO,MAAM,4BAA4B,EAAE,cAAc,CAAC,mCAAmC,CAgB5F,CAAC;AAEF,eAAO,MAAM,6BAA6B,EAAE,cAAc,CAAC,oCAAoC,CA8B9F,CAAC;AAEF,eAAO,MAAM,wBAAwB,EAAE,cAAc,CAAC,+BAA+B,CAwBpF,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
2
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
3
|
// you may not use this file except in compliance with the License.
|
|
4
4
|
// You may obtain a copy of the License at
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
14
|
import { Stack, TextField } from '@mui/material';
|
|
15
|
-
import {
|
|
15
|
+
import { DEFAULT_PROM, getPrometheusTimeRange } from '../model';
|
|
16
|
+
import { replaceTemplateVariables, parseTemplateVariables } from '../utils';
|
|
16
17
|
import { MatcherEditor } from './MatcherEditor';
|
|
17
18
|
function PrometheusLabelValuesVariableEditor(props) {
|
|
18
19
|
var _matchers;
|