Skip to content
This repository was archived by the owner on Nov 7, 2025. It is now read-only.

Commit 364add6

Browse files
authored
Omit non-existing indexes (#1173)
When we query multiple indexes, we may treat non-existent indexes as empty ones. This solves the case when we store daily based indexes in the common table and query with Grafana.
1 parent e3f5729 commit 364add6

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

quesma/quesma/search.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,6 @@ func (q *QueryRunner) HandleMultiSearch(ctx context.Context, defaultIndexName st
243243
StatusCode: http.StatusInternalServerError,
244244
GenericResult: queryparser.BadRequestParseError(err),
245245
}
246-
return nil, err
247246
}
248247

249248
responses = append(responses, wrappedErr)
@@ -505,7 +504,7 @@ func (q *QueryRunner) handleSearchCommon(ctx context.Context, indexPattern strin
505504
for _, indexName := range resolvedIndexes {
506505
table, _ = tables.Load(q.cfg.IndexConfig[indexName].TableName(indexName))
507506
if table == nil {
508-
return []byte{}, end_user_errors.ErrNoSuchTable.New(fmt.Errorf("can't load %s table", indexName)).Details("Table: %s", indexName)
507+
continue
509508
}
510509
if table.VirtualTable {
511510
virtualOnlyTables = append(virtualOnlyTables, indexName)

quesma/table_resolver/rules.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,14 @@ func makeDefaultWildcard(quesmaConf config.QuesmaConfiguration, pipeline string)
134134
for _, target := range targets {
135135
switch target {
136136
case config.ClickhouseTarget:
137+
var tableName string
138+
if quesmaConf.UseCommonTableForWildcard {
139+
tableName = common_table.TableName
140+
} else {
141+
tableName = resolveTableName(quesmaConf, part)
142+
}
137143
useConnectors = append(useConnectors, &quesma_api.ConnectorDecisionClickhouse{
138-
ClickhouseTableName: resolveTableName(quesmaConf, part),
144+
ClickhouseTableName: tableName,
139145
IsCommonTable: quesmaConf.UseCommonTableForWildcard,
140146
ClickhouseIndexes: []string{part},
141147
})

quesma/table_resolver/table_resolver_test.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ func TestTableResolver(t *testing.T) {
5757

5858
cfg := config.QuesmaConfiguration{IndexConfig: indexConf, DefaultQueryTarget: []string{config.ElasticsearchTarget}, DefaultIngestTarget: []string{config.ElasticsearchTarget}}
5959

60+
cfgClickhouseOnlyUseCommonTable := config.QuesmaConfiguration{IndexConfig: indexConf, DefaultQueryTarget: []string{config.ClickhouseTarget}, DefaultIngestTarget: []string{config.ClickhouseTarget}, UseCommonTableForWildcard: true}
61+
6062
tests := []struct {
6163
name string
6264
pipeline string
@@ -66,6 +68,7 @@ func TestTableResolver(t *testing.T) {
6668
virtualTables []string
6769
indexConf map[string]config.IndexConfiguration
6870
expected mux.Decision
71+
quesmaConf *config.QuesmaConfiguration
6972
}{
7073
{
7174
name: "elastic fallback",
@@ -266,6 +269,21 @@ func TestTableResolver(t *testing.T) {
266269
},
267270
indexConf: indexConf,
268271
},
272+
{
273+
name: "query pattern (not existing virtual table)",
274+
pipeline: mux.QueryPipeline,
275+
pattern: "common-index1,common-index2",
276+
virtualTables: []string{"common-index1"},
277+
expected: mux.Decision{
278+
UseConnectors: []mux.ConnectorDecision{&mux.ConnectorDecisionClickhouse{
279+
ClickhouseTableName: common_table.TableName,
280+
ClickhouseIndexes: []string{"common-index1", "common-index2"},
281+
IsCommonTable: true,
282+
}},
283+
},
284+
indexConf: indexConf,
285+
quesmaConf: &cfgClickhouseOnlyUseCommonTable,
286+
},
269287
{
270288
name: "query kibana internals",
271289
pipeline: mux.QueryPipeline,
@@ -377,6 +395,12 @@ func TestTableResolver(t *testing.T) {
377395

378396
for _, tt := range tests {
379397
t.Run(tt.name, func(t *testing.T) {
398+
399+
currentQuesmaConf := cfg
400+
if tt.quesmaConf != nil {
401+
currentQuesmaConf = *tt.quesmaConf
402+
}
403+
380404
tableDiscovery := clickhouse.NewEmptyTableDiscovery()
381405

382406
for _, index := range tt.clickhouseIndexes {
@@ -394,7 +418,7 @@ func TestTableResolver(t *testing.T) {
394418

395419
elasticResolver := elasticsearch.NewFixedIndexManagement(tt.elasticIndexes...)
396420

397-
resolver := NewTableResolver(cfg, tableDiscovery, elasticResolver)
421+
resolver := NewTableResolver(currentQuesmaConf, tableDiscovery, elasticResolver)
398422

399423
decision := resolver.Resolve(tt.pipeline, tt.pattern)
400424

0 commit comments

Comments
 (0)