@perses-dev/prometheus-plugin 0.21.1 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/dist/cjs/components/PromQL.js +56 -0
  2. package/dist/cjs/components/index.js +28 -0
  3. package/dist/cjs/index.js +1 -1
  4. package/dist/cjs/model/api-types.js +1 -1
  5. package/dist/cjs/model/index.js +1 -2
  6. package/dist/cjs/model/parse-sample-values.js +1 -1
  7. package/dist/cjs/model/prometheus-client.js +1 -1
  8. package/dist/cjs/model/prometheus-selectors.js +1 -1
  9. package/dist/cjs/model/templating.js +2 -2
  10. package/dist/cjs/model/time.js +1 -1
  11. package/dist/cjs/plugins/MatcherEditor.js +1 -1
  12. package/dist/cjs/plugins/prometheus-datasource.js +4 -1
  13. package/dist/cjs/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.js +3 -3
  14. package/dist/cjs/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js +14 -8
  15. package/dist/cjs/plugins/prometheus-time-series-query/get-time-series-data.js +9 -7
  16. package/dist/cjs/plugins/prometheus-time-series-query/index.js +1 -1
  17. package/dist/cjs/plugins/prometheus-time-series-query/query-editor-model.js +3 -3
  18. package/dist/cjs/plugins/prometheus-time-series-query/time-series-query-model.js +1 -1
  19. package/dist/cjs/plugins/prometheus-variables.js +10 -9
  20. package/dist/cjs/plugins/types.js +1 -1
  21. package/dist/cjs/plugins/variable.js +1 -1
  22. package/dist/cjs/test/setup-tests.js +1 -1
  23. package/dist/cjs/utils/index.js +28 -0
  24. package/dist/cjs/{model → utils}/utils.js +37 -2
  25. package/dist/cjs/{model → utils}/utils.test.js +47 -1
  26. package/dist/components/PromQL.d.ts +8 -0
  27. package/dist/components/PromQL.d.ts.map +1 -0
  28. package/dist/components/PromQL.js +45 -0
  29. package/dist/components/PromQL.js.map +1 -0
  30. package/dist/components/index.d.ts +2 -0
  31. package/dist/components/index.d.ts.map +1 -0
  32. package/dist/components/index.js +15 -0
  33. package/dist/components/index.js.map +1 -0
  34. package/dist/index.js +1 -1
  35. package/dist/index.js.map +1 -1
  36. package/dist/model/api-types.js +1 -1
  37. package/dist/model/api-types.js.map +1 -1
  38. package/dist/model/index.d.ts +0 -1
  39. package/dist/model/index.d.ts.map +1 -1
  40. package/dist/model/index.js +1 -2
  41. package/dist/model/index.js.map +1 -1
  42. package/dist/model/parse-sample-values.js +1 -1
  43. package/dist/model/parse-sample-values.js.map +1 -1
  44. package/dist/model/prometheus-client.d.ts +5 -0
  45. package/dist/model/prometheus-client.d.ts.map +1 -1
  46. package/dist/model/prometheus-client.js +1 -1
  47. package/dist/model/prometheus-client.js.map +1 -1
  48. package/dist/model/prometheus-selectors.js +1 -1
  49. package/dist/model/prometheus-selectors.js.map +1 -1
  50. package/dist/model/templating.js +2 -2
  51. package/dist/model/templating.js.map +1 -1
  52. package/dist/model/time.js +1 -1
  53. package/dist/model/time.js.map +1 -1
  54. package/dist/plugins/MatcherEditor.js +1 -1
  55. package/dist/plugins/MatcherEditor.js.map +1 -1
  56. package/dist/plugins/prometheus-datasource.d.ts.map +1 -1
  57. package/dist/plugins/prometheus-datasource.js +4 -1
  58. package/dist/plugins/prometheus-datasource.js.map +1 -1
  59. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.js +2 -2
  60. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.js.map +1 -1
  61. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.d.ts.map +1 -1
  62. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js +15 -9
  63. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js.map +1 -1
  64. package/dist/plugins/prometheus-time-series-query/get-time-series-data.d.ts.map +1 -1
  65. package/dist/plugins/prometheus-time-series-query/get-time-series-data.js +8 -6
  66. package/dist/plugins/prometheus-time-series-query/get-time-series-data.js.map +1 -1
  67. package/dist/plugins/prometheus-time-series-query/index.js +1 -1
  68. package/dist/plugins/prometheus-time-series-query/index.js.map +1 -1
  69. package/dist/plugins/prometheus-time-series-query/query-editor-model.d.ts +4 -5
  70. package/dist/plugins/prometheus-time-series-query/query-editor-model.d.ts.map +1 -1
  71. package/dist/plugins/prometheus-time-series-query/query-editor-model.js +3 -3
  72. package/dist/plugins/prometheus-time-series-query/query-editor-model.js.map +1 -1
  73. package/dist/plugins/prometheus-time-series-query/time-series-query-model.js +1 -1
  74. package/dist/plugins/prometheus-time-series-query/time-series-query-model.js.map +1 -1
  75. package/dist/plugins/prometheus-variables.d.ts.map +1 -1
  76. package/dist/plugins/prometheus-variables.js +3 -2
  77. package/dist/plugins/prometheus-variables.js.map +1 -1
  78. package/dist/plugins/types.js +1 -1
  79. package/dist/plugins/types.js.map +1 -1
  80. package/dist/plugins/variable.js +1 -1
  81. package/dist/plugins/variable.js.map +1 -1
  82. package/dist/test/setup-tests.js +1 -1
  83. package/dist/test/setup-tests.js.map +1 -1
  84. package/dist/utils/index.d.ts +2 -0
  85. package/dist/utils/index.d.ts.map +1 -0
  86. package/dist/utils/index.js +15 -0
  87. package/dist/utils/index.js.map +1 -0
  88. package/dist/{model → utils}/utils.d.ts +5 -0
  89. package/dist/{model → utils}/utils.d.ts.map +1 -1
  90. package/dist/{model → utils}/utils.js +37 -1
  91. package/dist/utils/utils.js.map +1 -0
  92. package/dist/{model → utils}/utils.test.d.ts +0 -0
  93. package/dist/{model → utils}/utils.test.d.ts.map +1 -1
  94. package/dist/{model → utils}/utils.test.js +48 -2
  95. package/dist/utils/utils.test.js.map +1 -0
  96. package/package.json +6 -3
  97. package/dist/model/utils.js.map +0 -1
  98. package/dist/model/utils.test.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/components/PromQL.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 CodeMirror, { ReactCodeMirrorProps } from '@uiw/react-codemirror';\nimport { PromQLExtension, CompleteConfiguration } from '@prometheus-io/codemirror-promql';\nimport { EditorView } from '@codemirror/view';\nimport { useTheme } from '@mui/material';\nimport { useMemo } from 'react';\n\nexport type PromQLEditorProps = { completeConfig: CompleteConfiguration } & Omit<\n ReactCodeMirrorProps,\n 'theme' | 'extensions'\n>;\n\nexport function PromQLEditor({ completeConfig, ...rest }: PromQLEditorProps) {\n const theme = useTheme();\n const isDarkMode = theme.palette.mode === 'dark';\n\n const promQLExtension = useMemo(() => {\n return new PromQLExtension().activateLinter(false).setComplete(completeConfig).asExtension();\n }, [completeConfig]);\n\n return (\n <CodeMirror\n {...rest}\n style={{ border: `1px solid ${theme.palette.divider}` }}\n theme={isDarkMode ? 'dark' : 'light'}\n basicSetup={{\n highlightActiveLine: false,\n highlightActiveLineGutter: false,\n foldGutter: false,\n }}\n extensions={[EditorView.lineWrapping, promQLExtension]}\n />\n );\n}\n"],"names":["CodeMirror","PromQLExtension","EditorView","useTheme","useMemo","PromQLEditor","completeConfig","rest","theme","isDarkMode","palette","mode","promQLExtension","activateLinter","setComplete","asExtension","style","border","divider","basicSetup","highlightActiveLine","highlightActiveLineGutter","foldGutter","extensions","lineWrapping"],"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,OAAOA,UAAU,MAAgC,uBAAuB,CAAC;AACzE,SAASC,eAAe,QAA+B,kCAAkC,CAAC;AAC1F,SAASC,UAAU,QAAQ,kBAAkB,CAAC;AAC9C,SAASC,QAAQ,QAAQ,eAAe,CAAC;AACzC,SAASC,OAAO,QAAQ,OAAO,CAAC;AAOhC,OAAO,SAASC,YAAY,CAAC,EAAEC,cAAc,CAAA,EAAE,GAAGC,IAAI,EAAqB,EAAE;IAC3E,MAAMC,KAAK,GAAGL,QAAQ,EAAE,AAAC;IACzB,MAAMM,UAAU,GAAGD,KAAK,CAACE,OAAO,CAACC,IAAI,KAAK,MAAM,AAAC;IAEjD,MAAMC,eAAe,GAAGR,OAAO,CAAC,IAAM;QACpC,OAAO,IAAIH,eAAe,EAAE,CAACY,cAAc,CAAC,KAAK,CAAC,CAACC,WAAW,CAACR,cAAc,CAAC,CAACS,WAAW,EAAE,CAAC;IAC/F,CAAC,EAAE;QAACT,cAAc;KAAC,CAAC,AAAC;IAErB,qBACE,KAACN,UAAU;QACR,GAAGO,IAAI;QACRS,KAAK,EAAE;YAAEC,MAAM,EAAE,CAAC,UAAU,EAAET,KAAK,CAACE,OAAO,CAACQ,OAAO,CAAC,CAAC;SAAE;QACvDV,KAAK,EAAEC,UAAU,GAAG,MAAM,GAAG,OAAO;QACpCU,UAAU,EAAE;YACVC,mBAAmB,EAAE,KAAK;YAC1BC,yBAAyB,EAAE,KAAK;YAChCC,UAAU,EAAE,KAAK;SAClB;QACDC,UAAU,EAAE;YAACrB,UAAU,CAACsB,YAAY;YAAEZ,eAAe;SAAC;MACtD,CACF;AACJ,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './PromQL';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAaA,cAAc,UAAU,CAAC"}
