diff --git a/cmd/jaeger/internal/command_test.go b/cmd/jaeger/internal/command_test.go index 2ba90be6fbcb..ca42342ab86f 100644 --- a/cmd/jaeger/internal/command_test.go +++ b/cmd/jaeger/internal/command_test.go @@ -23,11 +23,13 @@ func TestCommand(t *testing.T) { cmd.ParseFlags([]string{"--config", "bad-file-name"}) err := cmd.Execute() + require.Error(t, err) require.ErrorContains(t, err, "bad-file-name") t.Run("Should have es-mappings command", func(t *testing.T) { - _, _, subCommand := cmd.Find([]string{"es-mappings"}) - assert.NotNil(t, subCommand) + foundCmd, _, _ := cmd.Find([]string{"es-mappings"}) + assert.NotNil(t, foundCmd, "es-mappings command should be present") + assert.Equal(t, "es-mappings", foundCmd.Use, "Found command should match 'es-mappings'") }) } diff --git a/cmd/jaeger/internal/extension/jaegerstorage/extension_test.go b/cmd/jaeger/internal/extension/jaegerstorage/extension_test.go index 6213c9127655..3ccf680d5c09 100644 --- a/cmd/jaeger/internal/extension/jaegerstorage/extension_test.go +++ b/cmd/jaeger/internal/extension/jaegerstorage/extension_test.go @@ -224,6 +224,10 @@ func TestXYZsearch(t *testing.T) { Elasticsearch: &esCfg.Configuration{ Servers: []string{server.URL}, LogLevel: "error", + Rollover: esCfg.Rollover{ + Enabled: true, + IndexPattern: "index-*", + }, }, }) }) @@ -232,6 +236,10 @@ func TestXYZsearch(t *testing.T) { Opensearch: &esCfg.Configuration{ Servers: []string{server.URL}, LogLevel: "error", + Rollover: esCfg.Rollover{ + Enabled: true, + IndexPattern: "index-*", + }, }, }) }) diff --git a/pkg/es/config/config_test.go b/pkg/es/config/config_test.go index c295d37b70c1..1496caaeacc3 100644 --- a/pkg/es/config/config_test.go +++ b/pkg/es/config/config_test.go @@ -733,6 +733,10 @@ func TestValidate(t *testing.T) { name: "All valid input are set", config: &Configuration{ Servers: []string{"localhost:8000/dummyserver"}, + Rollover: Rollover{ + Enabled: true, + IndexPattern: "index-*", + }, }, expectedError: false, }, diff --git a/plugin/storage/es/es_mapping_generator.go b/plugin/storage/es/es_mapping_generator.go index 2124d88c0763..9c08894d194f 100644 --- a/plugin/storage/es/es_mapping_generator.go +++ b/plugin/storage/es/es_mapping_generator.go @@ -1,3 +1,6 @@ +// Copyright (c) 2024 The Jaeger Authors. +// SPDX-License-Identifier: Apache-2.0 + package es import ( @@ -12,16 +15,13 @@ func NewEsMappingsCommand() *cobra.Command { return &cobra.Command{ Use: "es-mappings", Short: "Print Elasticsearch index mappings to stdout", - Run: runESMappings, + Run: func(_ *cobra.Command, _ []string) { + execCmd := exec.Command("go", "run", "./cmd/esmapping-generator") + err := execCmd.Run() + if err != nil { + log.Fatalf("Error executing esmapping-generator: %v", err) + } + fmt.Println("esmapping-generator executed successfully") + }, } } - -func runESMappings(cmd *cobra.Command, args []string) { - execCmd := exec.Command("go", "run", "./cmd/esmapping-generator") - err := execCmd.Run() - if err != nil { - log.Fatalf("Error executing esmapping-generator: %v", err) - } - - fmt.Println("esmapping-generator executed successfully") -} diff --git a/plugin/storage/es/factory_test.go b/plugin/storage/es/factory_test.go index 4da9a6c6f451..75a0076f504b 100644 --- a/plugin/storage/es/factory_test.go +++ b/plugin/storage/es/factory_test.go @@ -267,9 +267,14 @@ func TestESStorageFactoryWithConfig(t *testing.T) { w.Write(mockEsServerResponse) })) defer server.Close() + cfg := escfg.Configuration{ Servers: []string{server.URL}, LogLevel: "error", + Rollover: escfg.Rollover{ + Enabled: true, + IndexPattern: "index-*", + }, } factory, err := NewFactoryWithConfig(cfg, metrics.NullFactory, zap.NewNop()) require.NoError(t, err) @@ -286,12 +291,28 @@ func TestConfigurationValidation(t *testing.T) { name: "valid configuration", cfg: escfg.Configuration{ Servers: []string{"http://localhost:9200"}, + Rollover: escfg.Rollover{ + Enabled: true, + IndexPattern: "index-*", + }, }, wantErr: false, }, { - name: "missing servers", - cfg: escfg.Configuration{}, + name: "missing servers", + cfg: escfg.Configuration{ + Rollover: escfg.Rollover{ + Enabled: true, + IndexPattern: "index-*", + }, + }, + wantErr: true, + }, + { + name: "missing rollover config", + cfg: escfg.Configuration{ + Servers: []string{"http://localhost:9200"}, + }, wantErr: true, }, } @@ -315,6 +336,10 @@ func TestESStorageFactoryWithConfigError(t *testing.T) { cfg := escfg.Configuration{ Servers: []string{"http://127.0.0.1:65535"}, LogLevel: "error", + Rollover: escfg.Rollover{ + Enabled: true, + IndexPattern: "index-*", + }, } _, err := NewFactoryWithConfig(cfg, metrics.NullFactory, zap.NewNop()) require.ErrorContains(t, err, "failed to create primary Elasticsearch client") diff --git a/plugin/storage/es/index_cleaner.go b/plugin/storage/es/index_cleaner.go index 519e7c0b8956..2bcf7cca4be2 100644 --- a/plugin/storage/es/index_cleaner.go +++ b/plugin/storage/es/index_cleaner.go @@ -1,3 +1,6 @@ +// Copyright (c) 2024 The Jaeger Authors. +// SPDX-License-Identifier: Apache-2.0 + package es import ( diff --git a/plugin/storage/es/index_rollover.go b/plugin/storage/es/index_rollover.go index 711f8f2b2941..be85cb6ea970 100644 --- a/plugin/storage/es/index_rollover.go +++ b/plugin/storage/es/index_rollover.go @@ -1,3 +1,6 @@ +// Copyright (c) 2024 The Jaeger Authors. +// SPDX-License-Identifier: Apache-2.0 + package es import (