Skip to content

Commit

Permalink
Fixed the suggestions
Browse files Browse the repository at this point in the history
Signed-off-by: Rohanraj123 <[email protected]>
  • Loading branch information
Rohanraj123 committed Dec 5, 2024
1 parent f1ac299 commit 5058ec2
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 23 deletions.
Binary file added cmd/es-index-cleaner/es-index-cleaner
Binary file not shown.
2 changes: 1 addition & 1 deletion cmd/jaeger/config-elasticsearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ processors:

exporters:
jaeger_storage_exporter:
trace_storage: some_storage
trace_storage: some_storage
6 changes: 2 additions & 4 deletions cmd/jaeger/internal/extension/jaegerstorage/extension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,7 @@ func TestXYZsearch(t *testing.T) {
Servers: []string{server.URL},
LogLevel: "error",
Rollover: esCfg.Rollover{
Enabled: true,
IndexPattern: "index-*",
Enabled: true,
},
},
})
Expand All @@ -237,8 +236,7 @@ func TestXYZsearch(t *testing.T) {
Servers: []string{server.URL},
LogLevel: "error",
Rollover: esCfg.Rollover{
Enabled: true,
IndexPattern: "index-*",
Enabled: true,
},
},
})
Expand Down
12 changes: 8 additions & 4 deletions pkg/es/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,19 @@ const (

// IndexCleaner struct for configuring index cleaning
type IndexCleaner struct {
Enabled bool `mapstructure:"enabled"`
// Enabled specifies whether the index cleaner functionality is enabled.
// when set to true, the index cleaner will periodically run based on the specified frequency.
Enabled bool `mapstructure:"enabled"`
// Frequency defines the interval at which the index cleaner runs.
Frequency time.Duration `mapstructure:"frequency" validate:"gt=0"`
}

// Rollover struct for configuring roll over
type Rollover struct {
Enabled bool `mapstructure:"enabled" valid:"required"`
IndexPattern string `mapstructure:"index_pattern" valid:"required"`
Frequency time.Duration `mapstructure:"frequency" validate:"gt=0"`
// Enabled specifies whether the rollover functionality is enabled.
Enabled bool `mapstructure:"enabled" valid:"required"`
// Frequency specifies the interval at which the rollover process runs.
Frequency time.Duration `mapstructure:"frequency" validate:"gt=0"`
}

// IndexOptions describes the index format and rollover frequency
Expand Down
3 changes: 1 addition & 2 deletions pkg/es/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -734,8 +734,7 @@ func TestValidate(t *testing.T) {
config: &Configuration{
Servers: []string{"localhost:8000/dummyserver"},
Rollover: Rollover{
Enabled: true,
IndexPattern: "index-*",
Enabled: true,
},
},
expectedError: false,
Expand Down
13 changes: 11 additions & 2 deletions plugin/storage/es/es_mapping_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,31 @@ package es
import (
"fmt"
"log"
"os"
"os/exec"

"github.com/spf13/cobra"
)

// NewEsMappingsCommand defines the new CLI command to run esmapping-generator
func NewEsMappingsCommand() *cobra.Command {
return &cobra.Command{
Use: "es-mappings",
Short: "Print Elasticsearch index mappings to stdout",
Run: func(_ *cobra.Command, _ []string) {
if _, err := os.Stat("./cmd/esmapping-generator"); os.IsNotExist(err) {
log.Fatalf("esmapping-generator not found: %v", err)
}

// Run the esmapping-generator command
execCmd := exec.Command("go", "run", "./cmd/esmapping-generator")
err := execCmd.Run()
output, err := execCmd.CombinedOutput()
if err != nil {
log.Fatalf("Error executing esmapping-generator: %v", err)
log.Printf("Error executing esmapping-generator: %v\nOutput: %s", err, output)
return
}
fmt.Println("esmapping-generator executed successfully")
fmt.Printf("%s\n", output)
},
}
}
12 changes: 4 additions & 8 deletions plugin/storage/es/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,7 @@ func TestESStorageFactoryWithConfig(t *testing.T) {
Servers: []string{server.URL},
LogLevel: "error",
Rollover: escfg.Rollover{
Enabled: true,
IndexPattern: "index-*",
Enabled: true,
},
}
factory, err := NewFactoryWithConfig(cfg, metrics.NullFactory, zap.NewNop())
Expand All @@ -292,8 +291,7 @@ func TestConfigurationValidation(t *testing.T) {
cfg: escfg.Configuration{
Servers: []string{"http://localhost:9200"},
Rollover: escfg.Rollover{
Enabled: true,
IndexPattern: "index-*",
Enabled: true,
},
},
wantErr: false,
Expand All @@ -302,8 +300,7 @@ func TestConfigurationValidation(t *testing.T) {
name: "missing servers",
cfg: escfg.Configuration{
Rollover: escfg.Rollover{
Enabled: true,
IndexPattern: "index-*",
Enabled: true,
},
},
wantErr: true,
Expand Down Expand Up @@ -337,8 +334,7 @@ func TestESStorageFactoryWithConfigError(t *testing.T) {
Servers: []string{"http://127.0.0.1:65535"},
LogLevel: "error",
Rollover: escfg.Rollover{
Enabled: true,
IndexPattern: "index-*",
Enabled: true,
},
}
_, err := NewFactoryWithConfig(cfg, metrics.NullFactory, zap.NewNop())
Expand Down
9 changes: 8 additions & 1 deletion plugin/storage/es/index_cleaner.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,14 @@ func (cfg *CleanerConfigWrapper) RunCleaner() {

// runESIndexCleaner runs the cmd/es-index-cleaner command.
func (cfg *CleanerConfigWrapper) runESIndexCleaner() error {
cmd := exec.Command("./cmd/es-index-cleaner")
if len(cfg.Servers) == 0 {
return fmt.Errorf("elasticsearch server URL is missing in configuration")
}

esURL := cfg.Servers[0]
numOfDays := int(cfg.MaxSpanAge.Hours() / 24)

cmd := exec.Command("./cmd/es-index-cleaner", fmt.Sprintf("%d", numOfDays), esURL)
cmd.Args = append(cmd.Args, "--max-span-age", cfg.MaxSpanAge.String())

err := cmd.Run()
Expand Down
3 changes: 2 additions & 1 deletion plugin/storage/es/index_rollover.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type RolloverConfigWrapper struct {
*config.Configuration
}

// RunRollover schedules and runs the rollover process based on the configured frequency.
func (cfg *RolloverConfigWrapper) RunRollover() {
if !cfg.Rollover.Enabled {
log.Println("Rollover is disabled, skipping...")
Expand All @@ -35,9 +36,9 @@ func (cfg *RolloverConfigWrapper) RunRollover() {
}
}

// runEsRollover executes the rollover tool.
func (cfg *RolloverConfigWrapper) runEsRollover() error {
cmd := exec.Command("./cmd/es-rollover")
cmd.Args = append(cmd.Args, "--index-pattern", cfg.Rollover.IndexPattern)

err := cmd.Run()
if err != nil {
Expand Down

0 comments on commit 5058ec2

Please sign in to comment.