Skip to content

Commit b2e84b4

Browse files
[es-index-cleaner] Use OTEL helper instead of tlscfg (#6259)
## Which problem is this PR solving? - Part of #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]>
1 parent 0b75042 commit b2e84b4

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

cmd/es-index-cleaner/app/flags.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import (
77
"flag"
88

99
"github.com/spf13/viper"
10+
"go.opentelemetry.io/collector/config/configtls"
11+
12+
"github.com/jaegertracing/jaeger/pkg/config/tlscfg"
1013
)
1114

1215
const (
@@ -19,6 +22,8 @@ const (
1922
password = "es.password"
2023
)
2124

25+
var tlsFlagsCfg = tlscfg.ClientFlagsConfig{Prefix: "es"}
26+
2227
// Config holds configuration for index cleaner binary.
2328
type Config struct {
2429
IndexPrefix string
@@ -29,6 +34,7 @@ type Config struct {
2934
Username string
3035
Password string
3136
TLSEnabled bool
37+
TLSConfig configtls.ClientConfig
3238
}
3339

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

4552
// InitFromViper initializes config from viper.Viper.
@@ -55,4 +62,9 @@ func (c *Config) InitFromViper(v *viper.Viper) {
5562
c.IndexDateSeparator = v.GetString(indexDateSeparator)
5663
c.Username = v.GetString(username)
5764
c.Password = v.GetString(password)
65+
opts, err := tlsFlagsCfg.InitFromViper(v)
66+
if err != nil {
67+
panic(err)
68+
}
69+
c.TLSConfig = opts.ToOtelClientConfig()
5870
}

cmd/es-index-cleaner/main.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package main
55

66
import (
7+
"context"
78
"encoding/base64"
89
"errors"
910
"fmt"
@@ -18,15 +19,13 @@ import (
1819

1920
"github.com/jaegertracing/jaeger/cmd/es-index-cleaner/app"
2021
"github.com/jaegertracing/jaeger/pkg/config"
21-
"github.com/jaegertracing/jaeger/pkg/config/tlscfg"
2222
"github.com/jaegertracing/jaeger/pkg/es/client"
2323
)
2424

2525
func main() {
2626
logger, _ := zap.NewProduction()
2727
v := viper.New()
2828
cfg := &app.Config{}
29-
tlsFlags := tlscfg.ClientFlagsConfig{Prefix: "es"}
3029

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

4443
cfg.InitFromViper(v)
45-
tlsOpts, err := tlsFlags.InitFromViper(v)
46-
if err != nil {
47-
return err
48-
}
49-
tlsCfg, err := tlsOpts.Config(logger)
44+
45+
ctx := context.Background()
46+
tlscfg, err := cfg.TLSConfig.LoadTLSConfig(ctx)
5047
if err != nil {
51-
return err
48+
return fmt.Errorf("error loading tls config : %w", err)
5249
}
53-
defer tlsOpts.Close()
5450

5551
c := &http.Client{
5652
Timeout: time.Duration(cfg.MasterNodeTimeoutSeconds) * time.Second,
5753
Transport: &http.Transport{
5854
Proxy: http.ProxyFromEnvironment,
59-
TLSClientConfig: tlsCfg,
55+
TLSClientConfig: tlscfg,
6056
},
6157
}
6258
i := client.IndicesClient{
@@ -101,7 +97,6 @@ func main() {
10197
v,
10298
command,
10399
cfg.AddFlags,
104-
tlsFlags.AddFlags,
105100
)
106101

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

0 commit comments

Comments
 (0)