Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 11 additions & 0 deletions cmd/agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package main

import (
"fmt"
"runtime"

"github.com/pkg/errors"
Expand All @@ -23,6 +24,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 +37,14 @@ 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 {
if c := new(flags.ExternalConfFlags).InitFromViper(v); c.ConfigFile != "" {
v.SetConfigFile(c.ConfigFile)
err := v.ReadInConfig()
if err != nil {
logger.Fatal(fmt.Sprintf("Fatal error config file: %s \n", c.ConfigFile), zap.Error(err))
}
}

builder := &app.Builder{}
builder.InitFromViper(v)
runtime.GOMAXPROCS(runtime.NumCPU())
Expand All @@ -58,6 +68,7 @@ func main() {
config.AddFlags(
v,
command,
flags.AddConfFileFlag,
app.AddFlags,
metrics.AddFlags,
)
Expand Down
12 changes: 11 additions & 1 deletion cmd/collector/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package main

import (
"fmt"
"net"
"net/http"
"os"
Expand Down Expand Up @@ -61,13 +62,21 @@ 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) {
if c := new(flags.ExternalConfFlags).InitFromViper(v); c.ConfigFile != "" {
v.SetConfigFile(c.ConfigFile)
err := v.ReadInConfig()
if err != nil {
logger.Fatal(fmt.Sprintf("Fatal error config file: %s \n", c.ConfigFile), zap.Error(err))
}
}

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 +139,7 @@ func main() {
config.AddFlags(
v,
command,
flags.AddConfFileFlag,
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
17 changes: 17 additions & 0 deletions cmd/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,25 @@ const (
logLevel = "log-level"
dependencyStorageType = "dependency-storage.type"
dependencyStorageDataFrequency = "dependency-storage.data-frequency"
configFile = "config-file"
)

// ExternalConfFlags holds configuration for external sources like configuration files
type ExternalConfFlags struct {
ConfigFile string
}

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

// InitFromViper initializes ExternalConfFlags with properties from viper
func (flags *ExternalConfFlags) InitFromViper(v *viper.Viper) *ExternalConfFlags {
flags.ConfigFile = v.GetString(configFile)
return flags
}

// SharedFlags holds flags configuration
type SharedFlags struct {
// SpanStorage defines common settings for Span Storage.
Expand Down
12 changes: 11 additions & 1 deletion cmd/query/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package main

import (
"fmt"
"net/http"
"os"
"os/signal"
Expand Down Expand Up @@ -54,10 +55,18 @@ 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) {
if c := new(flags.ExternalConfFlags).InitFromViper(v); c.ConfigFile != "" {
v.SetConfigFile(c.ConfigFile)
err := v.ReadInConfig()
if err != nil {
logger.Fatal(fmt.Sprintf("Fatal error config file: %s \n", c.ConfigFile), zap.Error(err))
}
}

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 +132,7 @@ func main() {
config.AddFlags(
v,
command,
flags.AddConfFileFlag,
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.

Nit: s/conf/config for making consistency

flags.AddFlags,
casOptions.AddFlags,
esOptions.AddFlags,
Expand Down
12 changes: 10 additions & 2 deletions cmd/standalone/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,17 @@ 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())
if c := new(flags.ExternalConfFlags).InitFromViper(v); c.ConfigFile != "" {
v.SetConfigFile(c.ConfigFile)
err := v.ReadInConfig()
if err != nil {
logger.Fatal(fmt.Sprintf("Fatal error config file: %s \n", c.ConfigFile), zap.Error(err))
}
}

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 +87,7 @@ func main() {
config.AddFlags(
v,
command,
flags.AddConfFileFlag,
flags.AddFlags,
collector.AddFlags,
query.AddFlags,
Expand Down