Skip to content

Commit

Permalink
[es-index-cleaner] Use OTEL helper instead of tlscfg (jaegertracing#6259
Browse files Browse the repository at this point in the history
)

## Which problem is this PR solving?
- Part of jaegertracing#4316 

## Description of the changes
- 

## How was this change tested?
- 

## Checklist
- [ ] I have read
https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md
- [ ] I have signed all commits
- [ ] I have added unit tests for the new functionality
- [ ] I have run lint and test steps successfully
  - for `jaeger`: `make lint test`
  - for `jaeger-ui`: `yarn lint` and `yarn test`

Signed-off-by: chahatsagarmain <[email protected]>
  • Loading branch information
chahatsagarmain authored Nov 26, 2024
1 parent 0b75042 commit b2e84b4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
12 changes: 12 additions & 0 deletions cmd/es-index-cleaner/app/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import (
"flag"

"github.com/spf13/viper"
"go.opentelemetry.io/collector/config/configtls"

"github.com/jaegertracing/jaeger/pkg/config/tlscfg"
)

const (
Expand All @@ -19,6 +22,8 @@ const (
password = "es.password"
)

var tlsFlagsCfg = tlscfg.ClientFlagsConfig{Prefix: "es"}

// Config holds configuration for index cleaner binary.
type Config struct {
IndexPrefix string
Expand All @@ -29,6 +34,7 @@ type Config struct {
Username string
Password string
TLSEnabled bool
TLSConfig configtls.ClientConfig
}

// AddFlags adds flags for TLS to the FlagSet.
Expand All @@ -40,6 +46,7 @@ func (*Config) AddFlags(flags *flag.FlagSet) {
flags.String(indexDateSeparator, "-", "Index date separator")
flags.String(username, "", "The username required by storage")
flags.String(password, "", "The password required by storage")
tlsFlagsCfg.AddFlags(flags)
}

// InitFromViper initializes config from viper.Viper.
Expand All @@ -55,4 +62,9 @@ func (c *Config) InitFromViper(v *viper.Viper) {
c.IndexDateSeparator = v.GetString(indexDateSeparator)
c.Username = v.GetString(username)
c.Password = v.GetString(password)
opts, err := tlsFlagsCfg.InitFromViper(v)
if err != nil {
panic(err)
}
c.TLSConfig = opts.ToOtelClientConfig()
}
17 changes: 6 additions & 11 deletions cmd/es-index-cleaner/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package main

import (
"context"
"encoding/base64"
"errors"
"fmt"
Expand All @@ -18,15 +19,13 @@ import (

"github.com/jaegertracing/jaeger/cmd/es-index-cleaner/app"
"github.com/jaegertracing/jaeger/pkg/config"
"github.com/jaegertracing/jaeger/pkg/config/tlscfg"
"github.com/jaegertracing/jaeger/pkg/es/client"
)

func main() {
logger, _ := zap.NewProduction()
v := viper.New()
cfg := &app.Config{}
tlsFlags := tlscfg.ClientFlagsConfig{Prefix: "es"}

command := &cobra.Command{
Use: "jaeger-es-index-cleaner NUM_OF_DAYS http://HOSTNAME:PORT",
Expand All @@ -42,21 +41,18 @@ func main() {
}

cfg.InitFromViper(v)
tlsOpts, err := tlsFlags.InitFromViper(v)
if err != nil {
return err
}
tlsCfg, err := tlsOpts.Config(logger)

ctx := context.Background()
tlscfg, err := cfg.TLSConfig.LoadTLSConfig(ctx)
if err != nil {
return err
return fmt.Errorf("error loading tls config : %w", err)
}
defer tlsOpts.Close()

c := &http.Client{
Timeout: time.Duration(cfg.MasterNodeTimeoutSeconds) * time.Second,
Transport: &http.Transport{
Proxy: http.ProxyFromEnvironment,
TLSClientConfig: tlsCfg,
TLSClientConfig: tlscfg,
},
}
i := client.IndicesClient{
Expand Down Expand Up @@ -101,7 +97,6 @@ func main() {
v,
command,
cfg.AddFlags,
tlsFlags.AddFlags,
)

if err := command.Execute(); err != nil {
Expand Down

0 comments on commit b2e84b4

Please sign in to comment.