Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions cmd/es-index-cleaner/app/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (*Config) AddFlags(flags *flag.FlagSet) {
}

// InitFromViper initializes config from viper.Viper.
func (c *Config) InitFromViper(v *viper.Viper) {
func (c *Config) InitFromViper(v *viper.Viper) error {
c.IndexPrefix = v.GetString(indexPrefix)
if c.IndexPrefix != "" {
c.IndexPrefix += "-"
Expand All @@ -66,7 +66,8 @@ func (c *Config) InitFromViper(v *viper.Viper) {
c.Password = v.GetString(password)
tlsCfg, err := tlsFlagsCfg.InitFromViper(v)
if err != nil {
panic(err)
return err
}
c.TLSConfig = tlsCfg
return nil
}
2 changes: 1 addition & 1 deletion cmd/es-index-cleaner/app/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestBindFlags(t *testing.T) {
})
require.NoError(t, err)

c.InitFromViper(v)
require.NoError(t, c.InitFromViper(v))
assert.Equal(t, "tenant1-", c.IndexPrefix)
assert.True(t, c.Rollover)
assert.True(t, c.Archive)
Expand Down
4 changes: 3 additions & 1 deletion cmd/es-index-cleaner/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ func main() {
return fmt.Errorf("could not parse NUM_OF_DAYS argument: %w", err)
}

cfg.InitFromViper(v)
if err := cfg.InitFromViper(v); err != nil {
return fmt.Errorf("failed to initialize config: %w", err)
}

ctx := context.Background()
tlscfg, err := cfg.TLSConfig.LoadTLSConfig(ctx)
Expand Down
4 changes: 3 additions & 1 deletion cmd/es-rollover/app/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ type ActionCreatorFunction func(client.Client, Config) Action
// ExecuteAction execute the action returned by the createAction function
func ExecuteAction(opts ActionExecuteOptions, createAction ActionCreatorFunction) error {
cfg := Config{}
cfg.InitFromViper(opts.Viper)
if err := cfg.InitFromViper(opts.Viper); err != nil {
return fmt.Errorf("failed to initialize config: %w", err)
}

ctx := context.Background()
tlsCfg, err := cfg.TLSConfig.LoadTLSConfig(ctx)
Expand Down
5 changes: 3 additions & 2 deletions cmd/es-rollover/app/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func AddFlags(flags *flag.FlagSet) {
}

// InitFromViper initializes config from viper.Viper.
func (c *Config) InitFromViper(v *viper.Viper) {
func (c *Config) InitFromViper(v *viper.Viper) error {
c.IndexPrefix = v.GetString(indexPrefix)
if c.IndexPrefix != "" {
c.IndexPrefix += "-"
Expand All @@ -71,7 +71,8 @@ func (c *Config) InitFromViper(v *viper.Viper) {
c.AdaptiveSampling = v.GetBool(adaptiveSampling)
tlsCfg, err := tlsFlagsCfg.InitFromViper(v)
if err != nil {
panic(err)
return err
}
c.TLSConfig = tlsCfg
return nil
}
2 changes: 1 addition & 1 deletion cmd/es-rollover/app/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestBindFlags(t *testing.T) {
})
require.NoError(t, err)

c.InitFromViper(v)
require.NoError(t, c.InitFromViper(v))
assert.Equal(t, "tenant1-", c.IndexPrefix)
assert.True(t, c.Archive)
assert.Equal(t, 150, c.Timeout)
Expand Down
8 changes: 4 additions & 4 deletions cmd/internal/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ func TryLoadConfigFile(v *viper.Viper) error {
}

// ParseJaegerTags parses the Jaeger tags string into a map.
func ParseJaegerTags(jaegerTags string) map[string]string {
func ParseJaegerTags(jaegerTags string) (map[string]string, error) {
if jaegerTags == "" {
return nil
return nil, nil
}
Comment on lines +42 to 45
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR description states that cmd/tracegen/main.go was updated to replace the logger-creation panic with graceful stderr reporting, but that change is not present in this PR’s diffs. Either include the cmd/tracegen/main.go update (it currently still panics on logger build failure) or adjust the PR description/scope so it matches the actual changes.

Copilot uses AI. Check for mistakes.
tagPairs := strings.Split(string(jaegerTags), ",")
tags := make(map[string]string)
for _, p := range tagPairs {
kv := strings.SplitN(p, "=", 2)
if len(kv) != 2 {
panic(fmt.Sprintf("invalid Jaeger tag pair %q, expected key=value", p))
return nil, fmt.Errorf("invalid Jaeger tag pair %q, expected key=value", p)
}
k, v := strings.TrimSpace(kv[0]), strings.TrimSpace(kv[1])

Expand Down Expand Up @@ -77,7 +77,7 @@ func ParseJaegerTags(jaegerTags string) map[string]string {
tags[k] = v
}

return tags
return tags, nil
}

// SharedFlags holds flags configuration
Expand Down
20 changes: 11 additions & 9 deletions cmd/internal/flags/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestParseJaegerTags(t *testing.T) {
assert.Nil(t, ParseJaegerTags(""))
tags, err := ParseJaegerTags("")
require.NoError(t, err)
assert.Nil(t, tags)

jaegerTags := fmt.Sprintf("%s,%s,%s,%s,%s,%s",
"key=value",
Expand All @@ -34,14 +37,13 @@ func TestParseJaegerTags(t *testing.T) {
"envVar5": "",
}

assert.Equal(t, expectedTags, ParseJaegerTags(jaegerTags))
tags, err = ParseJaegerTags(jaegerTags)
require.NoError(t, err)
assert.Equal(t, expectedTags, tags)
}

func TestParseJaegerTagsPanic(t *testing.T) {
assert.PanicsWithValue(t,
"invalid Jaeger tag pair \"no-equals-sign\", expected key=value",
func() {
ParseJaegerTags("no-equals-sign")
},
)
func TestParseJaegerTagsError(t *testing.T) {
_, err := ParseJaegerTags("no-equals-sign")
require.Error(t, err)
assert.ErrorContains(t, err, "invalid Jaeger tag pair")
}
Loading