Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 4 additions & 0 deletions cmd/agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"go.uber.org/zap"

"github.com/uber/jaeger/cmd/agent/app"
"github.com/uber/jaeger/cmd/flags"
"github.com/uber/jaeger/pkg/config"
"github.com/uber/jaeger/pkg/metrics"
)
Expand All @@ -35,6 +36,8 @@ func main() {
Short: "Jaeger agent is a local daemon program which collects tracing data.",
Long: `Jaeger agent is a daemon program that runs on every host and receives tracing data submitted by Jaeger client libraries.`,
RunE: func(cmd *cobra.Command, args []string) error {
flags.TryLoadConfigFile(v, logger)

builder := &app.Builder{}
builder.InitFromViper(v)
runtime.GOMAXPROCS(runtime.NumCPU())
Expand All @@ -58,6 +61,7 @@ func main() {
config.AddFlags(
v,
command,
flags.AddConfigFileFlag,
app.AddFlags,
metrics.AddFlags,
)
Expand Down
5 changes: 4 additions & 1 deletion cmd/collector/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,15 @@ func main() {
Long: `Jaeger collector receives traces from Jaeger agents and agent and runs them through
a processing pipeline.`,
Run: func(cmd *cobra.Command, args []string) {
flags.TryLoadConfigFile(v, logger)

sFlags := new(flags.SharedFlags).InitFromViper(v)
casOptions.InitFromViper(v)
esOptions.InitFromViper(v)

baseMetrics := xkit.Wrap(serviceName, expvar.NewFactory(10))

builderOpts := new(builder.CollectorOptions).InitFromViper(v)
sFlags := new(flags.SharedFlags).InitFromViper(v)

hc, err := healthcheck.Serve(http.StatusServiceUnavailable, builderOpts.CollectorHealthCheckHTTPPort, logger)
if err != nil {
Expand Down Expand Up @@ -130,6 +132,7 @@ func main() {
config.AddFlags(
v,
command,
flags.AddConfigFileFlag,
flags.AddFlags,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

any reason not to have config flag added as part of AddFlags? It would probably also avoid duplicating the code in L65-71 in all binaries, only do it in sFlags := new(flags.SharedFlags).InitFromViper(v)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I did a split for two reasons:

  1. agent does use flags.AddFlags
  2. flags.AddFlags can be specified in config file, so there would be twice sFlags := new(flags.SharedFlags).InitFromViper(v)

Copy link
Copy Markdown
Member

@yurishkuro yurishkuro Oct 11, 2017

Choose a reason for hiding this comment

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

I see - makes sense. In that case can we move L65-71 into that package too, so that we can have just a one liner in the mains? E.g. something like flags.TryLoadConfigFile(v, logger)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

also, by doing that we can make flags.ExternalConfFlags type private. I suggest renaming it to ConfigFile(Flag) ("external" is non-informative)

builder.AddFlags,
casOptions.AddFlags,
Expand Down
18 changes: 18 additions & 0 deletions cmd/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"time"

"github.com/spf13/viper"
"go.uber.org/zap"
)

const (
Expand All @@ -36,8 +37,25 @@ const (
logLevel = "log-level"
dependencyStorageType = "dependency-storage.type"
dependencyStorageDataFrequency = "dependency-storage.data-frequency"
configFile = "config-file"
)

// AddConfigFileFlag adds flags for ExternalConfFlags
func AddConfigFileFlag(flagSet *flag.FlagSet) {
flagSet.String(configFile, "", "Configuration file in JSON, TOML, YAML, HCL, or Java properties formats (default none). See spf13/viper for precedence.")
}

// TryLoadConfigFile initializes viper with config file specified as flag
func TryLoadConfigFile(v *viper.Viper, logger *zap.Logger) {
if file := v.GetString(configFile); file != "" {
v.SetConfigFile(file)
err := v.ReadInConfig()
if err != nil {
logger.Fatal("Error loading config file", zap.Error(err), zap.String(configFile, file))
}
}
}

// SharedFlags holds flags configuration
type SharedFlags struct {
// SpanStorage defines common settings for Span Storage.
Expand Down
5 changes: 4 additions & 1 deletion cmd/query/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@ func main() {
Short: "Jaeger query is a service to access tracing data",
Long: `Jaeger query is a service to access tracing data and host UI.`,
Run: func(cmd *cobra.Command, args []string) {
flags.TryLoadConfigFile(v, logger)

sFlags := new(flags.SharedFlags).InitFromViper(v)
casOptions.InitFromViper(v)
esOptions.InitFromViper(v)
queryOpts := new(builder.QueryOptions).InitFromViper(v)
sFlags := new(flags.SharedFlags).InitFromViper(v)

hc, err := healthcheck.Serve(http.StatusServiceUnavailable, queryOpts.QueryHealthCheckHTTPPort, logger)
if err != nil {
Expand Down Expand Up @@ -123,6 +125,7 @@ func main() {
config.AddFlags(
v,
command,
flags.AddConfigFileFlag,
flags.AddFlags,
casOptions.AddFlags,
esOptions.AddFlags,
Expand Down
6 changes: 4 additions & 2 deletions cmd/standalone/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ func main() {
Long: `Jaeger all-in-one distribution with agent, collector and query. Use with caution this version
uses only in-memory database.`,
RunE: func(cmd *cobra.Command, args []string) error {
runtime.GOMAXPROCS(runtime.NumCPU())
flags.TryLoadConfigFile(v, logger)

cOpts := new(collector.CollectorOptions).InitFromViper(v)
runtime.GOMAXPROCS(runtime.NumCPU())
sFlags := new(flags.SharedFlags).InitFromViper(v)
cOpts := new(collector.CollectorOptions).InitFromViper(v)
qOpts := new(query.QueryOptions).InitFromViper(v)

metricsFactory := xkit.Wrap("jaeger-standalone", expvar.NewFactory(10))
Expand All @@ -80,6 +81,7 @@ func main() {
config.AddFlags(
v,
command,
flags.AddConfigFileFlag,
flags.AddFlags,
collector.AddFlags,
query.AddFlags,
Expand Down