mirror of
https://github.com/prometheus/prometheus
synced 2025-02-16 03:57:27 +00:00
React UI: Simpler and relative-only query URL building (#6263)
I prefer just keeping it dumb (and it helps with a current Netlify deploy hack I have). Signed-off-by: Julius Volz <julius.volz@gmail.com>
This commit is contained in:
parent
8c0b76d1da
commit
5bc935337a
@ -116,33 +116,28 @@ class Panel extends Component<PanelProps, PanelState> {
|
|||||||
const endTime = this.getEndTime().valueOf() / 1000; // TODO: shouldn't valueof only work when it's a moment?
|
const endTime = this.getEndTime().valueOf() / 1000; // TODO: shouldn't valueof only work when it's a moment?
|
||||||
const startTime = endTime - this.props.options.range;
|
const startTime = endTime - this.props.options.range;
|
||||||
const resolution = this.props.options.resolution || Math.max(Math.floor(this.props.options.range / 250), 1);
|
const resolution = this.props.options.resolution || Math.max(Math.floor(this.props.options.range / 250), 1);
|
||||||
const url = new URL(window.location.href);
|
const params: URLSearchParams = new URLSearchParams({
|
||||||
const params: { [key: string]: string } = {
|
|
||||||
query: expr,
|
query: expr,
|
||||||
};
|
});
|
||||||
|
|
||||||
|
let path: string;
|
||||||
switch (this.props.options.type) {
|
switch (this.props.options.type) {
|
||||||
case 'graph':
|
case 'graph':
|
||||||
url.pathname = '../../api/v1/query_range';
|
path = '../../api/v1/query_range';
|
||||||
Object.assign(params, {
|
params.append('start', startTime.toString());
|
||||||
start: startTime,
|
params.append('end', endTime.toString());
|
||||||
end: endTime,
|
params.append('step', resolution.toString());
|
||||||
step: resolution,
|
|
||||||
});
|
|
||||||
// TODO path prefix here and elsewhere.
|
// TODO path prefix here and elsewhere.
|
||||||
break;
|
break;
|
||||||
case 'table':
|
case 'table':
|
||||||
url.pathname = '../../api/v1/query';
|
path = '../../api/v1/query';
|
||||||
Object.assign(params, {
|
params.append('time', endTime.toString());
|
||||||
time: endTime,
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Error('Invalid panel type "' + this.props.options.type + '"');
|
throw new Error('Invalid panel type "' + this.props.options.type + '"');
|
||||||
}
|
}
|
||||||
Object.keys(params).forEach(key => url.searchParams.append(key, params[key]));
|
|
||||||
|
|
||||||
fetch(url.toString(), { cache: 'no-store', signal: abortController.signal })
|
fetch(`${path}?${params}`, { cache: 'no-store', signal: abortController.signal })
|
||||||
.then(resp => resp.json())
|
.then(resp => resp.json())
|
||||||
.then(json => {
|
.then(json => {
|
||||||
if (json.status !== 'success') {
|
if (json.status !== 'success') {
|
||||||
|
Loading…
Reference in New Issue
Block a user