@perses-dev/prometheus-plugin 0.0.0-snapshot-time-range-height-80d08fc

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.
Files changed (113) hide show
  1. package/LICENSE +201 -0
  2. package/dist/cjs/index.js +34 -0
  3. package/dist/cjs/model/api-types.js +16 -0
  4. package/dist/cjs/model/index.js +34 -0
  5. package/dist/cjs/model/parse-sample-values.js +50 -0
  6. package/dist/cjs/model/prometheus-client.js +87 -0
  7. package/dist/cjs/model/prometheus-selectors.js +37 -0
  8. package/dist/cjs/model/templating.js +27 -0
  9. package/dist/cjs/model/time.js +54 -0
  10. package/dist/cjs/model/utils.js +69 -0
  11. package/dist/cjs/model/utils.test.js +126 -0
  12. package/dist/cjs/plugins/MatcherEditor.js +75 -0
  13. package/dist/cjs/plugins/prometheus-datasource.js +54 -0
  14. package/dist/cjs/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.js +36 -0
  15. package/dist/cjs/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js +81 -0
  16. package/dist/cjs/plugins/prometheus-time-series-query/get-time-series-data.js +84 -0
  17. package/dist/cjs/plugins/prometheus-time-series-query/index.js +28 -0
  18. package/dist/cjs/plugins/prometheus-time-series-query/query-editor-model.js +83 -0
  19. package/dist/cjs/plugins/prometheus-time-series-query/time-series-query-model.js +16 -0
  20. package/dist/cjs/plugins/prometheus-variables.js +218 -0
  21. package/dist/cjs/plugins/types.js +16 -0
  22. package/dist/cjs/plugins/variable.js +103 -0
  23. package/dist/cjs/test/setup-tests.js +17 -0
  24. package/dist/index.d.ts +6 -0
  25. package/dist/index.d.ts.map +1 -0
  26. package/dist/index.js +21 -0
  27. package/dist/index.js.map +1 -0
  28. package/dist/model/api-types.d.ts +80 -0
  29. package/dist/model/api-types.d.ts.map +1 -0
  30. package/dist/model/api-types.js +15 -0
  31. package/dist/model/api-types.js.map +1 -0
  32. package/dist/model/index.d.ts +8 -0
  33. package/dist/model/index.d.ts.map +1 -0
  34. package/dist/model/index.js +21 -0
  35. package/dist/model/index.js.map +1 -0
  36. package/dist/model/parse-sample-values.d.ts +16 -0
  37. package/dist/model/parse-sample-values.d.ts.map +1 -0
  38. package/dist/model/parse-sample-values.js +44 -0
  39. package/dist/model/parse-sample-values.js.map +1 -0
  40. package/dist/model/prometheus-client.d.ts +27 -0
  41. package/dist/model/prometheus-client.d.ts.map +1 -0
  42. package/dist/model/prometheus-client.js +81 -0
  43. package/dist/model/prometheus-client.js.map +1 -0
  44. package/dist/model/prometheus-selectors.d.ts +22 -0
  45. package/dist/model/prometheus-selectors.d.ts.map +1 -0
  46. package/dist/model/prometheus-selectors.js +30 -0
  47. package/dist/model/prometheus-selectors.js.map +1 -0
  48. package/dist/model/templating.d.ts +6 -0
  49. package/dist/model/templating.d.ts.map +1 -0
  50. package/dist/model/templating.js +21 -0
  51. package/dist/model/templating.js.map +1 -0
  52. package/dist/model/time.d.ts +24 -0
  53. package/dist/model/time.d.ts.map +1 -0
  54. package/dist/model/time.js +49 -0
  55. package/dist/model/time.js.map +1 -0
  56. package/dist/model/utils.d.ts +14 -0
  57. package/dist/model/utils.d.ts.map +1 -0
  58. package/dist/model/utils.js +60 -0
  59. package/dist/model/utils.js.map +1 -0
  60. package/dist/model/utils.test.d.ts +2 -0
  61. package/dist/model/utils.test.d.ts.map +1 -0
  62. package/dist/model/utils.test.js +124 -0
  63. package/dist/model/utils.test.js.map +1 -0
  64. package/dist/plugins/MatcherEditor.d.ts +8 -0
  65. package/dist/plugins/MatcherEditor.d.ts.map +1 -0
  66. package/dist/plugins/MatcherEditor.js +64 -0
  67. package/dist/plugins/MatcherEditor.js.map +1 -0
  68. package/dist/plugins/prometheus-datasource.d.ts +7 -0
  69. package/dist/plugins/prometheus-datasource.d.ts.map +1 -0
  70. package/dist/plugins/prometheus-datasource.js +48 -0
  71. package/dist/plugins/prometheus-datasource.js.map +1 -0
  72. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.d.ts +7 -0
  73. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.d.ts.map +1 -0
  74. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.js +32 -0
  75. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.js.map +1 -0
  76. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.d.ts +7 -0
  77. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.d.ts.map +1 -0
  78. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js +77 -0
  79. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js.map +1 -0
  80. package/dist/plugins/prometheus-time-series-query/get-time-series-data.d.ts +4 -0
  81. package/dist/plugins/prometheus-time-series-query/get-time-series-data.d.ts.map +1 -0
  82. package/dist/plugins/prometheus-time-series-query/get-time-series-data.js +78 -0
  83. package/dist/plugins/prometheus-time-series-query/get-time-series-data.js.map +1 -0
  84. package/dist/plugins/prometheus-time-series-query/index.d.ts +2 -0
  85. package/dist/plugins/prometheus-time-series-query/index.d.ts.map +1 -0
  86. package/dist/plugins/prometheus-time-series-query/index.js +15 -0
  87. package/dist/plugins/prometheus-time-series-query/index.js.map +1 -0
  88. package/dist/plugins/prometheus-time-series-query/query-editor-model.d.ts +24 -0
  89. package/dist/plugins/prometheus-time-series-query/query-editor-model.d.ts.map +1 -0
  90. package/dist/plugins/prometheus-time-series-query/query-editor-model.js +78 -0
  91. package/dist/plugins/prometheus-time-series-query/query-editor-model.js.map +1 -0
  92. package/dist/plugins/prometheus-time-series-query/time-series-query-model.d.ts +13 -0
  93. package/dist/plugins/prometheus-time-series-query/time-series-query-model.d.ts.map +1 -0
  94. package/dist/plugins/prometheus-time-series-query/time-series-query-model.js +15 -0
  95. package/dist/plugins/prometheus-time-series-query/time-series-query-model.js.map +1 -0
  96. package/dist/plugins/prometheus-variables.d.ts +6 -0
  97. package/dist/plugins/prometheus-variables.d.ts.map +1 -0
  98. package/dist/plugins/prometheus-variables.js +205 -0
  99. package/dist/plugins/prometheus-variables.js.map +1 -0
  100. package/dist/plugins/types.d.ts +16 -0
  101. package/dist/plugins/types.d.ts.map +1 -0
  102. package/dist/plugins/types.js +15 -0
  103. package/dist/plugins/types.js.map +1 -0
  104. package/dist/plugins/variable.d.ts +8 -0
  105. package/dist/plugins/variable.d.ts.map +1 -0
  106. package/dist/plugins/variable.js +97 -0
  107. package/dist/plugins/variable.js.map +1 -0
  108. package/dist/test/setup-tests.d.ts +2 -0
  109. package/dist/test/setup-tests.d.ts.map +1 -0
  110. package/dist/test/setup-tests.js +15 -0
  111. package/dist/test/setup-tests.js.map +1 -0
  112. package/package.json +46 -0
  113. package/plugin.json +58 -0
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,81 @@
1
+ // Copyright 2022 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ import { fetchJson } from '@perses-dev/core';
14
+ /**
15
+ * Calls the `/api/v1/query` endpoint to get metrics data.
16
+ */ export function instantQuery(params, queryOptions) {
17
+ return fetchWithPost('/api/v1/query', params, queryOptions);
18
+ }
19
+ /**
20
+ * Calls the `/api/v1/query_range` endpoint to get metrics data.
21
+ */ export function rangeQuery(params, queryOptions) {
22
+ return fetchWithPost('/api/v1/query_range', params, queryOptions);
23
+ }
24
+ /**
25
+ * Calls the `/api/v1/labels` endpoint to get a list of label names.
26
+ */ export function labelNames(params, queryOptions) {
27
+ return fetchWithPost('/api/v1/labels', params, queryOptions);
28
+ }
29
+ /**
30
+ * Calls the `/api/v1/label/{labelName}/values` endpoint to get a list of values for a label.
31
+ */ export function labelValues(params, queryOptions) {
32
+ const { labelName , ...searchParams } = params;
33
+ const apiURI = `/api/v1/label/${encodeURIComponent(labelName)}/values`;
34
+ return fetchWithGet(apiURI, searchParams, queryOptions);
35
+ }
36
+ function fetchWithGet(apiURI, params, queryOptions) {
37
+ const { datasourceUrl } = queryOptions;
38
+ let url = `${datasourceUrl}${apiURI}`;
39
+ const urlParams = createSearchParams(params).toString();
40
+ if (urlParams !== '') {
41
+ url += `?${urlParams}`;
42
+ }
43
+ return fetchJson(url, {
44
+ method: 'GET'
45
+ });
46
+ }
47
+ function fetchWithPost(apiURI, params, queryOptions) {
48
+ const { datasourceUrl } = queryOptions;
49
+ const url = `${datasourceUrl}${apiURI}`;
50
+ const init = {
51
+ method: 'POST',
52
+ headers: {
53
+ 'Content-Type': 'application/x-www-form-urlencoded'
54
+ },
55
+ body: createSearchParams(params)
56
+ };
57
+ return fetchJson(url, init);
58
+ }
59
+ /**
60
+ * Creates URLSearchParams from a request params object.
61
+ */ function createSearchParams(params) {
62
+ const searchParams = new URLSearchParams();
63
+ for(const key in params){
64
+ const value = params[key];
65
+ if (value === undefined) continue;
66
+ if (typeof value === 'string') {
67
+ searchParams.append(key, value);
68
+ continue;
69
+ }
70
+ if (typeof value === 'number') {
71
+ searchParams.append(key, value.toString());
72
+ continue;
73
+ }
74
+ for (const val of value){
75
+ searchParams.append(key, val);
76
+ }
77
+ }
78
+ return searchParams;
79
+ }
80
+
81
+ //# sourceMappingURL=prometheus-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/model/prometheus-client.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { 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":"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"}
@@ -0,0 +1,22 @@
1
+ import { DatasourceSelector } from '@perses-dev/core';
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,6 @@
1
+ /**
2
+ * Type alias to indicate what parts of the API support template variables.
3
+ */
4
+ export declare type TemplateString = string;
5
+ export declare function useReplaceTemplateString(templateString?: TemplateString): string;
6
+ //# sourceMappingURL=templating.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"templating.d.ts","sourceRoot":"","sources":["../../src/model/templating.ts"],"names":[],"mappings":"AAgBA;;GAEG;AACH,oBAAY,cAAc,GAAG,MAAM,CAAC;AAEpC,wBAAgB,wBAAwB,CAAC,cAAc,CAAC,EAAE,cAAc,UAIvE"}
@@ -0,0 +1,21 @@
1
+ // Copyright 2022 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ import { useTemplateVariableValues } from '@perses-dev/plugin-system';
14
+ import { replaceTemplateVariables, parseTemplateVariables } from './utils';
15
+ export function useReplaceTemplateString(templateString) {
16
+ const templateVariablesInTemplate = parseTemplateVariables(templateString || '');
17
+ const variables = useTemplateVariableValues(templateVariablesInTemplate);
18
+ return replaceTemplateVariables(templateString || '', variables);
19
+ }
20
+
21
+ //# sourceMappingURL=templating.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/model/templating.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { useTemplateVariableValues } from '@perses-dev/plugin-system';\nimport { replaceTemplateVariables, parseTemplateVariables } from './utils';\n\n/**\n * Type alias to indicate what parts of the API support template variables.\n */\nexport type TemplateString = string;\n\nexport function useReplaceTemplateString(templateString?: TemplateString) {\n const templateVariablesInTemplate = parseTemplateVariables(templateString || '');\n const variables = useTemplateVariableValues(templateVariablesInTemplate);\n return replaceTemplateVariables(templateString || '', variables);\n}\n"],"names":["useTemplateVariableValues","replaceTemplateVariables","parseTemplateVariables","useReplaceTemplateString","templateString","templateVariablesInTemplate","variables"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,yBAAyB,QAAQ,2BAA2B,CAAC;AACtE,SAASC,wBAAwB,EAAEC,sBAAsB,QAAQ,SAAS,CAAC;AAO3E,OAAO,SAASC,wBAAwB,CAACC,cAA+B,EAAE;IACxE,MAAMC,2BAA2B,GAAGH,sBAAsB,CAACE,cAAc,IAAI,EAAE,CAAC,AAAC;IACjF,MAAME,SAAS,GAAGN,yBAAyB,CAACK,2BAA2B,CAAC,AAAC;IACzE,OAAOJ,wBAAwB,CAACG,cAAc,IAAI,EAAE,EAAEE,SAAS,CAAC,CAAC;AACnE,CAAC"}
@@ -0,0 +1,24 @@
1
+ import { AbsoluteTimeRange, DurationString } from '@perses-dev/core';
2
+ import { UnixTimestampSeconds } from './api-types';
3
+ export interface PrometheusTimeRange {
4
+ start: UnixTimestampSeconds;
5
+ end: UnixTimestampSeconds;
6
+ }
7
+ /**
8
+ * Converts an AbsoluteTimeRange to Prometheus time in Unix time (i.e. in seconds).
9
+ */
10
+ export declare function getPrometheusTimeRange(timeRange: AbsoluteTimeRange): {
11
+ start: number;
12
+ end: number;
13
+ };
14
+ /**
15
+ * Gets the step to use for a Prom range query. Tries to take into account a suggested step size (probably based on the
16
+ * width of a visualization where the data will be graphed), any minimum step/resolution set by the user, and a "safe"
17
+ * step based on the max data points we want to allow returning from a Prom query.
18
+ */
19
+ export declare function getRangeStep(timeRange: PrometheusTimeRange, minStepSeconds?: number, resolution?: number, suggestedStepMs?: number): number;
20
+ /**
21
+ * Converts a DurationString to seconds, rounding down.
22
+ */
23
+ export declare function getDurationStringSeconds(durationString?: DurationString): number | undefined;
24
+ //# sourceMappingURL=time.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"time.d.ts","sourceRoot":"","sources":["../../src/model/time.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAuB,MAAM,kBAAkB,CAAC;AAE1F,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,oBAAoB,CAAC;IAC5B,GAAG,EAAE,oBAAoB,CAAC;CAC3B;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,iBAAiB;;;EAMlE;AAMD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,mBAAmB,EAAE,cAAc,SAAK,EAAE,UAAU,SAAI,EAAE,eAAe,SAAI,UAUpH;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,cAAc,CAAC,EAAE,cAAc,sBAMvE"}
@@ -0,0 +1,49 @@
1
+ // Copyright 2022 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ import { parseDurationString } from '@perses-dev/core';
14
+ import { milliseconds, getUnixTime } from 'date-fns';
15
+ /**
16
+ * Converts an AbsoluteTimeRange to Prometheus time in Unix time (i.e. in seconds).
17
+ */ export function getPrometheusTimeRange(timeRange) {
18
+ const { start , end } = timeRange;
19
+ return {
20
+ start: Math.ceil(getUnixTime(start)),
21
+ end: Math.ceil(getUnixTime(end))
22
+ };
23
+ }
24
+ // Max data points to allow returning from a Prom Query, used to calculate a
25
+ // "safe" step for a range query
26
+ const MAX_PROM_DATA_POINTS = 10000;
27
+ /**
28
+ * Gets the step to use for a Prom range query. Tries to take into account a suggested step size (probably based on the
29
+ * width of a visualization where the data will be graphed), any minimum step/resolution set by the user, and a "safe"
30
+ * step based on the max data points we want to allow returning from a Prom query.
31
+ */ export function getRangeStep(timeRange, minStepSeconds = 15, resolution = 1, suggestedStepMs = 0) {
32
+ const suggestedStepSeconds = suggestedStepMs / 1000;
33
+ const queryRangeSeconds = timeRange.end - timeRange.start;
34
+ let safeStep = queryRangeSeconds / MAX_PROM_DATA_POINTS;
35
+ if (safeStep > 1) {
36
+ safeStep = Math.ceil(safeStep);
37
+ }
38
+ return Math.max(suggestedStepSeconds * resolution, minStepSeconds, safeStep);
39
+ }
40
+ /**
41
+ * Converts a DurationString to seconds, rounding down.
42
+ */ export function getDurationStringSeconds(durationString) {
43
+ if (durationString === undefined) return undefined;
44
+ const duration = parseDurationString(durationString);
45
+ const ms = milliseconds(duration);
46
+ return Math.floor(ms / 1000);
47
+ }
48
+
49
+ //# sourceMappingURL=time.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/model/time.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 { 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"}
@@ -0,0 +1,14 @@
1
+ import { VariableValue } from '@perses-dev/core';
2
+ import { VariableStateMap } from '@perses-dev/plugin-system';
3
+ export declare function replaceTemplateVariables(text: string, variableState: VariableStateMap): string;
4
+ export declare function replaceTemplateVariable(text: string, varName: string, templateVariableValue: VariableValue): string;
5
+ /**
6
+ * Returns a list of template variables
7
+ */
8
+ export declare const parseTemplateVariables: (text: string) => string[];
9
+ /**
10
+ * Types for metric labels, used in series_name_format implementation
11
+ */
12
+ export declare type SeriesLabels = Record<string, string>;
13
+ export declare function formatSeriesName(inputFormat: string, seriesLabels: SeriesLabels): string;
14
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/model/utils.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAE7D,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,gBAAgB,GAAG,MAAM,CAW9F;AAED,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,qBAAqB,EAAE,aAAa,UAW1G;AAMD;;GAEG;AACH,eAAO,MAAM,sBAAsB,SAAU,MAAM,aAYlD,CAAC;AAEF;;GAEG;AACH,oBAAY,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAMlD,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY,GAAG,MAAM,CAGxF"}
@@ -0,0 +1,60 @@
1
+ // Copyright 2022 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ export function replaceTemplateVariables(text, variableState) {
14
+ const variables = parseTemplateVariables(text);
15
+ let finalText = text;
16
+ variables.forEach((v)=>{
17
+ const variable = variableState[v];
18
+ if (variable && (variable === null || variable === void 0 ? void 0 : variable.value)) {
19
+ finalText = replaceTemplateVariable(finalText, v, variable === null || variable === void 0 ? void 0 : variable.value);
20
+ }
21
+ });
22
+ return finalText;
23
+ }
24
+ export function replaceTemplateVariable(text, varName, templateVariableValue) {
25
+ const variableTemplate = '$' + varName;
26
+ let replaceString = '';
27
+ if (Array.isArray(templateVariableValue)) {
28
+ replaceString = `(${templateVariableValue.join('|')})`; // regex style
29
+ }
30
+ if (typeof templateVariableValue === 'string') {
31
+ replaceString = templateVariableValue;
32
+ }
33
+ return text.replaceAll(variableTemplate, replaceString);
34
+ }
35
+ // TODO: Fix this lint error
36
+ // eslint-disable-next-line no-useless-escape
37
+ const TEMPLATE_VARIABLE_REGEX = /\$(\w+)|\${(\w+)(?:\.([^:^\}]+))?(?::([^\}]+))?}/gm;
38
+ /**
39
+ * Returns a list of template variables
40
+ */ export const parseTemplateVariables = (text)=>{
41
+ const regex = TEMPLATE_VARIABLE_REGEX;
42
+ const matches = new Set();
43
+ let match;
44
+ while((match = regex.exec(text)) !== null){
45
+ if (match && match.length > 1 && match[1]) {
46
+ matches.add(match[1]);
47
+ }
48
+ }
49
+ // return unique matches
50
+ return Array.from(matches.values());
51
+ };
52
+ /*
53
+ * Formatter used for series name display in legends and tooltips
54
+ * Regex replaces label {{ name }} with resolved label value
55
+ */ export function formatSeriesName(inputFormat, seriesLabels) {
56
+ const resolveLabelsRegex = /\{\{\s*(.+?)\s*\}\}/g;
57
+ return inputFormat.replace(resolveLabelsRegex, (_, g)=>seriesLabels[g] ? seriesLabels[g] : g);
58
+ }
59
+
60
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/model/utils.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 { VariableValue } from '@perses-dev/core';\nimport { VariableStateMap } from '@perses-dev/plugin-system';\n\nexport function replaceTemplateVariables(text: string, variableState: VariableStateMap): string {\n const variables = parseTemplateVariables(text);\n let finalText = text;\n variables.forEach((v) => {\n const variable = variableState[v];\n if (variable && variable?.value) {\n finalText = replaceTemplateVariable(finalText, v, variable?.value);\n }\n });\n\n return finalText;\n}\n\nexport function replaceTemplateVariable(text: string, varName: string, templateVariableValue: VariableValue) {\n const variableTemplate = '$' + varName;\n let replaceString = '';\n if (Array.isArray(templateVariableValue)) {\n replaceString = `(${templateVariableValue.join('|')})`; // regex style\n }\n if (typeof templateVariableValue === 'string') {\n replaceString = templateVariableValue;\n }\n\n return text.replaceAll(variableTemplate, replaceString);\n}\n\n// TODO: Fix this lint error\n// eslint-disable-next-line no-useless-escape\nconst TEMPLATE_VARIABLE_REGEX = /\\$(\\w+)|\\${(\\w+)(?:\\.([^:^\\}]+))?(?::([^\\}]+))?}/gm;\n\n/**\n * Returns a list of template variables\n */\nexport const parseTemplateVariables = (text: string) => {\n const regex = TEMPLATE_VARIABLE_REGEX;\n const matches = new Set<string>();\n let match;\n\n while ((match = regex.exec(text)) !== null) {\n if (match && match.length > 1 && match[1]) {\n matches.add(match[1]);\n }\n }\n // return unique matches\n return Array.from(matches.values());\n};\n\n/**\n * Types for metric labels, used in series_name_format implementation\n */\nexport type SeriesLabels = Record<string, string>;\n\n/*\n * Formatter used for series name display in legends and tooltips\n * Regex replaces label {{ name }} with resolved label value\n */\nexport function formatSeriesName(inputFormat: string, seriesLabels: SeriesLabels): string {\n const resolveLabelsRegex = /\\{\\{\\s*(.+?)\\s*\\}\\}/g;\n return inputFormat.replace(resolveLabelsRegex, (_, g) => (seriesLabels[g] ? seriesLabels[g] : g));\n}\n"],"names":["replaceTemplateVariables","text","variableState","variables","parseTemplateVariables","finalText","forEach","v","variable","value","replaceTemplateVariable","varName","templateVariableValue","variableTemplate","replaceString","Array","isArray","join","replaceAll","TEMPLATE_VARIABLE_REGEX","regex","matches","Set","match","exec","length","add","from","values","formatSeriesName","inputFormat","seriesLabels","resolveLabelsRegex","replace","_","g"],"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;AAKjC,OAAO,SAASA,wBAAwB,CAACC,IAAY,EAAEC,aAA+B,EAAU;IAC9F,MAAMC,SAAS,GAAGC,sBAAsB,CAACH,IAAI,CAAC,AAAC;IAC/C,IAAII,SAAS,GAAGJ,IAAI,AAAC;IACrBE,SAAS,CAACG,OAAO,CAAC,CAACC,CAAC,GAAK;QACvB,MAAMC,QAAQ,GAAGN,aAAa,CAACK,CAAC,CAAC,AAAC;QAClC,IAAIC,QAAQ,IAAIA,CAAAA,QAAQ,aAARA,QAAQ,WAAO,GAAfA,KAAAA,CAAe,GAAfA,QAAQ,CAAEC,KAAK,CAAA,EAAE;YAC/BJ,SAAS,GAAGK,uBAAuB,CAACL,SAAS,EAAEE,CAAC,EAAEC,QAAQ,aAARA,QAAQ,WAAO,GAAfA,KAAAA,CAAe,GAAfA,QAAQ,CAAEC,KAAK,CAAC,CAAC;QACrE,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAOJ,SAAS,CAAC;AACnB,CAAC;AAED,OAAO,SAASK,uBAAuB,CAACT,IAAY,EAAEU,OAAe,EAAEC,qBAAoC,EAAE;IAC3G,MAAMC,gBAAgB,GAAG,GAAG,GAAGF,OAAO,AAAC;IACvC,IAAIG,aAAa,GAAG,EAAE,AAAC;IACvB,IAAIC,KAAK,CAACC,OAAO,CAACJ,qBAAqB,CAAC,EAAE;QACxCE,aAAa,GAAG,CAAC,CAAC,EAAEF,qBAAqB,CAACK,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,cAAc;IACxE,CAAC;IACD,IAAI,OAAOL,qBAAqB,KAAK,QAAQ,EAAE;QAC7CE,aAAa,GAAGF,qBAAqB,CAAC;IACxC,CAAC;IAED,OAAOX,IAAI,CAACiB,UAAU,CAACL,gBAAgB,EAAEC,aAAa,CAAC,CAAC;AAC1D,CAAC;AAED,4BAA4B;AAC5B,6CAA6C;AAC7C,MAAMK,uBAAuB,uDAAuD,AAAC;AAErF;;CAEC,GACD,OAAO,MAAMf,sBAAsB,GAAG,CAACH,IAAY,GAAK;IACtD,MAAMmB,KAAK,GAAGD,uBAAuB,AAAC;IACtC,MAAME,OAAO,GAAG,IAAIC,GAAG,EAAU,AAAC;IAClC,IAAIC,KAAK,AAAC;IAEV,MAAO,AAACA,CAAAA,KAAK,GAAGH,KAAK,CAACI,IAAI,CAACvB,IAAI,CAAC,CAAA,KAAM,IAAI,CAAE;QAC1C,IAAIsB,KAAK,IAAIA,KAAK,CAACE,MAAM,GAAG,CAAC,IAAIF,KAAK,CAAC,CAAC,CAAC,EAAE;YACzCF,OAAO,CAACK,GAAG,CAACH,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QACxB,CAAC;IACH,CAAC;IACD,wBAAwB;IACxB,OAAOR,KAAK,CAACY,IAAI,CAACN,OAAO,CAACO,MAAM,EAAE,CAAC,CAAC;AACtC,CAAC,CAAC;AAOF;;;CAGC,GACD,OAAO,SAASC,gBAAgB,CAACC,WAAmB,EAAEC,YAA0B,EAAU;IACxF,MAAMC,kBAAkB,yBAAyB,AAAC;IAClD,OAAOF,WAAW,CAACG,OAAO,CAACD,kBAAkB,EAAE,CAACE,CAAC,EAAEC,CAAC,GAAMJ,YAAY,CAACI,CAAC,CAAC,GAAGJ,YAAY,CAACI,CAAC,CAAC,GAAGA,CAAC,AAAC,CAAC,CAAC;AACpG,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=utils.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.test.d.ts","sourceRoot":"","sources":["../../src/model/utils.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,124 @@
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 { parseTemplateVariables, replaceTemplateVariable, replaceTemplateVariables, formatSeriesName } from './utils';
14
+ describe('parseTemplateVariables()', ()=>{
15
+ const tests = [
16
+ {
17
+ text: 'hello $var1 world $var2',
18
+ variables: [
19
+ 'var1',
20
+ 'var2'
21
+ ]
22
+ }
23
+ ];
24
+ tests.forEach(({ text , variables })=>{
25
+ it(`parses ${text}`, ()=>{
26
+ expect(parseTemplateVariables(text)).toEqual(variables);
27
+ });
28
+ });
29
+ });
30
+ describe('replaceTemplateVariable()', ()=>{
31
+ const tests = [
32
+ {
33
+ text: 'hello $var1',
34
+ varName: 'var1',
35
+ value: 'world',
36
+ expected: 'hello world'
37
+ },
38
+ {
39
+ text: 'hello $var1 $var1',
40
+ varName: 'var1',
41
+ value: 'world',
42
+ expected: 'hello world world'
43
+ },
44
+ {
45
+ text: 'hello $var1',
46
+ varName: 'var1',
47
+ value: [
48
+ 'world',
49
+ 'w'
50
+ ],
51
+ expected: 'hello (world|w)'
52
+ },
53
+ {
54
+ text: 'hello $var1 $var1',
55
+ varName: 'var1',
56
+ value: [
57
+ 'world',
58
+ 'w'
59
+ ],
60
+ expected: 'hello (world|w) (world|w)'
61
+ }
62
+ ];
63
+ tests.forEach(({ text , value , varName , expected })=>{
64
+ it(`replaces ${text} ${value}`, ()=>{
65
+ expect(replaceTemplateVariable(text, varName, value)).toEqual(expected);
66
+ });
67
+ });
68
+ });
69
+ describe('replaceTemplateVariables()', ()=>{
70
+ const tests = [
71
+ {
72
+ text: 'hello $var1 $var2',
73
+ state: {
74
+ var1: {
75
+ value: 'world',
76
+ loading: false
77
+ },
78
+ var2: {
79
+ value: 'world',
80
+ loading: false
81
+ }
82
+ },
83
+ expected: 'hello world world'
84
+ },
85
+ {
86
+ text: 'hello $var1 $var2',
87
+ state: {
88
+ var1: {
89
+ value: 'world',
90
+ loading: false
91
+ },
92
+ var2: {
93
+ value: [
94
+ 'a',
95
+ 'b'
96
+ ],
97
+ loading: false
98
+ }
99
+ },
100
+ expected: 'hello world (a|b)'
101
+ }
102
+ ];
103
+ tests.forEach(({ text , state , expected })=>{
104
+ it(`replaces ${text} ${JSON.stringify(state)}`, ()=>{
105
+ expect(replaceTemplateVariables(text, state)).toEqual(expected);
106
+ });
107
+ });
108
+ });
109
+ describe('formatSeriesName', ()=>{
110
+ it('should resolve label name tokens to label values from query response', ()=>{
111
+ // example from query: node_load15{instance=~\"(demo.do.prometheus.io:9100)\",job='$job'}
112
+ const inputFormat = 'Test {{job}} {{instance}}';
113
+ const metric = {
114
+ __name__: 'node_load15',
115
+ env: 'demo',
116
+ instance: 'demo.do.prometheus.io:9100',
117
+ job: 'node'
118
+ };
119
+ const output = 'Test node demo.do.prometheus.io:9100';
120
+ expect(formatSeriesName(inputFormat, metric)).toEqual(output);
121
+ });
122
+ });
123
+
124
+ //# sourceMappingURL=utils.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/model/utils.test.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 { parseTemplateVariables, replaceTemplateVariable, replaceTemplateVariables, formatSeriesName } from './utils';\n\ndescribe('parseTemplateVariables()', () => {\n const tests = [\n {\n text: 'hello $var1 world $var2',\n variables: ['var1', 'var2'],\n },\n ];\n\n tests.forEach(({ text, variables }) => {\n it(`parses ${text}`, () => {\n expect(parseTemplateVariables(text)).toEqual(variables);\n });\n });\n});\n\ndescribe('replaceTemplateVariable()', () => {\n const tests = [\n {\n text: 'hello $var1',\n varName: 'var1',\n value: 'world',\n expected: 'hello world',\n },\n {\n text: 'hello $var1 $var1',\n varName: 'var1',\n value: 'world',\n expected: 'hello world world',\n },\n {\n text: 'hello $var1',\n varName: 'var1',\n value: ['world', 'w'],\n expected: 'hello (world|w)',\n },\n {\n text: 'hello $var1 $var1',\n varName: 'var1',\n value: ['world', 'w'],\n expected: 'hello (world|w) (world|w)',\n },\n ];\n\n tests.forEach(({ text, value, varName, expected }) => {\n it(`replaces ${text} ${value}`, () => {\n expect(replaceTemplateVariable(text, varName, value)).toEqual(expected);\n });\n });\n});\n\ndescribe('replaceTemplateVariables()', () => {\n const tests = [\n {\n text: 'hello $var1 $var2',\n state: {\n var1: { value: 'world', loading: false },\n var2: { value: 'world', loading: false },\n },\n expected: 'hello world world',\n },\n {\n text: 'hello $var1 $var2',\n state: {\n var1: { value: 'world', loading: false },\n var2: { value: ['a', 'b'], loading: false },\n },\n expected: 'hello world (a|b)',\n },\n ];\n\n tests.forEach(({ text, state, expected }) => {\n it(`replaces ${text} ${JSON.stringify(state)}`, () => {\n expect(replaceTemplateVariables(text, state)).toEqual(expected);\n });\n });\n});\n\ndescribe('formatSeriesName', () => {\n it('should resolve label name tokens to label values from query response', () => {\n // example from query: node_load15{instance=~\\\"(demo.do.prometheus.io:9100)\\\",job='$job'}\n const inputFormat = 'Test {{job}} {{instance}}';\n\n const metric = {\n __name__: 'node_load15',\n env: 'demo',\n instance: 'demo.do.prometheus.io:9100',\n job: 'node',\n };\n\n const output = 'Test node demo.do.prometheus.io:9100';\n\n expect(formatSeriesName(inputFormat, metric)).toEqual(output);\n });\n});\n"],"names":["parseTemplateVariables","replaceTemplateVariable","replaceTemplateVariables","formatSeriesName","describe","tests","text","variables","forEach","it","expect","toEqual","varName","value","expected","state","var1","loading","var2","JSON","stringify","inputFormat","metric","__name__","env","instance","job","output"],"mappings":"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"}
@@ -0,0 +1,8 @@
1
+ /// <reference types="react" />
2
+ declare type MatcherEditorProps = {
3
+ matchers: string[];
4
+ onChange: (matchers: string[]) => void;
5
+ };
6
+ export declare function MatcherEditor({ matchers, onChange }: MatcherEditorProps): JSX.Element;
7
+ export {};
8
+ //# sourceMappingURL=MatcherEditor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MatcherEditor.d.ts","sourceRoot":"","sources":["../../src/plugins/MatcherEditor.tsx"],"names":[],"mappings":";AAiBA,aAAK,kBAAkB,GAAG;IACxB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,QAAQ,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;CACxC,CAAC;AAEF,wBAAgB,aAAa,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE,kBAAkB,eA6CvE"}
@@ -0,0 +1,64 @@
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 { Stack, TextField, Button, Box, IconButton } from '@mui/material';
15
+ import { produce } from 'immer';
16
+ import TrashIcon from 'mdi-material-ui/TrashCan';
17
+ export function MatcherEditor({ matchers , onChange }) {
18
+ return /*#__PURE__*/ _jsxs(Stack, {
19
+ spacing: 1,
20
+ children: [
21
+ matchers.map((matcher, index)=>/*#__PURE__*/ _jsxs(Box, {
22
+ display: "flex",
23
+ children: [
24
+ /*#__PURE__*/ _jsx(TextField, {
25
+ fullWidth: true,
26
+ label: "Series Selector",
27
+ value: matcher,
28
+ onChange: (e)=>{
29
+ const newMatchers = produce(matchers, (draft)=>{
30
+ draft[index] = e.target.value;
31
+ });
32
+ onChange(newMatchers);
33
+ }
34
+ }),
35
+ /*#__PURE__*/ _jsx(IconButton, {
36
+ onClick: ()=>{
37
+ const newMatchers = produce(matchers, (draft)=>{
38
+ draft.splice(index, 1);
39
+ });
40
+ onChange(newMatchers);
41
+ },
42
+ children: /*#__PURE__*/ _jsx(TrashIcon, {})
43
+ })
44
+ ]
45
+ }, index)),
46
+ /*#__PURE__*/ _jsx(Box, {
47
+ children: /*#__PURE__*/ _jsx(Button, {
48
+ fullWidth: false,
49
+ color: "secondary",
50
+ variant: "outlined",
51
+ onClick: ()=>{
52
+ const newMatchers = produce(matchers, (draft)=>{
53
+ draft.push('');
54
+ });
55
+ onChange(newMatchers);
56
+ },
57
+ children: "Add Series Selector"
58
+ })
59
+ })
60
+ ]
61
+ });
62
+ }
63
+
64
+ //# sourceMappingURL=MatcherEditor.js.map