diff --git a/quesma/clickhouse/clickhouse.go b/quesma/clickhouse/clickhouse.go index fad56fcb0..a35cec466 100644 --- a/quesma/clickhouse/clickhouse.go +++ b/quesma/clickhouse/clickhouse.go @@ -72,6 +72,9 @@ type LogManagerIFace interface { ResolveIndexPattern(ctx context.Context, schema schema.Registry, pattern string) (results []string, err error) FindTable(tableName string) (result *Table) ProcessQuery(ctx context.Context, table *Table, query *model.Query) (rows []model.QueryResultRow, performanceResult PerformanceResult, err error) + CountMultiple(ctx context.Context, tables ...string) (int64, error) + Count(ctx context.Context, table string) (int64, error) + GetTableDefinitions() (TableMap, error) } func NewTableMap() *TableMap { diff --git a/quesma/eql/query_translator.go b/quesma/eql/query_translator.go index d8c31638f..dc35fa35b 100644 --- a/quesma/eql/query_translator.go +++ b/quesma/eql/query_translator.go @@ -21,7 +21,7 @@ import ( // It implements quesma.IQueryTranslator for EQL queries. type ClickhouseEQLQueryTranslator struct { - ClickhouseLM *clickhouse.LogManager + ClickhouseLM clickhouse.LogManagerIFace Table *clickhouse.Table Ctx context.Context } diff --git a/quesma/quesma/query_translator.go b/quesma/quesma/query_translator.go index 76abc91fd..7ade28bdf 100644 --- a/quesma/quesma/query_translator.go +++ b/quesma/quesma/query_translator.go @@ -33,7 +33,7 @@ const ( QueryLanguageEQL = "eql" ) -func NewQueryTranslator(ctx context.Context, language QueryLanguage, schema schema.Schema, table *clickhouse.Table, logManager *clickhouse.LogManager, dateMathRenderer string, indexes []string, configuration *config.QuesmaConfiguration) (queryTranslator IQueryTranslator) { +func NewQueryTranslator(ctx context.Context, language QueryLanguage, schema schema.Schema, table *clickhouse.Table, logManager clickhouse.LogManagerIFace, dateMathRenderer string, indexes []string, configuration *config.QuesmaConfiguration) (queryTranslator IQueryTranslator) { switch language { case QueryLanguageEQL: return &eql.ClickhouseEQLQueryTranslator{ClickhouseLM: logManager, Table: table, Ctx: ctx} diff --git a/quesma/quesma/search.go b/quesma/quesma/search.go index 09480018f..59e0b423a 100644 --- a/quesma/quesma/search.go +++ b/quesma/quesma/search.go @@ -46,7 +46,7 @@ type QueryRunner struct { cancel context.CancelFunc AsyncRequestStorage async_search_storage.AsyncRequestResultStorage AsyncQueriesContexts async_search_storage.AsyncQueryContextStorage - logManager *clickhouse.LogManager + logManager clickhouse.LogManagerIFace cfg *config.QuesmaConfiguration im elasticsearch.IndexManagement debugInfoCollector diag.DebugInfoCollector @@ -83,7 +83,7 @@ func (q *QueryRunner) EnableQueryOptimization(cfg *config.QuesmaConfiguration) { q.transformationPipeline.transformers = append(q.transformationPipeline.transformers, optimize.NewOptimizePipeline(cfg)) } -func NewQueryRunner(lm *clickhouse.LogManager, +func NewQueryRunner(lm clickhouse.LogManagerIFace, cfg *config.QuesmaConfiguration, im elasticsearch.IndexManagement, qmc diag.DebugInfoCollector, @@ -360,7 +360,10 @@ func (q *QueryRunner) handleSearchCommon(ctx context.Context, indexPattern strin var responseBody []byte startTime := time.Now() - id := ctx.Value(tracing.RequestIdCtxKey).(string) + id := "FAKE_ID" + if val := ctx.Value(tracing.RequestIdCtxKey); val != nil { + id = val.(string) + } path := "" if value := ctx.Value(tracing.RequestPath); value != nil { if str, ok := value.(string); ok { @@ -480,8 +483,6 @@ func (q *QueryRunner) handleSearchCommon(ctx context.Context, indexPattern strin func (q *QueryRunner) storeAsyncSearch(qmc diag.DebugInfoCollector, id, asyncId string, startTime time.Time, path string, body types.JSON, result asyncSearchWithError, keep bool, opaqueId string) (responseBody []byte, err error) { - took := time.Since(startTime) - bodyAsBytes, _ := body.Bytes() if result.err == nil { okStatus := 200 asyncResponse := queryparser.SearchToAsyncSearchResponse(result.response, asyncId, false, &okStatus) @@ -491,16 +492,20 @@ func (q *QueryRunner) storeAsyncSearch(qmc diag.DebugInfoCollector, id, asyncId err = result.err } - qmc.PushSecondaryInfo(&diag.QueryDebugSecondarySource{ - Id: id, - AsyncId: asyncId, - OpaqueId: opaqueId, - Path: path, - IncomingQueryBody: bodyAsBytes, - QueryBodyTranslated: result.translatedQueryBody, - QueryTranslatedResults: responseBody, - SecondaryTook: took, - }) + if qmc != nil { + took := time.Since(startTime) + bodyAsBytes, _ := body.Bytes() + qmc.PushSecondaryInfo(&diag.QueryDebugSecondarySource{ + Id: id, + AsyncId: asyncId, + OpaqueId: opaqueId, + Path: path, + IncomingQueryBody: bodyAsBytes, + QueryBodyTranslated: result.translatedQueryBody, + QueryTranslatedResults: responseBody, + SecondaryTook: took, + }) + } if keep { compressedBody := responseBody diff --git a/quesma/table_resolver/table_resolver_dummy.go b/quesma/table_resolver/table_resolver_dummy.go new file mode 100644 index 000000000..df3fef812 --- /dev/null +++ b/quesma/table_resolver/table_resolver_dummy.go @@ -0,0 +1,39 @@ +// Copyright Quesma, licensed under the Elastic License 2.0. +// SPDX-License-Identifier: Elastic-2.0 + +package table_resolver + +import ( + mux "quesma_v2/core" +) + +// DummyTableResolver is a dummy implementation of TableResolver to satisfy the QueryRunner and make it be compatible with the v2 api +// thanks to this we can reuse the existing QueryRunner implementation without any changes. +type DummyTableResolver struct{} + +func NewDummyTableResolver() *DummyTableResolver { + return &DummyTableResolver{} +} + +func (t DummyTableResolver) Start() {} + +func (t DummyTableResolver) Stop() {} + +func (t DummyTableResolver) Resolve(_ string, indexPattern string) *mux.Decision { + return &mux.Decision{ + UseConnectors: []mux.ConnectorDecision{ + &mux.ConnectorDecisionClickhouse{ + ClickhouseTableName: indexPattern, + ClickhouseIndexes: []string{indexPattern}, // TODO this won't work for 'common table' feature + //IsCommonTable: false, + }, + }, + } + +} + +func (t DummyTableResolver) Pipelines() []string { return []string{} } + +func (t DummyTableResolver) RecentDecisions() []mux.PatternDecisions { + return []mux.PatternDecisions{} +}