@perses-dev/prometheus-plugin 0.58.0-beta.0 → 0.58.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/__mf/js/Prometheus.e5d7ce90.js +7 -0
- package/__mf/js/async/1728.bbe08f31.js +1 -0
- package/__mf/js/async/2177.adb95f75.js +7 -0
- package/__mf/js/async/2228.53db17f4.js +2 -0
- package/__mf/js/async/{7462.e9a1c8bc.js.LICENSE.txt → 2228.53db17f4.js.LICENSE.txt} +17 -1
- package/__mf/js/async/2979.1d711dae.js +1 -0
- package/__mf/js/async/3075.08023434.js +1 -0
- package/__mf/js/async/3613.8ccc0992.js +22 -0
- package/__mf/js/async/425.b9d2dc6f.js +1 -0
- package/__mf/js/async/4626.90ae092f.js +1 -0
- package/__mf/js/async/5440.9f33f7a9.js +2 -0
- package/__mf/js/async/{5440.52ec91ad.js.LICENSE.txt → 5440.9f33f7a9.js.LICENSE.txt} +3 -3
- package/__mf/js/async/7729.2e55d1c3.js +3 -0
- package/__mf/js/async/8356.6a2bfd53.js +1 -0
- package/__mf/js/async/9020.058fd99c.js +1 -0
- package/__mf/js/async/9537.d1466e1b.js +1 -0
- package/__mf/js/async/9594.d1a3d0d9.js +1 -0
- package/__mf/js/async/__federation_expose_PrometheusDatasource.ef5f1df2.js +1 -0
- package/__mf/js/async/__federation_expose_PrometheusExplorer.e3461057.js +1 -0
- package/__mf/js/async/__federation_expose_PrometheusLabelNamesVariable.31fc9961.js +1 -0
- package/__mf/js/async/__federation_expose_PrometheusLabelValuesVariable.c3dbff14.js +1 -0
- package/__mf/js/async/__federation_expose_PrometheusPromQLVariable.cfc93e6f.js +1 -0
- package/__mf/js/async/__federation_expose_PrometheusTimeSeriesQuery.0e2db857.js +1 -0
- package/__mf/js/main.0a0f0efb.js +7 -0
- package/lib/cjs/components/promql/format.js +6 -6
- package/lib/cjs/components/promql/serialize.js +4 -4
- package/lib/cjs/components/query.js +9 -2
- package/lib/cjs/explore/PrometheusMetricsFinder/utils.js +17 -4
- package/lib/cjs/model/prometheus-client.js +4 -4
- package/lib/cjs/model/time.js +2 -2
- package/lib/cjs/plugins/PrometheusLabelValuesVariable.js +72 -6
- package/lib/cjs/plugins/interpolation.js +7 -0
- package/lib/cjs/plugins/prometheus-time-series-query/get-time-series-data.js +2 -2
- package/lib/cjs/plugins/prometheus-time-series-query/replace-prom-builtin-variables.js +3 -3
- package/lib/components/TreeNode.d.ts.map +1 -1
- package/lib/components/TreeNode.js.map +1 -1
- package/lib/components/promql/format.d.ts.map +1 -1
- package/lib/components/promql/format.js +6 -6
- package/lib/components/promql/format.js.map +1 -1
- package/lib/components/promql/serialize.js +4 -4
- package/lib/components/promql/serialize.js.map +1 -1
- package/lib/components/query.d.ts +2 -1
- package/lib/components/query.d.ts.map +1 -1
- package/lib/components/query.js +10 -3
- package/lib/components/query.js.map +1 -1
- package/lib/explore/PrometheusExplorer.d.ts.map +1 -1
- package/lib/explore/PrometheusExplorer.js +1 -1
- package/lib/explore/PrometheusExplorer.js.map +1 -1
- package/lib/explore/PrometheusMetricsFinder/PrometheusMetricsFinder.d.ts +1 -1
- package/lib/explore/PrometheusMetricsFinder/PrometheusMetricsFinder.d.ts.map +1 -1
- package/lib/explore/PrometheusMetricsFinder/PrometheusMetricsFinder.js.map +1 -1
- package/lib/explore/PrometheusMetricsFinder/display/list/MetricList.d.ts +1 -1
- package/lib/explore/PrometheusMetricsFinder/display/list/MetricList.d.ts.map +1 -1
- package/lib/explore/PrometheusMetricsFinder/display/list/MetricList.js.map +1 -1
- package/lib/explore/PrometheusMetricsFinder/filter/FilterInputs.d.ts +1 -1
- package/lib/explore/PrometheusMetricsFinder/filter/FilterInputs.d.ts.map +1 -1
- package/lib/explore/PrometheusMetricsFinder/filter/FilterInputs.js.map +1 -1
- package/lib/explore/PrometheusMetricsFinder/filter/FinderFilters.d.ts +1 -1
- package/lib/explore/PrometheusMetricsFinder/filter/FinderFilters.d.ts.map +1 -1
- package/lib/explore/PrometheusMetricsFinder/filter/FinderFilters.js.map +1 -1
- package/lib/explore/PrometheusMetricsFinder/overview/MetricOverview.d.ts +1 -1
- package/lib/explore/PrometheusMetricsFinder/overview/MetricOverview.d.ts.map +1 -1
- package/lib/explore/PrometheusMetricsFinder/overview/MetricOverview.js.map +1 -1
- package/lib/explore/PrometheusMetricsFinder/overview/tabs/JobTab.d.ts +1 -1
- package/lib/explore/PrometheusMetricsFinder/overview/tabs/JobTab.d.ts.map +1 -1
- package/lib/explore/PrometheusMetricsFinder/overview/tabs/JobTab.js +1 -1
- package/lib/explore/PrometheusMetricsFinder/overview/tabs/JobTab.js.map +1 -1
- package/lib/explore/PrometheusMetricsFinder/overview/tabs/OverviewTab.d.ts +1 -1
- package/lib/explore/PrometheusMetricsFinder/overview/tabs/OverviewTab.d.ts.map +1 -1
- package/lib/explore/PrometheusMetricsFinder/overview/tabs/OverviewTab.js +1 -1
- package/lib/explore/PrometheusMetricsFinder/overview/tabs/OverviewTab.js.map +1 -1
- package/lib/explore/PrometheusMetricsFinder/overview/tabs/SimilarTab.d.ts +1 -1
- package/lib/explore/PrometheusMetricsFinder/overview/tabs/SimilarTab.d.ts.map +1 -1
- package/lib/explore/PrometheusMetricsFinder/overview/tabs/SimilarTab.js +1 -1
- package/lib/explore/PrometheusMetricsFinder/overview/tabs/SimilarTab.js.map +1 -1
- package/lib/explore/PrometheusMetricsFinder/types.d.ts +1 -1
- package/lib/explore/PrometheusMetricsFinder/types.js.map +1 -1
- package/lib/explore/PrometheusMetricsFinder/utils.d.ts +2 -1
- package/lib/explore/PrometheusMetricsFinder/utils.d.ts.map +1 -1
- package/lib/explore/PrometheusMetricsFinder/utils.js +18 -5
- package/lib/explore/PrometheusMetricsFinder/utils.js.map +1 -1
- package/lib/model/api-types.d.ts +1 -1
- package/lib/model/api-types.js.map +1 -1
- package/lib/model/prometheus-client.d.ts +1 -1
- package/lib/model/prometheus-client.d.ts.map +1 -1
- package/lib/model/prometheus-client.js +1 -1
- package/lib/model/prometheus-client.js.map +1 -1
- package/lib/model/prometheus-selectors.d.ts +1 -1
- package/lib/model/prometheus-selectors.d.ts.map +1 -1
- package/lib/model/prometheus-selectors.js.map +1 -1
- package/lib/model/time.d.ts +1 -1
- package/lib/model/time.d.ts.map +1 -1
- package/lib/model/time.js +1 -1
- package/lib/model/time.js.map +1 -1
- package/lib/plugins/PrometheusDatasourceEditor.d.ts.map +1 -1
- package/lib/plugins/PrometheusDatasourceEditor.js.map +1 -1
- package/lib/plugins/PrometheusLabelValuesVariable.d.ts.map +1 -1
- package/lib/plugins/PrometheusLabelValuesVariable.js +72 -6
- package/lib/plugins/PrometheusLabelValuesVariable.js.map +1 -1
- package/lib/plugins/interpolation.d.ts +2 -1
- package/lib/plugins/interpolation.d.ts.map +1 -1
- package/lib/plugins/interpolation.js +4 -0
- package/lib/plugins/interpolation.js.map +1 -1
- package/lib/plugins/prometheus-datasource.d.ts.map +1 -1
- package/lib/plugins/prometheus-datasource.js.map +1 -1
- package/lib/plugins/prometheus-time-series-query/get-time-series-data.d.ts.map +1 -1
- package/lib/plugins/prometheus-time-series-query/get-time-series-data.js +1 -1
- package/lib/plugins/prometheus-time-series-query/get-time-series-data.js.map +1 -1
- package/lib/plugins/prometheus-time-series-query/query-editor-model.d.ts +1 -1
- package/lib/plugins/prometheus-time-series-query/query-editor-model.js.map +1 -1
- package/lib/plugins/prometheus-time-series-query/replace-prom-builtin-variables.js +3 -3
- package/lib/plugins/prometheus-time-series-query/replace-prom-builtin-variables.js.map +1 -1
- package/lib/plugins/prometheus-time-series-query/time-series-query-model.d.ts +1 -1
- package/lib/plugins/prometheus-time-series-query/time-series-query-model.d.ts.map +1 -1
- package/lib/plugins/prometheus-time-series-query/time-series-query-model.js.map +1 -1
- package/lib/plugins/types.d.ts +1 -1
- package/lib/plugins/types.d.ts.map +1 -1
- package/lib/plugins/types.js.map +1 -1
- package/mf-manifest.json +125 -119
- package/mf-stats.json +127 -121
- package/package.json +9 -7
- package/__mf/js/Prometheus.c5cd832d.js +0 -7
- package/__mf/js/async/1728.310a7d33.js +0 -1
- package/__mf/js/async/2292.27a5ec4d.js +0 -4
- package/__mf/js/async/2292.27a5ec4d.js.LICENSE.txt +0 -15
- package/__mf/js/async/3829.f250b55a.js +0 -7
- package/__mf/js/async/4402.99ae853d.js +0 -1
- package/__mf/js/async/4626.e7ed0d7d.js +0 -1
- package/__mf/js/async/4800.cc42977e.js +0 -22
- package/__mf/js/async/4887.8af3673d.js +0 -1
- package/__mf/js/async/5440.52ec91ad.js +0 -2
- package/__mf/js/async/5697.e17ba256.js +0 -1
- package/__mf/js/async/7462.e9a1c8bc.js +0 -2
- package/__mf/js/async/8292.11dc2ca3.js +0 -1
- package/__mf/js/async/8356.e845a073.js +0 -1
- package/__mf/js/async/8634.e3cfb057.js +0 -1
- package/__mf/js/async/__federation_expose_PrometheusDatasource.d4892cae.js +0 -1
- package/__mf/js/async/__federation_expose_PrometheusExplorer.681841d8.js +0 -1
- package/__mf/js/async/__federation_expose_PrometheusLabelNamesVariable.86c44577.js +0 -1
- package/__mf/js/async/__federation_expose_PrometheusLabelValuesVariable.ff683936.js +0 -1
- package/__mf/js/async/__federation_expose_PrometheusPromQLVariable.bac03b61.js +0 -1
- package/__mf/js/async/__federation_expose_PrometheusTimeSeriesQuery.9a495e56.js +0 -1
- package/__mf/js/main.afe2fc64.js +0 -7
- /package/__mf/css/async/{3829.85c2cbf6.css → 2177.85c2cbf6.css} +0 -0
- /package/__mf/js/async/{3829.f250b55a.js.LICENSE.txt → 2177.adb95f75.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{4800.cc42977e.js.LICENSE.txt → 3613.8ccc0992.js.LICENSE.txt} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/plugins/PrometheusDatasourceEditor.tsx"],"sourcesContent":["// Copyright 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 { Box, IconButton, TextField, Typography } from '@mui/material';\nimport { QueryParamValues } from '@perses-dev/components';\nimport { DurationString } from '@perses-dev/core';\nimport { HTTPSettingsEditor } from '@perses-dev/plugin-system';\nimport MinusIcon from 'mdi-material-ui/Minus';\nimport PlusIcon from 'mdi-material-ui/Plus';\nimport { ReactElement, useRef, useState } from 'react';\nimport { DEFAULT_SCRAPE_INTERVAL, PrometheusDatasourceSpec } from './types';\n\ninterface QueryParamEntry {\n // Unique identifier for the entry, added to avoid using array index as key\n id: string;\n key: string;\n value: string;\n}\n\nexport interface PrometheusDatasourceEditorProps {\n value: PrometheusDatasourceSpec;\n onChange: (next: PrometheusDatasourceSpec) => void;\n isReadonly?: boolean;\n}\n\nexport function PrometheusDatasourceEditor(props: PrometheusDatasourceEditorProps): ReactElement {\n const { value, onChange, isReadonly } = props;\n\n // Counter for generating unique IDs\n const nextIdRef = useRef(0);\n\n // Use local state to maintain an array of entries during editing, instead of\n // manipulating a map directly which causes weird UX.\n const [entries, setEntries] = useState<QueryParamEntry[]>(() => {\n const queryParams: QueryParamValues = value.queryParams ?? {};\n return Object.entries(queryParams).map(([key, val]) => ({\n id: String(nextIdRef.current++),\n key,\n value: Array.isArray(val) ? val.join(',') : val,\n }));\n });\n\n // Check for duplicate keys\n const keyMap = new Map<string, number>();\n const duplicateKeys = new Set<string>();\n entries.forEach(({ key }) => {\n if (key !== '') {\n const count = (keyMap.get(key) || 0) + 1;\n keyMap.set(key, count);\n if (count > 1) {\n duplicateKeys.add(key);\n }\n }\n });\n const hasDuplicates = duplicateKeys.size > 0;\n\n // Convert entries array to object and trigger onChange.\n // Values containing commas are stored as arrays to preserve the round-trip\n // with the load-time join(',') in useState above.\n const syncToParent = (newEntries: QueryParamEntry[]): void => {\n const newParams: Record<string, string | string[]> = {};\n newEntries.forEach(({ key, value }) => {\n if (key !== '') {\n const parts = value.split(',');\n newParams[key] = parts.length > 1 ? parts : value;\n }\n });\n\n onChange({\n ...value,\n queryParams: Object.keys(newParams).length > 0 ? newParams : undefined,\n });\n };\n\n const handleQueryParamChange = (id: string, field: 'key' | 'value', newValue: string): void => {\n const newEntries = entries.map((entry) => {\n if (entry.id !== id) return entry;\n return field === 'key' ? { ...entry, key: newValue } : { ...entry, value: newValue };\n });\n setEntries(newEntries);\n syncToParent(newEntries);\n };\n\n const addQueryParam = (): void => {\n const newEntries = [...entries, { id: String(nextIdRef.current++), key: '', value: '' }];\n setEntries(newEntries);\n syncToParent(newEntries);\n };\n\n const removeQueryParam = (id: string): void => {\n const newEntries = entries.filter((entry) => entry.id !== id);\n setEntries(newEntries);\n syncToParent(newEntries);\n };\n\n const initialSpecDirect: PrometheusDatasourceSpec = {\n directUrl: '',\n };\n\n const initialSpecProxy: PrometheusDatasourceSpec = {\n proxy: {\n kind: 'HTTPProxy',\n spec: {\n allowedEndpoints: [\n // list of standard endpoints suggested by default\n {\n endpointPattern: '/api/v1/labels',\n method: 'POST',\n },\n {\n endpointPattern: '/api/v1/series',\n method: 'POST',\n },\n {\n endpointPattern: '/api/v1/metadata',\n method: 'GET',\n },\n {\n endpointPattern: '/api/v1/query',\n method: 'POST',\n },\n {\n endpointPattern: '/api/v1/query_range',\n method: 'POST',\n },\n {\n endpointPattern: '/api/v1/label/([a-zA-Z0-9_-]+)/values',\n method: 'GET',\n },\n {\n endpointPattern: '/api/v1/parse_query',\n method: 'POST',\n },\n ],\n url: '',\n },\n },\n };\n\n return (\n <>\n <Typography variant=\"h4\" mb={2}>\n General Settings\n </Typography>\n <TextField\n size=\"small\"\n fullWidth\n label=\"Scrape Interval\"\n value={value.scrapeInterval || ''}\n placeholder={`Default: ${DEFAULT_SCRAPE_INTERVAL}`}\n InputProps={{\n readOnly: isReadonly,\n }}\n InputLabelProps={{ shrink: isReadonly ? true : undefined }}\n onChange={(e) => onChange({ ...value, scrapeInterval: e.target.value as DurationString })}\n helperText=\"Set it to match the typical scrape interval used in your Prometheus instance.\"\n />\n <HTTPSettingsEditor\n value={value}\n onChange={onChange}\n isReadonly={isReadonly}\n initialSpecDirect={initialSpecDirect}\n initialSpecProxy={initialSpecProxy}\n />\n <Typography variant=\"h5\" mt={2} mb={1}>\n Query Parameters\n </Typography>\n {entries.length > 0 && (\n <>\n {entries.map((entry) => (\n <Box key={entry.id} display=\"flex\" alignItems=\"center\" gap={2} mb={1}>\n <TextField\n size=\"small\"\n label=\"Key\"\n value={entry.key}\n placeholder=\"Parameter name\"\n disabled={isReadonly}\n onChange={(e) => handleQueryParamChange(entry.id, 'key', e.target.value)}\n error={duplicateKeys.has(entry.key)}\n sx={{ minWidth: 150 }}\n />\n <TextField\n size=\"small\"\n label=\"Value\"\n value={entry.value}\n placeholder=\"Parameter value\"\n disabled={isReadonly}\n onChange={(e) => handleQueryParamChange(entry.id, 'value', e.target.value)}\n sx={{ minWidth: 150, flexGrow: 1 }}\n />\n {!isReadonly && (\n <IconButton onClick={() => removeQueryParam(entry.id)}>\n <MinusIcon />\n </IconButton>\n )}\n </Box>\n ))}\n </>\n )}\n {hasDuplicates && (\n <Typography variant=\"body2\" color=\"error\" mb={1}>\n Duplicate parameter keys detected. Each key must be unique.\n </Typography>\n )}\n {entries.length === 0 && (\n <Typography variant=\"body2\" color=\"textSecondary\">\n No query parameters configured. Use query parameters to pass additional options to Prometheus (e.g.,\n dedup=false for Thanos).\n </Typography>\n )}\n {!isReadonly && (\n <IconButton onClick={addQueryParam}>\n <PlusIcon />\n </IconButton>\n )}\n </>\n );\n}\n"],"names":["Box","IconButton","TextField","Typography","HTTPSettingsEditor","MinusIcon","PlusIcon","useRef","useState","DEFAULT_SCRAPE_INTERVAL","PrometheusDatasourceEditor","props","value","onChange","isReadonly","nextIdRef","entries","setEntries","queryParams","Object","map","key","val","id","String","current","Array","isArray","join","keyMap","Map","duplicateKeys","Set","forEach","count","get","set","add","hasDuplicates","size","syncToParent","newEntries","newParams","parts","split","length","keys","undefined","handleQueryParamChange","field","newValue","entry","addQueryParam","removeQueryParam","filter","initialSpecDirect","directUrl","initialSpecProxy","proxy","kind","spec","allowedEndpoints","endpointPattern","method","url","variant","mb","fullWidth","label","scrapeInterval","placeholder","InputProps","readOnly","InputLabelProps","shrink","e","target","helperText","mt","display","alignItems","gap","disabled","error","has","sx","minWidth","flexGrow","onClick","color"],"mappings":";AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,GAAG,EAAEC,UAAU,EAAEC,SAAS,EAAEC,UAAU,QAAQ,gBAAgB;AAGvE,SAASC,kBAAkB,QAAQ,4BAA4B;AAC/D,OAAOC,eAAe,wBAAwB;AAC9C,OAAOC,cAAc,uBAAuB;AAC5C,SAAuBC,MAAM,EAAEC,QAAQ,QAAQ,QAAQ;AACvD,SAASC,uBAAuB,QAAkC,UAAU;AAe5E,OAAO,SAASC,2BAA2BC,KAAsC;IAC/E,MAAM,EAAEC,KAAK,EAAEC,QAAQ,EAAEC,UAAU,EAAE,GAAGH;IAExC,oCAAoC;IACpC,MAAMI,YAAYR,OAAO;IAEzB,6EAA6E;IAC7E,qDAAqD;IACrD,MAAM,CAACS,SAASC,WAAW,GAAGT,SAA4B;QACxD,MAAMU,cAAgCN,MAAMM,WAAW,IAAI,CAAC;QAC5D,OAAOC,OAAOH,OAAO,CAACE,aAAaE,GAAG,CAAC,CAAC,CAACC,KAAKC,IAAI,GAAM,CAAA;gBACtDC,IAAIC,OAAOT,UAAUU,OAAO;gBAC5BJ;gBACAT,OAAOc,MAAMC,OAAO,CAACL,OAAOA,IAAIM,IAAI,CA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;gBAAKa,IAAI;gBAAGZ,IAAI;0BAAG;;YAGtClD,QAAQ6B,MAAM,GAAG,mBAChB;0BACG7B,QAAQI,GAAG,CAAC,CAAC+B,sBACZ,MAACnD;wBAAmB+E,SAAQ;wBAAOC,YAAW;wBAASC,KAAK;wBAAGf,IAAI;;0CACjE,KAAChE;gCACCqC,MAAK;gCACL6B,OAAM;gCACNxD,OAAOuC,MAAM9B,GAAG;gCAChBiD,aAAY;gCACZY,UAAUpE;gCACVD,UAAU,CAAC8D,IAAM3B,uBAAuBG,MAAM5B,EAAE,EAAE,OAAOoD,EAAEC,MAAM,CAAChE,KAAK;gCACvEuE,OAAOpD,cAAcqD,GAAG,CAACjC,MAAM9B,GAAG;gCAClCgE,IAAI;oCAAEC,UAAU;gCAAI;;0CAEtB,KAACpF;gCACCqC,MAAK;gCACL6B,OAAM;gCACNxD,OAAOuC,MAAMvC,KAAK;gCAClB0D,aAAY;gCACZY,UAAUpE;gCACVD,UAAU,CAAC8D,IAAM3B,uBAAuBG,MAAM5B,EAAE,EAAE,SAASoD,EAAEC,MAAM,CAAChE,KAAK;gCACzEyE,IAAI;oCAAEC,UAAU;oCAAKC,UAAU;gCAAE;;4BAElC,CAACzE,4BACA,KAACb;gCAAWuF,SAAS,IAAMnC,iBAAiBF,MAAM5B,EAAE;0CAClD,cAAA,KAAClB;;;uBAtBG8C,MAAM5B,EAAE;;YA6BvBe,+BACC,KAACnC;gBAAW8D,SAAQ;gBAAQwB,OAAM;gBAAQvB,IAAI;0BAAG;;YAIlDlD,QAAQ6B,MAAM,KAAK,mBAClB,KAAC1C;gBAAW8D,SAAQ;gBAAQwB,OAAM;0BAAgB;;YAKnD,CAAC3E,4BACA,KAACb;gBAAWuF,SAASpC;0BACnB,cAAA,KAAC9C;;;;AAKX"}
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/PrometheusDatasourceEditor.tsx"],"sourcesContent":["// Copyright 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 { Box, IconButton, TextField, Typography } from '@mui/material';\nimport { QueryParamValues } from '@perses-dev/components';\nimport { HTTPSettingsEditor } from '@perses-dev/plugin-system';\nimport MinusIcon from 'mdi-material-ui/Minus';\nimport PlusIcon from 'mdi-material-ui/Plus';\nimport { ReactElement, useRef, useState } from 'react';\nimport { DurationString } from '@perses-dev/spec';\nimport { DEFAULT_SCRAPE_INTERVAL, PrometheusDatasourceSpec } from './types';\n\ninterface QueryParamEntry {\n // Unique identifier for the entry, added to avoid using array index as key\n id: string;\n key: string;\n value: string;\n}\n\nexport interface PrometheusDatasourceEditorProps {\n value: PrometheusDatasourceSpec;\n onChange: (next: PrometheusDatasourceSpec) => void;\n isReadonly?: boolean;\n}\n\nexport function PrometheusDatasourceEditor(props: PrometheusDatasourceEditorProps): ReactElement {\n const { value, onChange, isReadonly } = props;\n\n // Counter for generating unique IDs\n const nextIdRef = useRef(0);\n\n // Use local state to maintain an array of entries during editing, instead of\n // manipulating a map directly which causes weird UX.\n const [entries, setEntries] = useState<QueryParamEntry[]>(() => {\n const queryParams: QueryParamValues = value.queryParams ?? {};\n return Object.entries(queryParams).map(([key, val]) => ({\n id: String(nextIdRef.current++),\n key,\n value: Array.isArray(val) ? val.join(',') : val,\n }));\n });\n\n // Check for duplicate keys\n const keyMap = new Map<string, number>();\n const duplicateKeys = new Set<string>();\n entries.forEach(({ key }) => {\n if (key !== '') {\n const count = (keyMap.get(key) || 0) + 1;\n keyMap.set(key, count);\n if (count > 1) {\n duplicateKeys.add(key);\n }\n }\n });\n const hasDuplicates = duplicateKeys.size > 0;\n\n // Convert entries array to object and trigger onChange.\n // Values containing commas are stored as arrays to preserve the round-trip\n // with the load-time join(',') in useState above.\n const syncToParent = (newEntries: QueryParamEntry[]): void => {\n const newParams: Record<string, string | string[]> = {};\n newEntries.forEach(({ key, value }) => {\n if (key !== '') {\n const parts = value.split(',');\n newParams[key] = parts.length > 1 ? parts : value;\n }\n });\n\n onChange({\n ...value,\n queryParams: Object.keys(newParams).length > 0 ? newParams : undefined,\n });\n };\n\n const handleQueryParamChange = (id: string, field: 'key' | 'value', newValue: string): void => {\n const newEntries = entries.map((entry) => {\n if (entry.id !== id) return entry;\n return field === 'key' ? { ...entry, key: newValue } : { ...entry, value: newValue };\n });\n setEntries(newEntries);\n syncToParent(newEntries);\n };\n\n const addQueryParam = (): void => {\n const newEntries = [...entries, { id: String(nextIdRef.current++), key: '', value: '' }];\n setEntries(newEntries);\n syncToParent(newEntries);\n };\n\n const removeQueryParam = (id: string): void => {\n const newEntries = entries.filter((entry) => entry.id !== id);\n setEntries(newEntries);\n syncToParent(newEntries);\n };\n\n const initialSpecDirect: PrometheusDatasourceSpec = {\n directUrl: '',\n };\n\n const initialSpecProxy: PrometheusDatasourceSpec = {\n proxy: {\n kind: 'HTTPProxy',\n spec: {\n allowedEndpoints: [\n // list of standard endpoints suggested by default\n {\n endpointPattern: '/api/v1/labels',\n method: 'POST',\n },\n {\n endpointPattern: '/api/v1/series',\n method: 'POST',\n },\n {\n endpointPattern: '/api/v1/metadata',\n method: 'GET',\n },\n {\n endpointPattern: '/api/v1/query',\n method: 'POST',\n },\n {\n endpointPattern: '/api/v1/query_range',\n method: 'POST',\n },\n {\n endpointPattern: '/api/v1/label/([a-zA-Z0-9_-]+)/values',\n method: 'GET',\n },\n {\n endpointPattern: '/api/v1/parse_query',\n method: 'POST',\n },\n ],\n url: '',\n },\n },\n };\n\n return (\n <>\n <Typography variant=\"h4\" mb={2}>\n General Settings\n </Typography>\n <TextField\n size=\"small\"\n fullWidth\n label=\"Scrape Interval\"\n value={value.scrapeInterval || ''}\n placeholder={`Default: ${DEFAULT_SCRAPE_INTERVAL}`}\n InputProps={{\n readOnly: isReadonly,\n }}\n InputLabelProps={{ shrink: isReadonly ? true : undefined }}\n onChange={(e) => onChange({ ...value, scrapeInterval: e.target.value as DurationString })}\n helperText=\"Set it to match the typical scrape interval used in your Prometheus instance.\"\n />\n <HTTPSettingsEditor\n value={value}\n onChange={onChange}\n isReadonly={isReadonly}\n initialSpecDirect={initialSpecDirect}\n initialSpecProxy={initialSpecProxy}\n />\n <Typography variant=\"h5\" mt={2} mb={1}>\n Query Parameters\n </Typography>\n {entries.length > 0 && (\n <>\n {entries.map((entry) => (\n <Box key={entry.id} display=\"flex\" alignItems=\"center\" gap={2} mb={1}>\n <TextField\n size=\"small\"\n label=\"Key\"\n value={entry.key}\n placeholder=\"Parameter name\"\n disabled={isReadonly}\n onChange={(e) => handleQueryParamChange(entry.id, 'key', e.target.value)}\n error={duplicateKeys.has(entry.key)}\n sx={{ minWidth: 150 }}\n />\n <TextField\n size=\"small\"\n label=\"Value\"\n value={entry.value}\n placeholder=\"Parameter value\"\n disabled={isReadonly}\n onChange={(e) => handleQueryParamChange(entry.id, 'value', e.target.value)}\n sx={{ minWidth: 150, flexGrow: 1 }}\n />\n {!isReadonly && (\n <IconButton onClick={() => removeQueryParam(entry.id)}>\n <MinusIcon />\n </IconButton>\n )}\n </Box>\n ))}\n </>\n )}\n {hasDuplicates && (\n <Typography variant=\"body2\" color=\"error\" mb={1}>\n Duplicate parameter keys detected. Each key must be unique.\n </Typography>\n )}\n {entries.length === 0 && (\n <Typography variant=\"body2\" color=\"textSecondary\">\n No query parameters configured. Use query parameters to pass additional options to Prometheus (e.g.,\n dedup=false for Thanos).\n </Typography>\n )}\n {!isReadonly && (\n <IconButton onClick={addQueryParam}>\n <PlusIcon />\n </IconButton>\n )}\n </>\n );\n}\n"],"names":["Box","IconButton","TextField","Typography","HTTPSettingsEditor","MinusIcon","PlusIcon","useRef","useState","DEFAULT_SCRAPE_INTERVAL","PrometheusDatasourceEditor","props","value","onChange","isReadonly","nextIdRef","entries","setEntries","queryParams","Object","map","key","val","id","String","current","Array","isArray","join","keyMap","Map","duplicateKeys","Set","forEach","count","get","set","add","hasDuplicates","size","syncToParent","newEntries","newParams","parts","split","length","keys","undefined","handleQueryParamChange","field","newValue","entry","addQueryParam","removeQueryParam","filter","initialSpecDirect","directUrl","initialSpecProxy","proxy","kind","spec","allowedEndpoints","endpointPattern","method","url","variant","mb","fullWidth","label","scrapeInterval","placeholder","InputProps","readOnly","InputLabelProps","shrink","e","target","helperText","mt","display","alignItems","gap","disabled","error","has","sx","minWidth","flexGrow","onClick","color"],"mappings":";AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,GAAG,EAAEC,UAAU,EAAEC,SAAS,EAAEC,UAAU,QAAQ,gBAAgB;AAEvE,SAASC,kBAAkB,QAAQ,4BAA4B;AAC/D,OAAOC,eAAe,wBAAwB;AAC9C,OAAOC,cAAc,uBAAuB;AAC5C,SAAuBC,MAAM,EAAEC,QAAQ,QAAQ,QAAQ;AAEvD,SAASC,uBAAuB,QAAkC,UAAU;AAe5E,OAAO,SAASC,2BAA2BC,KAAsC;IAC/E,MAAM,EAAEC,KAAK,EAAEC,QAAQ,EAAEC,UAAU,EAAE,GAAGH;IAExC,oCAAoC;IACpC,MAAMI,YAAYR,OAAO;IAEzB,6EAA6E;IAC7E,qDAAqD;IACrD,MAAM,CAACS,SAASC,WAAW,GAAGT,SAA4B;QACxD,MAAMU,cAAgCN,MAAMM,WAAW,IAAI,CAAC;QAC5D,OAAOC,OAAOH,OAAO,CAACE,aAAaE,GAAG,CAAC,CAAC,CAACC,KAAKC,IAAI,GAAM,CAAA;gBACtDC,IAAIC,OAAOT,UAAUU,OAAO;gBAC5BJ;gBACAT,OAAOc,MAAMC,O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/plugins/PrometheusLabelValuesVariable.tsx"],"names":[],"mappings":"AAaA,OAAO,EACL,cAAc,
|
|
1
|
+
{"version":3,"file":"PrometheusLabelValuesVariable.d.ts","sourceRoot":"","sources":["../../../src/plugins/PrometheusLabelValuesVariable.tsx"],"names":[],"mappings":"AAaA,OAAO,EACL,cAAc,EAOf,MAAM,2BAA2B,CAAC;AAKnC,OAAO,EAAE,oCAAoC,EAA4B,MAAM,SAAS,CAAC;AAuEzF,eAAO,MAAM,6BAA6B,EAAE,cAAc,CAAC,oCAAoC,CA2D9F,CAAC"}
|
|
@@ -14,6 +14,60 @@ import { replaceVariables, parseVariables, datasourceSelectValueToSelector, isVa
|
|
|
14
14
|
import { DEFAULT_PROM, getPrometheusTimeRange, PROM_DATASOURCE_KIND } from '../model';
|
|
15
15
|
import { stringArrayToVariableOptions, PrometheusLabelValuesVariableEditor } from './prometheus-variables';
|
|
16
16
|
import { resolvePrometheusDatasource } from './interpolation';
|
|
17
|
+
function extractDatasourceVariables(datasourceSpec) {
|
|
18
|
+
try {
|
|
19
|
+
const spec = datasourceSpec.plugin.spec;
|
|
20
|
+
// Pure function to extract variables from string or array values
|
|
21
|
+
const extractFromValue = (value)=>{
|
|
22
|
+
if (typeof value === 'string') {
|
|
23
|
+
return parseVariables(value);
|
|
24
|
+
} else if (Array.isArray(value)) {
|
|
25
|
+
return value.flatMap((item)=>{
|
|
26
|
+
return typeof item === 'string' ? parseVariables(item) : [];
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
return [];
|
|
30
|
+
};
|
|
31
|
+
const allVariables = [];
|
|
32
|
+
// Extract variables from queryParams
|
|
33
|
+
if (spec.queryParams) {
|
|
34
|
+
Object.values(spec.queryParams).forEach((value)=>{
|
|
35
|
+
allVariables.push(...extractFromValue(value));
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
// Extract variables from directUrl
|
|
39
|
+
if (spec.directUrl) {
|
|
40
|
+
allVariables.push(...extractFromValue(spec.directUrl));
|
|
41
|
+
}
|
|
42
|
+
// Extract variables from proxy configuration
|
|
43
|
+
if (spec.proxy?.spec) {
|
|
44
|
+
// Extract from proxy URL
|
|
45
|
+
if (spec.proxy.spec.url) {
|
|
46
|
+
allVariables.push(...extractFromValue(spec.proxy.spec.url));
|
|
47
|
+
}
|
|
48
|
+
// Extract from proxy headers
|
|
49
|
+
if (spec.proxy.spec.headers) {
|
|
50
|
+
Object.values(spec.proxy.spec.headers).forEach((value)=>{
|
|
51
|
+
if (typeof value === 'string') {
|
|
52
|
+
allVariables.push(...extractFromValue(value));
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return Array.from(new Set(allVariables)); // Remove duplicates
|
|
58
|
+
} catch {
|
|
59
|
+
return [];
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function getDatasourceVariablesFromCache(datasourceSelector, datasourceStore) {
|
|
63
|
+
try {
|
|
64
|
+
if (!datasourceStore.getDatasourceSpecSync) return [];
|
|
65
|
+
const datasourceSpec = datasourceStore.getDatasourceSpecSync(datasourceSelector);
|
|
66
|
+
return datasourceSpec ? extractDatasourceVariables(datasourceSpec) : [];
|
|
67
|
+
} catch {
|
|
68
|
+
return [];
|
|
69
|
+
}
|
|
70
|
+
}
|
|
17
71
|
export const PrometheusLabelValuesVariable = {
|
|
18
72
|
getVariableOptions: async (spec, ctx)=>{
|
|
19
73
|
const pluginDef = spec;
|
|
@@ -30,16 +84,28 @@ export const PrometheusLabelValuesVariable = {
|
|
|
30
84
|
data: stringArrayToVariableOptions(options)
|
|
31
85
|
};
|
|
32
86
|
},
|
|
33
|
-
dependsOn: (spec)=>{
|
|
87
|
+
dependsOn: (spec, ctx)=>{
|
|
34
88
|
const matcherVariables = spec.matchers?.map((m)=>parseVariables(m)).flat() || [];
|
|
35
89
|
const labelVariables = parseVariables(spec.labelName);
|
|
36
90
|
const datasourceVariables = spec.datasource && isVariableDatasource(spec.datasource) ? parseVariables(spec.datasource) : [];
|
|
91
|
+
let datasourceVariablesFromCache = [];
|
|
92
|
+
if (ctx?.datasourceStore && ctx?.variables) {
|
|
93
|
+
const datasourceValue = spec.datasource ?? DEFAULT_PROM;
|
|
94
|
+
const datasourceSelector = typeof datasourceValue === 'string' ? {
|
|
95
|
+
kind: PROM_DATASOURCE_KIND,
|
|
96
|
+
name: datasourceValue
|
|
97
|
+
} : datasourceValue;
|
|
98
|
+
datasourceVariablesFromCache = getDatasourceVariablesFromCache(datasourceSelector, ctx.datasourceStore);
|
|
99
|
+
}
|
|
100
|
+
const allDependencies = [
|
|
101
|
+
...matcherVariables,
|
|
102
|
+
...labelVariables,
|
|
103
|
+
...datasourceVariables,
|
|
104
|
+
...datasourceVariablesFromCache
|
|
105
|
+
];
|
|
106
|
+
const uniqueDependencies = Array.from(new Set(allDependencies));
|
|
37
107
|
return {
|
|
38
|
-
variables:
|
|
39
|
-
...matcherVariables,
|
|
40
|
-
...labelVariables,
|
|
41
|
-
...datasourceVariables
|
|
42
|
-
]
|
|
108
|
+
variables: uniqueDependencies
|
|
43
109
|
};
|
|
44
110
|
},
|
|
45
111
|
OptionsEditorComponent: PrometheusLabelValuesVariableEditor,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/plugins/PrometheusLabelValuesVariable.tsx"],"sourcesContent":["// Copyright 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 {\n VariablePlugin,\n GetVariableOptionsContext,\n replaceVariables,\n parseVariables,\n datasourceSelectValueToSelector,\n isVariableDatasource,\n} from '@perses-dev/plugin-system';\nimport { DEFAULT_PROM, getPrometheusTimeRange, PROM_DATASOURCE_KIND } from '../model';\nimport { stringArrayToVariableOptions, PrometheusLabelValuesVariableEditor } from './prometheus-variables';\nimport { resolvePrometheusDatasource } from './interpolation';\nimport { PrometheusLabelValuesVariableOptions } from './types';\n\nexport const PrometheusLabelValuesVariable: VariablePlugin<PrometheusLabelValuesVariableOptions> = {\n getVariableOptions: async (spec: PrometheusLabelValuesVariableOptions, ctx: GetVariableOptionsContext) => {\n const pluginDef = spec;\n const datasourceSelector =\n datasourceSelectValueToSelector(\n spec.datasource ?? DEFAULT_PROM,\n ctx.variables,\n await ctx.datasourceStore.listDatasourceSelectItems(PROM_DATASOURCE_KIND)\n ) ?? DEFAULT_PROM;\n const { client, requestOptions } = await resolvePrometheusDatasource(\n ctx.datasourceStore,\n datasourceSelector,\n ctx.variables\n );\n const match = pluginDef.matchers ? pluginDef.matchers.map((m) => replaceVariables(m, ctx.variables)) : undefined;\n\n const timeRange = getPrometheusTimeRange(ctx.timeRange);\n\n const { data: options } = await client.labelValues(\n {\n labelName: replaceVariables(pluginDef.labelName, ctx.variables),\n 'match[]': match,\n ...timeRange,\n },\n requestOptions\n );\n return {\n data: stringArrayToVariableOptions(options),\n };\n },\n dependsOn: (spec: PrometheusLabelValuesVariableOptions) => {\n const matcherVariables = spec.matchers?.map((m) => parseVariables(m)).flat() || [];\n const labelVariables = parseVariables(spec.labelName);\n const datasourceVariables =\n spec.datasource && isVariableDatasource(spec.datasource) ? parseVariables(spec.datasource) : [];\n
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/PrometheusLabelValuesVariable.tsx"],"sourcesContent":["// Copyright 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 {\n VariablePlugin,\n GetVariableOptionsContext,\n replaceVariables,\n parseVariables,\n datasourceSelectValueToSelector,\n isVariableDatasource,\n DatasourceStore,\n} from '@perses-dev/plugin-system';\nimport { DatasourceSelector, DatasourceSpec } from '@perses-dev/spec';\nimport { DEFAULT_PROM, getPrometheusTimeRange, PROM_DATASOURCE_KIND } from '../model';\nimport { stringArrayToVariableOptions, PrometheusLabelValuesVariableEditor } from './prometheus-variables';\nimport { resolvePrometheusDatasource } from './interpolation';\nimport { PrometheusLabelValuesVariableOptions, PrometheusDatasourceSpec } from './types';\n\nfunction extractDatasourceVariables(datasourceSpec: DatasourceSpec<PrometheusDatasourceSpec>): string[] {\n try {\n const spec = datasourceSpec.plugin.spec;\n\n // Pure function to extract variables from string or array values\n const extractFromValue = (value: string | string[]): string[] => {\n if (typeof value === 'string') {\n return parseVariables(value);\n } else if (Array.isArray(value)) {\n return value.flatMap((item) => {\n return typeof item === 'string' ? parseVariables(item) : [];\n });\n }\n return [];\n };\n\n const allVariables: string[] = [];\n\n // Extract variables from queryParams\n if (spec.queryParams) {\n Object.values(spec.queryParams).forEach((value) => {\n allVariables.push(...extractFromValue(value));\n });\n }\n\n // Extract variables from directUrl\n if (spec.directUrl) {\n allVariables.push(...extractFromValue(spec.directUrl));\n }\n\n // Extract variables from proxy configuration\n if (spec.proxy?.spec) {\n // Extract from proxy URL\n if (spec.proxy.spec.url) {\n allVariables.push(...extractFromValue(spec.proxy.spec.url));\n }\n\n // Extract from proxy headers\n if (spec.proxy.spec.headers) {\n Object.values(spec.proxy.spec.headers).forEach((value) => {\n if (typeof value === 'string') {\n allVariables.push(...extractFromValue(value));\n }\n });\n }\n }\n\n return Array.from(new Set(allVariables)); // Remove duplicates\n } catch {\n return [];\n }\n}\n\nfunction getDatasourceVariablesFromCache(\n datasourceSelector: DatasourceSelector,\n datasourceStore: DatasourceStore\n): string[] {\n try {\n if (!datasourceStore.getDatasourceSpecSync) return [];\n\n const datasourceSpec = datasourceStore.getDatasourceSpecSync(datasourceSelector) as\n | DatasourceSpec<PrometheusDatasourceSpec>\n | undefined;\n return datasourceSpec ? extractDatasourceVariables(datasourceSpec) : [];\n } catch {\n return [];\n }\n}\n\nexport const PrometheusLabelValuesVariable: VariablePlugin<PrometheusLabelValuesVariableOptions> = {\n getVariableOptions: async (spec: PrometheusLabelValuesVariableOptions, ctx: GetVariableOptionsContext) => {\n const pluginDef = spec;\n const datasourceSelector =\n datasourceSelectValueToSelector(\n spec.datasource ?? DEFAULT_PROM,\n ctx.variables,\n await ctx.datasourceStore.listDatasourceSelectItems(PROM_DATASOURCE_KIND)\n ) ?? DEFAULT_PROM;\n\n const { client, requestOptions } = await resolvePrometheusDatasource(\n ctx.datasourceStore,\n datasourceSelector,\n ctx.variables\n );\n const match = pluginDef.matchers ? pluginDef.matchers.map((m) => replaceVariables(m, ctx.variables)) : undefined;\n\n const timeRange = getPrometheusTimeRange(ctx.timeRange);\n\n const { data: options } = await client.labelValues(\n {\n labelName: replaceVariables(pluginDef.labelName, ctx.variables),\n 'match[]': match,\n ...timeRange,\n },\n requestOptions\n );\n return {\n data: stringArrayToVariableOptions(options),\n };\n },\n dependsOn: (spec: PrometheusLabelValuesVariableOptions, ctx?: GetVariableOptionsContext) => {\n const matcherVariables = spec.matchers?.map((m) => parseVariables(m)).flat() || [];\n const labelVariables = parseVariables(spec.labelName);\n const datasourceVariables =\n spec.datasource && isVariableDatasource(spec.datasource) ? parseVariables(spec.datasource) : [];\n\n let datasourceVariablesFromCache: string[] = [];\n if (ctx?.datasourceStore && ctx?.variables) {\n const datasourceValue = spec.datasource ?? DEFAULT_PROM;\n const datasourceSelector: DatasourceSelector =\n typeof datasourceValue === 'string' ? { kind: PROM_DATASOURCE_KIND, name: datasourceValue } : datasourceValue;\n datasourceVariablesFromCache = getDatasourceVariablesFromCache(datasourceSelector, ctx.datasourceStore);\n }\n\n const allDependencies = [\n ...matcherVariables,\n ...labelVariables,\n ...datasourceVariables,\n ...datasourceVariablesFromCache,\n ];\n const uniqueDependencies = Array.from(new Set(allDependencies));\n\n return {\n variables: uniqueDependencies,\n };\n },\n OptionsEditorComponent: PrometheusLabelValuesVariableEditor,\n createInitialOptions: () => ({ labelName: '' }),\n};\n"],"names":["replaceVariables","parseVariables","datasourceSelectValueToSelector","isVariableDatasource","DEFAULT_PROM","getPrometheusTimeRange","PROM_DATASOURCE_KIND","stringArrayToVariableOptions","PrometheusLabelValuesVariableEditor","resolvePrometheusDatasource","extractDatasourceVariables","datasourceSpec","spec","plugin","extractFromValue","value","Array","isArray","flatMap","item","allVariables","queryParams","Object","values","forEach","push","directUrl","proxy","url","headers","from","Set","getDatasourceVariablesFromCache","datasourceSelector","datasourceStore","getDatasourceSpecSync","PrometheusLabelValuesVariable","getVariableOptions","ctx","pluginDef","datasource","variables","listDatasourceSelectItems","client","requestOptions","match","matchers","map","m","undefined","timeRange","data","options","labelValues","labelName","dependsOn","matcherVariables","flat","labelVariables","datasourceVariables","datasourceVariablesFromCache","datasourceValue","kind","name","allDependencies","uniqueDependencies","OptionsEditorComponent","createInitialOptions"],"mappings":"AAAA,+BAA+B;AAC/B,oEAAoE;AACpE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,sEAAsE;AACtE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAGEA,gBAAgB,EAChBC,cAAc,EACdC,+BAA+B,EAC/BC,oBAAoB,QAEf,4BAA4B;AAEnC,SAASC,YAAY,EAAEC,sBAAsB,EAAEC,oBAAoB,QAAQ,WAAW;AACtF,SAASC,4BAA4B,EAAEC,mCAAmC,QAAQ,yBAAyB;AAC3G,SAASC,2BAA2B,QAAQ,kBAAkB;AAG9D,SAASC,2BAA2BC,cAAwD;IAC1F,IAAI;QACF,MAAMC,OAAOD,eAAeE,MAAM,CAACD,IAAI;QAEvC,iEAAiE;QACjE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W;YAC1C,MAAMoB,kBAAkBjD,KAAK4B,UAAU,IAAIpC;YAC3C,MAAM6B,qBACJ,OAAO4B,oBAAoB,WAAW;gBAAEC,MAAMxD;gBAAsByD,MAAMF;YAAgB,IAAIA;YAChGD,+BAA+B5B,gCAAgCC,oBAAoBK,IAAIJ,eAAe;QACxG;QAEA,MAAM8B,kBAAkB;eACnBR;eACAE;eACAC;eACAC;SACJ;QACD,MAAMK,qBAAqBjD,MAAMc,IAAI,CAAC,IAAIC,IAAIiC;QAE9C,OAAO;YACLvB,WAAWwB;QACb;IACF;IACAC,wBAAwB1D;IACxB2D,sBAAsB,IAAO,CAAA;YAAEb,WAAW;QAAG,CAAA;AAC/C,EAAE"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { DatasourceSelector, DatasourceSpec } from '@perses-dev/core';
|
|
2
1
|
import { VariableStateMap } from '@perses-dev/components';
|
|
3
2
|
import { DatasourceStore } from '@perses-dev/plugin-system';
|
|
3
|
+
import { DatasourceSelector, DatasourceSpec } from '@perses-dev/spec';
|
|
4
4
|
import { ClientRequestOptions, PrometheusClient } from '../model';
|
|
5
5
|
import { PrometheusDatasourceSpec } from './types';
|
|
6
6
|
export interface ResolvedPrometheusDatasource {
|
|
@@ -9,4 +9,5 @@ export interface ResolvedPrometheusDatasource {
|
|
|
9
9
|
}
|
|
10
10
|
export declare function resolvePrometheusDatasource(datasourceStore: DatasourceStore, selector: DatasourceSelector, variableState: VariableStateMap): Promise<ResolvedPrometheusDatasource>;
|
|
11
11
|
export declare function interpolateDatasourceProxyParams(datasource: DatasourceSpec<PrometheusDatasourceSpec>, variableState: VariableStateMap): ClientRequestOptions;
|
|
12
|
+
export declare function getInterpolatedRequestOptions(datasourceStore: DatasourceStore, datasource: DatasourceSelector, variableState: VariableStateMap): Promise<ClientRequestOptions>;
|
|
12
13
|
//# sourceMappingURL=interpolation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interpolation.d.ts","sourceRoot":"","sources":["../../../src/plugins/interpolation.ts"],"names":[],"mappings":"AAaA,OAAO,
|
|
1
|
+
{"version":3,"file":"interpolation.d.ts","sourceRoot":"","sources":["../../../src/plugins/interpolation.ts"],"names":[],"mappings":"AAaA,OAAO,EAA8C,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AACtG,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAClE,OAAO,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAEnD,MAAM,WAAW,4BAA4B;IAC3C,MAAM,EAAE,gBAAgB,CAAC;IACzB,cAAc,EAAE,oBAAoB,CAAC;CACtC;AAED,wBAAsB,2BAA2B,CAC/C,eAAe,EAAE,eAAe,EAChC,QAAQ,EAAE,kBAAkB,EAC5B,aAAa,EAAE,gBAAgB,GAC9B,OAAO,CAAC,4BAA4B,CAAC,CAOvC;AAED,wBAAgB,gCAAgC,CAC9C,UAAU,EAAE,cAAc,CAAC,wBAAwB,CAAC,EACpD,aAAa,EAAE,gBAAgB,GAC9B,oBAAoB,CAStB;AAED,wBAAsB,6BAA6B,CACjD,eAAe,EAAE,eAAe,EAChC,UAAU,EAAE,kBAAkB,EAC9B,aAAa,EAAE,gBAAgB,GAC9B,OAAO,CAAC,oBAAoB,CAAC,CAG/B"}
|
|
@@ -34,5 +34,9 @@ export function interpolateDatasourceProxyParams(datasource, variableState) {
|
|
|
34
34
|
queryParams: rawQueryParams ? interpolateQueryParams(rawQueryParams, variableState) : undefined
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
|
+
export async function getInterpolatedRequestOptions(datasourceStore, datasource, variableState) {
|
|
38
|
+
const datasourceSpec = await datasourceStore.getDatasource(datasource);
|
|
39
|
+
return interpolateDatasourceProxyParams(datasourceSpec, variableState);
|
|
40
|
+
}
|
|
37
41
|
|
|
38
42
|
//# sourceMappingURL=interpolation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/plugins/interpolation.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/interpolation.ts"],"sourcesContent":["// Copyright 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 { interpolateHeaders, interpolateQueryParams, VariableStateMap } from '@perses-dev/components';\nimport { DatasourceStore } from '@perses-dev/plugin-system';\nimport { DatasourceSelector, DatasourceSpec } from '@perses-dev/spec';\nimport { ClientRequestOptions, PrometheusClient } from '../model';\nimport { PrometheusDatasourceSpec } from './types';\n\nexport interface ResolvedPrometheusDatasource {\n client: PrometheusClient;\n requestOptions: ClientRequestOptions;\n}\n\nexport async function resolvePrometheusDatasource(\n datasourceStore: DatasourceStore,\n selector: DatasourceSelector,\n variableState: VariableStateMap\n): Promise<ResolvedPrometheusDatasource> {\n const [client, datasource] = await Promise.all([\n datasourceStore.getDatasourceClient<PrometheusClient>(selector),\n datasourceStore.getDatasource(selector) as Promise<DatasourceSpec<PrometheusDatasourceSpec>>,\n ]);\n const { headers, queryParams } = interpolateDatasourceProxyParams(datasource, variableState);\n return { client, requestOptions: { headers, queryParams } };\n}\n\nexport function interpolateDatasourceProxyParams(\n datasource: DatasourceSpec<PrometheusDatasourceSpec>,\n variableState: VariableStateMap\n): ClientRequestOptions {\n const spec = datasource.plugin.spec;\n const rawHeaders = spec.proxy?.spec?.headers;\n const rawQueryParams = spec.queryParams;\n\n return {\n headers: rawHeaders ? interpolateHeaders(rawHeaders, variableState) : undefined,\n queryParams: rawQueryParams ? interpolateQueryParams(rawQueryParams, variableState) : undefined,\n };\n}\n\nexport async function getInterpolatedRequestOptions(\n datasourceStore: DatasourceStore,\n datasource: DatasourceSelector,\n variableState: VariableStateMap\n): Promise<ClientRequestOptions> {\n const datasourceSpec = (await datasourceStore.getDatasource(datasource)) as DatasourceSpec<PrometheusDatasourceSpec>;\n return interpolateDatasourceProxyParams(datasourceSpec, variableState);\n}\n"],"names":["interpolateHeaders","interpolateQueryParams","resolvePrometheusDatasource","datasourceStore","selector","variableState","client","datasource","Promise","all","getDatasourceClient","getDatasource","headers","queryParams","interpolateDatasourceProxyParams","requestOptions","spec","plugin","rawHeaders","proxy","rawQueryParams","undefined","getInterpolatedRequestOptions","datasourceSpec"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,kBAAkB,EAAEC,sBAAsB,QAA0B,yBAAyB;AAWtG,OAAO,eAAeC,4BACpBC,eAAgC,EAChCC,QAA4B,EAC5BC,aAA+B;IAE/B,MAAM,CAACC,QAAQC,WAAW,GAAG,MAAMC,QAAQC,GAAG,CAAC;QAC7CN,gBAAgBO,mBAAmB,CAAmBN;QACtDD,gBAAgBQ,aAAa,CAACP;KAC/B;IACD,MAAM,EAAEQ,OAAO,EAAEC,WAAW,EAAE,GAAGC,iCAAiCP,YAAYF;IAC9E,OAAO;QAAEC;QAAQS,gBAAgB;YAAEH;YAASC;QAAY;IAAE;AAC5D;AAEA,OAAO,SAASC,iCACdP,UAAoD,EACpDF,aAA+B;IAE/B,MAAMW,OAAOT,WAAWU,MAAM,CAACD,IAAI;IACnC,MAAME,aAAaF,KAAKG,KAAK,EAAEH,MAAMJ;IACrC,MAAMQ,iBAAiBJ,KAAKH,WAAW;IAEvC,OAAO;QACLD,SAASM,aAAalB,mBAAmBkB,YAAYb,iBAAiBgB;QACtER,aAAaO,iBAAiBnB,uBAAuBmB,gBAAgBf,iBAAiBgB;IACxF;AACF;AAEA,OAAO,eAAeC,8BACpBnB,eAAgC,EAChCI,UAA8B,EAC9BF,aAA+B;IAE/B,MAAMkB,iBAAkB,MAAMpB,gBAAgBQ,aAAa,CAACJ;IAC5D,OAAOO,iCAAiCS,gBAAgBlB;AAC1D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prometheus-datasource.d.ts","sourceRoot":"","sources":["../../../src/plugins/prometheus-datasource.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"prometheus-datasource.d.ts","sourceRoot":"","sources":["../../../src/plugins/prometheus-datasource.tsx"],"names":[],"mappings":"AAcA,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAG7D,OAAO,EASL,gBAAgB,EAIjB,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AA8FnD,eAAO,MAAM,oBAAoB,EAAE,gBAAgB,CAAC,wBAAwB,EAAE,gBAAgB,CAK7F,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/plugins/prometheus-datasource.tsx"],"sourcesContent":["// Copyright 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 { QueryParamValues } from '@perses-dev/components';\nimport { BuiltinVariableDefinition
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/prometheus-datasource.tsx"],"sourcesContent":["// Copyright 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 { QueryParamValues } from '@perses-dev/components';\nimport { DatasourcePlugin } from '@perses-dev/plugin-system';\nimport { BuiltinVariableDefinition } from '@perses-dev/spec';\nimport { RequestHeaders } from '@perses-dev/client';\nimport {\n ClientRequestOptions,\n healthCheck,\n instantQuery,\n labelNames,\n labelValues,\n mergeQueryParams,\n metricMetadata,\n parseQuery,\n PrometheusClient,\n QueryOptions,\n rangeQuery,\n series,\n} from '../model';\nimport { PrometheusDatasourceEditor } from './PrometheusDatasourceEditor';\nimport { PrometheusDatasourceSpec } from './types';\n\nfunction wrapClientMethod<P, R>(\n fn: (params: P, opts: QueryOptions) => Promise<R>,\n datasourceUrl: string,\n specHeaders?: RequestHeaders,\n specQueryParams?: QueryParamValues\n): (params: P, options?: ClientRequestOptions) => Promise<R> {\n return (params: P, options?: ClientRequestOptions) =>\n fn(params, {\n datasourceUrl,\n headers: options?.headers ?? specHeaders,\n signal: options?.signal,\n queryParams: mergeQueryParams(specQueryParams, options?.queryParams),\n });\n}\n\n/**\n * Creates a PrometheusClient for a specific datasource spec.\n */\nconst createClient: DatasourcePlugin<PrometheusDatasourceSpec, PrometheusClient>['createClient'] = (spec, options) => {\n const { directUrl, proxy, queryParams } = spec;\n const { proxyUrl } = options;\n\n // Use the direct URL if specified, but fallback to the proxyUrl by default if not specified\n const datasourceUrl = directUrl ?? proxyUrl;\n if (datasourceUrl === undefined) {\n throw new Error('No URL specified for Prometheus client. You can use directUrl in the spec to configure it.');\n }\n\n const specHeaders = proxy?.spec.headers;\n\n // Could think about this becoming a class, although it definitely doesn't have to be\n return {\n options: {\n datasourceUrl,\n },\n healthCheck: healthCheck({ datasourceUrl, headers: specHeaders, queryParams }),\n instantQuery: wrapClientMethod(instantQuery, datasourceUrl, specHeaders, queryParams),\n rangeQuery: wrapClientMethod(rangeQuery, datasourceUrl, specHeaders, queryParams),\n labelNames: wrapClientMethod(labelNames, datasourceUrl, specHeaders, queryParams),\n labelValues: wrapClientMethod(labelValues, datasourceUrl, specHeaders, queryParams),\n metricMetadata: wrapClientMethod(metricMetadata, datasourceUrl, specHeaders, queryParams),\n series: wrapClientMethod(series, datasourceUrl, specHeaders, queryParams),\n parseQuery: wrapClientMethod(parseQuery, datasourceUrl, specHeaders, queryParams),\n };\n};\n\nconst getBuiltinVariableDefinitions: () => BuiltinVariableDefinition[] = () => {\n return [\n {\n kind: 'BuiltinVariable',\n spec: {\n name: '__interval',\n value: () => '$__interval', // will be overriden when time series query is called\n source: 'Prometheus',\n display: {\n name: '__interval',\n description:\n 'For dynamic queries that adapt across different time ranges, use $__interval instead of hardcoded intervals. It represents the actual spacing between data points: it’s calculated based on the current time range and the panel pixel width (taking the \"Min step\" as a lower bound).',\n hidden: true,\n },\n },\n },\n {\n kind: 'BuiltinVariable',\n spec: {\n name: '__interval_ms',\n value: () => '$__interval_ms', // will be overriden when time series query is called\n source: 'Prometheus',\n display: {\n name: '__interval_ms',\n description: 'Same as $__interval but in milliseconds.',\n hidden: true,\n },\n },\n },\n {\n kind: 'BuiltinVariable',\n spec: {\n name: '__rate_interval',\n value: () => '$__rate_interval', // will be overriden when time series query is called\n source: 'Prometheus',\n display: {\n name: '__rate_interval',\n description:\n 'Use this one rather than $__interval as the range parameter of functions like rate, increase, etc. With such function it is advised to choose a range that is at least 4x the scrape interval (this is to allow for various races, and to be resilient to a failed scrape). $__rate_interval provides that, as it is defined as `max($__interval + Min Step, 4 * Min Step)`, where Min Step value should represent the scrape interval of the metrics.',\n hidden: true,\n },\n },\n },\n ] as BuiltinVariableDefinition[];\n};\n\nexport const PrometheusDatasource: DatasourcePlugin<PrometheusDatasourceSpec, PrometheusClient> = {\n createClient,\n getBuiltinVariableDefinitions,\n OptionsEditorComponent: PrometheusDatasourceEditor,\n createInitialOptions: () => ({ directUrl: '' }),\n};\n"],"names":["healthCheck","instantQuery","labelNames","labelValues","mergeQueryParams","metricMetadata","parseQuery","rangeQuery","series","PrometheusDatasourceEditor","wrapClientMethod","fn","datasourceUrl","specHeaders","specQueryParams","params","options","headers","signal","queryParams","createClient","spec","directUrl","proxy","proxyUrl","undefined","Error","getBuiltinVariableDefinitions","kind","name","value","source","display","description","hidden","PrometheusDatasource","OptionsEditorComponent","createInitialOptions"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAMjC,SAEEA,WAAW,EACXC,YAAY,EACZC,UAAU,EACVC,WAAW,EACXC,gBAAgB,EAChBC,cAAc,EACdC,UAAU,EAGVC,UAAU,EACVC,MAAM,QACD,WAAW;AAClB,SAASC,0BAA0B,QAAQ,+BAA+B;AAG1E,SAASC,iBACPC,EAAiD,EACjDC,aAAqB,EACrBC,WAA4B,EAC5BC,eAAkC;IAElC,OAAO,CAACC,QAAWC,UACjBL,GAAGI,QAAQ;YACTH;YACAK,SAASD,SAASC,WAAWJ;YAC7BK,QAAQF,SAASE;YACjBC,aAAaf,iBAAiBU,iBAAiBE,SAASG;QAC1D;AACJ;A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AAEA,OAAO,MAAMC,uBAAqF;IAChGf;IACAO;IACAS,wBAAwB3B;IACxB4B,sBAAsB,IAAO,CAAA;YAAEf,WAAW;QAAG,CAAA;AAC/C,EAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-time-series-data.d.ts","sourceRoot":"","sources":["../../../../src/plugins/prometheus-time-series-query/get-time-series-data.ts"],"names":[],"mappings":"
|
|
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,EAAE,qBAAqB,EAAqD,MAAM,2BAA2B,CAAC;AA0BrH,OAAO,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAG1E,eAAO,MAAM,iBAAiB,EAAE,qBAAqB,CAAC,6BAA6B,CAAC,CAAC,mBAAmB,CAuHvG,CAAC"}
|
|
@@ -10,9 +10,9 @@
|
|
|
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 { parseDurationString } from '@perses-dev/core';
|
|
14
13
|
import { datasourceSelectValueToSelector, replaceVariables } from '@perses-dev/plugin-system';
|
|
15
14
|
import { fromUnixTime, milliseconds } from 'date-fns';
|
|
15
|
+
import { parseDurationString } from '@perses-dev/spec';
|
|
16
16
|
import { parseValueTuple, getDurationStringSeconds, getPrometheusTimeRange, getRangeStep, DEFAULT_PROM, PROM_DATASOURCE_KIND } from '../../model';
|
|
17
17
|
import { getFormattedPrometheusSeriesName } from '../../utils';
|
|
18
18
|
import { interpolateDatasourceProxyParams } from '../interpolation';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/plugins/prometheus-time-series-query/get-time-series-data.ts"],"sourcesContent":["// Copyright 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 {\n DatasourceSpec,\n DurationString,\n Notice,\n parseDurationString,\n TimeSeries,\n TimeSeriesData,\n} from '@perses-dev/core';\nimport { TimeSeriesQueryPlugin, datasourceSelectValueToSelector, replaceVariables } from '@perses-dev/plugin-system';\nimport { fromUnixTime, milliseconds } from 'date-fns';\nimport {\n parseValueTuple,\n PrometheusClient,\n getDurationStringSeconds,\n getPrometheusTimeRange,\n getRangeStep,\n DEFAULT_PROM,\n MatrixData,\n VectorData,\n ScalarData,\n InstantQueryResultType,\n PROM_DATASOURCE_KIND,\n} from '../../model';\nimport { getFormattedPrometheusSeriesName } from '../../utils';\nimport { interpolateDatasourceProxyParams } from '../interpolation';\nimport { DEFAULT_SCRAPE_INTERVAL, PrometheusDatasourceSpec } from '../types';\nimport { PrometheusTimeSeriesQuerySpec } from './time-series-query-model';\nimport { replacePromBuiltinVariables } from './replace-prom-builtin-variables';\n\nexport const getTimeSeriesData: TimeSeriesQueryPlugin<PrometheusTimeSeriesQuerySpec>['getTimeSeriesData'] = async (\n spec,\n context,\n abortSignal\n) => {\n if (spec.query === undefined || spec.query === null || spec.query === '') {\n // Do not make a request to the backend, instead return an empty TimeSeriesData\n return { series: [] };\n }\n\n const listDatasourceSelectItems = await context.datasourceStore.listDatasourceSelectItems(PROM_DATASOURCE_KIND);\n\n const selectedDatasource =\n datasourceSelectValueToSelector(\n spec.datasource ?? DEFAULT_PROM,\n context.variableState,\n listDatasourceSelectItems\n ) ?? DEFAULT_PROM;\n\n const datasource = (await context.datasourceStore.getDatasource(\n selectedDatasource\n )) as DatasourceSpec<PrometheusDatasourceSpec>;\n const interpolatedOptions = interpolateDatasourceProxyParams(datasource, context.variableState);\n\n const datasourceScrapeInterval = Math.trunc(\n milliseconds(parseDurationString(datasource.plugin.spec.scrapeInterval ?? DEFAULT_SCRAPE_INTERVAL)) / 1000\n );\n\n // Min step is the lower bound of the interval between data points\n // If no value is provided for it, it should default to the scrape interval of the datasource\n const minStep =\n getDurationStringSeconds(\n // resolve any variable that may have been provided\n // TODO add a validation check to make sure the variable is a DurationString, to avoid the back & forth cast here\n replaceVariables(spec.minStep as string, context.variableState) as DurationString\n ) ?? datasourceScrapeInterval;\n\n const timeRange = getPrometheusTimeRange(context.timeRange);\n const step = getRangeStep(timeRange, minStep, undefined, context.suggestedStepMs); // TODO: resolution\n\n // Align the time range so that it's a multiple of the step\n let { start, end } = timeRange;\n\n const utcOffsetSec = new Date().getTimezoneOffset() * 60;\n\n const alignedEnd = Math.floor((end + utcOffsetSec) / step) * step - utcOffsetSec;\n const alignedStart = Math.floor((start + utcOffsetSec) / step) * step - utcOffsetSec;\n start = alignedStart;\n end = alignedEnd;\n\n /* Ensure end is always greater than start:\n If the step is greater than equal to the diff of end and start,\n both start, and end will eventually be rounded to the same value,\n Consequently, the time range will be zero, which does not return any valid value\n */\n if (end === start) {\n end = start + step;\n console.warn(`Step (${step}) was larger than the time range! end of time range was set accordingly.`);\n }\n\n // Replace variable placeholders in PromQL query\n const intervalMs = step * 1000;\n const minStepMs = minStep * 1000;\n\n let query = replacePromBuiltinVariables(spec.query, minStepMs, intervalMs);\n query = replaceVariables(query, context.variableState);\n\n let seriesNameFormat = spec.seriesNameFormat;\n // if series name format is defined, replace variable placeholders in series name format\n if (seriesNameFormat) {\n seriesNameFormat = replaceVariables(seriesNameFormat, context.variableState);\n }\n\n // Get the datasource, using the default Prom Datasource if one isn't specified in the query\n const client: PrometheusClient = await context.datasourceStore.getDatasourceClient(selectedDatasource);\n\n // Make the request to Prom\n\n let response;\n switch (context.mode) {\n case 'instant':\n response = await client.instantQuery({ query, time: end }, { ...interpolatedOptions, signal: abortSignal });\n break;\n case 'range':\n default:\n response = await client.rangeQuery({ query, start, end, step }, { ...interpolatedOptions, signal: abortSignal });\n break;\n }\n\n // TODO: What about error responses from Prom that have a response body?\n const result = response.data;\n\n // Custom display for response header warnings, configurable error responses display coming next\n const notices: Notice[] = [];\n if (response.status === 'success') {\n const warnings = response.warnings ?? [];\n const warningMessage = warnings[0] ?? '';\n if (warningMessage !== '') {\n notices.push({\n type: 'warning',\n message: warningMessage,\n });\n }\n }\n\n // Transform response\n const chartData: TimeSeriesData = {\n // Return the time range and step we actually used for the query\n timeRange: { start: fromUnixTime(start), end: fromUnixTime(end) },\n stepMs: step * 1000,\n\n series: buildTimeSeries(query, result, seriesNameFormat),\n metadata: {\n notices,\n executedQueryString: query,\n },\n };\n\n return chartData;\n};\n\nfunction buildVectorData(query: string, data: VectorData, seriesNameFormat: string | undefined): TimeSeries[] {\n return data.result.map((res) => {\n const { metric, value, histogram } = res;\n\n // Account for seriesNameFormat from query editor when determining name to show in legend, tooltip, etc.\n const { name, formattedName } = getFormattedPrometheusSeriesName(query, metric, seriesNameFormat);\n\n if (histogram) {\n return {\n name,\n formattedName,\n labels: metric,\n values: [parseValueTuple([histogram[0], histogram[1].sum])],\n histograms: [histogram],\n };\n }\n\n return {\n name,\n formattedName,\n labels: metric,\n values: [parseValueTuple(value)],\n };\n });\n}\n\nfunction buildMatrixData(query: string, data: MatrixData, seriesNameFormat: string | undefined): TimeSeries[] {\n return data.result.map((res) => {\n const { metric, values, histograms } = res;\n\n // Account for seriesNameFormat from query editor when determining name to show in legend, tooltip, etc.\n const { name, formattedName } = getFormattedPrometheusSeriesName(query, metric, seriesNameFormat);\n\n if (histograms) {\n return {\n name,\n formattedName,\n labels: metric,\n values: histograms.map((histogram) => parseValueTuple([histogram[0], histogram[1].sum])),\n histograms: histograms.map((histogram) => histogram),\n };\n }\n\n return {\n name,\n formattedName,\n labels: metric,\n values: values.map(parseValueTuple),\n };\n });\n}\n\nfunction buildScalarData(query: string, data: ScalarData, seriesNameFormat: string | undefined): TimeSeries[] {\n const { name, formattedName } = getFormattedPrometheusSeriesName(query, {}, seriesNameFormat);\n return [\n {\n name,\n values: [parseValueTuple(data.result)],\n formattedName,\n },\n ];\n}\n\nfunction buildTimeSeries(query: string, data?: InstantQueryResultType, seriesNameFormat?: string): TimeSeries[] {\n if (!data) {\n return [];\n }\n\n const resultType = data.resultType;\n switch (resultType) {\n case 'vector':\n return buildVectorData(query, data, seriesNameFormat);\n case 'matrix':\n return buildMatrixData(query, data, seriesNameFormat);\n case 'scalar':\n return buildScalarData(query, data, seriesNameFormat);\n default:\n console.warn('Unknown result type', resultType, data);\n return [];\n }\n}\n"],"names":["parseDurationString","datasourceSelectValueToSelector","replaceVariables","fromUnixTime","milliseconds","parseValueTuple","getDurationStringSeconds","getPrometheusTimeRange","getRangeStep","DEFAULT_PROM","PROM_DATASOURCE_KIND","getFormattedPrometheusSeriesName","interpolateDatasourceProxyParams","DEFAULT_SCRAPE_INTERVAL","replacePromBuiltinVariables","getTimeSeriesData","spec","context","abortSignal","query","undefined","series","listDatasourceSelectItems","datasourceStore","selectedDatasource","datasource","variableState","getDatasource","interpolatedOptions","datasourceScrapeInterval","Math","trunc","plugin","scrapeInterval","minStep","timeRange","step","suggestedStepMs","start","end","utcOffsetSec","Date","getTimezoneOffset","alignedEnd","floor","alignedStart","console","warn","intervalMs","minStepMs","seriesNameFormat","client","getDatasourceClient","response","mode","instantQuery","time","signal","rangeQuery","result","data","notices","status","warnings","warningMessage","push","type","message","chartData","stepMs","buildTimeSeries","metadata","executedQueryString","buildVectorData","map","res","metric","value","histogram","name","formattedName","labels","values","sum","histograms","buildMatrixData","buildScalarData","resultType"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAIEA,mBAAmB,QAGd,mBAA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ACC;QACtB,MAAM,EAAEC,MAAM,EAAEM,MAAM,EAAEE,UAAU,EAAE,GAAGT;QAEvC,wGAAwG;QACxG,MAAM,EAAEI,IAAI,EAAEC,aAAa,EAAE,GAAGrE,iCAAiCQ,OAAOyD,QAAQ1B;QAEhF,IAAIkC,YAAY;YACd,OAAO;gBACLL;gBACAC;gBACAC,QAAQL;gBACRM,QAAQE,WAAWV,GAAG,CAAC,CAACI,YAAczE,gBAAgB;wBAACyE,SAAS,CAAC,EAAE;wBAAEA,SAAS,CAAC,EAAE,CAACK,GAAG;qBAAC;gBACtFC,YAAYA,WAAWV,GAAG,CAAC,CAACI,YAAcA;YAC5C;QACF;QAEA,OAAO;YACLC;YACAC;YACAC,QAAQL;YACRM,QAAQA,OAAOR,GAAG,CAACrE;QACrB;IACF;AACF;AAEA,SAASiF,gBAAgBnE,KAAa,EAAEyC,IAAgB,EAAEV,gBAAoC;IAC5F,MAAM,EAAE6B,IAAI,EAAEC,aAAa,EAAE,GAAGrE,iCAAiCQ,OAAO,CAAC,GAAG+B;IAC5E,OAAO;QACL;YACE6B;YACAG,QAAQ;gBAAC7E,gBAAgBuD,KAAKD,MAAM;aAAE;YACtCqB;QACF;KACD;AACH;AAEA,SAASV,gBAAgBnD,KAAa,EAAEyC,IAA6B,EAAEV,gBAAyB;IAC9F,IAAI,CAACU,MAAM;QACT,OAAO,EAAE;IACX;IAEA,MAAM2B,aAAa3B,KAAK2B,UAAU;IAClC,OAAQA;QACN,KAAK;YACH,OAAOd,gBAAgBtD,OAAOyC,MAAMV;QACtC,KAAK;YACH,OAAOmC,gBAAgBlE,OAAOyC,MAAMV;QACtC,KAAK;YACH,OAAOoC,gBAAgBnE,OAAOyC,MAAMV;QACtC;YACEJ,QAAQC,IAAI,CAAC,uBAAuBwC,YAAY3B;YAChD,OAAO,EAAE;IACb;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/plugins/prometheus-time-series-query/get-time-series-data.ts"],"sourcesContent":["// Copyright 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, datasourceSelectValueToSelector, replaceVariables } from '@perses-dev/plugin-system';\nimport { fromUnixTime, milliseconds } from 'date-fns';\nimport {\n DatasourceSpec,\n DurationString,\n Notice,\n parseDurationString,\n TimeSeries,\n TimeSeriesData,\n} from '@perses-dev/spec';\nimport {\n parseValueTuple,\n PrometheusClient,\n getDurationStringSeconds,\n getPrometheusTimeRange,\n getRangeStep,\n DEFAULT_PROM,\n MatrixData,\n VectorData,\n ScalarData,\n InstantQueryResultType,\n PROM_DATASOURCE_KIND,\n} from '../../model';\nimport { getFormattedPrometheusSeriesName } from '../../utils';\nimport { interpolateDatasourceProxyParams } from '../interpolation';\nimport { DEFAULT_SCRAPE_INTERVAL, PrometheusDatasourceSpec } from '../types';\nimport { PrometheusTimeSeriesQuerySpec } from './time-series-query-model';\nimport { replacePromBuiltinVariables } from './replace-prom-builtin-variables';\n\nexport const getTimeSeriesData: TimeSeriesQueryPlugin<PrometheusTimeSeriesQuerySpec>['getTimeSeriesData'] = async (\n spec,\n context,\n abortSignal\n) => {\n if (spec.query === undefined || spec.query === null || spec.query === '') {\n // Do not make a request to the backend, instead return an empty TimeSeriesData\n return { series: [] };\n }\n\n const listDatasourceSelectItems = await context.datasourceStore.listDatasourceSelectItems(PROM_DATASOURCE_KIND);\n\n const selectedDatasource =\n datasourceSelectValueToSelector(\n spec.datasource ?? DEFAULT_PROM,\n context.variableState,\n listDatasourceSelectItems\n ) ?? DEFAULT_PROM;\n\n const datasource = (await context.datasourceStore.getDatasource(\n selectedDatasource\n )) as DatasourceSpec<PrometheusDatasourceSpec>;\n const interpolatedOptions = interpolateDatasourceProxyParams(datasource, context.variableState);\n\n const datasourceScrapeInterval = Math.trunc(\n milliseconds(parseDurationString(datasource.plugin.spec.scrapeInterval ?? DEFAULT_SCRAPE_INTERVAL)) / 1000\n );\n\n // Min step is the lower bound of the interval between data points\n // If no value is provided for it, it should default to the scrape interval of the datasource\n const minStep =\n getDurationStringSeconds(\n // resolve any variable that may have been provided\n // TODO add a validation check to make sure the variable is a DurationString, to avoid the back & forth cast here\n replaceVariables(spec.minStep as string, context.variableState) as DurationString\n ) ?? datasourceScrapeInterval;\n\n const timeRange = getPrometheusTimeRange(context.timeRange);\n const step = getRangeStep(timeRange, minStep, undefined, context.suggestedStepMs); // TODO: resolution\n\n // Align the time range so that it's a multiple of the step\n let { start, end } = timeRange;\n\n const utcOffsetSec = new Date().getTimezoneOffset() * 60;\n\n const alignedEnd = Math.floor((end + utcOffsetSec) / step) * step - utcOffsetSec;\n const alignedStart = Math.floor((start + utcOffsetSec) / step) * step - utcOffsetSec;\n start = alignedStart;\n end = alignedEnd;\n\n /* Ensure end is always greater than start:\n If the step is greater than equal to the diff of end and start,\n both start, and end will eventually be rounded to the same value,\n Consequently, the time range will be zero, which does not return any valid value\n */\n if (end === start) {\n end = start + step;\n console.warn(`Step (${step}) was larger than the time range! end of time range was set accordingly.`);\n }\n\n // Replace variable placeholders in PromQL query\n const intervalMs = step * 1000;\n const minStepMs = minStep * 1000;\n\n let query = replacePromBuiltinVariables(spec.query, minStepMs, intervalMs);\n query = replaceVariables(query, context.variableState);\n\n let seriesNameFormat = spec.seriesNameFormat;\n // if series name format is defined, replace variable placeholders in series name format\n if (seriesNameFormat) {\n seriesNameFormat = replaceVariables(seriesNameFormat, context.variableState);\n }\n\n // Get the datasource, using the default Prom Datasource if one isn't specified in the query\n const client: PrometheusClient = await context.datasourceStore.getDatasourceClient(selectedDatasource);\n\n // Make the request to Prom\n\n let response;\n switch (context.mode) {\n case 'instant':\n response = await client.instantQuery({ query, time: end }, { ...interpolatedOptions, signal: abortSignal });\n break;\n case 'range':\n default:\n response = await client.rangeQuery({ query, start, end, step }, { ...interpolatedOptions, signal: abortSignal });\n break;\n }\n\n // TODO: What about error responses from Prom that have a response body?\n const result = response.data;\n\n // Custom display for response header warnings, configurable error responses display coming next\n const notices: Notice[] = [];\n if (response.status === 'success') {\n const warnings = response.warnings ?? [];\n const warningMessage = warnings[0] ?? '';\n if (warningMessage !== '') {\n notices.push({\n type: 'warning',\n message: warningMessage,\n });\n }\n }\n\n // Transform response\n const chartData: TimeSeriesData = {\n // Return the time range and step we actually used for the query\n timeRange: { start: fromUnixTime(start), end: fromUnixTime(end) },\n stepMs: step * 1000,\n\n series: buildTimeSeries(query, result, seriesNameFormat),\n metadata: {\n notices,\n executedQueryString: query,\n },\n };\n\n return chartData;\n};\n\nfunction buildVectorData(query: string, data: VectorData, seriesNameFormat: string | undefined): TimeSeries[] {\n return data.result.map((res) => {\n const { metric, value, histogram } = res;\n\n // Account for seriesNameFormat from query editor when determining name to show in legend, tooltip, etc.\n const { name, formattedName } = getFormattedPrometheusSeriesName(query, metric, seriesNameFormat);\n\n if (histogram) {\n return {\n name,\n formattedName,\n labels: metric,\n values: [parseValueTuple([histogram[0], histogram[1].sum])],\n histograms: [histogram],\n };\n }\n\n return {\n name,\n formattedName,\n labels: metric,\n values: [parseValueTuple(value)],\n };\n });\n}\n\nfunction buildMatrixData(query: string, data: MatrixData, seriesNameFormat: string | undefined): TimeSeries[] {\n return data.result.map((res) => {\n const { metric, values, histograms } = res;\n\n // Account for seriesNameFormat from query editor when determining name to show in legend, tooltip, etc.\n const { name, formattedName } = getFormattedPrometheusSeriesName(query, metric, seriesNameFormat);\n\n if (histograms) {\n return {\n name,\n formattedName,\n labels: metric,\n values: histograms.map((histogram) => parseValueTuple([histogram[0], histogram[1].sum])),\n histograms: histograms.map((histogram) => histogram),\n };\n }\n\n return {\n name,\n formattedName,\n labels: metric,\n values: values.map(parseValueTuple),\n };\n });\n}\n\nfunction buildScalarData(query: string, data: ScalarData, seriesNameFormat: string | undefined): TimeSeries[] {\n const { name, formattedName } = getFormattedPrometheusSeriesName(query, {}, seriesNameFormat);\n return [\n {\n name,\n values: [parseValueTuple(data.result)],\n formattedName,\n },\n ];\n}\n\nfunction buildTimeSeries(query: string, data?: InstantQueryResultType, seriesNameFormat?: string): TimeSeries[] {\n if (!data) {\n return [];\n }\n\n const resultType = data.resultType;\n switch (resultType) {\n case 'vector':\n return buildVectorData(query, data, seriesNameFormat);\n case 'matrix':\n return buildMatrixData(query, data, seriesNameFormat);\n case 'scalar':\n return buildScalarData(query, data, seriesNameFormat);\n default:\n console.warn('Unknown result type', resultType, data);\n return [];\n }\n}\n"],"names":["datasourceSelectValueToSelector","replaceVariables","fromUnixTime","milliseconds","parseDurationString","parseValueTuple","getDurationStringSeconds","getPrometheusTimeRange","getRangeStep","DEFAULT_PROM","PROM_DATASOURCE_KIND","getFormattedPrometheusSeriesName","interpolateDatasourceProxyParams","DEFAULT_SCRAPE_INTERVAL","replacePromBuiltinVariables","getTimeSeriesData","spec","context","abortSignal","query","undefined","series","listDatasourceSelectItems","datasourceStore","selectedDatasource","datasource","variableState","getDatasource","interpolatedOptions","datasourceScrapeInterval","Math","trunc","plugin","scrapeInterval","minStep","timeRange","step","suggestedStepMs","start","end","utcOffsetSec","Date","getTimezoneOffset","alignedEnd","floor","alignedStart","console","warn","intervalMs","minStepMs","seriesNameFormat","client","getDatasourceClient","response","mode","instantQuery","time","signal","rangeQuery","result","data","notices","status","warnings","warningMessage","push","type","message","chartData","stepMs","buildTimeSeries","metadata","executedQueryString","buildVectorData","map","res","metric","value","histogram","name","formattedName","labels","values","sum","histograms","buildMatrixData","buildScalarData","resultType"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;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{ OptionsEditorProps } from '@perses-dev/plugin-system';
|
|
2
|
-
import { DurationString } from '@perses-dev/
|
|
2
|
+
import { DurationString } from '@perses-dev/spec';
|
|
3
3
|
import { PrometheusTimeSeriesQuerySpec } from './time-series-query-model';
|
|
4
4
|
export type PrometheusTimeSeriesQueryEditorProps = OptionsEditorProps<PrometheusTimeSeriesQuerySpec>;
|
|
5
5
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/plugins/prometheus-time-series-query/query-editor-model.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { useState } from 'react';\nimport { produce } from 'immer';\nimport { OptionsEditorProps } from '@perses-dev/plugin-system';\nimport { DurationString } from '@perses-dev/
|
|
1
|
+
{"version":3,"sources":["../../../../src/plugins/prometheus-time-series-query/query-editor-model.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { useState } from 'react';\nimport { produce } from 'immer';\nimport { OptionsEditorProps } from '@perses-dev/plugin-system';\nimport { DurationString } from '@perses-dev/spec';\nimport { PrometheusTimeSeriesQuerySpec } from './time-series-query-model';\n\nexport type PrometheusTimeSeriesQueryEditorProps = OptionsEditorProps<PrometheusTimeSeriesQuerySpec>;\n\n/**\n * A hook for managing the `query` state in PrometheusTimeSeriesQuerySpec. Returns the `query` value, along with\n * `onChange` and `onBlur` event handlers to the input. Keeps a local copy of the user's input and only syncs those\n * changes with the overall spec value once the input is blurred to prevent re-running queries in the panel's preview\n * every time the user types.\n */\nexport function useQueryState(props: PrometheusTimeSeriesQueryEditorProps): {\n query: string;\n handleQueryChange: (e: string) => void;\n handleQueryBlur: () => void;\n} {\n const { onChange, value } = props;\n\n // Local copy of the query's value\n const [query, setQuery] = useState(value.query);\n\n // This is basically \"getDerivedStateFromProps\" to make sure if spec's value changes external to this component,\n // we render with the latest value\n const [lastSyncedQuery, setLastSyncedQuery] = useState(value.query);\n if (value.query !== lastSyncedQuery) {\n setQuery(value.query);\n setLastSyncedQuery(value.query);\n }\n\n // Update our local state's copy as the user types\n const handleQueryChange = (e: string): void => {\n setQuery(e);\n };\n\n // Propagate changes to the query's value when the input is blurred to avoid constantly re-running queries in the\n // PanelPreview\n const handleQueryBlur = (): void => {\n setLastSyncedQuery(query);\n onChange(\n produce(value, (draft) => {\n draft.query = query;\n })\n );\n };\n\n return { query, handleQueryChange, handleQueryBlur };\n}\n\n/**\n * Hook to manage `seriesNameFormat` state to ensure panel preview does not rerender until text input is blurred\n */\nexport function useFormatState(props: PrometheusTimeSeriesQueryEditorProps): {\n format: string | undefined;\n handleFormatChange: (e: string) => void;\n handleFormatBlur: () => void;\n} {\n const { onChange, value } = props;\n\n // TODO: reusable hook or helper util instead of duplicating from useQueryState\n const [format, setFormat] = useState(value.seriesNameFormat);\n const [lastSyncedFormat, setLastSyncedFormat] = useState(value.seriesNameFormat);\n if (value.seriesNameFormat !== lastSyncedFormat) {\n setFormat(value.seriesNameFormat);\n setLastSyncedFormat(value.seriesNameFormat);\n }\n\n // Update our local state as the user types\n const handleFormatChange = (e: string): void => {\n setFormat(e);\n };\n\n // Propagate changes to the panel preview component when seriesNameFormat TextField is blurred\n const handleFormatBlur = (): void => {\n setLastSyncedFormat(format);\n onChange(\n produce(value, (draft) => {\n draft.seriesNameFormat = format;\n })\n );\n };\n\n return { format, handleFormatChange, handleFormatBlur };\n}\n\n/**\n * Hook to manage `minStep` state to ensure panel preview does not rerender until text input is blurred\n */\nexport function useMinStepState(props: PrometheusTimeSeriesQueryEditorProps): {\n minStep: string | undefined;\n handleMinStepChange: (e: DurationString | undefined) => void;\n handleMinStepBlur: () => void;\n} {\n const { onChange, value } = props;\n\n // TODO: reusable hook or helper util instead of duplicating from useQueryState\n const [minStep, setMinStep] = useState(value.minStep);\n const [lastSyncedMinStep, setLastSyncedMinStep] = useState(value.minStep);\n if (value.minStep !== lastSyncedMinStep) {\n setMinStep(value.minStep);\n setLastSyncedMinStep(value.minStep);\n }\n\n // Update our local state as the user types\n const handleMinStepChange = (e: DurationString | undefined): void => {\n setMinStep(e);\n };\n\n // Propagate changes to the panel preview component when minStep TextField is blurred\n const handleMinStepBlur = (): void => {\n setLastSyncedMinStep(minStep);\n onChange(\n produce(value, (draft) => {\n draft.minStep = minStep;\n })\n );\n };\n\n return { minStep, handleMinStepChange, handleMinStepBlur };\n}\n"],"names":["useState","produce","useQueryState","props","onChange","value","query","setQuery","lastSyncedQuery","setLastSyncedQuery","handleQueryChange","e","handleQueryBlur","draft","useFormatState","format","setFormat","seriesNameFormat","lastSyncedFormat","setLastSyncedFormat","handleFormatChange","handleFormatBlur","useMinStepState","minStep","setMinStep","lastSyncedMinStep","setLastSyncedMinStep","handleMinStepChange","handleMinStepBlur"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,QAAQ,QAAQ,QAAQ;AACjC,SAASC,OAAO,QAAQ,QAAQ;AAOhC;;;;;CAKC,GACD,OAAO,SAASC,cAAcC,KAA2C;IAKvE,MAAM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EC,QAAQ,EAAEC,KAAK,EAAE,GAAGF;IAE5B,+EAA+E;IAC/E,MAAM,CAACoB,SAASC,WAAW,GAAGxB,SAASK,MAAMkB,OAAO;IACpD,MAAM,CAACE,mBAAmBC,qBAAqB,GAAG1B,SAASK,MAAMkB,OAAO;IACxE,IAAIlB,MAAMkB,OAAO,KAAKE,mBAAmB;QACvCD,WAAWnB,MAAMkB,OAAO;QACxBG,qBAAqBrB,MAAMkB,OAAO;IACpC;IAEA,2CAA2C;IAC3C,MAAMI,sBAAsB,CAAChB;QAC3Ba,WAAWb;IACb;IAEA,qFAAqF;IACrF,MAAMiB,oBAAoB;QACxBF,qBAAqBH;QACrBnB,SACEH,QAAQI,OAAO,CAACQ;YACdA,MAAMU,OAAO,GAAGA;QAClB;IAEJ;IAEA,OAAO;QAAEA;QAASI;QAAqBC;IAAkB;AAC3D"}
|
|
@@ -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 { replaceVariable } from '@perses-dev/plugin-system';
|
|
14
|
-
import {
|
|
14
|
+
import { convertTimeToDuration, formatDuration } from '@perses-dev/spec';
|
|
15
15
|
/*
|
|
16
16
|
* Replace variable placeholders in a PromQL query
|
|
17
17
|
|
|
@@ -22,11 +22,11 @@ import { formatDuration, msToPrometheusDuration } from '@perses-dev/core';
|
|
|
22
22
|
* @returns a PromQL expression with variable placeholders replaced by their values
|
|
23
23
|
*/ export function replacePromBuiltinVariables(query, minStepMs, intervalMs) {
|
|
24
24
|
let updatedQuery = replaceVariable(query, '__interval_ms', intervalMs.toString());
|
|
25
|
-
updatedQuery = replaceVariable(updatedQuery, '__interval', formatDuration(
|
|
25
|
+
updatedQuery = replaceVariable(updatedQuery, '__interval', formatDuration(convertTimeToDuration(intervalMs)));
|
|
26
26
|
// The $__rate_interval variable is meant to be used with the rate() promQL function.
|
|
27
27
|
// It is defined as max($__interval + Min step, 4 * Min step)
|
|
28
28
|
const rateIntervalMs = Math.max(intervalMs + minStepMs, 4 * minStepMs);
|
|
29
|
-
updatedQuery = replaceVariable(updatedQuery, '__rate_interval', formatDuration(
|
|
29
|
+
updatedQuery = replaceVariable(updatedQuery, '__rate_interval', formatDuration(convertTimeToDuration(rateIntervalMs)));
|
|
30
30
|
return updatedQuery;
|
|
31
31
|
}
|
|
32
32
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/plugins/prometheus-time-series-query/replace-prom-builtin-variables.ts"],"sourcesContent":["// Copyright 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 { replaceVariable } from '@perses-dev/plugin-system';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../src/plugins/prometheus-time-series-query/replace-prom-builtin-variables.ts"],"sourcesContent":["// Copyright 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 { replaceVariable } from '@perses-dev/plugin-system';\nimport { convertTimeToDuration, formatDuration } from '@perses-dev/spec';\n\n/*\n * Replace variable placeholders in a PromQL query\n\n * @param query The base promQL expression that contains variable placeholders\n * @param minStepMs the lower bound of the interval between data points, in milliseconds\n * @param intervalMs the actual interval between data points, in milliseconds\n * \n * @returns a PromQL expression with variable placeholders replaced by their values\n */\nexport function replacePromBuiltinVariables(query: string, minStepMs: number, intervalMs: number): string {\n let updatedQuery = replaceVariable(query, '__interval_ms', intervalMs.toString());\n updatedQuery = replaceVariable(updatedQuery, '__interval', formatDuration(convertTimeToDuration(intervalMs)));\n\n // The $__rate_interval variable is meant to be used with the rate() promQL function.\n // It is defined as max($__interval + Min step, 4 * Min step)\n const rateIntervalMs = Math.max(intervalMs + minStepMs, 4 * minStepMs);\n updatedQuery = replaceVariable(\n updatedQuery,\n '__rate_interval',\n formatDuration(convertTimeToDuration(rateIntervalMs))\n );\n\n return updatedQuery;\n}\n"],"names":["replaceVariable","convertTimeToDuration","formatDuration","replacePromBuiltinVariables","query","minStepMs","intervalMs","updatedQuery","toString","rateIntervalMs","Math","max"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,eAAe,QAAQ,4BAA4B;AAC5D,SAASC,qBAAqB,EAAEC,cAAc,QAAQ,mBAAmB;AAEzE;;;;;;;;CAQC,GACD,OAAO,SAASC,4BAA4BC,KAAa,EAAEC,SAAiB,EAAEC,UAAkB;IAC9F,IAAIC,eAAeP,gBAAgBI,OAAO,iBAAiBE,WAAWE,QAAQ;IAC9ED,eAAeP,gBAAgBO,cAAc,cAAcL,eAAeD,sBAAsBK;IAEhG,qFAAqF;IACrF,6DAA6D;IAC7D,MAAMG,iBAAiBC,KAAKC,GAAG,CAACL,aAAaD,WAAW,IAAIA;IAC5DE,eAAeP,gBACbO,cACA,mBACAL,eAAeD,sBAAsBQ;IAGvC,OAAOF;AACT"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DurationString } from '@perses-dev/core';
|
|
2
1
|
import { DatasourceSelectValue } from '@perses-dev/plugin-system';
|
|
2
|
+
import { DurationString } from '@perses-dev/spec';
|
|
3
3
|
import { PrometheusDatasourceSelector } from '../../model';
|
|
4
4
|
/**
|
|
5
5
|
* The spec/options for the PrometheusTimeSeriesQuery plugin.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time-series-query-model.d.ts","sourceRoot":"","sources":["../../../../src/plugins/prometheus-time-series-query/time-series-query-model.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"time-series-query-model.d.ts","sourceRoot":"","sources":["../../../../src/plugins/prometheus-time-series-query/time-series-query-model.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAC;AAC3D;;GAEG;AACH,MAAM,WAAW,6BAA6B;IAC5C,KAAK,EAAE,MAAM,CAAC;IACd,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,qBAAqB,CAAC,4BAA4B,CAAC,CAAC;CAClE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/plugins/prometheus-time-series-query/time-series-query-model.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../src/plugins/prometheus-time-series-query/time-series-query-model.ts"],"sourcesContent":["// Copyright 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 { DatasourceSelectValue } from '@perses-dev/plugin-system';\nimport { DurationString } from '@perses-dev/spec';\nimport { PrometheusDatasourceSelector } from '../../model';\n/**\n * The spec/options for the PrometheusTimeSeriesQuery plugin.\n */\nexport interface PrometheusTimeSeriesQuerySpec {\n query: string;\n seriesNameFormat?: string;\n minStep?: DurationString;\n resolution?: number;\n datasource?: DatasourceSelectValue<PrometheusDatasourceSelector>;\n}\n"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAKjC;;CAEC,GACD,WAMC"}
|
package/lib/plugins/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { QueryParamValues } from '@perses-dev/components';
|
|
2
|
-
import { DurationString, HTTPProxy } from '@perses-dev/core';
|
|
3
2
|
import { DatasourceSelectValue } from '@perses-dev/plugin-system';
|
|
3
|
+
import { DurationString, HTTPProxy } from '@perses-dev/spec';
|
|
4
4
|
import { PrometheusDatasourceSelector } from '../model';
|
|
5
5
|
export declare const DEFAULT_SCRAPE_INTERVAL: DurationString;
|
|
6
6
|
export interface PrometheusDatasourceSpec {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/plugins/types.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/plugins/types.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,4BAA4B,EAAE,MAAM,UAAU,CAAC;AAExD,eAAO,MAAM,uBAAuB,EAAE,cAAqB,CAAC;AAE5D,MAAM,WAAW,wBAAwB;IACvC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,WAAW,CAAC,EAAE,gBAAgB,CAAC;CAChC;AAED,MAAM,WAAW,6BAA6B;IAC5C,UAAU,CAAC,EAAE,qBAAqB,CAAC,4BAA4B,CAAC,CAAC;CAClE;AAED,MAAM,MAAM,mCAAmC,GAAG,6BAA6B,GAAG;IAChF,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,oCAAoC,GAAG,6BAA6B,GAAG;IACjF,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,+BAA+B,GAAG,6BAA6B,GAAG;IAE5E,IAAI,EAAE,MAAM,CAAC;IAGb,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC"}
|
package/lib/plugins/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/plugins/types.ts"],"sourcesContent":["// Copyright 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 { QueryParamValues } from '@perses-dev/components';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/types.ts"],"sourcesContent":["// Copyright 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 { QueryParamValues } from '@perses-dev/components';\nimport { DatasourceSelectValue } from '@perses-dev/plugin-system';\nimport { DurationString, HTTPProxy } from '@perses-dev/spec';\nimport { PrometheusDatasourceSelector } from '../model';\n\nexport const DEFAULT_SCRAPE_INTERVAL: DurationString = '1m';\n\nexport interface PrometheusDatasourceSpec {\n directUrl?: string;\n proxy?: HTTPProxy;\n scrapeInterval?: DurationString; // default to 1m\n queryParams?: QueryParamValues;\n}\n\nexport interface PrometheusVariableOptionsBase {\n datasource?: DatasourceSelectValue<PrometheusDatasourceSelector>;\n}\n\nexport type PrometheusLabelNamesVariableOptions = PrometheusVariableOptionsBase & {\n matchers?: string[];\n};\n\nexport type PrometheusLabelValuesVariableOptions = PrometheusVariableOptionsBase & {\n labelName: string;\n matchers?: string[];\n};\n\nexport type PrometheusPromQLVariableOptions = PrometheusVariableOptionsBase & {\n // expr is the PromQL expression.\n expr: string;\n // labelName is the name of the label that will be used after the PromQL query is performed to select the label value.\n // Note: This field is not part of the Prometheus API.\n labelName: string;\n};\n"],"names":["DEFAULT_SCRAPE_INTERVAL"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAOjC,OAAO,MAAMA,0BAA0C,KAAK"}
|