Skip to content

Commit

Permalink
Add Engine Selector/ Dropdown to Query UI
Browse files Browse the repository at this point in the history
Engine Selector is a dropdown that sets an engine to be used to
run the query. Currently two engines `thanos` and `prometheus`.

This dropdown sends a query param `engine` to query api, which
runs the api using the engine provided. Provided to run query
using multiple query engines from Query UI.

Signed-off-by: Pradyumna Krishna <[email protected]>
  • Loading branch information
PradyumnaKrishna committed Apr 5, 2023
1 parent 00eca42 commit 8ef7010
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 40 deletions.
80 changes: 40 additions & 40 deletions pkg/ui/bindata.go

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions pkg/ui/react-app/src/components/Dropdown.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React, { FC, memo } from 'react';
import { FormGroup, Label, Input, InputProps } from 'reactstrap';

export interface DropdownOption {
name: string;
value: string;
}

interface DropdownProps extends InputProps {
options: DropdownOption[];
}

const Dropdown: FC<DropdownProps> = ({ children, selected, options, id, ...rest }) => {
return (
<FormGroup className="custom-control d-inline">
<Label for={id} className="control-label">
{children}
</Label>
<Input
{...rest}
id={id}
type="select"
value={selected}
className="control-input custom-select"
style={{
width: 'auto',
marginLeft: '10px',
}}
>
{options.map(function (option) {
return <option value={option.value}>{option.name}</option>;
})}
</Input>
</FormGroup>
);
};

export default memo(Dropdown);
1 change: 1 addition & 0 deletions pkg/ui/react-app/src/pages/graph/Panel.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const defaultProps: PanelProps = {
defaultStep: '1s',
enableHighlighting: true,
enableLinter: true,
engine: 'prometheus',
};

describe('Panel', () => {
Expand Down
3 changes: 3 additions & 0 deletions pkg/ui/react-app/src/pages/graph/Panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface PanelProps {
enableHighlighting: boolean;
enableLinter: boolean;
defaultStep: string;
engine: string;
}

interface PanelState {
Expand Down Expand Up @@ -169,11 +170,13 @@ class Panel extends Component<PanelProps & PathPrefixProps, PanelState> {
params.append('end', endTime.toString());
params.append('step', resolution.toString());
params.append('max_source_resolution', this.props.options.maxSourceResolution);
params.append('engine', this.props.engine);
// TODO path prefix here and elsewhere.
break;
case 'table':
path = '/api/v1/query';
params.append('time', endTime.toString());
params.append('engine', this.props.engine);
break;
default:
throw new Error('Invalid panel type "' + this.props.options.type + '"');
Expand Down
18 changes: 18 additions & 0 deletions pkg/ui/react-app/src/pages/graph/PanelList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { UncontrolledAlert, Button } from 'reactstrap';

import Panel, { PanelOptions, PanelDefaultOptions } from './Panel';
import Checkbox from '../../components/Checkbox';
import Dropdown from '../../components/Dropdown';
import PathPrefixProps from '../../types/PathPrefixProps';
import { StoreListProps } from '../../thanos/pages/stores/Stores';
import { Store } from '../../thanos/pages/stores/store';
Expand All @@ -30,6 +31,7 @@ interface PanelListProps extends PathPrefixProps, RouteComponentProps {
enableHighlighting: boolean;
enableLinter: boolean;
defaultStep: string;
engine: string;
}

export const PanelListContent: FC<PanelListProps> = ({
Expand All @@ -42,6 +44,7 @@ export const PanelListContent: FC<PanelListProps> = ({
enableHighlighting,
enableLinter,
defaultStep,
engine,
...rest
}) => {
const [panels, setPanels] = useState(rest.panels);
Expand Down Expand Up @@ -123,6 +126,7 @@ export const PanelListContent: FC<PanelListProps> = ({
stores={storeData}
enableAutocomplete={enableAutocomplete}
enableHighlighting={enableHighlighting}
engine={engine}
enableLinter={enableLinter}
defaultStep={defaultStep}
/>
Expand All @@ -144,6 +148,11 @@ const PanelList: FC<RouteComponentProps & PathPrefixProps> = ({ pathPrefix = ''
const [enableAutocomplete, setEnableAutocomplete] = useLocalStorage('enable-autocomplete', true);
const [enableHighlighting, setEnableHighlighting] = useLocalStorage('enable-syntax-highlighting', true);
const [enableLinter, setEnableLinter] = useLocalStorage('enable-linter', true);
const [engine, setEngine] = useLocalStorage<string>('engine', 'prometheus');
const engineOptions = [
{ name: 'Prometheus', value: 'prometheus' },
{ name: 'Thanos', value: 'thanos' },
];

const { response: metricsRes, error: metricsErr } = useFetch<string[]>(`${pathPrefix}/api/v1/label/__name__/values`);
const {
Expand Down Expand Up @@ -204,6 +213,14 @@ const PanelList: FC<RouteComponentProps & PathPrefixProps> = ({ pathPrefix = ''
</Checkbox>
</div>
<div className="float-right">
<Dropdown
selected={engine}
options={engineOptions}
id="engine-dropdown"
onChange={({ target }) => setEngine(target.value)}
>
Engine
</Dropdown>
<Checkbox
wrapperStyles={{ marginLeft: 20, display: 'inline-block' }}
id="autocomplete-checkbox"
Expand Down Expand Up @@ -266,6 +283,7 @@ const PanelList: FC<RouteComponentProps & PathPrefixProps> = ({ pathPrefix = ''
enableHighlighting={enableHighlighting}
enableLinter={enableLinter}
defaultStep={defaultStep}
engine={engine}
queryHistoryEnabled={enableQueryHistory}
isLoading={storesLoading || flagsLoading}
/>
Expand Down

0 comments on commit 8ef7010

Please sign in to comment.