Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for aggregations on quickwit ui #4974

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

trinity-1686a
Copy link
Contributor

@trinity-1686a trinity-1686a commented May 11, 2024

Description

fix #3223
add support for aggregation on quickwit ui

image
image

How was this PR tested?

manually. I have no idea how to properly test an ui

Disclaimer

this is my first time interacting with React, and I'm far from being an UI/UX person. What I've done might have huge pitfalls I can't comprehend.

@trinity-1686a
Copy link
Contributor Author

first bug: the API URL link at the bottom is very broken with aggregations

@trinity-1686a
Copy link
Contributor Author

trinity-1686a commented May 11, 2024

term aggregation crash if no matching document
fixed

@fmassot fmassot requested review from ddelemeny and removed request for fmassot May 12, 2024 09:48
Copy link
Contributor

@ddelemeny ddelemeny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job ! Spotted a few things to improve to avoid React/MUI complaints in console + a resource leak to fix.

use FormControl properly

don't use lists, or set a key for each element

change casing of some css properties
Copy link
Contributor

@ddelemeny ddelemeny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Second pass : some minor changes, some react arcane stuff and some safety boundaries required.

import { TimeRangeSelect } from './TimeRangeSelect';
import PlayArrowIcon from '@mui/icons-material/PlayArrow';
import { SearchComponentProps } from "../utils/SearchComponentProps";

export function QueryEditorActionBar(props: SearchComponentProps) {
const timestamp_field_name = props.index?.metadata.index_config.doc_mapping.timestamp_field;
const shouldDisplayTimeRangeSelect = timestamp_field_name ?? false;

const handleChange = (_event: React.SyntheticEvent, newTab: number) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect this to trigger a "mode" change (conditional rendering of the UI) and an initializing run of the request. The current tab switch behavior is weirdly inconsequential.

type="number"
onChange={(e) => handleTermCountChange(pos, e)}
value={agg.term.size}
sx={{ "margin-left": "10px" }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be camelCased.

variant="standard"
label="Field"
onChange={(e) => handleTermFieldChange(pos, e)}
sx={{ "margin-left": "10px" }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be camelCased.

break;
}
case "rm": {
console.log("av", newAggregations);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rm console logs

if (aggregationConfig.histogram === null && aggregationConfig.term === null) {
const initialAggregation = Object.assign({}, ...aggregations);
const initialSearchRequest = {...props.searchRequest, aggregationConfig: initialAggregation};
props.onSearchRequestUpdate(initialSearchRequest);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will cause a setState in the parent component from the render fn of the current one, which triggers a render somewhere else in the tree. Undesired side-effect inside a render, not allowed (react will warn in the console).

You can wrap this init block in a useEffect(()=>{/*init here*/},[/*deps*/]) call. Leave the deps array empty if the effect is to be executed once.


const drawAdditional = (pos: number, aggs: ({term: TermAgg} | {histogram: HistogramAgg})[]) => {
const agg = aggs[pos]
if (isHistogram(agg)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may very well crash the tab of the unsuspecting user, trying to render thousands of buckets.
Search params being serialized in the urls make it even worse (refresh won't help).

I'd favor computing a safe-to-render resolution based on the selected time range.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so i should remove that Select? What should i do when no time range is selected? Send 2 requests for the lowest/highest timestamp matching the query?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, removing the option here is probably the best course, you can check how it's done on the grafana plugin here : https://github.com/quickwit-oss/quickwit-datasource/blob/main/src/utils/time.ts

On addressing the no-timerange issue, there are a few possibilities:

  • provide a default range -> quite simple, that's how grafana works in the context of log exploration but it comes with a slight change of expectations from the UI. Should probably be cleared on search in order to allow min/max queries without constraints.
  • fetch dataset bounds -> on the elastic api, this could be done in one round trip over the _msearch endpoint, not sure about the index api.
  • reissue modified request -> another interesting option would be to issue a first request as it is done now, check the result, and if necessary reissue the request with adjusted bounds and resolution. More of a gamble, success is fast, fail is slower.
  • forbid unbounded queries -> just show an alert prompting the user to select bounds. Not the most friendly approach but definitely simple to implement.

Reorganize jest mocks, add `@mui/x-charts` mock
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

date-picker only half responsive
3 participants