@perses-dev/prometheus-plugin 0.57.0-beta.0 → 0.57.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/__mf/js/{Prometheus.2bb892ab.js → Prometheus.9877d89e.js} +3 -3
- package/__mf/js/async/1728.531c96f9.js +1 -0
- package/__mf/js/async/3499.bef2e2e5.js +1 -0
- package/__mf/js/async/3652.6b591718.js +7 -0
- package/__mf/js/async/392.f1b4a590.js +2 -0
- package/__mf/js/async/425.1ec8867f.js +1 -0
- package/__mf/js/async/4657.f0c3ccd6.js +2 -0
- package/__mf/js/async/54.e6002704.js +22 -0
- package/__mf/js/async/5440.8ced5513.js +2 -0
- package/__mf/js/async/{5440.c13c3533.js.LICENSE.txt → 5440.8ced5513.js.LICENSE.txt} +3 -3
- package/__mf/js/async/9010.ca50fa9e.js +2 -0
- package/__mf/js/async/{9020.c19782f1.js → 9020.ebc1cad3.js} +1 -1
- package/__mf/js/async/{__federation_expose_PrometheusDatasource.6f63e147.js → __federation_expose_PrometheusDatasource.b97f9012.js} +1 -1
- package/__mf/js/async/{__federation_expose_PrometheusExplorer.584a073d.js → __federation_expose_PrometheusExplorer.eba3b416.js} +1 -1
- package/__mf/js/async/{__federation_expose_PrometheusLabelNamesVariable.40984a4d.js → __federation_expose_PrometheusLabelNamesVariable.bd38a89c.js} +1 -1
- package/__mf/js/async/{__federation_expose_PrometheusLabelValuesVariable.bd3eb00c.js → __federation_expose_PrometheusLabelValuesVariable.eb12e168.js} +1 -1
- package/__mf/js/async/{__federation_expose_PrometheusPromQLVariable.5cca8417.js → __federation_expose_PrometheusPromQLVariable.7ccb0601.js} +1 -1
- package/__mf/js/async/{__federation_expose_PrometheusTimeSeriesQuery.f59141f4.js → __federation_expose_PrometheusTimeSeriesQuery.08f11ea9.js} +1 -1
- package/__mf/js/{main.9617b605.js → main.78fc6444.js} +5 -5
- package/lib/bootstrap.js +1 -1
- package/lib/bootstrap.js.map +1 -1
- package/lib/cjs/bootstrap.js +1 -1
- package/lib/cjs/components/PromQLEditor.js +1 -1
- package/lib/cjs/components/TreeNode.js +1 -1
- package/lib/cjs/components/index.js +1 -1
- package/lib/cjs/components/promql/ast.js +1 -1
- package/lib/cjs/components/promql/format.js +1 -1
- package/lib/cjs/components/promql/functionSignatures.js +1 -1
- package/lib/cjs/components/promql/serialize.js +1 -1
- package/lib/cjs/components/promql/utils.js +1 -1
- package/lib/cjs/components/query.js +1 -1
- package/lib/cjs/env.d.js +1 -1
- package/lib/cjs/explore/PrometheusExplorer.js +1 -1
- package/lib/cjs/explore/PrometheusMetricsFinder/PrometheusMetricsFinder.js +1 -1
- package/lib/cjs/explore/PrometheusMetricsFinder/display/MetricChip.js +1 -1
- package/lib/cjs/explore/PrometheusMetricsFinder/display/list/MetricList.js +1 -1
- package/lib/cjs/explore/PrometheusMetricsFinder/filter/FilterInputs.js +1 -1
- package/lib/cjs/explore/PrometheusMetricsFinder/filter/FinderFilters.js +1 -1
- package/lib/cjs/explore/PrometheusMetricsFinder/index.js +1 -1
- package/lib/cjs/explore/PrometheusMetricsFinder/overview/MetricOverview.js +1 -1
- package/lib/cjs/explore/PrometheusMetricsFinder/overview/tabs/JobTab.js +1 -1
- package/lib/cjs/explore/PrometheusMetricsFinder/overview/tabs/OverviewTab.js +1 -1
- package/lib/cjs/explore/PrometheusMetricsFinder/overview/tabs/SimilarTab.js +1 -1
- package/lib/cjs/explore/PrometheusMetricsFinder/types.js +1 -1
- package/lib/cjs/explore/PrometheusMetricsFinder/utils.js +1 -1
- package/lib/cjs/explore/index.js +12 -0
- package/lib/cjs/getPluginModule.js +12 -0
- package/lib/cjs/index-federation.js +1 -1
- package/lib/cjs/index.js +12 -0
- package/lib/cjs/model/api-types.js +1 -1
- package/lib/cjs/model/index.js +1 -1
- package/lib/cjs/model/parse-sample-values.js +1 -1
- package/lib/cjs/model/prometheus-client.js +1 -1
- package/lib/cjs/model/prometheus-selectors.js +1 -1
- package/lib/cjs/model/time.js +1 -1
- package/lib/cjs/plugins/MatcherEditor.js +1 -1
- package/lib/cjs/plugins/PrometheusDatasourceEditor.js +1 -1
- package/lib/cjs/plugins/PrometheusLabelNamesVariable.js +12 -0
- package/lib/cjs/plugins/PrometheusLabelValuesVariable.js +12 -0
- package/lib/cjs/plugins/PrometheusPromQLVariable.js +12 -0
- package/lib/cjs/plugins/index.js +12 -0
- package/lib/cjs/plugins/prometheus-datasource.js +1 -1
- package/lib/cjs/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.js +1 -1
- package/lib/cjs/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js +1 -1
- package/lib/cjs/plugins/prometheus-time-series-query/get-time-series-data.js +1 -1
- package/lib/cjs/plugins/prometheus-time-series-query/index.js +1 -1
- package/lib/cjs/plugins/prometheus-time-series-query/query-editor-model.js +1 -1
- package/lib/cjs/plugins/prometheus-time-series-query/replace-prom-builtin-variables.js +1 -1
- package/lib/cjs/plugins/prometheus-time-series-query/time-series-query-model.js +1 -1
- package/lib/cjs/plugins/prometheus-variables.js +1 -1
- package/lib/cjs/plugins/test/setup-tests.js +1 -1
- package/lib/cjs/plugins/types.js +1 -1
- package/lib/cjs/plugins/variable.js +1 -1
- package/lib/cjs/setup-tests.js +1 -1
- package/lib/cjs/utils/index.js +1 -1
- package/lib/cjs/utils/utils.js +1 -1
- package/lib/components/PromQLEditor.js +1 -1
- package/lib/components/PromQLEditor.js.map +1 -1
- package/lib/components/TreeNode.js +1 -1
- package/lib/components/TreeNode.js.map +1 -1
- package/lib/components/index.js +1 -1
- package/lib/components/index.js.map +1 -1
- package/lib/components/promql/ast.js +1 -1
- package/lib/components/promql/ast.js.map +1 -1
- package/lib/components/promql/format.js +1 -1
- package/lib/components/promql/format.js.map +1 -1
- package/lib/components/promql/functionSignatures.js +1 -1
- package/lib/components/promql/functionSignatures.js.map +1 -1
- package/lib/components/promql/serialize.js +1 -1
- package/lib/components/promql/serialize.js.map +1 -1
- package/lib/components/promql/utils.js +1 -1
- package/lib/components/promql/utils.js.map +1 -1
- package/lib/components/query.js +1 -1
- package/lib/components/query.js.map +1 -1
- package/lib/env.d.js +1 -1
- package/lib/env.d.js.map +1 -1
- package/lib/explore/PrometheusExplorer.js +1 -1
- package/lib/explore/PrometheusExplorer.js.map +1 -1
- package/lib/explore/PrometheusMetricsFinder/PrometheusMetricsFinder.js +1 -1
- package/lib/explore/PrometheusMetricsFinder/PrometheusMetricsFinder.js.map +1 -1
- package/lib/explore/PrometheusMetricsFinder/display/MetricChip.js +1 -1
- package/lib/explore/PrometheusMetricsFinder/display/MetricChip.js.map +1 -1
- package/lib/explore/PrometheusMetricsFinder/display/list/MetricList.js +1 -1
- package/lib/explore/PrometheusMetricsFinder/display/list/MetricList.js.map +1 -1
- package/lib/explore/PrometheusMetricsFinder/filter/FilterInputs.js +1 -1
- package/lib/explore/PrometheusMetricsFinder/filter/FilterInputs.js.map +1 -1
- package/lib/explore/PrometheusMetricsFinder/filter/FinderFilters.js +1 -1
- package/lib/explore/PrometheusMetricsFinder/filter/FinderFilters.js.map +1 -1
- package/lib/explore/PrometheusMetricsFinder/index.js +1 -1
- package/lib/explore/PrometheusMetricsFinder/index.js.map +1 -1
- package/lib/explore/PrometheusMetricsFinder/overview/MetricOverview.js +1 -1
- package/lib/explore/PrometheusMetricsFinder/overview/MetricOverview.js.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.js +1 -1
- package/lib/explore/PrometheusMetricsFinder/overview/tabs/OverviewTab.js.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.js +1 -1
- package/lib/explore/PrometheusMetricsFinder/types.js.map +1 -1
- package/lib/explore/PrometheusMetricsFinder/utils.js +1 -1
- package/lib/explore/PrometheusMetricsFinder/utils.js.map +1 -1
- package/lib/explore/index.d.ts.map +1 -1
- package/lib/explore/index.js +12 -0
- package/lib/explore/index.js.map +1 -1
- package/lib/getPluginModule.d.ts.map +1 -1
- package/lib/getPluginModule.js +12 -0
- package/lib/getPluginModule.js.map +1 -1
- package/lib/index-federation.js +1 -1
- package/lib/index-federation.js.map +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +12 -0
- package/lib/index.js.map +1 -1
- package/lib/model/api-types.js +1 -1
- package/lib/model/api-types.js.map +1 -1
- package/lib/model/index.js +1 -1
- package/lib/model/index.js.map +1 -1
- package/lib/model/parse-sample-values.js +1 -1
- package/lib/model/parse-sample-values.js.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.js +1 -1
- package/lib/model/prometheus-selectors.js.map +1 -1
- package/lib/model/time.js +1 -1
- package/lib/model/time.js.map +1 -1
- package/lib/plugins/MatcherEditor.js +1 -1
- package/lib/plugins/MatcherEditor.js.map +1 -1
- package/lib/plugins/PrometheusDatasourceEditor.js +1 -1
- package/lib/plugins/PrometheusDatasourceEditor.js.map +1 -1
- package/lib/plugins/PrometheusLabelNamesVariable.d.ts.map +1 -1
- package/lib/plugins/PrometheusLabelNamesVariable.js +12 -0
- package/lib/plugins/PrometheusLabelNamesVariable.js.map +1 -1
- package/lib/plugins/PrometheusLabelValuesVariable.d.ts.map +1 -1
- package/lib/plugins/PrometheusLabelValuesVariable.js +12 -0
- package/lib/plugins/PrometheusLabelValuesVariable.js.map +1 -1
- package/lib/plugins/PrometheusPromQLVariable.d.ts.map +1 -1
- package/lib/plugins/PrometheusPromQLVariable.js +12 -0
- package/lib/plugins/PrometheusPromQLVariable.js.map +1 -1
- package/lib/plugins/index.d.ts.map +1 -1
- package/lib/plugins/index.js +12 -0
- package/lib/plugins/index.js.map +1 -1
- package/lib/plugins/prometheus-datasource.js +1 -1
- package/lib/plugins/prometheus-datasource.js.map +1 -1
- package/lib/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.js +1 -1
- package/lib/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.js.map +1 -1
- package/lib/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js +1 -1
- package/lib/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js.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/index.js +1 -1
- package/lib/plugins/prometheus-time-series-query/index.js.map +1 -1
- package/lib/plugins/prometheus-time-series-query/query-editor-model.js +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 +1 -1
- 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.js +1 -1
- package/lib/plugins/prometheus-time-series-query/time-series-query-model.js.map +1 -1
- package/lib/plugins/prometheus-variables.js +1 -1
- package/lib/plugins/prometheus-variables.js.map +1 -1
- package/lib/plugins/test/setup-tests.js +1 -1
- package/lib/plugins/test/setup-tests.js.map +1 -1
- package/lib/plugins/types.js +1 -1
- package/lib/plugins/types.js.map +1 -1
- package/lib/plugins/variable.js +1 -1
- package/lib/plugins/variable.js.map +1 -1
- package/lib/setup-tests.js +1 -1
- package/lib/setup-tests.js.map +1 -1
- package/lib/utils/index.js +1 -1
- package/lib/utils/index.js.map +1 -1
- package/lib/utils/utils.js +1 -1
- package/lib/utils/utils.js.map +1 -1
- package/mf-manifest.json +73 -73
- package/mf-stats.json +73 -73
- package/package.json +6 -6
- package/__mf/js/async/1490.7e5068f1.js +0 -22
- package/__mf/js/async/1728.af16c4ec.js +0 -1
- package/__mf/js/async/2984.7182c2f5.js +0 -1
- package/__mf/js/async/2999.1d8347df.js +0 -1
- package/__mf/js/async/3664.ba8b26b6.js +0 -2
- package/__mf/js/async/392.7cda691a.js +0 -2
- package/__mf/js/async/5440.c13c3533.js +0 -2
- package/__mf/js/async/5501.6166367c.js +0 -2
- package/__mf/js/async/6149.19799c37.js +0 -7
- /package/__mf/js/async/{6149.19799c37.js.LICENSE.txt → 3652.6b591718.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{392.7cda691a.js.LICENSE.txt → 392.f1b4a590.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{3664.ba8b26b6.js.LICENSE.txt → 4657.f0c3ccd6.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{1490.7e5068f1.js.LICENSE.txt → 54.e6002704.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{5501.6166367c.js.LICENSE.txt → 9010.ca50fa9e.js.LICENSE.txt} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../src/explore/PrometheusMetricsFinder/overview/tabs/OverviewTab.tsx"],"sourcesContent":["// Copyright 2024 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { DatasourceSelector } from '@perses-dev/core';\nimport { ReactElement, useMemo, useState } from 'react';\nimport {\n Autocomplete,\n Button,\n Chip,\n CircularProgress,\n Divider,\n IconButton,\n MenuItem,\n Select,\n SelectChangeEvent,\n Skeleton,\n Stack,\n StackProps,\n TextField,\n Typography,\n useMediaQuery,\n useTheme,\n} from '@mui/material';\nimport PlusIcon from 'mdi-material-ui/Plus';\nimport CheckIcon from 'mdi-material-ui/Check';\nimport CloseIcon from 'mdi-material-ui/Close';\nimport { ErrorAlert } from '@perses-dev/components';\nimport { LabelFilter, LabelValueCounter, Operator } from '../../types';\nimport { ListboxComponent } from '../../filter/FilterInputs';\nimport { useMetricMetadata, useSeriesStates } from '../../utils';\nimport { MetricChip } from '../../display/MetricChip';\n\nexport interface LabelValuesRowProps extends StackProps {\n label: string;\n valueCounters: LabelValueCounter[];\n onFilterAdd: (filter: LabelFilter) => void;\n orderBy?: 'asc' | 'amount';\n}\n\nexport function LabelValuesRow({ label, valueCounters, onFilterAdd, ...props }: LabelValuesRowProps): ReactElement {\n const [isAddingFilter, setIsAddingFilter] = useState(false);\n const [operator, setOperator] = useState<Operator>('=');\n const [value, setValue] = useState('');\n const [showAllValues, setShowAllValues] = useState(false);\n const isMobileSize = useMediaQuery(useTheme().breakpoints.down('md'));\n\n const displayedValueCounters = useMemo(() => {\n if (showAllValues) {\n return valueCounters;\n }\n return valueCounters.slice(0, 5);\n }, [showAllValues, valueCounters]);\n\n return (\n <Stack\n key={label}\n sx={{ width: '100%' }}\n direction={isMobileSize ? 'column' : 'row'}\n alignItems=\"center\"\n gap={2}\n {...props}\n >\n <Stack\n sx={{ width: '100%', height: '100%' }}\n justifyContent=\"space-between\"\n alignContent=\"center\"\n direction={isMobileSize ? 'column' : 'row'}\n >\n <Typography sx={{ fontFamily: 'monospace' }} pl={isMobileSize ? 0 : 1}>\n {label}\n </Typography>\n <Stack direction=\"row\" gap={1} alignItems=\"center\">\n {isAddingFilter ? (\n <>\n <Select\n size=\"small\"\n value={operator}\n variant=\"outlined\"\n onChange={(event: SelectChangeEvent) => {\n setOperator(event.target.value as Operator);\n }}\n >\n <MenuItem value=\"=\">=</MenuItem>\n <MenuItem value=\"!=\">!=</MenuItem>\n <MenuItem value=\"=~\">=~</MenuItem>\n <MenuItem value=\"!~\">!~</MenuItem>\n </Select>\n <Autocomplete\n freeSolo\n limitTags={1}\n disableClearable\n options={valueCounters.map((counters) => counters.labelValue)}\n value={value}\n ListboxComponent={ListboxComponent}\n sx={{ width: 250 }}\n renderInput={(params) => {\n return <TextField {...params} label=\"Value\" variant=\"outlined\" fullWidth size=\"small\" />;\n }}\n onInputChange={(_, newValue) => {\n setValue(newValue);\n }}\n />\n <IconButton\n aria-label=\"confirm\"\n onClick={() => {\n onFilterAdd({ label, labelValues: [value], operator });\n setIsAddingFilter(false);\n }}\n >\n <CheckIcon />\n </IconButton>\n <IconButton\n aria-label=\"cancel\"\n onClick={() => {\n setIsAddingFilter(false);\n }}\n >\n <CloseIcon />\n </IconButton>\n </>\n ) : (\n <Button startIcon={<PlusIcon />} aria-label=\"add filter\" onClick={() => setIsAddingFilter(true)}>\n Add filter\n </Button>\n )}\n </Stack>\n </Stack>\n\n <Stack sx={{ width: '100%' }} gap={0.5}>\n <Stack direction=\"row\" gap={0.5}>\n <Typography variant=\"subtitle1\">{valueCounters.length} values</Typography>\n {valueCounters.length > 5 && (\n <Button variant=\"text\" size=\"small\" sx={{ padding: 0 }} onClick={() => setShowAllValues((prev) => !prev)}>\n {showAllValues ? '[-]' : '[+]'}\n </Button>\n )}\n </Stack>\n\n <Stack sx={{ overflow: isMobileSize ? 'auto' : 'unset' }}>\n {displayedValueCounters.map((labelValueCounter) => (\n <Stack key={`${label}-${labelValueCounter.labelValue}`} direction=\"row\" gap={2}>\n <Typography\n sx={{\n color: (theme) => theme.palette.success.main,\n fontFamily: 'monospace',\n ':hover': { backgroundColor: 'rgba(127,127,127,0.35)', cursor: 'pointer' },\n textWrap: isMobileSize ? 'nowrap' : 'unset',\n }}\n onClick={() => onFilterAdd({ label, labelValues: [labelValueCounter.labelValue], operator: '=' })}\n >\n {labelValueCounter.labelValue}\n </Typography>\n <Typography sx={{ textWrap: 'nowrap' }}>({labelValueCounter.counter} series)</Typography>\n </Stack>\n ))}\n </Stack>\n <Stack width=\"100%\" textAlign={isMobileSize ? 'center' : 'unset'}>\n {showAllValues ? (\n <Button variant=\"text\" sx={{ width: 'fit-content' }} onClick={() => setShowAllValues(false)}>\n Hide full values\n </Button>\n ) : (\n <>\n {valueCounters.length > 5 && (\n <Button variant=\"text\" sx={{ width: 'fit-content' }} onClick={() => setShowAllValues(true)}>\n Show {valueCounters.length - 5} more values\n </Button>\n )}\n </>\n )}\n </Stack>\n </Stack>\n </Stack>\n );\n}\n\nexport interface LabelValuesTableProps extends StackProps {\n labelValueCounters: Map<string, LabelValueCounter[]>;\n isLoading?: boolean;\n onFilterAdd: (filter: LabelFilter) => void;\n}\n\nexport function LabelValuesTable({\n labelValueCounters,\n isLoading,\n onFilterAdd,\n ...props\n}: LabelValuesTableProps): ReactElement {\n const labels: string[] = useMemo(() => {\n return [...labelValueCounters.keys()].sort();\n }, [labelValueCounters]);\n\n if (isLoading) {\n return (\n <Stack width=\"100%\" sx={{ alignItems: 'center', justifyContent: 'center' }}>\n <CircularProgress />\n </Stack>\n );\n }\n\n return (\n <Stack sx={{ width: '100%' }} divider={<Divider flexItem orientation=\"horizontal\" />} gap={2} {...props}>\n <Stack gap={2} direction=\"row\" sx={{ width: '100%' }}>\n <Stack sx={{ width: '100%' }}>\n <Typography variant=\"h3\">Label</Typography>\n </Stack>\n <Stack sx={{ width: '100%' }}>\n <Typography variant=\"h3\">Values</Typography>\n </Stack>\n </Stack>\n {labels.map((label) => (\n <LabelValuesRow\n key={label}\n label={label}\n valueCounters={labelValueCounters.get(label) ?? []}\n onFilterAdd={onFilterAdd}\n />\n ))}\n </Stack>\n );\n}\n\nexport interface OverviewTabProps extends StackProps {\n metricName: string;\n datasource: DatasourceSelector;\n filters: LabelFilter[];\n onFilterAdd: (filter: LabelFilter) => void;\n}\n\nexport function OverviewTab({\n metricName,\n datasource,\n filters,\n onFilterAdd,\n ...props\n}: OverviewTabProps): ReactElement {\n const { metadata, isLoading: isMetadataLoading, error: metadataError } = useMetricMetadata(metricName, datasource);\n const { series, labelValueCounters, isLoading, error } = useSeriesStates(metricName, filters, datasource);\n\n return (\n <Stack gap={2} {...props}>\n <Stack direction=\"row\" gap={3} mt={1} justifyContent=\"space-between\">\n <Stack gap={1}>\n <Typography variant=\"h1\" sx={{ fontFamily: 'monospace' }}>\n {metricName}\n </Typography>\n <Typography>Description:</Typography>\n {isMetadataLoading ? (\n <Skeleton variant=\"text\" width={180} />\n ) : (\n <Typography style={{ fontStyle: metadata?.help ? 'initial' : 'italic' }}>\n {metadataError ? 'Failed to fetch metadata' : (metadata?.help ?? 'unknown')}\n </Typography>\n )}\n </Stack>\n <Stack gap={1} justifyContent=\"center\">\n {isMetadataLoading ? (\n <Skeleton variant=\"rounded\" width={75} />\n ) : metadataError ? (\n <Chip label=\"failed to fetch\" color=\"error\" sx={{ fontStyle: 'italic' }} />\n ) : (\n <MetricChip label={metadata?.type ?? 'unknown'} />\n )}\n <Typography>\n Result:{' '}\n {isLoading ? (\n <Skeleton variant=\"text\" width={20} sx={{ display: 'inline-block' }} />\n ) : error ? (\n <strong>failed to fetch series</strong>\n ) : (\n <strong>{series?.length ?? 'unknown'} series</strong>\n )}\n </Typography>\n </Stack>\n </Stack>\n\n {error ? (\n <ErrorAlert\n error={{\n name: `Failed to fetch series ${error?.status && `(${error.status})`}`,\n message: error?.message ?? 'Failed to fetch series',\n }}\n />\n ) : series?.length === 0 ? (\n <Stack {...props}>\n <Typography sx={{ color: (theme) => theme.palette.warning.main }}>\n No series found with current filters.\n </Typography>\n </Stack>\n ) : (\n <LabelValuesTable labelValueCounters={labelValueCounters} onFilterAdd={onFilterAdd} isLoading={isLoading} />\n )}\n </Stack>\n );\n}\n"],"names":["useMemo","useState","Autocomplete","Button","Chip","CircularProgress","Divider","IconButton","MenuItem","Select","Skeleton","Stack","TextField","Typography","useMediaQuery","useTheme","PlusIcon","CheckIcon","CloseIcon","ErrorAlert","ListboxComponent","useMetricMetadata","useSeriesStates","MetricChip","LabelValuesRow","label","valueCounters","onFilterAdd","props","isAddingFilter","setIsAddingFilter","operator","setOperator","value","setValue","showAllValues","setShowAllValues","isMobileSize","breakpoints","down","displayedValueCounters","slice","sx","width","direction","alignItems","gap","height","justifyContent","alignContent","fontFamily","pl","size","variant","onChange","event","target","freeSolo","limitTags","disableClearable","options","map","counters","labelValue","renderInput","params","fullWidth","onInputChange","_","newValue","aria-label","onClick","labelValues","startIcon","length","padding","prev","overflow","labelValueCounter","color","theme","palette","success","main","backgroundColor","cursor","textWrap","counter","textAlign","LabelValuesTable","labelValueCounters","isLoading","labels","keys","sort","divider","flexItem","orientation","get","OverviewTab","metricName","datasource","filters","metadata","isMetadataLoading","error","metadataError","series","mt","style","fontStyle","help","type","display","strong","name","status","message","warning"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAGjC,SAAuBA,OAAO,EAAEC,QAAQ,QAAQ,QAAQ;AACxD,SACEC,YAAY,EACZC,MAAM,EACNC,IAAI,EACJC,gBAAgB,EAChBC,OAAO,EACPC,UAAU,EACVC,QAAQ,EACRC,MAAM,EAENC,QAAQ,EACRC,KAAK,EAELC,SAAS,EACTC,UAAU,EACVC,aAAa,EACbC,QAAQ,QACH,gBAAgB;AACvB,OAAOC,cAAc,uBAAuB;AAC5C,OAAOC,eAAe,wBAAwB;AAC9C,OAAOC,eAAe,wBAAwB;AAC9C,SAASC,UAAU,QAAQ,yBAAyB;AAEpD,SAASC,gBAAgB,QAAQ,4BAA4B;AAC7D,SAASC,iBAAiB,EAAEC,eAAe,QAAQ,cAAc;AACjE,SAASC,UAAU,QAAQ,2BAA2B;AAStD,OAAO,SAASC,eAAe,EAAEC,KAAK,EAAEC,aAAa,EAAEC,WAAW,EAAE,GAAGC,OAA4B;IACjG,MAAM,CAACC,gBAAgBC,kBAAkB,GAAG7B,SAAS;IACrD,MAAM,CAAC8B,UAAUC,YAAY,GAAG/B,SAAmB;IACnD,MAAM,CAACgC,OAAOC,S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oE,WAAW;gCAAS;+CAEtE,KAACvF;gCAAWE,OAAO8E,UAAUS,QAAQ;;0CAEvC,MAACnG;;oCAAW;oCACF;oCACP8E,0BACC,KAACjF;wCAAS2C,SAAQ;wCAAOV,OAAO;wCAAID,IAAI;4CAAEuE,SAAS;wCAAe;yCAChER,sBACF,KAACS;kDAAO;uDAER,MAACA;;4CAAQP,QAAQjC,UAAU;4CAAU;;;;;;;;;YAM5C+B,sBACC,KAACtF;gBACCsF,OAAO;oBACLU,MAAM,CAAC,uBAAuB,EAAEV,OAAOW,UAAU,CAAC,CAAC,EAAEX,MAAMW,MAAM,CAAC,CAAC,CAAC,EAAE;oBACtEC,SAASZ,OAAOY,WAAW;gBAC7B;iBAEAV,QAAQjC,WAAW,kBACrB,KAAC/D;gBAAO,GAAGiB,KAAK;0BACd,cAAA,KAACf;oBAAW6B,IAAI;wBAAEqC,OAAO,CAACC,QAAUA,MAAMC,OAAO,CAACqC,OAAO,CAACnC,IAAI;oBAAC;8BAAG;;+BAKpE,KAACM;gBAAiBC,oBAAoBA;gBAAoB/D,aAAaA;gBAAagE,WAAWA;;;;AAIvG"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/explore/PrometheusMetricsFinder/overview/tabs/OverviewTab.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 { DatasourceSelector } from '@perses-dev/core';\nimport { ReactElement, useMemo, useState } from 'react';\nimport {\n Autocomplete,\n Button,\n Chip,\n CircularProgress,\n Divider,\n IconButton,\n MenuItem,\n Select,\n SelectChangeEvent,\n Skeleton,\n Stack,\n StackProps,\n TextField,\n Typography,\n useMediaQuery,\n useTheme,\n} from '@mui/material';\nimport PlusIcon from 'mdi-material-ui/Plus';\nimport CheckIcon from 'mdi-material-ui/Check';\nimport CloseIcon from 'mdi-material-ui/Close';\nimport { ErrorAlert } from '@perses-dev/components';\nimport { LabelFilter, LabelValueCounter, Operator } from '../../types';\nimport { ListboxComponent } from '../../filter/FilterInputs';\nimport { useMetricMetadata, useSeriesStates } from '../../utils';\nimport { MetricChip } from '../../display/MetricChip';\n\nexport interface LabelValuesRowProps extends StackProps {\n label: string;\n valueCounters: LabelValueCounter[];\n onFilterAdd: (filter: LabelFilter) => void;\n orderBy?: 'asc' | 'amount';\n}\n\nexport function LabelValuesRow({ label, valueCounters, onFilterAdd, ...props }: LabelValuesRowProps): ReactElement {\n const [isAddingFilter, setIsAddingFilter] = useState(false);\n const [operator, setOperator] = useState<Operator>('=');\n const [value, setValue] = useState('');\n const [showAllValues, setShowAllValues] = useState(false);\n const isMobileSize = useMediaQuery(useTheme().breakpoints.down('md'));\n\n const displayedValueCounters = useMemo(() => {\n if (showAllValues) {\n return valueCounters;\n }\n return valueCounters.slice(0, 5);\n }, [showAllValues, valueCounters]);\n\n return (\n <Stack\n key={label}\n sx={{ width: '100%' }}\n direction={isMobileSize ? 'column' : 'row'}\n alignItems=\"center\"\n gap={2}\n {...props}\n >\n <Stack\n sx={{ width: '100%', height: '100%' }}\n justifyContent=\"space-between\"\n alignContent=\"center\"\n direction={isMobileSize ? 'column' : 'row'}\n >\n <Typography sx={{ fontFamily: 'monospace' }} pl={isMobileSize ? 0 : 1}>\n {label}\n </Typography>\n <Stack direction=\"row\" gap={1} alignItems=\"center\">\n {isAddingFilter ? (\n <>\n <Select\n size=\"small\"\n value={operator}\n variant=\"outlined\"\n onChange={(event: SelectChangeEvent) => {\n setOperator(event.target.value as Operator);\n }}\n >\n <MenuItem value=\"=\">=</MenuItem>\n <MenuItem value=\"!=\">!=</MenuItem>\n <MenuItem value=\"=~\">=~</MenuItem>\n <MenuItem value=\"!~\">!~</MenuItem>\n </Select>\n <Autocomplete\n freeSolo\n limitTags={1}\n disableClearable\n options={valueCounters.map((counters) => counters.labelValue)}\n value={value}\n ListboxComponent={ListboxComponent}\n sx={{ width: 250 }}\n renderInput={(params) => {\n return <TextField {...params} label=\"Value\" variant=\"outlined\" fullWidth size=\"small\" />;\n }}\n onInputChange={(_, newValue) => {\n setValue(newValue);\n }}\n />\n <IconButton\n aria-label=\"confirm\"\n onClick={() => {\n onFilterAdd({ label, labelValues: [value], operator });\n setIsAddingFilter(false);\n }}\n >\n <CheckIcon />\n </IconButton>\n <IconButton\n aria-label=\"cancel\"\n onClick={() => {\n setIsAddingFilter(false);\n }}\n >\n <CloseIcon />\n </IconButton>\n </>\n ) : (\n <Button startIcon={<PlusIcon />} aria-label=\"add filter\" onClick={() => setIsAddingFilter(true)}>\n Add filter\n </Button>\n )}\n </Stack>\n </Stack>\n\n <Stack sx={{ width: '100%' }} gap={0.5}>\n <Stack direction=\"row\" gap={0.5}>\n <Typography variant=\"subtitle1\">{valueCounters.length} values</Typography>\n {valueCounters.length > 5 && (\n <Button variant=\"text\" size=\"small\" sx={{ padding: 0 }} onClick={() => setShowAllValues((prev) => !prev)}>\n {showAllValues ? '[-]' : '[+]'}\n </Button>\n )}\n </Stack>\n\n <Stack sx={{ overflow: isMobileSize ? 'auto' : 'unset' }}>\n {displayedValueCounters.map((labelValueCounter) => (\n <Stack key={`${label}-${labelValueCounter.labelValue}`} direction=\"row\" gap={2}>\n <Typography\n sx={{\n color: (theme) => theme.palette.success.main,\n fontFamily: 'monospace',\n ':hover': { backgroundColor: 'rgba(127,127,127,0.35)', cursor: 'pointer' },\n textWrap: isMobileSize ? 'nowrap' : 'unset',\n }}\n onClick={() => onFilterAdd({ label, labelValues: [labelValueCounter.labelValue], operator: '=' })}\n >\n {labelValueCounter.labelValue}\n </Typography>\n <Typography sx={{ textWrap: 'nowrap' }}>({labelValueCounter.counter} series)</Typography>\n </Stack>\n ))}\n </Stack>\n <Stack width=\"100%\" textAlign={isMobileSize ? 'center' : 'unset'}>\n {showAllValues ? (\n <Button variant=\"text\" sx={{ width: 'fit-content' }} onClick={() => setShowAllValues(false)}>\n Hide full values\n </Button>\n ) : (\n <>\n {valueCounters.length > 5 && (\n <Button variant=\"text\" sx={{ width: 'fit-content' }} onClick={() => setShowAllValues(true)}>\n Show {valueCounters.length - 5} more values\n </Button>\n )}\n </>\n )}\n </Stack>\n </Stack>\n </Stack>\n );\n}\n\nexport interface LabelValuesTableProps extends StackProps {\n labelValueCounters: Map<string, LabelValueCounter[]>;\n isLoading?: boolean;\n onFilterAdd: (filter: LabelFilter) => void;\n}\n\nexport function LabelValuesTable({\n labelValueCounters,\n isLoading,\n onFilterAdd,\n ...props\n}: LabelValuesTableProps): ReactElement {\n const labels: string[] = useMemo(() => {\n return [...labelValueCounters.keys()].sort();\n }, [labelValueCounters]);\n\n if (isLoading) {\n return (\n <Stack width=\"100%\" sx={{ alignItems: 'center', justifyContent: 'center' }}>\n <CircularProgress />\n </Stack>\n );\n }\n\n return (\n <Stack sx={{ width: '100%' }} divider={<Divider flexItem orientation=\"horizontal\" />} gap={2} {...props}>\n <Stack gap={2} direction=\"row\" sx={{ width: '100%' }}>\n <Stack sx={{ width: '100%' }}>\n <Typography variant=\"h3\">Label</Typography>\n </Stack>\n <Stack sx={{ width: '100%' }}>\n <Typography variant=\"h3\">Values</Typography>\n </Stack>\n </Stack>\n {labels.map((label) => (\n <LabelValuesRow\n key={label}\n label={label}\n valueCounters={labelValueCounters.get(label) ?? []}\n onFilterAdd={onFilterAdd}\n />\n ))}\n </Stack>\n );\n}\n\nexport interface OverviewTabProps extends StackProps {\n metricName: string;\n datasource: DatasourceSelector;\n filters: LabelFilter[];\n onFilterAdd: (filter: LabelFilter) => void;\n}\n\nexport function OverviewTab({\n metricName,\n datasource,\n filters,\n onFilterAdd,\n ...props\n}: OverviewTabProps): ReactElement {\n const { metadata, isLoading: isMetadataLoading, error: metadataError } = useMetricMetadata(metricName, datasource);\n const { series, labelValueCounters, isLoading, error } = useSeriesStates(metricName, filters, datasource);\n\n return (\n <Stack gap={2} {...props}>\n <Stack direction=\"row\" gap={3} mt={1} justifyContent=\"space-between\">\n <Stack gap={1}>\n <Typography variant=\"h1\" sx={{ fontFamily: 'monospace' }}>\n {metricName}\n </Typography>\n <Typography>Description:</Typography>\n {isMetadataLoading ? (\n <Skeleton variant=\"text\" width={180} />\n ) : (\n <Typography style={{ fontStyle: metadata?.help ? 'initial' : 'italic' }}>\n {metadataError ? 'Failed to fetch metadata' : (metadata?.help ?? 'unknown')}\n </Typography>\n )}\n </Stack>\n <Stack gap={1} justifyContent=\"center\">\n {isMetadataLoading ? (\n <Skeleton variant=\"rounded\" width={75} />\n ) : metadataError ? (\n <Chip label=\"failed to fetch\" color=\"error\" sx={{ fontStyle: 'italic' }} />\n ) : (\n <MetricChip label={metadata?.type ?? 'unknown'} />\n )}\n <Typography>\n Result:{' '}\n {isLoading ? (\n <Skeleton variant=\"text\" width={20} sx={{ display: 'inline-block' }} />\n ) : error ? (\n <strong>failed to fetch series</strong>\n ) : (\n <strong>{series?.length ?? 'unknown'} series</strong>\n )}\n </Typography>\n </Stack>\n </Stack>\n\n {error ? (\n <ErrorAlert\n error={{\n name: `Failed to fetch series ${error?.status && `(${error.status})`}`,\n message: error?.message ?? 'Failed to fetch series',\n }}\n />\n ) : series?.length === 0 ? (\n <Stack {...props}>\n <Typography sx={{ color: (theme) => theme.palette.warning.main }}>\n No series found with current filters.\n </Typography>\n </Stack>\n ) : (\n <LabelValuesTable labelValueCounters={labelValueCounters} onFilterAdd={onFilterAdd} isLoading={isLoading} />\n )}\n </Stack>\n );\n}\n"],"names":["useMemo","useState","Autocomplete","Button","Chip","CircularProgress","Divider","IconButton","MenuItem","Select","Skeleton","Stack","TextField","Typography","useMediaQuery","useTheme","PlusIcon","CheckIcon","CloseIcon","ErrorAlert","ListboxComponent","useMetricMetadata","useSeriesStates","MetricChip","LabelValuesRow","label","valueCounters","onFilterAdd","props","isAddingFilter","setIsAddingFilter","operator","setOperator","value","setValue","showAllValues","setShowAllValues","isMobileSize","breakpoints","down","displayedValueCounters","slice","sx","width","direction","alignItems","gap","height","justifyContent","alignContent","fontFamily","pl","size","variant","onChange","event","target","freeSolo","limitTags","disableClearable","options","map","counters","labelValue","renderInput","params","fullWidth","onInputChange","_","newValue","aria-label","onClick","labelValues","startIcon","length","padding","prev","overflow","labelValueCounter","color","theme","palette","success","main","backgroundColor","cursor","textWrap","counter","textAlign","LabelValuesTable","labelValueCounters","isLoading","labels","keys","sort","divider","flexItem","orientation","get","OverviewTab","metricName","datasource","filters","metadata","isMetadataLoading","error","metadataError","series","mt","style","fontStyle","help","type","display","strong","name","status","message","warning"],"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;;AAGjC,SAAuBA,OAAO,EAAEC,QAAQ,QAAQ,QAAQ;AACxD,SACEC,YAAY,EACZC,MAAM,EACNC,IAAI,EACJC,gBAAgB,EAChBC,OAAO,EACPC,UAAU,EACVC,QAAQ,EACRC,MAAM,EAENC,QAAQ,EACRC,KAAK,EAELC,SAAS,EACTC,UAAU,EACVC,aAAa,EACbC,QAAQ,QACH,gBAAgB;AACvB,OAAOC,cAAc,uBAAuB;AAC5C,OAAOC,eAAe,wBAAwB;AAC9C,OAAOC,eAAe,wBAAwB;AAC9C,SAASC,UAAU,QAAQ,yBAAyB;AAEpD,SAASC,gBAAgB,QAAQ,4BAA4B;AAC7D,SAASC,iBAAiB,EAAEC,eAAe,QAAQ,cAAc;AACjE,SAASC,UAAU,QAAQ,2BAA2B;AAStD,OAAO,SAASC,eAAe,EAAEC,KAAK,EAAEC,aAAa,EAAEC,WAAW,EAAE,GAAGC,OAA4B;IACjG,MAAM,CAACC,gBAAgBC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C,SAAQ;gCAAUV,OAAO;iCACjC+D,8BACF,KAACtG;gCAAKqB,OAAM;gCAAkBsD,OAAM;gCAAQrC,IAAI;oCAAEoE,WAAW;gCAAS;+CAEtE,KAACvF;gCAAWE,OAAO8E,UAAUS,QAAQ;;0CAEvC,MAACnG;;oCAAW;oCACF;oCACP8E,0BACC,KAACjF;wCAAS2C,SAAQ;wCAAOV,OAAO;wCAAID,IAAI;4CAAEuE,SAAS;wCAAe;yCAChER,sBACF,KAACS;kDAAO;uDAER,MAACA;;4CAAQP,QAAQjC,UAAU;4CAAU;;;;;;;;;YAM5C+B,sBACC,KAACtF;gBACCsF,OAAO;oBACLU,MAAM,CAAC,uBAAuB,EAAEV,OAAOW,UAAU,CAAC,CAAC,EAAEX,MAAMW,MAAM,CAAC,CAAC,CAAC,EAAE;oBACtEC,SAASZ,OAAOY,WAAW;gBAC7B;iBAEAV,QAAQjC,WAAW,kBACrB,KAAC/D;gBAAO,GAAGiB,KAAK;0BACd,cAAA,KAACf;oBAAW6B,IAAI;wBAAEqC,OAAO,CAACC,QAAUA,MAAMC,OAAO,CAACqC,OAAO,CAACnC,IAAI;oBAAC;8BAAG;;+BAKpE,KAACM;gBAAiBC,oBAAoBA;gBAAoB/D,aAAaA;gBAAagE,WAAWA;;;;AAIvG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../src/explore/PrometheusMetricsFinder/overview/tabs/SimilarTab.tsx"],"sourcesContent":["// Copyright
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/explore/PrometheusMetricsFinder/overview/tabs/SimilarTab.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 { DatasourceSelector } from '@perses-dev/core';\nimport { CircularProgress, Stack, StackProps } from '@mui/material';\nimport { ReactElement, useMemo } from 'react';\nimport { MetricList } from '../../display/list/MetricList';\nimport { LabelFilter } from '../../types';\nimport { useLabelValues } from '../../utils';\n\nexport interface SimilarTabProps extends StackProps {\n filters: LabelFilter[];\n datasource: DatasourceSelector;\n isMetadataEnabled?: boolean;\n onExplore: (metricName: string) => void;\n}\n\nexport function SimilarTab({\n filters,\n datasource,\n isMetadataEnabled,\n onExplore,\n ...props\n}: SimilarTabProps): ReactElement {\n const filtersWithoutName: LabelFilter[] = useMemo(() => {\n return filters.filter((filter) => filter.label !== '__name__');\n }, [filters]);\n const { data, isLoading } = useLabelValues('__name__', filtersWithoutName, datasource);\n\n if (isLoading) {\n return (\n <Stack width=\"100%\" sx={{ alignItems: 'center', justifyContent: 'center' }}>\n <CircularProgress />\n </Stack>\n );\n }\n\n return (\n <MetricList\n metricNames={data?.data ?? []}\n datasource={datasource}\n filters={filtersWithoutName}\n isMetadataEnabled={isMetadataEnabled}\n onExplore={onExplore}\n {...props}\n />\n );\n}\n"],"names":["CircularProgress","Stack","useMemo","MetricList","useLabelValues","SimilarTab","filters","datasource","isMetadataEnabled","onExplore","props","filtersWithoutName","filter","label","data","isLoading","width","sx","alignItems","justifyContent","metricNames"],"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;;AAGjC,SAASA,gBAAgB,EAAEC,KAAK,QAAoB,gBAAgB;AACpE,SAAuBC,OAAO,QAAQ,QAAQ;AAC9C,SAASC,UAAU,QAAQ,gCAAgC;AAE3D,SAASC,cAAc,QAAQ,cAAc;AAS7C,OAAO,SAASC,WAAW,EACzBC,OAAO,EACPC,UAAU,EACVC,iBAAiB,EACjBC,SAAS,EACT,GAAGC,OACa;IAChB,MAAMC,qBAAoCT,QAAQ;QAChD,OAAOI,QAAQM,MAAM,CAAC,CAACA,SAAWA,OAAOC,KAAK,KAAK;IACrD,GAAG;QAACP;KAAQ;IACZ,MAAM,EAAEQ,IAAI,EAAEC,SAAS,EAAE,GAAGX,eAAe,YAAYO,oBAAoBJ;IAE3E,IAAIQ,WAAW;QACb,qBACE,KAACd;YAAMe,OAAM;YAAOC,IAAI;gBAAEC,YAAY;gBAAUC,gBAAgB;YAAS;sBACvE,cAAA,KAACnB;;IAGP;IAEA,qBACE,KAACG;QACCiB,aAAaN,MAAMA,QAAQ,EAAE;QAC7BP,YAAYA;QACZD,SAASK;QACTH,mBAAmBA;QACnBC,WAAWA;QACV,GAAGC,KAAK;;AAGf"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/explore/PrometheusMetricsFinder/types.ts"],"sourcesContent":["// Copyright
|
|
1
|
+
{"version":3,"sources":["../../../../src/explore/PrometheusMetricsFinder/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 { DatasourceSelector } from '@perses-dev/core';\n\nexport type Operator = '=' | '!=' | '=~' | '!~';\n\nexport interface Settings {\n isMetadataEnabled: boolean;\n isPanelEnabled: boolean;\n}\n\nexport interface FinderQueryParams {\n datasource?: DatasourceSelector;\n filters?: LabelFilter[];\n exploredMetric?: string;\n}\n\nexport interface LabelFilter {\n label: string;\n labelValues: string[];\n operator: Operator;\n}\n\nexport function computeFilterExpr(filters: LabelFilter[]): string {\n return `${filters.map((filter) => `${filter.label}${filter.operator}\"${filter.labelValues.join('|')}\"`).join(',')}`;\n}\n\nexport interface LabelValueCounter {\n labelValue: string;\n counter: number;\n}\n"],"names":["computeFilterExpr","filters","map","filter","label","operator","labelValues","join"],"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;AAuBjC,OAAO,SAASA,kBAAkBC,OAAsB;IACtD,OAAO,GAAGA,QAAQC,GAAG,CAAC,CAACC,SAAW,GAAGA,OAAOC,KAAK,GAAGD,OAAOE,QAAQ,CAAC,CAAC,EAAEF,OAAOG,WAAW,CAACC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAEA,IAAI,CAAC,MAAM;AACrH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/explore/PrometheusMetricsFinder/utils.ts"],"sourcesContent":["// Copyright 2024 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { DatasourceSelector, StatusError } from '@perses-dev/core';\nimport { useDatasourceClient, useTimeRange } from '@perses-dev/plugin-system';\nimport { useQuery, UseQueryResult } from '@tanstack/react-query';\nimport { useMemo } from 'react';\nimport {\n LabelNamesRequestParameters,\n LabelValuesRequestParameters,\n LabelValuesResponse,\n Metric,\n MetricMetadata,\n MetricMetadataRequestParameters,\n MetricMetadataResponse,\n PrometheusClient,\n SeriesRequestParameters,\n SeriesResponse,\n} from '../../model';\nimport { computeFilterExpr, LabelFilter, LabelValueCounter } from './types';\n\n// Retrieve metric metadata from the Prometheus API\nexport function useMetricMetadata(\n metricName: string,\n datasource: DatasourceSelector,\n enabled?: boolean\n): {\n isLoading: false | true;\n metadata: MetricMetadata | undefined;\n error: StatusError | null;\n} {\n const { data: client } = useDatasourceClient<PrometheusClient>(datasource);\n\n // histograms and summaries timeseries desc are not always added to prefixed timeseries\n const name = metricName.replace(/(_count|_sum|_bucket)$/, '');\n\n const { data, isLoading, error } = useQuery<MetricMetadataResponse, StatusError>({\n enabled: !!client && enabled,\n queryKey: ['metricMetadata', name], // Not indexed on datasource, assuming a metric metadata should be similar across datasources\n queryFn: async () => {\n const params: MetricMetadataRequestParameters = { metric: name };\n\n return await client!.metricMetadata(params);\n },\n });\n\n // Find the first result with help text\n const metadata: MetricMetadata | undefined = useMemo(() => {\n for (const metric of data?.data?.[name] ?? []) {\n if (metric.help.length > 0) {\n return metric;\n }\n }\n return undefined;\n }, [data, name]);\n\n return { metadata, isLoading, error };\n}\n\nexport function useLabels(\n filters: LabelFilter[],\n datasource: DatasourceSelector\n): UseQueryResult<LabelValuesResponse, StatusError> {\n const {\n absoluteTimeRange: { start, end },\n } = useTimeRange();\n const { data: client } = useDatasourceClient<PrometheusClient>(datasource);\n\n return useQuery<LabelValuesResponse, StatusError>({\n enabled: !!client,\n queryKey: ['labels', 'datasource', datasource.name, 'start', start, 'end', end, 'filters', ...filters],\n queryFn: async () => {\n const params: LabelNamesRequestParameters = {\n start: start.valueOf() / 1000,\n end: end.valueOf() / 1000,\n };\n if (filters.length) {\n params['match[]'] = [`{${computeFilterExpr(filters)}}`];\n }\n\n return await client!.labelNames(params);\n },\n });\n}\n\n// Retrieve label values from the Prometheus API for a given label name and filters\nexport function useLabelValues(\n labelName: string,\n filters: LabelFilter[],\n datasource: DatasourceSelector\n): UseQueryResult<LabelValuesResponse, StatusError> {\n const {\n absoluteTimeRange: { start, end },\n } = useTimeRange();\n const { data: client } = useDatasourceClient<PrometheusClient>(datasource);\n\n return useQuery<LabelValuesResponse, StatusError>({\n enabled: !!client,\n queryKey: ['labelValues', labelName, 'datasource', datasource.name, 'start', start, 'end', 'filters', ...filters],\n queryFn: async () => {\n const params: LabelValuesRequestParameters = {\n labelName: labelName,\n start: start.valueOf() / 1000,\n end: end.valueOf() / 1000,\n };\n if (filters.length) {\n params['match[]'] = [`{${computeFilterExpr(filters)}}`];\n }\n\n return await client!.labelValues(params);\n },\n });\n}\n\n// Retrieve series from the Prometheus API for a given metric name and filters\n// Also computes the number of times a label value appears for the given metric name and filters\nexport function useSeriesStates(\n metricName: string,\n filters: LabelFilter[],\n datasource: DatasourceSelector\n): {\n series: Metric[] | undefined;\n labelValueCounters: Map<string, Array<{ labelValue: string; counter: number }>>;\n isLoading: boolean;\n isError: boolean;\n error: StatusError | null;\n} {\n const {\n absoluteTimeRange: { start, end },\n } = useTimeRange();\n const { data: client } = useDatasourceClient<PrometheusClient>(datasource);\n\n const {\n data: seriesData,\n isLoading,\n isError,\n error,\n } = useQuery<SeriesResponse, StatusError>({\n enabled: !!client,\n queryKey: ['series', metricName, 'datasource', datasource, 'start', start, 'end', 'filters', ...filters],\n queryFn: async () => {\n const params: SeriesRequestParameters = {\n 'match[]': [`{${computeFilterExpr(filters)}}`],\n start: start.valueOf() / 1000,\n end: end.valueOf() / 1000,\n };\n\n return await client!.series(params);\n },\n });\n\n const labelValueCounters: Map<string, Array<{ labelValue: string; counter: number }>> = useMemo(() => {\n const result = new Map<string, LabelValueCounter[]>();\n if (seriesData?.data === undefined) {\n return result;\n }\n\n for (const series of seriesData.data) {\n for (const [label, value] of Object.entries(series)) {\n const labelCounters = result.get(label);\n if (labelCounters === undefined) {\n result.set(label, [{ labelValue: value, counter: 1 }]);\n continue;\n }\n\n const labelValueCounter = labelCounters.find((counter) => counter.labelValue === value);\n if (labelValueCounter === undefined) {\n labelCounters.push({ labelValue: value, counter: 1 });\n } else {\n labelValueCounter.counter += 1;\n }\n }\n }\n\n return result;\n }, [seriesData]);\n\n return { series: seriesData?.data, labelValueCounters, isLoading, isError, error };\n}\n"],"names":["useDatasourceClient","useTimeRange","useQuery","useMemo","computeFilterExpr","useMetricMetadata","metricName","datasource","enabled","data","client","name","replace","isLoading","error","queryKey","queryFn","params","metric","metricMetadata","metadata","help","length","undefined","useLabels","filters","absoluteTimeRange","start","end","valueOf","labelNames","useLabelValues","labelName","labelValues","useSeriesStates","seriesData","isError","series","labelValueCounters","result","Map","label","value","Object","entries","labelCounters","get","set","labelValue","counter","labelValueCounter","find","push"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAGjC,SAASA,mBAAmB,EAAEC,YAAY,QAAQ,4BAA4B;AAC9E,SAASC,QAAQ,QAAwB,wBAAwB;AACjE,SAASC,OAAO,QAAQ,QAAQ;AAahC,SAASC,iBAAiB,QAAwC,UAAU;AAE5E,mDAAmD;AACnD,OAAO,SAASC,kBACdC,UAAkB,EAClBC,UAA8B,EAC9BC,OAAiB;IAMjB,MAAM,EAAEC,MAAMC,MAAM,EAAE,GAAGV,oBAAsCO;IAE/D,uFAAuF;IACvF,MAAMI,OAAOL,WAAWM,OAAO,CAAC,0BAA0B;IAE1D,MAAM,EAAEH,IAAI,EAAEI,SAAS,EAAEC,KAAK,EAAE,GAAGZ,SAA8C;QAC/EM,SAAS,CAAC,CAACE,UAAUF;QACrBO,UAAU;YAAC;YAAkBJ;SAAK;QAClCK,SAAS;YACP,MAAMC,SAA0C;gBAAEC,QAAQP;YAAK;YAE/D,OAAO,MAAMD,OAAQS,cAAc,CAACF;QACtC;IACF;IAEA,uCAAuC;IACvC,MAAMG,WAAuCjB,QAAQ;QACnD,KAAK,MAAMe,UAAUT,MAAMA,MAAM,CAACE,KAAK,IAAI,EAA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AC;4BAAEO,YAAYN;4BAAOO,SAAS;wBAAE;qBAAE;oBACrD;gBACF;gBAEA,MAAMC,oBAAoBL,cAAcM,IAAI,CAAC,CAACF,UAAYA,QAAQD,UAAU,KAAKN;gBACjF,IAAIQ,sBAAsB3B,WAAW;oBACnCsB,cAAcO,IAAI,CAAC;wBAAEJ,YAAYN;wBAAOO,SAAS;oBAAE;gBACrD,OAAO;oBACLC,kBAAkBD,OAAO,IAAI;gBAC/B;YACF;QACF;QAEA,OAAOV;IACT,GAAG;QAACJ;KAAW;IAEf,OAAO;QAAEE,QAAQF,YAAY1B;QAAM6B;QAAoBzB;QAAWuB;QAAStB;IAAM;AACnF"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/explore/PrometheusMetricsFinder/utils.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 { DatasourceSelector, StatusError } from '@perses-dev/core';\nimport { useDatasourceClient, useTimeRange } from '@perses-dev/plugin-system';\nimport { useQuery, UseQueryResult } from '@tanstack/react-query';\nimport { useMemo } from 'react';\nimport {\n LabelNamesRequestParameters,\n LabelValuesRequestParameters,\n LabelValuesResponse,\n Metric,\n MetricMetadata,\n MetricMetadataRequestParameters,\n MetricMetadataResponse,\n PrometheusClient,\n SeriesRequestParameters,\n SeriesResponse,\n} from '../../model';\nimport { computeFilterExpr, LabelFilter, LabelValueCounter } from './types';\n\n// Retrieve metric metadata from the Prometheus API\nexport function useMetricMetadata(\n metricName: string,\n datasource: DatasourceSelector,\n enabled?: boolean\n): {\n isLoading: false | true;\n metadata: MetricMetadata | undefined;\n error: StatusError | null;\n} {\n const { data: client } = useDatasourceClient<PrometheusClient>(datasource);\n\n // histograms and summaries timeseries desc are not always added to prefixed timeseries\n const name = metricName.replace(/(_count|_sum|_bucket)$/, '');\n\n const { data, isLoading, error } = useQuery<MetricMetadataResponse, StatusError>({\n enabled: !!client && enabled,\n queryKey: ['metricMetadata', name], // Not indexed on datasource, assuming a metric metadata should be similar across datasources\n queryFn: async () => {\n const params: MetricMetadataRequestParameters = { metric: name };\n\n return await client!.metricMetadata(params);\n },\n });\n\n // Find the first result with help text\n const metadata: MetricMetadata | undefined = useMemo(() => {\n for (const metric of data?.data?.[name] ?? []) {\n if (metric.help.length > 0) {\n return metric;\n }\n }\n return undefined;\n }, [data, name]);\n\n return { metadata, isLoading, error };\n}\n\nexport function useLabels(\n filters: LabelFilter[],\n datasource: DatasourceSelector\n): UseQueryResult<LabelValuesResponse, StatusError> {\n const {\n absoluteTimeRange: { start, end },\n } = useTimeRange();\n const { data: client } = useDatasourceClient<PrometheusClient>(datasource);\n\n return useQuery<LabelValuesResponse, StatusError>({\n enabled: !!client,\n queryKey: ['labels', 'datasource', datasource.name, 'start', start, 'end', end, 'filters', ...filters],\n queryFn: async () => {\n const params: LabelNamesRequestParameters = {\n start: start.valueOf() / 1000,\n end: end.valueOf() / 1000,\n };\n if (filters.length) {\n params['match[]'] = [`{${computeFilterExpr(filters)}}`];\n }\n\n return await client!.labelNames(params);\n },\n });\n}\n\n// Retrieve label values from the Prometheus API for a given label name and filters\nexport function useLabelValues(\n labelName: string,\n filters: LabelFilter[],\n datasource: DatasourceSelector\n): UseQueryResult<LabelValuesResponse, StatusError> {\n const {\n absoluteTimeRange: { start, end },\n } = useTimeRange();\n const { data: client } = useDatasourceClient<PrometheusClient>(datasource);\n\n return useQuery<LabelValuesResponse, StatusError>({\n enabled: !!client,\n queryKey: ['labelValues', labelName, 'datasource', datasource.name, 'start', start, 'end', 'filters', ...filters],\n queryFn: async () => {\n const params: LabelValuesRequestParameters = {\n labelName: labelName,\n start: start.valueOf() / 1000,\n end: end.valueOf() / 1000,\n };\n if (filters.length) {\n params['match[]'] = [`{${computeFilterExpr(filters)}}`];\n }\n\n return await client!.labelValues(params);\n },\n });\n}\n\n// Retrieve series from the Prometheus API for a given metric name and filters\n// Also computes the number of times a label value appears for the given metric name and filters\nexport function useSeriesStates(\n metricName: string,\n filters: LabelFilter[],\n datasource: DatasourceSelector\n): {\n series: Metric[] | undefined;\n labelValueCounters: Map<string, Array<{ labelValue: string; counter: number }>>;\n isLoading: boolean;\n isError: boolean;\n error: StatusError | null;\n} {\n const {\n absoluteTimeRange: { start, end },\n } = useTimeRange();\n const { data: client } = useDatasourceClient<PrometheusClient>(datasource);\n\n const {\n data: seriesData,\n isLoading,\n isError,\n error,\n } = useQuery<SeriesResponse, StatusError>({\n enabled: !!client,\n queryKey: ['series', metricName, 'datasource', datasource, 'start', start, 'end', 'filters', ...filters],\n queryFn: async () => {\n const params: SeriesRequestParameters = {\n 'match[]': [`{${computeFilterExpr(filters)}}`],\n start: start.valueOf() / 1000,\n end: end.valueOf() / 1000,\n };\n\n return await client!.series(params);\n },\n });\n\n const labelValueCounters: Map<string, Array<{ labelValue: string; counter: number }>> = useMemo(() => {\n const result = new Map<string, LabelValueCounter[]>();\n if (seriesData?.data === undefined) {\n return result;\n }\n\n for (const series of seriesData.data) {\n for (const [label, value] of Object.entries(series)) {\n const labelCounters = result.get(label);\n if (labelCounters === undefined) {\n result.set(label, [{ labelValue: value, counter: 1 }]);\n continue;\n }\n\n const labelValueCounter = labelCounters.find((counter) => counter.labelValue === value);\n if (labelValueCounter === undefined) {\n labelCounters.push({ labelValue: value, counter: 1 });\n } else {\n labelValueCounter.counter += 1;\n }\n }\n }\n\n return result;\n }, [seriesData]);\n\n return { series: seriesData?.data, labelValueCounters, isLoading, isError, error };\n}\n"],"names":["useDatasourceClient","useTimeRange","useQuery","useMemo","computeFilterExpr","useMetricMetadata","metricName","datasource","enabled","data","client","name","replace","isLoading","error","queryKey","queryFn","params","metric","metricMetadata","metadata","help","length","undefined","useLabels","filters","absoluteTimeRange","start","end","valueOf","labelNames","useLabelValues","labelName","labelValues","useSeriesStates","seriesData","isError","series","labelValueCounters","result","Map","label","value","Object","entries","labelCounters","get","set","labelValue","counter","labelValueCounter","find","push"],"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;AAGjC,SAASA,mBAAmB,EAAEC,YAAY,QAAQ,4BAA4B;AAC9E,SAASC,QAAQ,QAAwB,wBAAwB;AACjE,SAASC,OAAO,QAAQ,QAAQ;AAahC,SAASC,iBAAiB,QAAwC,UAAU;AAE5E,mDAAmD;AACnD,OAAO,SAASC,kBACdC,UAAkB,EAClBC,UAA8B,EAC9BC,OAAiB;IAMjB,MAAM,EAAEC,MAAMC,MAAM,EAAE,GAAGV,oBAAsCO;IAE/D,uFAAuF;IACvF,MAAMI,OAAOL,WAAWM,OAAO,CAAC,0BAA0B;IAE1D,MAAM,EAAEH,IAAI,EAAEI,SAAS,EAAEC,KAAK,EAAE,GAAGZ,SAA8C;QAC/EM,SAAS,CAAC,CAACE,UAAUF;QACrBO,UAAU;YAAC;YAAkBJ;SAAK;QAClCK,SAAS;YACP,MAAMC,SAA0C;gBAAEC,QAAQP;YAAK;YAE/D,OAAO,MAAMD,OAAQS,cAAc,CAACF;QACtC;IACF;IAEA,uCAAuC;IACvC,MAAMG,WAAuCjB,QAAQ;QACnD,KAAK,MAAMe,UAAUT,MAAMA,MAAM,CAACE,KAAK,IAAI,EAAE,CAAE;YAC7C,IAAIO,OAAOG,IAAI,CAACC,MAAM,GAAG,GAAG;gBAC1B,OAAOJ;YACT;QACF;QACA,OAAOK;IACT,GAAG;QAACd;QAAME;KAAK;IAEf,OAAO;QAAES;QAAUP;QAAWC;IAAM;AACtC;AAEA,OAAO,SA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,IAAI,CAAC;wBAAEJ,YAAYN;wBAAOO,SAAS;oBAAE;gBACrD,OAAO;oBACLC,kBAAkBD,OAAO,IAAI;gBAC/B;YACF;QACF;QAEA,OAAOV;IACT,GAAG;QAACJ;KAAW;IAEf,OAAO;QAAEE,QAAQF,YAAY1B;QAAM6B;QAAoBzB;QAAWuB;QAAStB;IAAM;AACnF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/explore/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/explore/index.ts"],"names":[],"mappings":"AAaA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,sBAAsB,CAAC"}
|
package/lib/explore/index.js
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
// Copyright The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the \"License\");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an \"AS IS\" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
1
13
|
export * from './PrometheusMetricsFinder';
|
|
2
14
|
export * from './PrometheusExplorer';
|
|
3
15
|
|
package/lib/explore/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/explore/index.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../../src/explore/index.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\nexport * from './PrometheusMetricsFinder';\nexport * from './PrometheusExplorer';\n"],"names":[],"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,cAAc,4BAA4B;AAC1C,cAAc,uBAAuB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getPluginModule.d.ts","sourceRoot":"","sources":["../../src/getPluginModule.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getPluginModule.d.ts","sourceRoot":"","sources":["../../src/getPluginModule.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,oBAAoB,EAAoB,MAAM,2BAA2B,CAAC;AAGnF;;GAEG;AACH,wBAAgB,eAAe,IAAI,oBAAoB,CAUtD"}
|
package/lib/getPluginModule.js
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
// Copyright The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the \"License\");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an \"AS IS\" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
1
13
|
import packageJson from '../package.json';
|
|
2
14
|
/**
|
|
3
15
|
* Returns the plugin module information from package.json
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/getPluginModule.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../src/getPluginModule.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 { PluginModuleResource, PluginModuleSpec } from '@perses-dev/plugin-system';\nimport packageJson from '../package.json';\n\n/**\n * Returns the plugin module information from package.json\n */\nexport function getPluginModule(): PluginModuleResource {\n const { name, version, perses } = packageJson;\n return {\n kind: 'PluginModule',\n metadata: {\n name,\n version,\n },\n spec: perses as PluginModuleSpec,\n };\n}\n"],"names":["packageJson","getPluginModule","name","version","perses","kind","metadata","spec"],"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;AAGjC,OAAOA,iBAAiB,kBAAkB;AAE1C;;CAEC,GACD,OAAO,SAASC;IACd,MAAM,EAAEC,IAAI,EAAEC,OAAO,EAAEC,MAAM,EAAE,GAAGJ;IAClC,OAAO;QACLK,MAAM;QACNC,UAAU;YACRJ;YACAC;QACF;QACAI,MAAMH;IACR;AACF"}
|
package/lib/index-federation.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index-federation.ts"],"sourcesContent":["// Copyright
|
|
1
|
+
{"version":3,"sources":["../../src/index-federation.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('./bootstrap');\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;AAEjC,MAAM,CAAC"}
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAaA,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
// Copyright The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the \"License\");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an \"AS IS\" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
1
13
|
export * from './components';
|
|
2
14
|
export * from './explore';
|
|
3
15
|
export { getPluginModule } from './getPluginModule';
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../src/index.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\nexport * from './components';\nexport * from './explore';\nexport { getPluginModule } from './getPluginModule';\nexport * from './model';\nexport * from './plugins';\n"],"names":["getPluginModule"],"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,cAAc,eAAe;AAC7B,cAAc,YAAY;AAC1B,SAASA,eAAe,QAAQ,oBAAoB;AACpD,cAAc,UAAU;AACxB,cAAc,YAAY"}
|
package/lib/model/api-types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/model/api-types.ts"],"sourcesContent":["// Copyright
|
|
1
|
+
{"version":3,"sources":["../../../src/model/api-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 { DurationString } from '@perses-dev/core';\nimport ASTNode from '../components/promql/ast';\n\n// Just reuse dashboard model's type and re-export\nexport type { DurationString };\n\nexport interface SuccessResponse<T> {\n status: 'success';\n data: T;\n rawResponse?: Response;\n warnings?: string[];\n}\n\nexport interface ErrorResponse<T> {\n status: 'error';\n data?: T;\n errorType: string;\n error: string;\n}\n\nexport type ApiResponse<T> = SuccessResponse<T> | ErrorResponse<T>;\n\nexport type DurationSeconds = number;\n\nexport type UnixTimestampSeconds = number;\n\nexport type ValueTuple = [unixTimeSeconds: UnixTimestampSeconds, sampleValue: string];\n\nexport type BucketTuple = [bucket: number, upperBound: string, lowerBound: string, count: string];\n\nexport type HistogramValue = { count: number; sum: string; buckets?: BucketTuple[] };\n\nexport type HistogramTuple = [unixTimeSeconds: UnixTimestampSeconds, value: HistogramValue];\n\nexport type Metric = Record<string, string>;\n\nexport interface VectorData {\n resultType: 'vector';\n result: Array<{\n metric: Metric;\n value: ValueTuple;\n histogram?: HistogramTuple;\n }>;\n}\n\nexport interface MatrixData {\n resultType: 'matrix';\n result: Array<{\n metric: Metric;\n values: ValueTuple[];\n histograms?: HistogramTuple[];\n }>;\n}\n\nexport interface ScalarData {\n resultType: 'scalar';\n result: ValueTuple;\n}\n\nexport interface StringData {\n resultType: 'string';\n result: ValueTuple;\n}\n\nexport interface InstantQueryRequestParameters {\n query: string;\n time?: UnixTimestampSeconds;\n timeout?: DurationString;\n}\n\nexport type InstantQueryResultType = MatrixData | VectorData | ScalarData | StringData;\n\n// Ref https://prometheus.io/docs/prometheus/latest/querying/api/#instant-queries\nexport type InstantQueryResponse = ApiResponse<InstantQueryResultType>;\n\nexport type MonitoredInstantQueryResponse = InstantQueryResponse & {\n responseTime: number;\n};\n\nexport interface RangeQueryRequestParameters {\n query: string;\n start: UnixTimestampSeconds;\n end: UnixTimestampSeconds;\n step: DurationSeconds;\n timeout?: DurationString;\n}\n\nexport type RangeQueryResponse = ApiResponse<MatrixData>;\n\nexport interface SeriesRequestParameters {\n 'match[]': string[];\n start?: UnixTimestampSeconds;\n end?: UnixTimestampSeconds;\n limit?: number;\n}\n\nexport type SeriesResponse = ApiResponse<Metric[]>;\n\nexport interface LabelNamesRequestParameters {\n start?: UnixTimestampSeconds;\n end?: UnixTimestampSeconds;\n 'match[]'?: string[];\n limit?: number;\n}\n\nexport type LabelNamesResponse = ApiResponse<string[]>;\n\nexport interface LabelValuesRequestParameters {\n labelName: string;\n start?: UnixTimestampSeconds;\n end?: UnixTimestampSeconds;\n 'match[]'?: string[];\n limit?: number;\n}\n\nexport type LabelValuesResponse = ApiResponse<string[]>;\n\nexport interface MetricMetadata {\n type: string;\n help: string;\n unit?: string;\n}\n\nexport interface MetricMetadataRequestParameters {\n limit?: number;\n metric?: string;\n}\n\nexport type MetricMetadataResponse = ApiResponse<Record<string, MetricMetadata[]>>;\n\n// ref: https://prometheus.io/docs/prometheus/3.0/querying/api/#parsing-a-promql-expressions-into-a-abstract-syntax-tree-ast\nexport interface ParseQueryRequestParameters {\n query: string;\n}\n\nexport type ParseQueryResponse = ApiResponse<ASTNode>;\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;AAyIjC,WAAsD"}
|
package/lib/model/index.js
CHANGED
package/lib/model/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/model/index.ts"],"sourcesContent":["// Copyright
|
|
1
|
+
{"version":3,"sources":["../../../src/model/index.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\nexport * from './api-types';\nexport * from './parse-sample-values';\nexport * from './prometheus-client';\nexport * from './prometheus-selectors';\nexport * from './time';\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;AAEjC,cAAc,cAAc;AAC5B,cAAc,wBAAwB;AACtC,cAAc,sBAAsB;AACpC,cAAc,yBAAyB;AACvC,cAAc,SAAS"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/model/parse-sample-values.ts"],"sourcesContent":["// Copyright
|
|
1
|
+
{"version":3,"sources":["../../../src/model/parse-sample-values.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { ValueTuple } from './api-types';\n\n/**\n * ValueTuple from the Prom server, parsed into ms and floating point number\n */\nexport type ParsedValueTuple = [unixTimeMs: number, value: number];\n\n/**\n * Parse a ValueTuple from a PromServer response into the a millisecond-based\n * unix time and a numeric sample value.\n */\nexport function parseValueTuple(data: ValueTuple): ParsedValueTuple {\n const [unixTimeSeconds, sampleValue] = data;\n\n // Prom returns unix time in seconds, so convert to ms\n return [unixTimeSeconds * 1000, parseSampleValue(sampleValue)];\n}\n\n/**\n * Parses a string sample value from Prometheus, usually included as the\n * second member of a ValueTuple.\n */\nexport function parseSampleValue(sampleValue: ValueTuple[1]): number {\n // Account for Prometheus' representation of +/- infinity, otherwise just\n // parse the sample value as a float\n let value: number;\n switch (sampleValue) {\n case '+Inf':\n value = Number.POSITIVE_INFINITY;\n break;\n case '-Inf':\n value = Number.NEGATIVE_INFINITY;\n break;\n default:\n value = parseFloat(sampleValue);\n }\n return value;\n}\n"],"names":["parseValueTuple","data","unixTimeSeconds","sampleValue","parseSampleValue","value","Number","POSITIVE_INFINITY","NEGATIVE_INFINITY","parseFloat"],"mappings":"AAAA,+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;AASjC;;;CAGC,GACD,OAAO,SAASA,gBAAgBC,IAAgB;IAC9C,MAAM,CAACC,iBAAiBC,YAAY,GAAGF;IAEvC,sDAAsD;IACtD,OAAO;QAACC,kBAAkB;QAAME,iBAAiBD;KAAa;AAChE;AAEA;;;CAGC,GACD,OAAO,SAASC,iBAAiBD,WAA0B;IACzD,yEAAyE;IACzE,oCAAoC;IACpC,IAAIE;IACJ,OAAQF;QACN,KAAK;YACHE,QAAQC,OAAOC,iBAAiB;YAChC;QACF,KAAK;YACHF,QAAQC,OAAOE,iBAAiB;YAChC;QACF;YACEH,QAAQI,WAAWN;IACvB;IACA,OAAOE;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/model/prometheus-client.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { fetch, fetchJson, RequestHeaders } from '@perses-dev/core';\nimport { DatasourceClient } from '@perses-dev/plugin-system';\nimport {\n InstantQueryRequestParameters,\n InstantQueryResponse,\n LabelNamesRequestParameters,\n LabelNamesResponse,\n LabelValuesRequestParameters,\n LabelValuesResponse,\n MetricMetadataRequestParameters,\n MetricMetadataResponse,\n ParseQueryRequestParameters,\n ParseQueryResponse,\n RangeQueryRequestParameters,\n RangeQueryResponse,\n SeriesRequestParameters,\n SeriesResponse,\n SuccessResponse,\n} from './api-types';\n\ninterface PrometheusClientOptions {\n datasourceUrl: string;\n headers?: RequestHeaders;\n}\n\nexport interface PrometheusClient extends DatasourceClient {\n options: PrometheusClientOptions;\n instantQuery(\n params: InstantQueryRequestParameters,\n headers?: RequestHeaders,\n signal?: AbortSignal\n ): Promise<InstantQueryResponse>;\n rangeQuery(\n params: RangeQueryRequestParameters,\n headers?: RequestHeaders,\n signal?: AbortSignal\n ): Promise<RangeQueryResponse>;\n labelNames(\n params: LabelNamesRequestParameters,\n headers?: RequestHeaders,\n signal?: AbortSignal\n ): Promise<LabelNamesResponse>;\n labelValues(\n params: LabelValuesRequestParameters,\n headers?: RequestHeaders,\n signal?: AbortSignal\n ): Promise<LabelValuesResponse>;\n metricMetadata(\n params: MetricMetadataRequestParameters,\n headers?: RequestHeaders,\n signal?: AbortSignal\n ): Promise<MetricMetadataResponse>;\n series(params: SeriesRequestParameters, headers?: RequestHeaders, signal?: AbortSignal): Promise<SeriesResponse>;\n parseQuery(\n params: ParseQueryRequestParameters,\n headers?: RequestHeaders,\n signal?: AbortSignal\n ): Promise<ParseQueryResponse>;\n}\n\nexport interface QueryOptions {\n datasourceUrl: string;\n headers?: RequestHeaders;\n abortSignal?: AbortSignal;\n queryParams?: Record<string, string>;\n}\n\n/**\n * Builds a query string from datasource-level query parameters.\n * Optionally merges with existing URLSearchParams.\n * Returns empty string if no parameters, otherwise returns query string with leading '?'.\n */\nfunction buildQueryString(queryParams?: Record<string, string>, initialParams?: URLSearchParams): string {\n const urlParams = initialParams || new URLSearchParams();\n\n if (queryParams) {\n Object.entries(queryParams).forEach(([key, value]) => {\n urlParams.set(key, value);\n });\n }\n\n const queryString = urlParams.toString();\n return queryString !== '' ? `?${queryString}` : '';\n}\n\n/**\n * Calls the `/-/healthy` endpoint to check if the datasource is healthy.\n */\nexport function healthCheck(queryOptions: QueryOptions) {\n return async (): Promise<boolean> => {\n const url = `${queryOptions.datasourceUrl}/-/healthy${buildQueryString(queryOptions.queryParams)}`;\n\n try {\n const resp = await fetch(url, { headers: queryOptions.headers, signal: queryOptions.abortSignal });\n return resp.status === 200;\n } catch {\n return false;\n }\n };\n}\n\n/**\n * Calls the `/api/v1/query` endpoint to get metrics data.\n */\nexport function instantQuery(\n params: InstantQueryRequestParameters,\n queryOptions: QueryOptions\n): Promise<InstantQueryResponse> {\n return fetchWithPost<InstantQueryRequestParameters, InstantQueryResponse>('/api/v1/query', params, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/query_range` endpoint to get metrics data.\n */\nexport function rangeQuery(\n params: RangeQueryRequestParameters,\n queryOptions: QueryOptions\n): Promise<RangeQueryResponse> {\n return fetchWithPost<RangeQueryRequestParameters, RangeQueryResponse>('/api/v1/query_range', params, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/labels` endpoint to get a list of label names.\n */\nexport function labelNames(\n params: LabelNamesRequestParameters,\n queryOptions: QueryOptions\n): Promise<LabelNamesResponse> {\n return fetchWithPost<LabelNamesRequestParameters, LabelNamesResponse>('/api/v1/labels', params, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/label/{labelName}/values` endpoint to get a list of values for a label.\n */\nexport function labelValues(\n params: LabelValuesRequestParameters,\n queryOptions: QueryOptions\n): Promise<LabelValuesResponse> {\n const { labelName, ...searchParams } = params;\n\n // In case label name is empty, we'll receive a 404, so we can replace it by an empty list, which is less confusing.\n // Note that an empty list is the prometheus result if the label does not exist.\n if (labelName.length === 0) {\n return new Promise((resolve) => {\n resolve({ data: [] as string[] } as SuccessResponse<string[]>);\n });\n }\n\n const apiURI = `/api/v1/label/${encodeURIComponent(labelName)}/values`;\n return fetchWithGet<typeof searchParams, LabelValuesResponse>(apiURI, searchParams, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/label/{labelName}/values` endpoint to get a list of values for a label.\n */\nexport function metricMetadata(\n params: MetricMetadataRequestParameters,\n queryOptions: QueryOptions\n): Promise<MetricMetadataResponse> {\n const apiURI = `/api/v1/metadata`;\n return fetchWithGet<MetricMetadataRequestParameters, MetricMetadataResponse>(apiURI, params, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/series` endpoint to finding series by label matchers.\n */\nexport function series(params: SeriesRequestParameters, queryOptions: QueryOptions): Promise<SeriesResponse> {\n const apiURI = `/api/v1/series`;\n return fetchWithPost<SeriesRequestParameters, SeriesResponse>(apiURI, params, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/parse_query` to parse the given promQL expresion into an abstract syntax tree (AST).\n */\nexport function parseQuery(\n params: ParseQueryRequestParameters,\n queryOptions: QueryOptions\n): Promise<ParseQueryResponse> {\n const apiURI = `/api/v1/parse_query`;\n return fetchWithPost<ParseQueryRequestParameters, ParseQueryResponse>(apiURI, params, queryOptions);\n}\n\nfunction fetchWithGet<T extends RequestParams<T>, TResponse>(\n apiURI: string,\n params: T,\n queryOptions: QueryOptions\n): Promise<TResponse> {\n const { datasourceUrl, headers, queryParams } = queryOptions;\n const url = `${datasourceUrl}${apiURI}${buildQueryString(queryParams, createSearchParams(params))}`;\n return fetchJson<TResponse>(url, { method: 'GET', headers });\n}\n\nfunction fetchWithPost<T extends RequestParams<T>, TResponse>(\n apiURI: string,\n params: T,\n queryOptions: QueryOptions\n): Promise<TResponse> {\n const { datasourceUrl, headers, abortSignal: signal, queryParams } = queryOptions;\n const url = `${datasourceUrl}${apiURI}${buildQueryString(queryParams)}`;\n\n const init = {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/x-www-form-urlencoded',\n ...headers,\n },\n signal,\n body: createSearchParams(params),\n };\n return fetchResults<TResponse>(url, init);\n}\n\n// Request parameter values we know how to serialize\ntype ParamValue = string | string[] | number | undefined;\n\n// Used to constrain the types that can be passed to createSearchParams to\n// just the ones we know how to serialize\ntype RequestParams<T> = {\n [K in keyof T]: ParamValue;\n};\n\n/**\n * Creates URLSearchParams from a request params object.\n */\nfunction createSearchParams<T extends RequestParams<T>>(params: T): URLSearchParams {\n const searchParams = new URLSearchParams();\n for (const key in params) {\n const value: ParamValue = params[key];\n if (value === undefined) continue;\n\n if (typeof value === 'string') {\n searchParams.append(key, value);\n continue;\n }\n\n if (typeof value === 'number') {\n searchParams.append(key, value.toString());\n continue;\n }\n\n for (const val of value) {\n searchParams.append(key, val);\n }\n }\n return searchParams;\n}\n\n/**\n * Fetch JSON and parse warnings for query inspector\n */\nexport async function fetchResults<T>(...args: Parameters<typeof global.fetch>): Promise<T> {\n const response = await fetch(...args);\n const json: T = await response.json();\n return { ...json, rawResponse: response };\n}\n"],"names":["fetch","fetchJson","buildQueryString","queryParams","initialParams","urlParams","URLSearchParams","Object","entries","forEach","key","value","set","queryString","toString","healthCheck","queryOptions","url","datasourceUrl","resp","headers","signal","abortSignal","status","instantQuery","params","fetchWithPost","rangeQuery","labelNames","labelValues","labelName","searchParams","length","Promise","resolve","data","apiURI","encodeURIComponent","fetchWithGet","metricMetadata","series","parseQuery","createSearchParams","method","init","body","fetchResults","undefined","append","val","args","response","json","rawResponse"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;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7B,KAAK2B;AACtC;AAWA;;CAEC,GACD,SAASF,mBAA+CjB,MAAS;IAC/D,MAAMM,eAAe,IAAIzB;IACzB,IAAK,MAAMI,OAAOe,OAAQ;QACxB,MAAMd,QAAoBc,MAAM,CAACf,IAAI;QACrC,IAAIC,UAAUoC,WAAW;QAEzB,IAAI,OAAOpC,UAAU,UAAU;YAC7BoB,aAAaiB,MAAM,CAACtC,KAAKC;YACzB;QACF;QAEA,IAAI,OAAOA,UAAU,UAAU;YAC7BoB,aAAaiB,MAAM,CAACtC,KAAKC,MAAMG,QAAQ;YACvC;QACF;QAEA,KAAK,MAAMmC,OAAOtC,MAAO;YACvBoB,aAAaiB,MAAM,CAACtC,KAAKuC;QAC3B;IACF;IACA,OAAOlB;AACT;AAEA;;CAEC,GACD,OAAO,eAAee,aAAgB,GAAGI,IAAqC;IAC5E,MAAMC,WAAW,MAAMnD,SAASkD;IAChC,MAAME,OAAU,MAAMD,SAASC,IAAI;IACnC,OAAO;QAAE,GAAGA,IAAI;QAAEC,aAAaF;IAAS;AAC1C"}
|
|
1
|
+
{"version":3,"sources":["../../../src/model/prometheus-client.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 { fetch, fetchJson, RequestHeaders } from '@perses-dev/core';\nimport { DatasourceClient } from '@perses-dev/plugin-system';\nimport {\n InstantQueryRequestParameters,\n InstantQueryResponse,\n LabelNamesRequestParameters,\n LabelNamesResponse,\n LabelValuesRequestParameters,\n LabelValuesResponse,\n MetricMetadataRequestParameters,\n MetricMetadataResponse,\n ParseQueryRequestParameters,\n ParseQueryResponse,\n RangeQueryRequestParameters,\n RangeQueryResponse,\n SeriesRequestParameters,\n SeriesResponse,\n SuccessResponse,\n} from './api-types';\n\ninterface PrometheusClientOptions {\n datasourceUrl: string;\n headers?: RequestHeaders;\n}\n\nexport interface PrometheusClient extends DatasourceClient {\n options: PrometheusClientOptions;\n instantQuery(\n params: InstantQueryRequestParameters,\n headers?: RequestHeaders,\n signal?: AbortSignal\n ): Promise<InstantQueryResponse>;\n rangeQuery(\n params: RangeQueryRequestParameters,\n headers?: RequestHeaders,\n signal?: AbortSignal\n ): Promise<RangeQueryResponse>;\n labelNames(\n params: LabelNamesRequestParameters,\n headers?: RequestHeaders,\n signal?: AbortSignal\n ): Promise<LabelNamesResponse>;\n labelValues(\n params: LabelValuesRequestParameters,\n headers?: RequestHeaders,\n signal?: AbortSignal\n ): Promise<LabelValuesResponse>;\n metricMetadata(\n params: MetricMetadataRequestParameters,\n headers?: RequestHeaders,\n signal?: AbortSignal\n ): Promise<MetricMetadataResponse>;\n series(params: SeriesRequestParameters, headers?: RequestHeaders, signal?: AbortSignal): Promise<SeriesResponse>;\n parseQuery(\n params: ParseQueryRequestParameters,\n headers?: RequestHeaders,\n signal?: AbortSignal\n ): Promise<ParseQueryResponse>;\n}\n\nexport interface QueryOptions {\n datasourceUrl: string;\n headers?: RequestHeaders;\n abortSignal?: AbortSignal;\n queryParams?: Record<string, string>;\n}\n\n/**\n * Builds a query string from datasource-level query parameters.\n * Optionally merges with existing URLSearchParams.\n * Returns empty string if no parameters, otherwise returns query string with leading '?'.\n */\nfunction buildQueryString(queryParams?: Record<string, string>, initialParams?: URLSearchParams): string {\n const urlParams = initialParams || new URLSearchParams();\n\n if (queryParams) {\n Object.entries(queryParams).forEach(([key, value]) => {\n urlParams.set(key, value);\n });\n }\n\n const queryString = urlParams.toString();\n return queryString !== '' ? `?${queryString}` : '';\n}\n\n/**\n * Calls the `/-/healthy` endpoint to check if the datasource is healthy.\n */\nexport function healthCheck(queryOptions: QueryOptions) {\n return async (): Promise<boolean> => {\n const url = `${queryOptions.datasourceUrl}/-/healthy${buildQueryString(queryOptions.queryParams)}`;\n\n try {\n const resp = await fetch(url, { headers: queryOptions.headers, signal: queryOptions.abortSignal });\n return resp.status === 200;\n } catch {\n return false;\n }\n };\n}\n\n/**\n * Calls the `/api/v1/query` endpoint to get metrics data.\n */\nexport function instantQuery(\n params: InstantQueryRequestParameters,\n queryOptions: QueryOptions\n): Promise<InstantQueryResponse> {\n return fetchWithPost<InstantQueryRequestParameters, InstantQueryResponse>('/api/v1/query', params, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/query_range` endpoint to get metrics data.\n */\nexport function rangeQuery(\n params: RangeQueryRequestParameters,\n queryOptions: QueryOptions\n): Promise<RangeQueryResponse> {\n return fetchWithPost<RangeQueryRequestParameters, RangeQueryResponse>('/api/v1/query_range', params, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/labels` endpoint to get a list of label names.\n */\nexport function labelNames(\n params: LabelNamesRequestParameters,\n queryOptions: QueryOptions\n): Promise<LabelNamesResponse> {\n return fetchWithPost<LabelNamesRequestParameters, LabelNamesResponse>('/api/v1/labels', params, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/label/{labelName}/values` endpoint to get a list of values for a label.\n */\nexport function labelValues(\n params: LabelValuesRequestParameters,\n queryOptions: QueryOptions\n): Promise<LabelValuesResponse> {\n const { labelName, ...searchParams } = params;\n\n // In case label name is empty, we'll receive a 404, so we can replace it by an empty list, which is less confusing.\n // Note that an empty list is the prometheus result if the label does not exist.\n if (labelName.length === 0) {\n return new Promise((resolve) => {\n resolve({ data: [] as string[] } as SuccessResponse<string[]>);\n });\n }\n\n const apiURI = `/api/v1/label/${encodeURIComponent(labelName)}/values`;\n return fetchWithGet<typeof searchParams, LabelValuesResponse>(apiURI, searchParams, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/label/{labelName}/values` endpoint to get a list of values for a label.\n */\nexport function metricMetadata(\n params: MetricMetadataRequestParameters,\n queryOptions: QueryOptions\n): Promise<MetricMetadataResponse> {\n const apiURI = `/api/v1/metadata`;\n return fetchWithGet<MetricMetadataRequestParameters, MetricMetadataResponse>(apiURI, params, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/series` endpoint to finding series by label matchers.\n */\nexport function series(params: SeriesRequestParameters, queryOptions: QueryOptions): Promise<SeriesResponse> {\n const apiURI = `/api/v1/series`;\n return fetchWithPost<SeriesRequestParameters, SeriesResponse>(apiURI, params, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/parse_query` to parse the given promQL expresion into an abstract syntax tree (AST).\n */\nexport function parseQuery(\n params: ParseQueryRequestParameters,\n queryOptions: QueryOptions\n): Promise<ParseQueryResponse> {\n const apiURI = `/api/v1/parse_query`;\n return fetchWithPost<ParseQueryRequestParameters, ParseQueryResponse>(apiURI, params, queryOptions);\n}\n\nfunction fetchWithGet<T extends RequestParams<T>, TResponse>(\n apiURI: string,\n params: T,\n queryOptions: QueryOptions\n): Promise<TResponse> {\n const { datasourceUrl, headers, queryParams } = queryOptions;\n const url = `${datasourceUrl}${apiURI}${buildQueryString(queryParams, createSearchParams(params))}`;\n return fetchJson<TResponse>(url, { method: 'GET', headers });\n}\n\nfunction fetchWithPost<T extends RequestParams<T>, TResponse>(\n apiURI: string,\n params: T,\n queryOptions: QueryOptions\n): Promise<TResponse> {\n const { datasourceUrl, headers, abortSignal: signal, queryParams } = queryOptions;\n const url = `${datasourceUrl}${apiURI}${buildQueryString(queryParams)}`;\n\n const init = {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/x-www-form-urlencoded',\n ...headers,\n },\n signal,\n body: createSearchParams(params),\n };\n return fetchResults<TResponse>(url, init);\n}\n\n// Request parameter values we know how to serialize\ntype ParamValue = string | string[] | number | undefined;\n\n// Used to constrain the types that can be passed to createSearchParams to\n// just the ones we know how to serialize\ntype RequestParams<T> = {\n [K in keyof T]: ParamValue;\n};\n\n/**\n * Creates URLSearchParams from a request params object.\n */\nfunction createSearchParams<T extends RequestParams<T>>(params: T): URLSearchParams {\n const searchParams = new URLSearchParams();\n for (const key in params) {\n const value: ParamValue = params[key];\n if (value === undefined) continue;\n\n if (typeof value === 'string') {\n searchParams.append(key, value);\n continue;\n }\n\n if (typeof value === 'number') {\n searchParams.append(key, value.toString());\n continue;\n }\n\n for (const val of value) {\n searchParams.append(key, val);\n }\n }\n return searchParams;\n}\n\n/**\n * Fetch JSON and parse warnings for query inspector\n */\nexport async function fetchResults<T>(...args: Parameters<typeof global.fetch>): Promise<T> {\n const response = await fetch(...args);\n const json: T = await response.json();\n return { ...json, rawResponse: response };\n}\n"],"names":["fetch","fetchJson","buildQueryString","queryParams","initialParams","urlParams","URLSearchParams","Object","entries","forEach","key","value","set","queryString","toString","healthCheck","queryOptions","url","datasourceUrl","resp","headers","signal","abortSignal","status","instantQuery","params","fetchWithPost","rangeQuery","labelNames","labelValues","labelName","searchParams","length","Promise","resolve","data","apiURI","encodeURIComponent","fetchWithGet","metricMetadata","series","parseQuery","createSearchParams","method","init","body","fetchResults","undefined","append","val","args","response","json","rawResponse"],"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,KAAK,EAAEC,SAAS,QAAwB,mBAAmB;AAmEpE;;;;CAIC,GACD,SAASC,iBAAiBC,WAAoC,EAAEC,aAA+B;IAC7F,MAAMC,YAAYD,iBAAiB,IAAIE;IAEvC,IAAIH,aAAa;QACfI,OAAOC,OAAO,CAACL,aAAaM,OAAO,CAAC,CAAC,CAACC,KAAKC,MAAM;YAC/CN,UAAUO,GAAG,CAACF,KAAKC;QACrB;IACF;IAEA,MAAME,cAAcR,UAAUS,QAAQ;IACtC,OAAOD,gBAAgB,KAAK,CAAC,CAAC,EAAEA,aAAa,GAAG;AAClD;AAEA;;CAEC,GACD,OAAO,SA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uC;QAC3B;IACF;IACA,OAAOlB;AACT;AAEA;;CAEC,GACD,OAAO,eAAee,aAAgB,GAAGI,IAAqC;IAC5E,MAAMC,WAAW,MAAMnD,SAASkD;IAChC,MAAME,OAAU,MAAMD,SAASC,IAAI;IACnC,OAAO;QAAE,GAAGA,IAAI;QAAEC,aAAaF;IAAS;AAC1C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/model/prometheus-selectors.ts"],"sourcesContent":["// Copyright
|
|
1
|
+
{"version":3,"sources":["../../../src/model/prometheus-selectors.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 { DatasourceSelector } from '@perses-dev/core';\nimport { DatasourceSelectValue, isVariableDatasource } from '@perses-dev/plugin-system';\n\nexport const PROM_DATASOURCE_KIND = 'PrometheusDatasource' as const;\n\n/**\n * DatasourceSelector for Prom Datasources.\n */\nexport interface PrometheusDatasourceSelector extends DatasourceSelector {\n kind: typeof PROM_DATASOURCE_KIND;\n}\n\n/**\n * A default selector that asks for the default Prom Datasource.\n */\nexport const DEFAULT_PROM: PrometheusDatasourceSelector = { kind: PROM_DATASOURCE_KIND };\n\n/**\n * Returns true if the provided datasourceSelectValue is the default PrometheusDatasourceSelector.\n */\nexport function isDefaultPromSelector(\n datasourceSelectValue: DatasourceSelectValue<PrometheusDatasourceSelector>\n): boolean {\n return !isVariableDatasource(datasourceSelectValue) && datasourceSelectValue.name === undefined;\n}\n\n/**\n * Type guard to make sure a datasourceSelectValue is a Prometheus one.\n */\nexport function isPrometheusDatasourceSelector(\n datasourceSelectValue: DatasourceSelectValue<DatasourceSelector>\n): datasourceSelectValue is PrometheusDatasourceSelector {\n return isVariableDatasource(datasourceSelectValue) || datasourceSelectValue.kind === PROM_DATASOURCE_KIND;\n}\n"],"names":["isVariableDatasource","PROM_DATASOURCE_KIND","DEFAULT_PROM","kind","isDefaultPromSelector","datasourceSelectValue","name","undefined","isPrometheusDatasourceSelector"],"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;AAGjC,SAAgCA,oBAAoB,QAAQ,4BAA4B;AAExF,OAAO,MAAMC,uBAAuB,uBAAgC;AASpE;;CAEC,GACD,OAAO,MAAMC,eAA6C;IAAEC,MAAMF;AAAqB,EAAE;AAEzF;;CAEC,GACD,OAAO,SAASG,sBACdC,qBAA0E;IAE1E,OAAO,CAACL,qBAAqBK,0BAA0BA,sBAAsBC,IAAI,KAAKC;AACxF;AAEA;;CAEC,GACD,OAAO,SAASC,+BACdH,qBAAgE;IAEhE,OAAOL,qBAAqBK,0BAA0BA,sBAAsBF,IAAI,KAAKF;AACvF"}
|
package/lib/model/time.js
CHANGED
package/lib/model/time.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/model/time.ts"],"sourcesContent":["// Copyright
|
|
1
|
+
{"version":3,"sources":["../../../src/model/time.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { AbsoluteTimeRange, DurationString, parseDurationString } from '@perses-dev/core';\nimport { milliseconds, getUnixTime } from 'date-fns';\nimport { UnixTimestampSeconds } from './api-types';\n\nexport interface PrometheusTimeRange {\n start: UnixTimestampSeconds;\n end: UnixTimestampSeconds;\n}\n\n/**\n * Converts an AbsoluteTimeRange to Prometheus time in Unix time (i.e. in seconds).\n */\nexport function getPrometheusTimeRange(timeRange: AbsoluteTimeRange): { start: number; end: number } {\n const { start, end } = timeRange;\n return {\n start: Math.ceil(getUnixTime(start)),\n end: Math.ceil(getUnixTime(end)),\n };\n}\n\n// Max data points to allow returning from a Prom Query, used to calculate a\n// \"safe\" step for a range query\nconst MAX_PROM_DATA_POINTS = 10000;\n\n/**\n * Gets the step to use for a Prom range query. Tries to take into account a suggested step size (probably based on the\n * width of a visualization where the data will be graphed), any minimum step/resolution set by the user, and a \"safe\"\n * step based on the max data points we want to allow returning from a Prom query.\n */\nexport function getRangeStep(\n timeRange: PrometheusTimeRange,\n minStepSeconds = 15,\n resolution = 1,\n suggestedStepMs = 0\n): number {\n const suggestedStepSeconds = suggestedStepMs / 1000;\n const queryRangeSeconds = timeRange.end - timeRange.start;\n\n let safeStep = queryRangeSeconds / MAX_PROM_DATA_POINTS;\n if (safeStep > 1) {\n safeStep = Math.ceil(safeStep);\n }\n\n return Math.max(suggestedStepSeconds * resolution, minStepSeconds, safeStep);\n}\n\n/**\n * Converts a DurationString to seconds, rounding down.\n */\nexport function getDurationStringSeconds(durationString?: DurationString): number | undefined {\n if (!durationString) return undefined;\n\n const duration = parseDurationString(durationString);\n const ms = milliseconds(duration);\n return Math.floor(ms / 1000);\n}\n"],"names":["parseDurationString","milliseconds","getUnixTime","getPrometheusTimeRange","timeRange","start","end","Math","ceil","MAX_PROM_DATA_POINTS","getRangeStep","minStepSeconds","resolution","suggestedStepMs","suggestedStepSeconds","queryRangeSeconds","safeStep","max","getDurationStringSeconds","durationString","undefined","duration","ms","floor"],"mappings":"AAAA,+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,SAA4CA,mBAAmB,QAAQ,mBAAmB;AAC1F,SAASC,YAAY,EAAEC,WAAW,QAAQ,WAAW;AAQrD;;CAEC,GACD,OAAO,SAASC,uBAAuBC,SAA4B;IACjE,MAAM,EAAEC,KAAK,EAAEC,GAAG,EAAE,GAAGF;IACvB,OAAO;QACLC,OAAOE,KAAKC,IAAI,CAACN,YAAYG;QAC7BC,KAAKC,KAAKC,IAAI,CAACN,YAAYI;IAC7B;AACF;AAEA,4EAA4E;AAC5E,gCAAgC;AAChC,MAAMG,uBAAuB;AAE7B;;;;CAIC,GACD,OAAO,SAASC,aACdN,SAA8B,EAC9BO,iBAAiB,EAAE,EACnBC,aAAa,CAAC,EACdC,kBAAkB,CAAC;IAEnB,MAAMC,uBAAuBD,kBAAkB;IAC/C,MAAME,oBAAoBX,UAAUE,GAAG,GAAGF,UAAUC,KAAK;IAEzD,IAAIW,WAAWD,oBAAoBN;IACnC,IAAIO,WAAW,GAAG;QAChBA,WAAWT,KAAKC,IAAI,CAACQ;IACvB;IAEA,OAAOT,KAAKU,GAAG,CAACH,uBAAuBF,YAAYD,gBAAgBK;AACrE;AAEA;;CAEC,GACD,OAAO,SAASE,yBAAyBC,cAA+B;IACtE,IAAI,CAACA,gBAAgB,OAAOC;IAE5B,MAAMC,WAAWrB,oBAAoBmB;IACrC,MAAMG,KAAKrB,aAAaoB;IACxB,OAAOd,KAAKgB,KAAK,CAACD,KAAK;AACzB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
// Copyright
|
|
2
|
+
// Copyright The Perses Authors
|
|
3
3
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
4
|
// you may not use this file except in compliance with the License.
|
|
5
5
|
// You may obtain a copy of the License at
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/plugins/MatcherEditor.tsx"],"sourcesContent":["// Copyright
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/MatcherEditor.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 { Stack, TextField, Button, Box, IconButton } from '@mui/material';\nimport { produce } from 'immer';\nimport TrashIcon from 'mdi-material-ui/TrashCan';\nimport { ReactElement } from 'react';\n\ntype MatcherEditorProps = {\n matchers: string[];\n onChange: (matchers: string[]) => void;\n isReadonly?: boolean;\n};\n\nexport function MatcherEditor({ matchers, onChange, isReadonly }: MatcherEditorProps): ReactElement {\n return (\n <Stack spacing={1} mb={2}>\n {matchers.map((matcher, index) => (\n <Box key={index} display=\"flex\">\n <TextField\n fullWidth\n label=\"Series Selector\"\n value={matcher}\n InputProps={{\n readOnly: isReadonly,\n }}\n onChange={(e) => {\n const newMatchers = produce(matchers, (draft) => {\n draft[index] = e.target.value;\n });\n onChange(newMatchers);\n }}\n />\n <IconButton\n onClick={() => {\n const newMatchers = produce(matchers, (draft) => {\n draft.splice(index, 1);\n });\n onChange(newMatchers);\n }}\n disabled={isReadonly}\n >\n <TrashIcon />\n </IconButton>\n </Box>\n ))}\n <Box>\n <Button\n fullWidth={false}\n color=\"secondary\"\n variant=\"outlined\"\n onClick={() => {\n const newMatchers = produce(matchers, (draft) => {\n draft.push('');\n });\n onChange(newMatchers);\n }}\n disabled={isReadonly}\n >\n Add Series Selector\n </Button>\n </Box>\n </Stack>\n );\n}\n"],"names":["Stack","TextField","Button","Box","IconButton","produce","TrashIcon","MatcherEditor","matchers","onChange","isReadonly","spacing","mb","map","matcher","index","display","fullWidth","label","value","InputProps","readOnly","e","newMatchers","draft","target","onClick","splice","disabled","color","variant","push"],"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,KAAK,EAAEC,SAAS,EAAEC,MAAM,EAAEC,GAAG,EAAEC,UAAU,QAAQ,gBAAgB;AAC1E,SAASC,OAAO,QAAQ,QAAQ;AAChC,OAAOC,eAAe,2BAA2B;AASjD,OAAO,SAASC,cAAc,EAAEC,QAAQ,EAAEC,QAAQ,EAAEC,UAAU,EAAsB;IAClF,qBACE,MAACV;QAAMW,SAAS;QAAGC,IAAI;;YACpBJ,SAASK,GAAG,CAAC,CAACC,SAASC,sBACtB,MAACZ;oBAAgBa,SAAQ;;sCACvB,KAACf;4BACCgB,SAAS;4BACTC,OAAM;4BACNC,OAAOL;4BACPM,YAAY;gCACVC,UAAUX;4BACZ;4BACAD,UAAU,CAACa;gCACT,MAAMC,cAAclB,QAAQG,UAAU,CAACgB;oCACrCA,KAAK,CAACT,MAAM,GAAGO,EAAEG,MAAM,CAACN,KAAK;gCAC/B;gCACAV,SAASc;4BACX;;sCAEF,KAACnB;4BACCsB,SAAS;gCACP,MAAMH,cAAclB,QAAQG,UAAU,CAACgB;oCACrCA,MAAMG,MAAM,CAACZ,OAAO;gCACtB;gCACAN,SAASc;4BACX;4BACAK,UAAUlB;sCAEV,cAAA,KAACJ;;;mBAxBKS;0BA4BZ,KAACZ;0BACC,cAAA,KAACD;oBACCe,WAAW;oBACXY,OAAM;oBACNC,SAAQ;oBACRJ,SAAS;wBACP,MAAMH,cAAclB,QAAQG,UAAU,CAACgB;4BACrCA,MAAMO,IAAI,CAAC;wBACb;wBACAtB,SAASc;oBACX;oBACAK,UAAUlB;8BACX;;;;;AAMT"}
|