Search: Fix tags query (#55851)

* Search: fix tags query

* Search: fix type
This commit is contained in:
Artur Wierzbicki 2022-09-27 21:16:49 +04:00 committed by GitHub
parent 3409979288
commit 814211282a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 16 deletions

View File

@ -63,11 +63,12 @@ func (s *searchHTTPService) doQuery(c *models.ReqContext) response.Response {
return response.Error(500, "error handling search request", resp.Error) return response.Error(500, "error handling search request", resp.Error)
} }
if len(resp.Frames) != 1 { if len(resp.Frames) == 0 {
return response.Error(500, "invalid search response", errors.New("invalid search response")) 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 { if err != nil {
return response.Error(500, "error marshalling response", err) return response.Error(500, "error marshalling response", err)
} }

View File

@ -1,6 +1,7 @@
import { import {
ArrayVector, ArrayVector,
DataFrame, DataFrame,
DataFrameJSON,
DataFrameView, DataFrameView,
getDisplayProcessor, getDisplayProcessor,
SelectableValue, SelectableValue,
@ -19,6 +20,10 @@ const loadingFrameName = 'Loading';
const searchURI = 'api/search-v2'; const searchURI = 'api/search-v2';
type SearchAPIResponse = {
frames: DataFrameJSON[];
};
export class BlugeSearcher implements GrafanaSearcher { export class BlugeSearcher implements GrafanaSearcher {
constructor(private fallbackSearcher: 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 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); return this.fallbackSearcher.tags(query);
} }
for (const frame of frames) {
if (frame.fields[0].name === 'tag') { if (frame.fields[0].name === 'tag') {
return getTermCountsFrom(frame); return getTermCountsFrom(frame);
} }
}
return []; return [];
} }
@ -92,9 +101,10 @@ export class BlugeSearcher implements GrafanaSearcher {
limit: query.limit ?? firstPageSize, 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) { if (first.name === loadingFrameName) {
return this.fallbackSearcher.search(query); return this.fallbackSearcher.search(query);
@ -138,13 +148,12 @@ export class BlugeSearcher implements GrafanaSearcher {
if (from >= meta.count) { if (from >= meta.count) {
return; return;
} }
const frame = toDataFrame( const resp = await getBackendSrv().post<SearchAPIResponse>(searchURI, {
await getBackendSrv().post(searchURI, {
...(req ?? {}), ...(req ?? {}),
from, from,
limit: nextPageSizes, limit: nextPageSizes,
}) });
); const frame = toDataFrame(resp.frames[0]);
if (!frame) { if (!frame) {
console.log('no results', frame); console.log('no results', frame);