Skip to content

Commit

Permalink
feat(influx): provide means to provide trace debug ids to httpc client
Browse files Browse the repository at this point in the history
  • Loading branch information
jsteenb2 committed Jun 10, 2020
1 parent 11364f9 commit 1d75e3e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
24 changes: 17 additions & 7 deletions cmd/influx/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,15 @@ func newHTTPClient() (*httpc.Client, error) {
version, runtime.GOOS, commit, date,
)

c, err := http.NewHTTPClient(
flags.Host,
flags.Token,
flags.skipVerify,
opts := []httpc.ClientOptFn{
httpc.WithUserAgentHeader(userAgent),
)
}
// This is useful for forcing tracing on a given endpoint.
if flags.traceDebugID != "" {
opts = append(opts, httpc.WithHeader("jaeger-debug-id", flags.traceDebugID))
}

c, err := http.NewHTTPClient(flags.Host, flags.Token, flags.skipVerify, opts...)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -146,8 +149,9 @@ func runEMiddlware(mw cobraRunEMiddleware) genericCLIOptFn {

type globalFlags struct {
config.Config
local bool
skipVerify bool
local bool
skipVerify bool
traceDebugID string
}

var flags globalFlags
Expand Down Expand Up @@ -203,6 +207,12 @@ func (b *cmdInfluxBuilder) cmd(childCmdFns ...func(f *globalFlags, opt genericCL
Desc: "HTTP address of Influx",
Persistent: true,
},
{
DestP: &flags.traceDebugID,
Flag: "trace-debug-id",
Hidden: true,
Persistent: true,
},
}
fOpts.mustRegister(cmd)

Expand Down
7 changes: 7 additions & 0 deletions kit/cli/viper.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type Opt struct {

EnvVar string
Flag string
Hidden bool
Persistent bool
Required bool
Short rune // using rune b/c it guarantees correctness. a short must always be a string of length 1
Expand Down Expand Up @@ -178,6 +179,12 @@ func BindOptions(cmd *cobra.Command, opts []Opt) {
// anyway, go ahead and make a PR and add another type.
panic(fmt.Errorf("unknown destination type %t", o.DestP))
}

// so weirdness with the flagset her, the flag must be set before marking it
// hidden. This is in contrast to the MarkRequired, which can be set before...
if o.Hidden {
flagset.MarkHidden(o.Flag)
}
}
}

Expand Down

0 comments on commit 1d75e3e

Please sign in to comment.