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

Thanos-Query UI: Use Partial Response enabled by default #6830

Closed
wants to merge 11 commits into from
4 changes: 2 additions & 2 deletions pkg/ui/react-app/src/pages/graph/Panel.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const defaultProps: PanelProps = {
maxSourceResolution: 'auto',
useDeduplication: true,
forceTracing: false,
usePartialResponse: false,
usePartialResponse: true,
storeMatches: [],
engine: 'prometheus',
analyze: false,
Expand Down Expand Up @@ -96,7 +96,7 @@ describe('Panel', () => {
maxSourceResolution: 'auto',
useDeduplication: true,
forceTracing: false,
usePartialResponse: false,
usePartialResponse: true,
storeMatches: [],
engine: 'prometheus',
analyze: false,
Expand Down
35 changes: 33 additions & 2 deletions pkg/ui/react-app/src/pages/graph/Panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ interface PanelState {
exprInputValue: string;
analysis: QueryTree | null;
explainOutput: ExplainTree | null;
traceId: string | null; //Include traceId in the state.
queryStatus: boolean;
hoverMessage: string | null;
isHovered: boolean;
}

Expand Down Expand Up @@ -93,7 +96,7 @@ export const PanelDefaultOptions: PanelOptions = {
maxSourceResolution: '0s',
useDeduplication: true,
forceTracing: false,
usePartialResponse: false,
usePartialResponse: true,
storeMatches: [],
engine: '',
analyze: false,
Expand All @@ -116,6 +119,9 @@ class Panel extends Component<PanelProps & PathPrefixProps, PanelState> {
exprInputValue: props.options.expr,
explainOutput: null,
analysis: null,
traceId: null, // Initialize traceId to null.
queryStatus: false,
hoverMessage: null,
isHovered: false,
};

Expand Down Expand Up @@ -238,7 +244,12 @@ class Panel extends Component<PanelProps & PathPrefixProps, PanelState> {
credentials: 'same-origin',
signal: abortController.signal,
})
.then((resp) => resp.json())
.then((resp) => {
const traceIdHeader = resp.headers.get('X-Thanos-Trace-Id');
this.setState({ traceId: traceIdHeader });
return resp.json();
})

.then((json) => {
if (json.status !== 'success') {
throw new Error(json.error || 'invalid response JSON');
Expand Down Expand Up @@ -333,6 +344,14 @@ class Panel extends Component<PanelProps & PathPrefixProps, PanelState> {
};
handleChangeForceTracing = (event: React.ChangeEvent<HTMLInputElement>): void => {
this.setOptions({ forceTracing: event.target.checked });

if (this.state.queryStatus && this.state.traceId) {
this.setState({ hoverMessage: `TraceID: ${this.state.traceId}` });
} else if (this.state.queryStatus) {
this.setState({ hoverMessage: 'TraceID is not available' });
} else {
this.setState({ hoverMessage: '' });
}
};

handleChangePartialResponse = (event: React.ChangeEvent<HTMLInputElement>): void => {
Expand Down Expand Up @@ -430,6 +449,7 @@ class Panel extends Component<PanelProps & PathPrefixProps, PanelState> {
let result = null;
if (json.data) {
result = json.data;
this.setState({ queryStatus: true });
}
this.setState({ explainOutput: result });
})
Expand Down Expand Up @@ -511,9 +531,20 @@ class Panel extends Component<PanelProps & PathPrefixProps, PanelState> {
id={`force-tracing-checkbox-${id}`}
onChange={this.handleChangeForceTracing}
defaultchecked={options.forceTracing}
onMouseEnter={this.handleMouseEnter}
onMouseLeave={this.handleMouseLeave}
>
Force Tracing
</Checkbox>
<div style={{ display: 'inline-block', marginLeft: 10 }}>
<span
className="trace-id-tooltip"
onMouseEnter={() => this.state.isHovered && this.setState({ hoverMessage: this.state.hoverMessage })}
onMouseLeave={() => this.setState({ hoverMessage: '' })}
>
{this.state.hoverMessage}
</span>
</div>
<Label
style={{ marginLeft: '10px', display: 'inline-block' }}
for={`select-engine=${id}`}
Expand Down