mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Search: Fix tags query (#55851)
* Search: fix tags query * Search: fix type
This commit is contained in:
parent
3409979288
commit
814211282a
@ -63,11 +63,12 @@ func (s *searchHTTPService) doQuery(c *models.ReqContext) response.Response {
|
||||
return response.Error(500, "error handling search request", resp.Error)
|
||||
}
|
||||
|
||||
if len(resp.Frames) != 1 {
|
||||
return response.Error(500, "invalid search response", errors.New("invalid search response"))
|
||||
if len(resp.Frames) == 0 {
|
||||
msg := "invalid search response"
|
||||
return response.Error(500, msg, errors.New(msg))
|
||||
}
|
||||
|
||||
bytes, err := resp.Frames[0].MarshalJSON()
|
||||
bytes, err := resp.MarshalJSON()
|
||||
if err != nil {
|
||||
return response.Error(500, "error marshalling response", err)
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
import {
|
||||
ArrayVector,
|
||||
DataFrame,
|
||||
DataFrameJSON,
|
||||
DataFrameView,
|
||||
getDisplayProcessor,
|
||||
SelectableValue,
|
||||
@ -19,6 +20,10 @@ const loadingFrameName = 'Loading';
|
||||
|
||||
const searchURI = 'api/search-v2';
|
||||
|
||||
type SearchAPIResponse = {
|
||||
frames: DataFrameJSON[];
|
||||
};
|
||||
|
||||
export class BlugeSearcher implements GrafanaSearcher {
|
||||
constructor(private fallbackSearcher: GrafanaSearcher) {}
|
||||
|
||||
@ -51,15 +56,19 @@ export class BlugeSearcher implements GrafanaSearcher {
|
||||
limit: 1, // 0 would be better, but is ignored by the backend
|
||||
};
|
||||
|
||||
const frame = toDataFrame(await getBackendSrv().post(searchURI, req));
|
||||
const resp = await getBackendSrv().post<SearchAPIResponse>(searchURI, req);
|
||||
const frames = resp.frames.map((f) => toDataFrame(f));
|
||||
|
||||
if (frame?.name === loadingFrameName) {
|
||||
if (frames[0]?.name === loadingFrameName) {
|
||||
return this.fallbackSearcher.tags(query);
|
||||
}
|
||||
|
||||
if (frame.fields[0].name === 'tag') {
|
||||
return getTermCountsFrom(frame);
|
||||
for (const frame of frames) {
|
||||
if (frame.fields[0].name === 'tag') {
|
||||
return getTermCountsFrom(frame);
|
||||
}
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
@ -92,9 +101,10 @@ export class BlugeSearcher implements GrafanaSearcher {
|
||||
limit: query.limit ?? firstPageSize,
|
||||
};
|
||||
|
||||
const rsp = await getBackendSrv().post(searchURI, req);
|
||||
const rsp = await getBackendSrv().post<SearchAPIResponse>(searchURI, req);
|
||||
const frames = rsp.frames.map((f) => toDataFrame(f));
|
||||
|
||||
const first = rsp ? toDataFrame(rsp) : { fields: [], length: 0 };
|
||||
const first = frames.length ? toDataFrame(frames[0]) : { fields: [], length: 0 };
|
||||
|
||||
if (first.name === loadingFrameName) {
|
||||
return this.fallbackSearcher.search(query);
|
||||
@ -138,13 +148,12 @@ export class BlugeSearcher implements GrafanaSearcher {
|
||||
if (from >= meta.count) {
|
||||
return;
|
||||
}
|
||||
const frame = toDataFrame(
|
||||
await getBackendSrv().post(searchURI, {
|
||||
...(req ?? {}),
|
||||
from,
|
||||
limit: nextPageSizes,
|
||||
})
|
||||
);
|
||||
const resp = await getBackendSrv().post<SearchAPIResponse>(searchURI, {
|
||||
...(req ?? {}),
|
||||
from,
|
||||
limit: nextPageSizes,
|
||||
});
|
||||
const frame = toDataFrame(resp.frames[0]);
|
||||
|
||||
if (!frame) {
|
||||
console.log('no results', frame);
|
||||
|
Loading…
Reference in New Issue
Block a user