Skip to content

Commit

Permalink
Add esmapping-generator into jaeger binary
Browse files Browse the repository at this point in the history
Signed-off-by: Rohanraj123 <[email protected]>
  • Loading branch information
Rohanraj123 committed Dec 4, 2024
1 parent 1e70914 commit f1ac299
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 15 deletions.
6 changes: 4 additions & 2 deletions cmd/jaeger/internal/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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'")
})
}

Expand Down
8 changes: 8 additions & 0 deletions cmd/jaeger/internal/extension/jaegerstorage/extension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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-*",
},
},
})
})
Expand All @@ -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-*",
},
},
})
})
Expand Down
4 changes: 4 additions & 0 deletions pkg/es/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
22 changes: 11 additions & 11 deletions plugin/storage/es/es_mapping_generator.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) 2024 The Jaeger Authors.
// SPDX-License-Identifier: Apache-2.0

package es

import (
Expand All @@ -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")

Check warning on line 24 in plugin/storage/es/es_mapping_generator.go

View check run for this annotation

Codecov / codecov/patch

plugin/storage/es/es_mapping_generator.go#L14-L24

Added lines #L14 - L24 were not covered by tests
},
}
}

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")
}
29 changes: 27 additions & 2 deletions plugin/storage/es/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
},
}
Expand All @@ -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")
Expand Down
3 changes: 3 additions & 0 deletions plugin/storage/es/index_cleaner.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) 2024 The Jaeger Authors.
// SPDX-License-Identifier: Apache-2.0

package es

import (
Expand Down
3 changes: 3 additions & 0 deletions plugin/storage/es/index_rollover.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) 2024 The Jaeger Authors.
// SPDX-License-Identifier: Apache-2.0

package es

import (
Expand Down

0 comments on commit f1ac299

Please sign in to comment.