@@ -0,0 +1,15 @@
1
+ // Copyright 2023 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 * from './PromQL';
14
+
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/components/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 './PromQL';\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,UAAU,CAAC"}
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
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
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.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 { PrometheusTimeSeriesQuery } from './plugins/prometheus-time-series-query';\n// @TODO: Move this to a more generic location;\nimport { StaticListVariable } from './plugins/variable';\nimport {\n PrometheusLabelNamesVariable,\n PrometheusLabelValuesVariable,\n PrometheusPromQLVariable,\n} from './plugins/prometheus-variables';\nimport { PrometheusDatasource } from './plugins/prometheus-datasource';\n\n// Export plugins under the same name as the kinds they handle from the plugin.json\nexport {\n PrometheusTimeSeriesQuery,\n StaticListVariable,\n PrometheusLabelNamesVariable,\n PrometheusLabelValuesVariable,\n PrometheusPromQLVariable,\n PrometheusDatasource,\n};\n"],"names":["PrometheusTimeSeriesQuery","StaticListVariable","PrometheusLabelNamesVariable","PrometheusLabelValuesVariable","PrometheusPromQLVariable","PrometheusDatasource"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,yBAAyB,QAAQ,wCAAwC,CAAC;AACnF,+CAA+C;AAC/C,SAASC,kBAAkB,QAAQ,oBAAoB,CAAC;AACxD,SACEC,4BAA4B,EAC5BC,6BAA6B,EAC7BC,wBAAwB,QACnB,gCAAgC,CAAC;AACxC,SAASC,oBAAoB,QAAQ,iCAAiC,CAAC;AAEvE,mFAAmF;AACnF,SACEL,yBAAyB,EACzBC,kBAAkB,EAClBC,4BAA4B,EAC5BC,6BAA6B,EAC7BC,wBAAwB,EACxBC,oBAAoB,GACpB"}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { PrometheusTimeSeriesQuery } from './plugins/prometheus-time-series-query';\n// @TODO: Move this to a more generic location;\nimport { StaticListVariable } from './plugins/variable';\nimport {\n PrometheusLabelNamesVariable,\n PrometheusLabelValuesVariable,\n PrometheusPromQLVariable,\n} from './plugins/prometheus-variables';\nimport { PrometheusDatasource } from './plugins/prometheus-datasource';\n\n// Export plugins under the same name as the kinds they handle from the plugin.json\nexport {\n PrometheusTimeSeriesQuery,\n StaticListVariable,\n PrometheusLabelNamesVariable,\n PrometheusLabelValuesVariable,\n PrometheusPromQLVariable,\n PrometheusDatasource,\n};\n"],"names":["PrometheusTimeSeriesQuery","StaticListVariable","PrometheusLabelNamesVariable","PrometheusLabelValuesVariable","PrometheusPromQLVariable","PrometheusDatasource"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,yBAAyB,QAAQ,wCAAwC,CAAC;AACnF,+CAA+C;AAC/C,SAASC,kBAAkB,QAAQ,oBAAoB,CAAC;AACxD,SACEC,4BAA4B,EAC5BC,6BAA6B,EAC7BC,wBAAwB,QACnB,gCAAgC,CAAC;AACxC,SAASC,oBAAoB,QAAQ,iCAAiC,CAAC;AAEvE,mFAAmF;AACnF,SACEL,yBAAyB,EACzBC,kBAAkB,EAClBC,4BAA4B,EAC5BC,6BAA6B,EAC7BC,wBAAwB,EACxBC,oBAAoB,GACpB"}
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
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
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/model/api-types.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 { DurationString } from '@perses-dev/core';\n\n// Just reuse dashboard model's type and re-export\nexport type { DurationString };\n\nexport interface SuccessResponse<T> {\n status: 'success';\n data: T;\n warnings?: string[];\n}\n\nexport interface ErrorResponse<T> {\n status: 'error';\n data?: T;\n errorType: string;\n error: string;\n}\n\nexport type ApiResponse<T> = SuccessResponse<T> | ErrorResponse<T>;\n\nexport type DurationSeconds = number;\n\nexport type UnixTimestampSeconds = number;\n\nexport type ValueTuple = [unixTimeSeconds: UnixTimestampSeconds, sampleValue: string];\n\nexport type Metric = Record<string, string>;\n\nexport interface VectorData {\n resultType: 'vector';\n result: Array<{\n metric: Metric;\n value: ValueTuple;\n }>;\n}\n\nexport interface MatrixData {\n resultType: 'matrix';\n result: Array<{\n metric: Metric;\n values: ValueTuple[];\n }>;\n}\n\nexport interface ScalarData {\n resultType: 'scalar';\n result: ValueTuple;\n}\n\nexport interface InstantQueryRequestParameters {\n query: string;\n time?: UnixTimestampSeconds;\n timeout?: DurationString;\n}\n\nexport type InstantQueryResponse = ApiResponse<MatrixData | VectorData | ScalarData>;\n\nexport interface RangeQueryRequestParameters {\n query: string;\n start: UnixTimestampSeconds;\n end: UnixTimestampSeconds;\n step: DurationSeconds;\n timeout?: DurationString;\n}\n\nexport type RangeQueryResponse = ApiResponse<MatrixData>;\n\nexport interface SeriesRequestParameters {\n 'match[]': string[];\n start: UnixTimestampSeconds;\n end: UnixTimestampSeconds;\n}\n\nexport type SeriesResponse = ApiResponse<Metric[]>;\n\nexport interface LabelNamesRequestParameters {\n start?: UnixTimestampSeconds;\n end?: UnixTimestampSeconds;\n 'match[]'?: string[];\n}\n\nexport type LabelNamesResponse = ApiResponse<string[]>;\n\nexport interface LabelValuesRequestParameters {\n labelName: string;\n start?: UnixTimestampSeconds;\n end?: UnixTimestampSeconds;\n 'match[]'?: string[];\n}\n\nexport type LabelValuesResponse = ApiResponse<string[]>;\n\nexport interface MetricMetadata {\n type: string;\n help: string;\n unit?: string;\n}\n\nexport interface MetricMetadataRequestParameters {\n limit?: number;\n metric?: string;\n}\n\nexport type MetricMetadataResponse = ApiResponse<Record<string, MetricMetadata[]>>;\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,WAuGmF"}
1
+ {"version":3,"sources":["../../src/model/api-types.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { DurationString } from '@perses-dev/core';\n\n// Just reuse dashboard model's type and re-export\nexport type { DurationString };\n\nexport interface SuccessResponse<T> {\n status: 'success';\n data: T;\n warnings?: string[];\n}\n\nexport interface ErrorResponse<T> {\n status: 'error';\n data?: T;\n errorType: string;\n error: string;\n}\n\nexport type ApiResponse<T> = SuccessResponse<T> | ErrorResponse<T>;\n\nexport type DurationSeconds = number;\n\nexport type UnixTimestampSeconds = number;\n\nexport type ValueTuple = [unixTimeSeconds: UnixTimestampSeconds, sampleValue: string];\n\nexport type Metric = Record<string, string>;\n\nexport interface VectorData {\n resultType: 'vector';\n result: Array<{\n metric: Metric;\n value: ValueTuple;\n }>;\n}\n\nexport interface MatrixData {\n resultType: 'matrix';\n result: Array<{\n metric: Metric;\n values: ValueTuple[];\n }>;\n}\n\nexport interface ScalarData {\n resultType: 'scalar';\n result: ValueTuple;\n}\n\nexport interface InstantQueryRequestParameters {\n query: string;\n time?: UnixTimestampSeconds;\n timeout?: DurationString;\n}\n\nexport type InstantQueryResponse = ApiResponse<MatrixData | VectorData | ScalarData>;\n\nexport interface RangeQueryRequestParameters {\n query: string;\n start: UnixTimestampSeconds;\n end: UnixTimestampSeconds;\n step: DurationSeconds;\n timeout?: DurationString;\n}\n\nexport type RangeQueryResponse = ApiResponse<MatrixData>;\n\nexport interface SeriesRequestParameters {\n 'match[]': string[];\n start: UnixTimestampSeconds;\n end: UnixTimestampSeconds;\n}\n\nexport type SeriesResponse = ApiResponse<Metric[]>;\n\nexport interface LabelNamesRequestParameters {\n start?: UnixTimestampSeconds;\n end?: UnixTimestampSeconds;\n 'match[]'?: string[];\n}\n\nexport type LabelNamesResponse = ApiResponse<string[]>;\n\nexport interface LabelValuesRequestParameters {\n labelName: string;\n start?: UnixTimestampSeconds;\n end?: UnixTimestampSeconds;\n 'match[]'?: string[];\n}\n\nexport type LabelValuesResponse = ApiResponse<string[]>;\n\nexport interface MetricMetadata {\n type: string;\n help: string;\n unit?: string;\n}\n\nexport interface MetricMetadataRequestParameters {\n limit?: number;\n metric?: string;\n}\n\nexport type MetricMetadataResponse = ApiResponse<Record<string, MetricMetadata[]>>;\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,WAuGmF"}
@@ -4,5 +4,4 @@ export * from './prometheus-client';
4
4
  export * from './prometheus-selectors';
5
5
  export * from './templating';
6
6
  export * from './time';
7
- export * from './utils';
8
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/model/index.ts"],"names":[],"mappings":"AAaA,cAAc,aAAa,CAAC;AAC5B,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/model/index.ts"],"names":[],"mappings":"AAaA,cAAc,aAAa,CAAC;AAC5B,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC"}
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
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
@@ -16,6 +16,5 @@ export * from './prometheus-client';
16
16
  export * from './prometheus-selectors';
17
17
  export * from './templating';
18
18
  export * from './time';
19
- export * from './utils';
20
19
 
21
20
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/model/index.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\nexport * from './api-types';\nexport * from './parse-sample-values';\nexport * from './prometheus-client';\nexport * from './prometheus-selectors';\nexport * from './templating';\nexport * from './time';\nexport * from './utils';\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,aAAa,CAAC;AAC5B,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC"}
1
+ {"version":3,"sources":["../../src/model/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 './api-types';\nexport * from './parse-sample-values';\nexport * from './prometheus-client';\nexport * from './prometheus-selectors';\nexport * from './templating';\nexport * from './time';\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,aAAa,CAAC;AAC5B,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC"}
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
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
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/model/parse-sample-values.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 { 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
+ {"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,5 +1,9 @@
1
1
  import { InstantQueryRequestParameters, InstantQueryResponse, LabelNamesRequestParameters, LabelNamesResponse, LabelValuesRequestParameters, LabelValuesResponse, RangeQueryRequestParameters, RangeQueryResponse } from './api-types';
2
+ interface PrometheusClientOptions {
3
+ datasourceUrl: string;
4
+ }
2
5
  export interface PrometheusClient {
6
+ options: PrometheusClientOptions;
3
7
  instantQuery(params: InstantQueryRequestParameters): Promise<InstantQueryResponse>;
4
8
  rangeQuery(params: RangeQueryRequestParameters): Promise<RangeQueryResponse>;
5
9
  labelNames(params: LabelNamesRequestParameters): Promise<LabelNamesResponse>;
@@ -24,4 +28,5 @@ export declare function labelNames(params: LabelNamesRequestParameters, queryOpt
24
28
  * Calls the `/api/v1/label/{labelName}/values` endpoint to get a list of values for a label.
25
29
  */
26
30
  export declare function labelValues(params: LabelValuesRequestParameters, queryOptions: QueryOptions): Promise<LabelValuesResponse>;
31
+ export {};
27
32
  //# sourceMappingURL=prometheus-client.d.ts.map
@@ -1 +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,2BAA2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W,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"}
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
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
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/model/prometheus-client.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { fetchJson } from '@perses-dev/core';\nimport {\n InstantQueryRequestParameters,\n InstantQueryResponse,\n LabelNamesRequestParameters,\n LabelNamesResponse,\n LabelValuesRequestParameters,\n LabelValuesResponse,\n RangeQueryRequestParameters,\n RangeQueryResponse,\n} from './api-types';\n\nexport interface PrometheusClient {\n instantQuery(params: InstantQueryRequestParameters): Promise<InstantQueryResponse>;\n rangeQuery(params: RangeQueryRequestParameters): Promise<RangeQueryResponse>;\n labelNames(params: LabelNamesRequestParameters): Promise<LabelNamesResponse>;\n labelValues(params: LabelValuesRequestParameters): Promise<LabelValuesResponse>;\n}\n\nexport interface QueryOptions {\n datasourceUrl: string;\n}\n\n/**\n * Calls the `/api/v1/query` endpoint to get metrics data.\n */\nexport function instantQuery(params: InstantQueryRequestParameters, queryOptions: QueryOptions) {\n return fetchWithPost<InstantQueryRequestParameters, InstantQueryResponse>('/api/v1/query', params, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/query_range` endpoint to get metrics data.\n */\nexport function rangeQuery(params: RangeQueryRequestParameters, queryOptions: QueryOptions) {\n return fetchWithPost<RangeQueryRequestParameters, RangeQueryResponse>('/api/v1/query_range', params, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/labels` endpoint to get a list of label names.\n */\nexport function labelNames(params: LabelNamesRequestParameters, queryOptions: QueryOptions) {\n return fetchWithPost<LabelNamesRequestParameters, LabelNamesResponse>('/api/v1/labels', params, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/label/{labelName}/values` endpoint to get a list of values for a label.\n */\nexport function labelValues(params: LabelValuesRequestParameters, queryOptions: QueryOptions) {\n const { labelName, ...searchParams } = params;\n const apiURI = `/api/v1/label/${encodeURIComponent(labelName)}/values`;\n return fetchWithGet<typeof searchParams, LabelValuesResponse>(apiURI, searchParams, queryOptions);\n}\n\nfunction fetchWithGet<T extends RequestParams<T>, TResponse>(apiURI: string, params: T, queryOptions: QueryOptions) {\n const { datasourceUrl } = queryOptions;\n\n let url = `${datasourceUrl}${apiURI}`;\n const urlParams = createSearchParams(params).toString();\n if (urlParams !== '') {\n url += `?${urlParams}`;\n }\n return fetchJson<TResponse>(url, { method: 'GET' });\n}\n\nfunction fetchWithPost<T extends RequestParams<T>, TResponse>(apiURI: string, params: T, queryOptions: QueryOptions) {\n const { datasourceUrl } = queryOptions;\n\n const url = `${datasourceUrl}${apiURI}`;\n const init = {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/x-www-form-urlencoded',\n },\n body: createSearchParams(params),\n };\n return fetchJson<TResponse>(url, init);\n}\n\n// Request parameter values we know how to serialize\ntype ParamValue = string | string[] | number | undefined;\n\n// Used to constrain the types that can be passed to createSearchParams to\n// just the ones we know how to serialize\ntype RequestParams<T> = {\n [K in keyof T]: ParamValue;\n};\n\n/**\n * Creates URLSearchParams from a request params object.\n */\nfunction createSearchParams<T extends RequestParams<T>>(params: T) {\n const searchParams = new URLSearchParams();\n for (const key in params) {\n const value: ParamValue = params[key];\n if (value === undefined) continue;\n\n if (typeof value === 'string') {\n searchParams.append(key, value);\n continue;\n }\n\n if (typeof value === 'number') {\n searchParams.append(key, value.toString());\n continue;\n }\n\n for (const val of value) {\n searchParams.append(key, val);\n }\n }\n return searchParams;\n}\n"],"names":["fetchJson","instantQuery","params","queryOptions","fetchWithPost","rangeQuery","labelNames","labelValues","labelName","searchParams","apiURI","encodeURIComponent","fetchWithGet","datasourceUrl","url","urlParams","createSearchParams","toString","method","init","headers","body","URLSearchParams","key","value","undefined","append","val"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,SAAS,QAAQ,kBAAkB,CAAC;AAuB7C;;CAEC,GACD,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,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GAAG,EAAEK,IAAI,CAAC,CAAC;AACzC,CAAC;AAWD;;CAEC,GACD,SAASH,kBAAkB,CAA6Bd,MAAS,EAAE;IACjE,MAAMO,YAAY,GAAG,IAAIa,eAAe,EAAE,AAAC;IAC3C,IAAK,MAAMC,GAAG,IAAIrB,MAAM,CAAE;QACxB,MAAMsB,KAAK,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
+ {"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 } 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}\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}\n\n/**\n * Calls the `/api/v1/query` endpoint to get metrics data.\n */\nexport function instantQuery(params: InstantQueryRequestParameters, queryOptions: QueryOptions) {\n return fetchWithPost<InstantQueryRequestParameters, InstantQueryResponse>('/api/v1/query', params, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/query_range` endpoint to get metrics data.\n */\nexport function rangeQuery(params: RangeQueryRequestParameters, queryOptions: QueryOptions) {\n return fetchWithPost<RangeQueryRequestParameters, RangeQueryResponse>('/api/v1/query_range', params, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/labels` endpoint to get a list of label names.\n */\nexport function labelNames(params: LabelNamesRequestParameters, queryOptions: QueryOptions) {\n return fetchWithPost<LabelNamesRequestParameters, LabelNamesResponse>('/api/v1/labels', params, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/label/{labelName}/values` endpoint to get a list of values for a label.\n */\nexport function labelValues(params: LabelValuesRequestParameters, queryOptions: QueryOptions) {\n const { labelName, ...searchParams } = params;\n const apiURI = `/api/v1/label/${encodeURIComponent(labelName)}/values`;\n return fetchWithGet<typeof searchParams, LabelValuesResponse>(apiURI, searchParams, queryOptions);\n}\n\nfunction fetchWithGet<T extends RequestParams<T>, TResponse>(apiURI: string, params: T, queryOptions: QueryOptions) {\n const { datasourceUrl } = queryOptions;\n\n let url = `${datasourceUrl}${apiURI}`;\n const urlParams = createSearchParams(params).toString();\n if (urlParams !== '') {\n url += `?${urlParams}`;\n }\n return fetchJson<TResponse>(url, { method: 'GET' });\n}\n\nfunction fetchWithPost<T extends RequestParams<T>, TResponse>(apiURI: string, params: T, queryOptions: QueryOptions) {\n const { datasourceUrl } = queryOptions;\n\n const url = `${datasourceUrl}${apiURI}`;\n const init = {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/x-www-form-urlencoded',\n },\n body: createSearchParams(params),\n };\n return fetchJson<TResponse>(url, init);\n}\n\n// Request parameter values we know how to serialize\ntype ParamValue = string | string[] | number | undefined;\n\n// Used to constrain the types that can be passed to createSearchParams to\n// just the ones we know how to serialize\ntype RequestParams<T> = {\n [K in keyof T]: ParamValue;\n};\n\n/**\n * Creates URLSearchParams from a request params object.\n */\nfunction createSearchParams<T extends RequestParams<T>>(params: T) {\n const searchParams = new URLSearchParams();\n for (const key in params) {\n const value: ParamValue = params[key];\n if (value === undefined) continue;\n\n if (typeof value === 'string') {\n searchParams.append(key, value);\n continue;\n }\n\n if (typeof value === 'number') {\n searchParams.append(key, value.toString());\n continue;\n }\n\n for (const val of value) {\n searchParams.append(key, val);\n }\n }\n return searchParams;\n}\n"],"names":["fetchJson","instantQuery","params","queryOptions","fetchWithPost","rangeQuery","labelNames","labelValues","labelName","searchParams","apiURI","encodeURIComponent","fetchWithGet","datasourceUrl","url","urlParams","createSearchParams","toString","method","init","headers","body","URLSearchParams","key","value","undefined","append","val"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,SAAS,QAAQ,kBAAkB,CAAC;AA4B7C;;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,CAAC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AAC,EAAED,aAAa,CAAC,EAAEH,MAAM,CAAC,CAAC,AAAC;IACxC,MAAMS,IAAI,GAAG;QACXD,MAAM,EAAE,MAAM;QACdE,OAAO,EAAE;YACP,cAAc,EAAE,mCAAmC;SACpD;QACDC,IAAI,EAAEL,kBAAkB,CAACd,MAAM,CAAC;KACjC,AAAC;IACF,OAAOF,SAAS,CAAYc,GAAG,EAAEK,IAAI,CAAC,CAAC;AACzC,CAAC;AAWD;;CAEC,GACD,SAASH,kBAAkB,CAA6Bd,MAAS,EAAE;IACjE,MAAMO,YAAY,GAAG,IAAIa,eAAe,EAAE,AAAC;IAC3C,IAAK,MAAMC,GAAG,IAAIrB,MAAM,CAAE;QACxB,MAAMsB,KAAK,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,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
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
@@ -1 +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"}
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"}
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
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 './utils';
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 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"}
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"}
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
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
@@ -1 +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"}
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,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
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
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/plugins/MatcherEditor.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { 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,GA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AAE,CAACY,KAAK,GAAK;4BAC/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
+ {"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,eAAe,CAAC;AAC1E,SAASC,OAAO,QAAQ,OAAO,CAAC;AAChC,OAAOC,SAAS,MAAM,0BAA0B,CAAC;AAOjD,OAAO,SAASC,aAAa,CAAC,EAAEC,QAAQ,CAAA,EAAEC,QAAQ,CAAA,EAAsB,EAAE;IACxE,qBACE,MAACT,KAAK;QAACU,OAAO,EAAE,CAAC;;YACdF,QAAQ,CAACG,GAAG,CAAC,CAACC,OAAO,EAAEC,KAAK,iBAC3B,MAACV,GAAG;oBAAaW,OAAO,EAAC,MAAM;;sCAC7B,KAACb,SAAS;4BACRc,SAAS;4BACTC,KAAK,EAAC,iBAAiB;4BACvBC,KAAK,EAAEL,OAAO;4BACdH,QAAQ,EAAE,CAACS,CAAC,GAAK;gCACf,MAAMC,WAAW,GAAGd,OAAO,CAACG,QAAQ,EAAE,CAACY,KAAK,GAAK;oCAC/CA,KAAK,CAACP,KAAK,CAAC,GAAGK,CAAC,CAACG,MAAM,CAACJ,KAAK,CAAC;gCAChC,CAAC,CAAC,AAAC;gCACHR,QAAQ,CAACU,WAAW,CAAC,CAAC;4BACxB,CAAC;0BACD;sCACF,KAACf,UAAU;4BACTkB,OAAO,EAAE,IAAM;gCACb,MAAMH,WAAW,GAAGd,OAAO,CAACG,QAAQ,EAAE,CAACY,KAAK,GAAK;oCAC/CA,KAAK,CAACG,MAAM,CAACV,KAAK,EAAE,CAAC,CAAC,CAAC;gCACzB,CAAC,CAAC,AAAC;gCACHJ,QAAQ,CAACU,WAAW,CAAC,CAAC;4BACxB,CAAC;sCAED,cAAA,KAACb,SAAS,KAAG;0BACF;;mBArBLO,KAAK,CAsBT,AACP,CAAC;0BACF,KAACV,GAAG;0BACF,cAAA,KAACD,MAAM;oBACLa,SAAS,EAAE,KAAK;oBAChBS,KAAK,EAAC,WAAW;oBACjBC,OAAO,EAAC,UAAU;oBAClBH,OAAO,EAAE,IAAM;wBACb,MAAMH,WAAW,GAAGd,OAAO,CAACG,QAAQ,EAAE,CAACY,KAAK,GAAK;4BAC/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 +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;CACrB;AAwBD,eAAO,MAAM,oBAAoB,EAAE,gBAAgB,CAAC,wBAAwB,EAAE,gBAAgB,CAI7F,CAAC"}
1
+ {"version":3,"file":"prometheus-datasource.d.ts","sourceRoot":"","sources":["../../src/plugins/prometheus-datasource.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAqD,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE/F,MAAM,WAAW,wBAAwB;IACvC,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AA2BD,eAAO,MAAM,oBAAoB,EAAE,gBAAgB,CAAC,wBAAwB,EAAE,gBAAgB,CAI7F,CAAC"}
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
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
@@ -23,6 +23,9 @@ import { instantQuery, rangeQuery, labelNames, labelValues } from '../model';
23
23
  }
24
24
  // Could think about this becoming a class, although it definitely doesn't have to be
25
25
  return {
26
+ options: {
27
+ datasourceUrl
28
+ },
26
29
  instantQuery: (params)=>instantQuery(params, {
27
30
  datasourceUrl
28
31
  }),
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/plugins/prometheus-datasource.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { DatasourcePlugin } from '@perses-dev/plugin-system';\nimport { instantQuery, rangeQuery, labelNames, labelValues, PrometheusClient } from '../model';\n\nexport interface PrometheusDatasourceSpec {\n direct_url?: string;\n}\n\n/**\n * Creates a PrometheusClient for a specific datasource spec.\n */\nconst createClient: DatasourcePlugin<PrometheusDatasourceSpec, PrometheusClient>['createClient'] = (spec, options) => {\n const { direct_url } = spec;\n const { proxyUrl } = options;\n\n // Use the direct URL if specified, but fallback to the proxyUrl by default if not specified\n const datasourceUrl = direct_url ?? proxyUrl;\n if (datasourceUrl === undefined) {\n throw new Error('No URL specified for Prometheus client. You can use direct_url in the spec to configure it.');\n }\n\n // Could think about this becoming a class, although it definitely doesn't have to be\n return {\n instantQuery: (params) => instantQuery(params, { datasourceUrl }),\n rangeQuery: (params) => rangeQuery(params, { datasourceUrl }),\n labelNames: (params) => labelNames(params, { datasourceUrl }),\n labelValues: (params) => labelValues(params, { datasourceUrl }),\n };\n};\n\nexport const PrometheusDatasource: DatasourcePlugin<PrometheusDatasourceSpec, PrometheusClient> = {\n createClient,\n OptionsEditorComponent: () => null,\n createInitialOptions: () => ({ direct_url: '' }),\n};\n"],"names":["instantQuery","rangeQuery","labelNames","labelValues","createClient","spec","options","direct_url","proxyUrl","datasourceUrl","undefined","Error","params","PrometheusDatasource","OptionsEditorComponent","createInitialOptions"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAGjC,SAASA,YAAY,EAAEC,UAAU,EAAEC,UAAU,EAAEC,WAAW,QAA0B,UAAU,CAAC;AAM/F;;CAEC,GACD,MAAMC,YAAY,GAAiF,CAACC,IAAI,EAAEC,OAAO,GAAK;IACpH,MAAM,EAAEC,UAAU,CAAA,EAAE,GAAGF,IAAI,AAAC;IAC5B,MAAM,EAAEG,QAAQ,CAAA,EAAE,GAAGF,OAAO,AAAC;IAE7B,4FAA4F;IAC5F,MAAMG,aAAa,GAAGF,UAAU,aAAVA,UAAU,cAAVA,UAAU,GAAIC,QAAQ,AAAC;IAC7C,IAAIC,aAAa,KAAKC,SAAS,EAAE;QAC/B,MAAM,IAAIC,KAAK,CAAC,6FAA6F,CAAC,CAAC;IACjH,CAAC;IAED,qFAAqF;IACrF,OAAO;QACLX,YAAY,EAAE,CAACY,MAAM,GAAKZ,YAAY,CAACY,MAAM,EAAE;gBAAEH,aAAa;aAAE,CAAC;QACjER,UAAU,EAAE,CAACW,MAAM,GAAKX,UAAU,CAACW,MAAM,EAAE;gBAAEH,aAAa;aAAE,CAAC;QAC7DP,UAAU,EAAE,CAACU,MAAM,GAAKV,UAAU,CAACU,MAAM,EAAE;gBAAEH,aAAa;aAAE,CAAC;QAC7DN,WAAW,EAAE,CAACS,MAAM,GAAKT,WAAW,CAACS,MAAM,EAAE;gBAAEH,aAAa;aAAE,CAAC;KAChE,CAAC;AACJ,CAAC,AAAC;AAEF,OAAO,MAAMI,oBAAoB,GAAiE;IAChGT,YAAY;IACZU,sBAAsB,EAAE,IAAM,IAAI;IAClCC,oBAAoB,EAAE,IAAO,CAAA;YAAER,UAAU,EAAE,EAAE;SAAE,CAAA,AAAC;CACjD,CAAC"}
1
+ {"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 { DatasourcePlugin } from '@perses-dev/plugin-system';\nimport { instantQuery, rangeQuery, labelNames, labelValues, PrometheusClient } from '../model';\n\nexport interface PrometheusDatasourceSpec {\n direct_url?: string;\n}\n\n/**\n * Creates a PrometheusClient for a specific datasource spec.\n */\nconst createClient: DatasourcePlugin<PrometheusDatasourceSpec, PrometheusClient>['createClient'] = (spec, options) => {\n const { direct_url } = spec;\n const { proxyUrl } = options;\n\n // Use the direct URL if specified, but fallback to the proxyUrl by default if not specified\n const datasourceUrl = direct_url ?? proxyUrl;\n if (datasourceUrl === undefined) {\n throw new Error('No URL specified for Prometheus client. You can use direct_url in the spec to configure it.');\n }\n\n // Could think about this becoming a class, although it definitely doesn't have to be\n return {\n options: {\n datasourceUrl,\n },\n instantQuery: (params) => instantQuery(params, { datasourceUrl }),\n rangeQuery: (params) => rangeQuery(params, { datasourceUrl }),\n labelNames: (params) => labelNames(params, { datasourceUrl }),\n labelValues: (params) => labelValues(params, { datasourceUrl }),\n };\n};\n\nexport const PrometheusDatasource: DatasourcePlugin<PrometheusDatasourceSpec, PrometheusClient> = {\n createClient,\n OptionsEditorComponent: () => null,\n createInitialOptions: () => ({ direct_url: '' }),\n};\n"],"names":["instantQuery","rangeQuery","labelNames","labelValues","createClient","spec","options","direct_url","proxyUrl","datasourceUrl","undefined","Error","params","PrometheusDatasource","OptionsEditorComponent","createInitialOptions"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAGjC,SAASA,YAAY,EAAEC,UAAU,EAAEC,UAAU,EAAEC,WAAW,QAA0B,UAAU,CAAC;AAM/F;;CAEC,GACD,MAAMC,YAAY,GAAiF,CAACC,IAAI,EAAEC,OAAO,GAAK;IACpH,MAAM,EAAEC,UAAU,CAAA,EAAE,GAAGF,IAAI,AAAC;IAC5B,MAAM,EAAEG,QAAQ,CAAA,EAAE,GAAGF,OAAO,AAAC;IAE7B,4FAA4F;IAC5F,MAAMG,aAAa,GAAGF,UAAU,aAAVA,UAAU,cAAVA,UAAU,GAAIC,QAAQ,AAAC;IAC7C,IAAIC,aAAa,KAAKC,SAAS,EAAE;QAC/B,MAAM,IAAIC,KAAK,CAAC,6FAA6F,CAAC,CAAC;IACjH,CAAC;IAED,qFAAqF;IACrF,OAAO;QACLL,OAAO,EAAE;YACPG,aAAa;SACd;QACDT,YAAY,EAAE,CAACY,MAAM,GAAKZ,YAAY,CAACY,MAAM,EAAE;gBAAEH,aAAa;aAAE,CAAC;QACjER,UAAU,EAAE,CAACW,MAAM,GAAKX,UAAU,CAACW,MAAM,EAAE;gBAAEH,aAAa;aAAE,CAAC;QAC7DP,UAAU,EAAE,CAACU,MAAM,GAAKV,UAAU,CAACU,MAAM,EAAE;gBAAEH,aAAa;aAAE,CAAC;QAC7DN,WAAW,EAAE,CAACS,MAAM,GAAKT,WAAW,CAACS,MAAM,EAAE;gBAAEH,aAAa;aAAE,CAAC;KAChE,CAAC;AACJ,CAAC,AAAC;AAEF,OAAO,MAAMI,oBAAoB,GAAiE;IAChGT,YAAY;IACZU,sBAAsB,EAAE,IAAM,IAAI;IAClCC,oBAAoB,EAAE,IAAO,CAAA;YAAER,UAAU,EAAE,EAAE;SAAE,CAAA,AAAC;CACjD,CAAC"}
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
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 '../../model';
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 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 { TimeSeriesQueryPlugin } from '@perses-dev/plugin-system';\nimport { parseTemplateVariables } from '../../model';\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
+ {"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,"file":"PrometheusTimeSeriesQueryEditor.d.ts","sourceRoot":"","sources":["../../../src/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.tsx"],"names":[],"mappings":";AAiBA,OAAO,EAAE,oCAAoC,EAAiC,MAAM,sBAAsB,CAAC;AAE3G;;GAEG;AACH,wBAAgB,+BAA+B,CAAC,KAAK,EAAE,oCAAoC,eAsD1F"}
1
+ {"version":3,"file":"PrometheusTimeSeriesQueryEditor.d.ts","sourceRoot":"","sources":["../../../src/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.tsx"],"names":[],"mappings":";AAkBA,OAAO,EAAE,oCAAoC,EAAiC,MAAM,sBAAsB,CAAC;AAE3G;;GAEG;AACH,wBAAgB,+BAA+B,CAAC,KAAK,EAAE,oCAAoC,eAwD1F"}
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
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
@@ -13,14 +13,18 @@
13
13
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
14
  import { produce } from 'immer';
15
15
  import { Stack, TextField, FormControl, InputLabel } from '@mui/material';
16
- import { DatasourceSelect } from '@perses-dev/plugin-system';
16
+ import { DatasourceSelect, useDatasourceClient } from '@perses-dev/plugin-system';
17
17
  import { DEFAULT_PROM, isDefaultPromSelector, isPrometheusDatasourceSelector } from '../../model';
18
+ import { PromQLEditor } from '../../components';
18
19
  import { useQueryState, useFormatState } from './query-editor-model';
19
20
  /**
20
21
  * The options editor component for editing a PrometheusTimeSeriesQuery's spec.
21
22
  */ export function PrometheusTimeSeriesQueryEditor(props) {
22
23
  const { onChange , value } = props;
23
24
  const { datasource } = value;
25
+ const selectedDatasource = datasource !== null && datasource !== void 0 ? datasource : DEFAULT_PROM;
26
+ const { data: client } = useDatasourceClient(selectedDatasource);
27
+ const promURL = client === null || client === void 0 ? void 0 : client.options.datasourceUrl;
24
28
  const { query , handleQueryChange , handleQueryBlur } = useQueryState(props);
25
29
  const { format , handleFormatChange , handleFormatBlur } = useFormatState(props);
26
30
  const handleDatasourceChange = (next)=>{
@@ -37,19 +41,21 @@ import { useQueryState, useFormatState } from './query-editor-model';
37
41
  return /*#__PURE__*/ _jsxs(Stack, {
38
42
  spacing: 2,
39
43
  children: [
40
- /*#__PURE__*/ _jsx(TextField, {
41
- fullWidth: true,
42
- label: "Query",
44
+ /*#__PURE__*/ _jsx(PromQLEditor, {
45
+ completeConfig: {
46
+ remote: {
47
+ url: promURL
48
+ }
49
+ },
43
50
  value: query,
44
51
  onChange: handleQueryChange,
45
- onBlur: handleQueryBlur,
46
- margin: "dense"
52
+ onBlur: handleQueryBlur
47
53
  }),
48
54
  /*#__PURE__*/ _jsx(TextField, {
49
55
  fullWidth: true,
50
56
  label: "Series Name Format",
51
57
  value: format !== null && format !== void 0 ? format : '',
52
- onChange: handleFormatChange,
58
+ onChange: (e)=>handleFormatChange(e.target.value),
53
59
  onBlur: handleFormatBlur,
54
60
  margin: "dense"
55
61
  }),
@@ -63,7 +69,7 @@ import { useQueryState, useFormatState } from './query-editor-model';
63
69
  }),
64
70
  /*#__PURE__*/ _jsx(DatasourceSelect, {
65
71
  datasourcePluginKind: "PrometheusDatasource",
66
- value: datasource !== null && datasource !== void 0 ? datasource : DEFAULT_PROM,
72
+ value: selectedDatasource,
67
73
  onChange: handleDatasourceChange,
68
74
  labelId: "prom-datasource-label",
69
75
  label: "Prometheus Datasource"
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { produce } from 'immer';\nimport { Stack, TextField, FormControl, InputLabel } from '@mui/material';\nimport { DatasourceSelect, DatasourceSelectProps } from '@perses-dev/plugin-system';\nimport { DEFAULT_PROM, isDefaultPromSelector, isPrometheusDatasourceSelector } from '../../model';\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\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 <TextField\n fullWidth\n label=\"Query\"\n value={query}\n onChange={handleQueryChange}\n onBlur={handleQueryBlur}\n margin=\"dense\"\n />\n <TextField\n fullWidth\n label=\"Series Name Format\"\n value={format ?? ''}\n onChange={handleFormatChange}\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={datasource ?? DEFAULT_PROM}\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","DEFAULT_PROM","isDefaultPromSelector","isPrometheusDatasourceSelector","useQueryState","useFormatState","PrometheusTimeSeriesQueryEditor","props","onChange","value","datasource","query","handleQueryChange","handleQueryBlur","format","handleFormatChange","handleFormatBlur","handleDatasourceChange","next","draft","nextDatasource","undefined","Error","spacing","fullWidth","label","onBlur","margin","id","datasourcePluginKind","labelId"],"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,OAAO,QAAQ,OAAO,CAAC;AAChC,SAASC,KAAK,EAAEC,SAAS,EAAEC,WAAW,EAAEC,UAAU,QAAQ,eAAe,CAAC;AAC1E,SAASC,gBAAgB,QAA+B,2BAA2B,CAAC;AACpF,SAASC,YAAY,EAAEC,qBAAqB,EAAEC,8BAA8B,QAAQ,aAAa,CAAC;AAClG,SAA+CC,aAAa,EAAEC,cAAc,QAAQ,sBAAsB,CAAC;AAE3G;;CAEC,GACD,OAAO,SAASC,+BAA+B,CAACC,KAA2C,EAAE;IAC3F,MAAM,EAAEC,QAAQ,CAAA,EAAEC,KAAK,CAAA,EAAE,GAAGF,KAAK,AAAC;IAClC,MAAM,EAAEG,UAAU,CAAA,EAAE,GAAGD,KAAK,AAAC;IAE7B,MAAM,EAAEE,KAAK,CAAA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AAa;kCACzE,KAAC5B,gBAAgB;wBACf6B,oBAAoB,EAAC,sBAAsB;wBAC3CpB,KAAK,EAAEC,UAAU,aAAVA,UAAU,cAAVA,UAAU,GAAIT,YAAY;wBACjCO,QAAQ,EAAES,sBAAsB;wBAChCa,OAAO,EAAC,uBAAuB;wBAC/BL,KAAK,EAAC,uBAAuB;sBAC7B;;cACU;;MACR,CACR;AACJ,CAAC"}
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":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,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ourceRoot":"","sources":["../../../src/plugins/prometheus-time-series-query/get-time-series-data.ts"],"names":[],"mappings":"AAaA,OAAO,EAAkB,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAYlF,OAAO,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAE1E,eAAO,MAAM,iBAAiB,EAAE,qBAAqB,CAAC,6BAA6B,CAAC,CAAC,mBAAmB,CAuEvG,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 2022 The Perses Authors
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, replaceTemplateVariables, DEFAULT_PROM, formatSeriesName } from '../../model';
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, just use the
62
- // overall query
63
- let name = Object.entries(metric).map(([labelName, labelValue])=>`${labelName}="${labelValue}"`).join(', ');
64
- if (name === '') name = query;
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;