From aa2bb5b37c275e427a66c006a3059a0e1381814a Mon Sep 17 00:00:00 2001 From: Piotr Grabowski Date: Thu, 1 Aug 2024 08:53:22 +0200 Subject: [PATCH] Fix spurious use of indexResolver preventing idling (#589) We have noticed that Quesma still has problems with properly idling (not making queries to ClickHouse Cloud to allow it to idle). The current idling logic relies on checking if table discovery was recently used. It turns out that idle Kibana very often does inserts to an internal `.kibana` index and to `/_monitoring/bulk` endpoint. Even though those requests are routed to Elastic, we still checked if `.kibana` or `_monitoring` are names of enabled indices using indexResolver - this use bumped the LastAccessTime, preventing idling. Fix the issue by avoiding a use of indexResolver if it's an endpoint (`_endpoint`) or if it's an internal index (starting with `.`). --- quesma/feature/not_supported.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/quesma/feature/not_supported.go b/quesma/feature/not_supported.go index 5669f7be5..d93f17e0b 100644 --- a/quesma/feature/not_supported.go +++ b/quesma/feature/not_supported.go @@ -5,7 +5,9 @@ package feature import ( "context" "fmt" + "quesma/elasticsearch" "regexp" + "strings" ) // https://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html @@ -80,6 +82,16 @@ func checkIfOurIndex(ctx context.Context, method string, path string, indexResol if len(match) > 1 { indexNamePart := match[1] var matched bool + + if strings.HasPrefix(indexNamePart, "_") { + // This is not actually an index, this is some endpoint (for example /_monitoring/bulk) + return false + } + // Optimization: avoid using indexResolver for internal indexes + if elasticsearch.IsInternalIndex(indexNamePart) { + return false + } + indexes, err := indexResolver(ctx, indexNamePart) if err != nil { logMessage("Error resolving index: %v", err)