diff --git a/quesma/quesma/search_opensearch_test.go b/quesma/quesma/search_opensearch_test.go index 538e61e04..59884957b 100644 --- a/quesma/quesma/search_opensearch_test.go +++ b/quesma/quesma/search_opensearch_test.go @@ -19,6 +19,7 @@ import ( ) func TestSearchOpensearch(t *testing.T) { + cfg := config.QuesmaConfiguration{IndexConfig: map[string]config.IndexConfiguration{tableName: {Enabled: true}}} table := clickhouse.Table{ Name: tableName, Config: clickhouse.NewDefaultCHConfig(), @@ -36,7 +37,7 @@ func TestSearchOpensearch(t *testing.T) { assert.NoError(t, err) defer db.Close() lm := clickhouse.NewLogManagerWithConnection(db, concurrent.NewMapWith(tableName, &table)) - managementConsole := ui.NewQuesmaManagementConsole(config.QuesmaConfiguration{}, nil, nil, make(<-chan tracing.LogWithLevel, 50000), telemetry.NewPhoneHomeEmptyAgent()) + managementConsole := ui.NewQuesmaManagementConsole(cfg, nil, nil, make(<-chan tracing.LogWithLevel, 50000), telemetry.NewPhoneHomeEmptyAgent()) cw := queryparser.ClickhouseQueryTranslator{ClickhouseLM: lm, Table: &table, Ctx: context.Background()} simpleQuery, queryInfo, _ := cw.ParseQuery(tt.QueryJson) @@ -49,7 +50,7 @@ func TestSearchOpensearch(t *testing.T) { } queryRunner := NewQueryRunner() - _, err = queryRunner.handleSearch(ctx, tableName, []byte(tt.QueryJson), config.QuesmaConfiguration{}, lm, nil, managementConsole) + _, err = queryRunner.handleSearch(ctx, tableName, []byte(tt.QueryJson), cfg, lm, nil, managementConsole) assert.NoError(t, err) if err = mock.ExpectationsWereMet(); err != nil { @@ -152,6 +153,7 @@ func TestHighlighter(t *testing.T) { ], "version": true }` + cfg := config.QuesmaConfiguration{IndexConfig: map[string]config.IndexConfiguration{tableName: {Enabled: true}}} table := clickhouse.Table{ Name: tableName, Config: clickhouse.NewDefaultCHConfig(), @@ -167,7 +169,7 @@ func TestHighlighter(t *testing.T) { assert.NoError(t, err) defer db.Close() lm := clickhouse.NewLogManagerWithConnection(db, concurrent.NewMapWith(tableName, &table)) - managementConsole := ui.NewQuesmaManagementConsole(config.QuesmaConfiguration{}, nil, nil, make(<-chan tracing.LogWithLevel, 50000), telemetry.NewPhoneHomeEmptyAgent()) + managementConsole := ui.NewQuesmaManagementConsole(cfg, nil, nil, make(<-chan tracing.LogWithLevel, 50000), telemetry.NewPhoneHomeEmptyAgent()) mock.ExpectQuery("").WillReturnRows(sqlmock.NewRows([]string{"message$*%:;", "host.name", "@timestamp"}). // careful, it's not always in this order, order is nondeterministic AddRow("abcd", "abcd", "abcd"). @@ -177,7 +179,7 @@ func TestHighlighter(t *testing.T) { AddRow("text", "text", "text")) queryRunner := NewQueryRunner() - response, err := queryRunner.handleSearch(ctx, tableName, []byte(query), config.QuesmaConfiguration{}, lm, nil, managementConsole) + response, err := queryRunner.handleSearch(ctx, tableName, []byte(query), cfg, lm, nil, managementConsole) assert.NoError(t, err) if err = mock.ExpectationsWereMet(); err != nil { t.Fatal("there were unfulfilled expections:", err) diff --git a/quesma/quesma/search_test.go b/quesma/quesma/search_test.go index 0612869f9..acb214d60 100644 --- a/quesma/quesma/search_test.go +++ b/quesma/quesma/search_test.go @@ -49,6 +49,7 @@ var ctx = context.WithValue(context.TODO(), tracing.RequestIdCtxKey, tracing.Get const tableName = `logs-generic-default` func TestAsyncSearchHandler(t *testing.T) { + cfg := config.QuesmaConfiguration{IndexConfig: map[string]config.IndexConfiguration{tableName: {Enabled: true}}} table := concurrent.NewMapWith(tableName, &clickhouse.Table{ Name: tableName, Config: clickhouse.NewDefaultCHConfig(), @@ -82,7 +83,7 @@ func TestAsyncSearchHandler(t *testing.T) { defer db.Close() assert.NoError(t, err) lm := clickhouse.NewLogManagerWithConnection(db, table) - managementConsole := ui.NewQuesmaManagementConsole(config.QuesmaConfiguration{}, nil, nil, make(<-chan tracing.LogWithLevel, 50000), telemetry.NewPhoneHomeEmptyAgent()) + managementConsole := ui.NewQuesmaManagementConsole(cfg, nil, nil, make(<-chan tracing.LogWithLevel, 50000), telemetry.NewPhoneHomeEmptyAgent()) for _, wantedRegex := range tt.WantedRegexes { if tt.WantedParseResult.Typ == model.ListAllFields { @@ -99,7 +100,7 @@ func TestAsyncSearchHandler(t *testing.T) { mock.ExpectQuery(wantedRegex).WillReturnRows(sqlmock.NewRows([]string{"@timestamp", "host.name"})) } queryRunner := NewQueryRunner() - _, err = queryRunner.handleAsyncSearch(ctx, config.QuesmaConfiguration{}, tableName, []byte(tt.QueryJson), lm, nil, managementConsole, defaultAsyncSearchTimeout, true) + _, err = queryRunner.handleAsyncSearch(ctx, cfg, tableName, []byte(tt.QueryJson), lm, nil, managementConsole, defaultAsyncSearchTimeout, true) assert.NoError(t, err) if err := mock.ExpectationsWereMet(); err != nil { @@ -110,6 +111,7 @@ func TestAsyncSearchHandler(t *testing.T) { } func TestAsyncSearchHandlerSpecialCharacters(t *testing.T) { + cfg := config.QuesmaConfiguration{IndexConfig: map[string]config.IndexConfiguration{tableName: {Enabled: true}}} table := clickhouse.Table{ Name: tableName, Config: clickhouse.NewDefaultCHConfig(), @@ -130,14 +132,14 @@ func TestAsyncSearchHandlerSpecialCharacters(t *testing.T) { defer db.Close() assert.NoError(t, err) lm := clickhouse.NewLogManagerWithConnection(db, concurrent.NewMapWith(tableName, &table)) - managementConsole := ui.NewQuesmaManagementConsole(config.QuesmaConfiguration{}, nil, nil, make(<-chan tracing.LogWithLevel, 50000), telemetry.NewPhoneHomeEmptyAgent()) + managementConsole := ui.NewQuesmaManagementConsole(cfg, nil, nil, make(<-chan tracing.LogWithLevel, 50000), telemetry.NewPhoneHomeEmptyAgent()) for _, expectedSql := range tt.ExpectedSQLs { mock.ExpectQuery(testdata.EscapeBrackets(expectedSql)).WillReturnRows(sqlmock.NewRows([]string{"@timestamp", "host.name"})) } queryRunner := NewQueryRunner() - _, err = queryRunner.handleAsyncSearch(ctx, config.QuesmaConfiguration{}, tableName, []byte(tt.QueryRequestJson), lm, nil, managementConsole, defaultAsyncSearchTimeout, true) + _, err = queryRunner.handleAsyncSearch(ctx, cfg, tableName, []byte(tt.QueryRequestJson), lm, nil, managementConsole, defaultAsyncSearchTimeout, true) assert.NoError(t, err) if err = mock.ExpectationsWereMet(); err != nil { @@ -163,6 +165,7 @@ var table = concurrent.NewMapWith(tableName, &clickhouse.Table{ }) func TestSearchHandler(t *testing.T) { + cfg := config.QuesmaConfiguration{IndexConfig: map[string]config.IndexConfiguration{tableName: {Enabled: true}}} for _, tt := range testdata.TestsSearch { t.Run(tt.Name, func(t *testing.T) { db, mock, err := sqlmock.New() @@ -173,13 +176,13 @@ func TestSearchHandler(t *testing.T) { assert.NoError(t, err) lm := clickhouse.NewLogManagerWithConnection(db, table) - managementConsole := ui.NewQuesmaManagementConsole(config.QuesmaConfiguration{}, nil, nil, make(<-chan tracing.LogWithLevel, 50000), telemetry.NewPhoneHomeEmptyAgent()) + managementConsole := ui.NewQuesmaManagementConsole(cfg, nil, nil, make(<-chan tracing.LogWithLevel, 50000), telemetry.NewPhoneHomeEmptyAgent()) for _, wantedRegex := range tt.WantedRegexes { mock.ExpectQuery(testdata.EscapeWildcard(testdata.EscapeBrackets(wantedRegex))). WillReturnRows(sqlmock.NewRows([]string{"@timestamp", "host.name"})) } queryRunner := NewQueryRunner() - _, _ = queryRunner.handleSearch(ctx, tableName, []byte(tt.QueryJson), config.QuesmaConfiguration{}, lm, nil, managementConsole) + _, _ = queryRunner.handleSearch(ctx, tableName, []byte(tt.QueryJson), cfg, lm, nil, managementConsole) if err := mock.ExpectationsWereMet(); err != nil { t.Fatal("there were unfulfilled expections:", err) @@ -190,6 +193,7 @@ func TestSearchHandler(t *testing.T) { // TODO this test gives wrong results?? func TestSearchHandlerNoAttrsConfig(t *testing.T) { + cfg := config.QuesmaConfiguration{IndexConfig: map[string]config.IndexConfiguration{tableName: {Enabled: true}}} for _, tt := range testdata.TestsSearchNoAttrs { t.Run(tt.Name, func(t *testing.T) { db, mock, err := sqlmock.New() @@ -200,12 +204,12 @@ func TestSearchHandlerNoAttrsConfig(t *testing.T) { assert.NoError(t, err) lm := clickhouse.NewLogManagerWithConnection(db, table) - managementConsole := ui.NewQuesmaManagementConsole(config.QuesmaConfiguration{}, nil, nil, make(<-chan tracing.LogWithLevel, 50000), telemetry.NewPhoneHomeEmptyAgent()) + managementConsole := ui.NewQuesmaManagementConsole(cfg, nil, nil, make(<-chan tracing.LogWithLevel, 50000), telemetry.NewPhoneHomeEmptyAgent()) for _, wantedRegex := range tt.WantedRegexes { mock.ExpectQuery(testdata.EscapeBrackets(wantedRegex)).WillReturnRows(sqlmock.NewRows([]string{"@timestamp", "host.name"})) } queryRunner := NewQueryRunner() - _, _ = queryRunner.handleSearch(ctx, tableName, []byte(tt.QueryJson), config.QuesmaConfiguration{}, lm, nil, managementConsole) + _, _ = queryRunner.handleSearch(ctx, tableName, []byte(tt.QueryJson), cfg, lm, nil, managementConsole) if err := mock.ExpectationsWereMet(); err != nil { t.Fatal("there were unfulfilled expections:", err) @@ -215,6 +219,7 @@ func TestSearchHandlerNoAttrsConfig(t *testing.T) { } func TestAsyncSearchFilter(t *testing.T) { + cfg := config.QuesmaConfiguration{IndexConfig: map[string]config.IndexConfiguration{tableName: {Enabled: true}}} for _, tt := range testdata.TestSearchFilter { t.Run(tt.Name, func(t *testing.T) { db, mock, err := sqlmock.New() @@ -225,12 +230,12 @@ func TestAsyncSearchFilter(t *testing.T) { assert.NoError(t, err) lm := clickhouse.NewLogManagerWithConnection(db, table) - managementConsole := ui.NewQuesmaManagementConsole(config.QuesmaConfiguration{}, nil, nil, make(<-chan tracing.LogWithLevel, 50000), telemetry.NewPhoneHomeEmptyAgent()) + managementConsole := ui.NewQuesmaManagementConsole(cfg, nil, nil, make(<-chan tracing.LogWithLevel, 50000), telemetry.NewPhoneHomeEmptyAgent()) for _, wantedRegex := range tt.WantedRegexes { mock.ExpectQuery(testdata.EscapeBrackets(wantedRegex)).WillReturnRows(sqlmock.NewRows([]string{"@timestamp", "host.name"})) } queryRunner := NewQueryRunner() - _, _ = queryRunner.handleAsyncSearch(ctx, config.QuesmaConfiguration{}, tableName, []byte(tt.QueryJson), lm, nil, managementConsole, defaultAsyncSearchTimeout, true) + _, _ = queryRunner.handleAsyncSearch(ctx, cfg, tableName, []byte(tt.QueryJson), lm, nil, managementConsole, defaultAsyncSearchTimeout, true) if err := mock.ExpectationsWereMet(); err != nil { t.Fatal("there were unfulfilled expections:", err) } @@ -243,6 +248,7 @@ func TestAsyncSearchFilter(t *testing.T) { // (testing of creating response is lacking), because of `sqlmock` limitation. // It can't return uint64, thus creating response code panics because of that. func TestHandlingDateTimeFields(t *testing.T) { + cfg := config.QuesmaConfiguration{IndexConfig: map[string]config.IndexConfiguration{tableName: {Enabled: true}}} // I'm testing querying for all 3 types of fields that we support right now. const dateTimeTimestampField = "timestamp" const dateTime64TimestampField = "timestamp64" @@ -294,7 +300,7 @@ func TestHandlingDateTimeFields(t *testing.T) { } defer db.Close() lm := clickhouse.NewLogManagerWithConnection(db, concurrent.NewMapWith(tableName, &table)) - managementConsole := ui.NewQuesmaManagementConsole(config.QuesmaConfiguration{}, nil, nil, make(<-chan tracing.LogWithLevel, 50000), telemetry.NewPhoneHomeEmptyAgent()) + managementConsole := ui.NewQuesmaManagementConsole(cfg, nil, nil, make(<-chan tracing.LogWithLevel, 50000), telemetry.NewPhoneHomeEmptyAgent()) for _, fieldName := range []string{dateTimeTimestampField, dateTime64TimestampField, dateTime64OurTimestampField} { mock.ExpectQuery(testdata.EscapeBrackets(`SELECT count() FROM "logs-generic-default" WHERE `)). @@ -303,7 +309,7 @@ func TestHandlingDateTimeFields(t *testing.T) { WillReturnRows(sqlmock.NewRows([]string{"key", "doc_count"})) // .AddRow(1000, uint64(10)).AddRow(1001, uint64(20))) // here rows should be added if uint64 were supported queryRunner := NewQueryRunner() - response, err := queryRunner.handleAsyncSearch(ctx, config.QuesmaConfiguration{}, tableName, []byte(query(fieldName)), lm, nil, managementConsole, defaultAsyncSearchTimeout, true) + response, err := queryRunner.handleAsyncSearch(ctx, cfg, tableName, []byte(query(fieldName)), lm, nil, managementConsole, defaultAsyncSearchTimeout, true) assert.NoError(t, err) var responseMap model.JsonMap @@ -320,6 +326,7 @@ func TestHandlingDateTimeFields(t *testing.T) { // (top 10 values, "other" value, min/max). // Both `_search`, and `_async_search` handlers are tested. func TestNumericFacetsQueries(t *testing.T) { + cfg := config.QuesmaConfiguration{IndexConfig: map[string]config.IndexConfiguration{tableName: {Enabled: true}}} table := concurrent.NewMapWith(tableName, &clickhouse.Table{ Name: tableName, Config: clickhouse.NewDefaultCHConfig(), @@ -346,7 +353,7 @@ func TestNumericFacetsQueries(t *testing.T) { defer db.Close() assert.NoError(t, err) lm := clickhouse.NewLogManagerWithConnection(db, table) - managementConsole := ui.NewQuesmaManagementConsole(config.QuesmaConfiguration{}, nil, nil, make(<-chan tracing.LogWithLevel, 50000), telemetry.NewPhoneHomeEmptyAgent()) + managementConsole := ui.NewQuesmaManagementConsole(cfg, nil, nil, make(<-chan tracing.LogWithLevel, 50000), telemetry.NewPhoneHomeEmptyAgent()) returnedBuckets := sqlmock.NewRows([]string{"", ""}) for _, row := range tt.ResultRows { @@ -359,9 +366,9 @@ func TestNumericFacetsQueries(t *testing.T) { queryRunner := NewQueryRunner() var response []byte if handlerName == "handleSearch" { - response, err = queryRunner.handleSearch(ctx, tableName, []byte(tt.QueryJson), config.QuesmaConfiguration{}, lm, nil, managementConsole) + response, err = queryRunner.handleSearch(ctx, tableName, []byte(tt.QueryJson), cfg, lm, nil, managementConsole) } else if handlerName == "handleAsyncSearch" { - response, err = queryRunner.handleAsyncSearch(ctx, config.QuesmaConfiguration{}, tableName, []byte(tt.QueryJson), lm, nil, managementConsole, defaultAsyncSearchTimeout, true) + response, err = queryRunner.handleAsyncSearch(ctx, cfg, tableName, []byte(tt.QueryJson), lm, nil, managementConsole, defaultAsyncSearchTimeout, true) } assert.NoError(t, err) @@ -408,7 +415,7 @@ func TestAllUnsupportedQueryTypesAreProperlyRecorded(t *testing.T) { assert.NoError(t, err) lm := clickhouse.NewLogManagerWithConnection(db, table) - cfg := config.QuesmaConfiguration{} + cfg := config.QuesmaConfiguration{IndexConfig: map[string]config.IndexConfiguration{tableName: {Enabled: true}}} logChan := logger.InitOnlyChannelLoggerForTests(cfg, &tracing.AsyncTraceLogger{AsyncQueryTrace: concurrent.NewMap[string, tracing.TraceCtx]()}) managementConsole := ui.NewQuesmaManagementConsole(cfg, nil, nil, logChan, telemetry.NewPhoneHomeEmptyAgent()) go managementConsole.RunOnlyChannelProcessor() @@ -459,7 +466,7 @@ func TestDifferentUnsupportedQueries(t *testing.T) { assert.NoError(t, err) lm := clickhouse.NewLogManagerWithConnection(db, table) - cfg := config.QuesmaConfiguration{} + cfg := config.QuesmaConfiguration{IndexConfig: map[string]config.IndexConfiguration{tableName: {Enabled: true}}} logChan := logger.InitOnlyChannelLoggerForTests(cfg, &tracing.AsyncTraceLogger{AsyncQueryTrace: concurrent.NewMap[string, tracing.TraceCtx]()}) managementConsole := ui.NewQuesmaManagementConsole(cfg, nil, nil, logChan, telemetry.NewPhoneHomeEmptyAgent()) go managementConsole.RunOnlyChannelProcessor()