-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Gabriel Bernal <[email protected]>
- Loading branch information
Showing
21 changed files
with
2,984 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
// Copyright 2024 The Perses Authors | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import { QueryDefinition } from '@perses-dev/core'; | ||
import { Box, Stack, Tab, Tabs } from '@mui/material'; | ||
import { DataQueriesProvider, MultiQueryEditor, useSuggestedStepMs } from '@perses-dev/plugin-system'; | ||
import { useExplorerManagerContext } from '@perses-dev/explore'; | ||
import useResizeObserver from 'use-resize-observer'; | ||
import { Panel } from '@perses-dev/dashboards'; | ||
import { ReactElement } from 'react'; | ||
import { DEFAULT_PROM } from '../model/prometheus-selectors'; | ||
import { FinderQueryParams } from './PrometheusMetricsFinder/types'; | ||
import { PrometheusMetricsFinder } from './PrometheusMetricsFinder'; | ||
|
||
interface MetricsExplorerQueryParams extends FinderQueryParams { | ||
tab?: string; | ||
queries?: QueryDefinition[]; | ||
} | ||
|
||
const PANEL_PREVIEW_HEIGHT = 700; | ||
|
||
function TimeSeriesPanel({ queries }: { queries: QueryDefinition[] }): ReactElement { | ||
const { width, ref: boxRef } = useResizeObserver(); | ||
const height = PANEL_PREVIEW_HEIGHT; | ||
|
||
const suggestedStepMs = useSuggestedStepMs(width); | ||
|
||
// map TimeSeriesQueryDefinition to Definition<UnknownSpec> | ||
const definitions = queries.length | ||
? queries.map((query) => { | ||
return { | ||
kind: query.spec.plugin.kind, | ||
spec: query.spec.plugin.spec, | ||
}; | ||
}) | ||
: []; | ||
|
||
return ( | ||
<Box ref={boxRef} height={height}> | ||
<DataQueriesProvider definitions={definitions} options={{ suggestedStepMs, mode: 'range' }}> | ||
<Panel | ||
panelOptions={{ | ||
hideHeader: true, | ||
}} | ||
definition={{ | ||
kind: 'Panel', | ||
spec: { queries: queries, display: { name: '' }, plugin: { kind: 'TimeSeriesChart', spec: {} } }, | ||
}} | ||
/> | ||
</DataQueriesProvider> | ||
</Box> | ||
); | ||
} | ||
|
||
function MetricDataTable({ queries }: { queries: QueryDefinition[] }): ReactElement { | ||
const height = PANEL_PREVIEW_HEIGHT; | ||
|
||
// map TimeSeriesQueryDefinition to Definition<UnknownSpec> | ||
const definitions = queries.map((query) => { | ||
return { | ||
kind: query.spec.plugin.kind, | ||
spec: query.spec.plugin.spec, | ||
}; | ||
}); | ||
|
||
return ( | ||
<Box height={height}> | ||
<DataQueriesProvider definitions={definitions} options={{ mode: 'instant' }}> | ||
<Panel | ||
panelOptions={{ | ||
hideHeader: true, | ||
}} | ||
definition={{ | ||
kind: 'Panel', | ||
spec: { queries: queries, display: { name: '' }, plugin: { kind: 'TimeSeriesTable', spec: {} } }, | ||
}} | ||
/> | ||
</DataQueriesProvider> | ||
</Box> | ||
); | ||
} | ||
|
||
export function PrometheusExplorer(): ReactElement { | ||
const { | ||
data: { tab = 'table', queries = [], datasource = DEFAULT_PROM, filters = [], exploredMetric = undefined }, | ||
setData, | ||
} = useExplorerManagerContext<MetricsExplorerQueryParams>(); | ||
|
||
return ( | ||
<Stack gap={2} sx={{ width: '100%' }}> | ||
<Tabs | ||
value={tab} | ||
onChange={(_, state) => setData({ tab: state, queries })} | ||
variant="scrollable" | ||
sx={{ borderBottom: 1, borderColor: 'divider' }} | ||
> | ||
<Tab value="table" label="Table" /> | ||
<Tab value="graph" label="Graph" /> | ||
<Tab value="finder" label="Finder" /> | ||
</Tabs> | ||
<Stack gap={1}> | ||
{tab === 'table' && ( | ||
<Stack> | ||
<MultiQueryEditor | ||
queryTypes={['TimeSeriesQuery']} | ||
onChange={(state) => setData({ tab, queries: state })} | ||
queries={queries} | ||
/> | ||
<MetricDataTable queries={queries} /> | ||
</Stack> | ||
)} | ||
{tab === 'graph' && ( | ||
<Stack> | ||
<MultiQueryEditor | ||
queryTypes={['TimeSeriesQuery']} | ||
onChange={(state) => setData({ tab, queries: state })} | ||
queries={queries} | ||
/> | ||
<TimeSeriesPanel queries={queries} /> | ||
</Stack> | ||
)} | ||
{tab === 'finder' && ( | ||
<Stack> | ||
<PrometheusMetricsFinder | ||
onChange={(state) => setData({ tab, ...state })} | ||
value={{ datasource, filters, exploredMetric }} | ||
/> | ||
</Stack> | ||
)} | ||
</Stack> | ||
</Stack> | ||
); | ||
} |
Oops, something went wrong.