From 8caca9f462a100d0792050ac3840e0f5ba8326ef Mon Sep 17 00:00:00 2001 From: Idriss Neumann Date: Wed, 22 Nov 2023 14:55:52 +0100 Subject: [PATCH] Fix: convert nano to ms and add searchAfter param --- pkg/quickwit/data_query.go | 7 +++++++ src/datasource.ts | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/pkg/quickwit/data_query.go b/pkg/quickwit/data_query.go index 32ee1f8..96efbf8 100644 --- a/pkg/quickwit/data_query.go +++ b/pkg/quickwit/data_query.go @@ -340,6 +340,13 @@ func processLogsQuery(q *Query, b *es.SearchRequestBuilder, from, to int64, defa b.Size(stringToIntWithDefaultValue(metric.Settings.Get("limit").MustString(), defaultSize)) // TODO when hightlight is supported in quickwit // b.AddHighlight() + + // This is currently used only for log context query to get + // log lines before and after the selected log line + searchAfter := metric.Settings.Get("searchAfter").MustArray() + for _, value := range searchAfter { + b.AddSearchAfter(value) + } } func processDocumentQuery(q *Query, b *es.SearchRequestBuilder, from, to int64, defaultTimeField string) { diff --git a/src/datasource.ts b/src/datasource.ts index 2e0193e..e17a863 100644 --- a/src/datasource.ts +++ b/src/datasource.ts @@ -436,6 +436,8 @@ export class QuickwitDataSource private makeLogContextDataRequest = (row: LogRowModel, options?: LogRowContextOptions) => { const direction = options?.direction || LogRowContextQueryDirection.Backward; + const searchAfterNs = row.dataFrame.fields.find((f) => f.name === 'sort')?.values.get(row.rowIndex) ?? [row.timeEpochNs] + const searchAfterMs = [Math.round(searchAfterNs[0]/1000000)] const logQuery: Logs = { type: 'logs', @@ -445,7 +447,7 @@ export class QuickwitDataSource // Sorting of results in the context query sortDirection: direction === LogRowContextQueryDirection.Backward ? 'desc' : 'asc', // Used to get the next log lines before/after the current log line using sort field of selected log line - searchAfter: row.dataFrame.fields.find((f) => f.name === 'sort')?.values.get(row.rowIndex) ?? [row.timeEpochMs], + searchAfter: searchAfterMs, }, };