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

TraceID : Fetching TraceID #6973

Merged
merged 7 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions pkg/ui/react-app/src/pages/graph/Panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,15 +231,23 @@ class Panel extends Component<PanelProps & PathPrefixProps, PanelState> {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'X-Thanos-Force-Tracing': 'true',
// Conditionally add the header if the checkbox is enabled
...(this.props.options.forceTracing ? { 'X-Thanos-Force-Tracing': 'true' } : {}),
},
cache: 'no-store',
credentials: 'same-origin',
signal: abortController.signal,
})
.then((resp) => resp.json())
.then((json) => {
.then((resp) => {
return resp.json().then((json) => {
return {
json,
headers: resp.headers,
};
});
})
.then(({ json, headers }) => {
if (json.status !== 'success') {
throw new Error(json.error || 'invalid response JSON');
}
Expand All @@ -254,20 +262,22 @@ class Panel extends Component<PanelProps & PathPrefixProps, PanelState> {
}
analysis = json.data.analysis;
}

const traceID = headers.get('X-Thanos-Trace-ID');
this.setState({
error: null,
data: json.data,
lastQueryParams: {
startTime,
endTime,
resolution,
traceID: traceID ? traceID : '',
},
warnings: json.warnings,
stats: {
loadTime: Date.now() - queryStart,
resolution,
resultSeries,
traceID,
},
loading: false,
analysis: analysis,
Expand Down
13 changes: 8 additions & 5 deletions pkg/ui/react-app/src/pages/graph/QueryStatsView.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { shallow } from 'enzyme';
import { mount } from 'enzyme';
import QueryStatsView from './QueryStatsView';

describe('QueryStatsView', () => {
Expand All @@ -8,10 +8,13 @@ describe('QueryStatsView', () => {
loadTime: 100,
resolution: 5,
resultSeries: 10000,
traceID: 'e575f9d4eab63a90cdc3dc4ef1b8dda0',
};
const queryStatsView = shallow(<QueryStatsView {...queryStatsProps} />);
expect(queryStatsView.prop('className')).toEqual('query-stats');
expect(queryStatsView.children().prop('className')).toEqual('float-right');
expect(queryStatsView.children().text()).toEqual('Load time: 100ms   Resolution: 5s   Result series: 10000');
const queryStatsView = mount(<QueryStatsView {...queryStatsProps} />);
expect(queryStatsView.find('.query-stats').prop('className')).toEqual('query-stats');
expect(queryStatsView.find('.float-right').prop('className')).toEqual('float-right');
expect(queryStatsView.find('.float-right').html()).toEqual(
`<span class="float-right">Load time: ${queryStatsProps.loadTime}ms   Resolution: ${queryStatsProps.resolution}s   Result series: ${queryStatsProps.resultSeries}   Trace ID: ${queryStatsProps.traceID}</span>`
);
});
});
9 changes: 5 additions & 4 deletions pkg/ui/react-app/src/pages/graph/QueryStatsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ export interface QueryStats {
loadTime: number;
resolution: number;
resultSeries: number;
traceID: string | null;
}

const QueryStatsView: FC<QueryStats> = (props) => {
const { loadTime, resolution, resultSeries } = props;
const { loadTime, resolution, resultSeries, traceID } = props;
const prev = `Load time: ${loadTime}ms &ensp; Resolution: ${resolution}s &ensp; Result series: ${resultSeries}`;
const str = traceID ? prev + ` &ensp; Trace ID: ${traceID}` : prev;

return (
<div className="query-stats">
<span className="float-right">
Load time: {loadTime}ms &ensp; Resolution: {resolution}s &ensp; Result series: {resultSeries}
</span>
<span className="float-right" dangerouslySetInnerHTML={{ __html: str }}></span>
</div>
);
};
Expand Down
1 change: 1 addition & 0 deletions pkg/ui/react-app/src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface QueryParams {
startTime: number;
endTime: number;
resolution: number;
traceID: string;
}

export type Rule = {
Expand Down
Loading