Skip to content

Commit

Permalink
Merge 466f7b7 into c7891a4
Browse files Browse the repository at this point in the history
  • Loading branch information
eundoosong committed Apr 30, 2018
2 parents c7891a4 + 466f7b7 commit fdd4ffc
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 36 deletions.
19 changes: 8 additions & 11 deletions cmd/collector/app/builder/builder_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ import (
)

const (
collectorQueueSize = "collector.queue-size"
collectorNumWorkers = "collector.num-workers"
collectorWriteCacheTTL = "collector.write-cache-ttl"
collectorPort = "collector.port"
collectorHTTPPort = "collector.http-port"
collectorZipkinHTTPort = "collector.zipkin.http-port"
collectorHealthCheckHTTPPort = "collector.health-check-http-port"
collectorQueueSize = "collector.queue-size"
collectorNumWorkers = "collector.num-workers"
collectorWriteCacheTTL = "collector.write-cache-ttl"
collectorPort = "collector.port"
collectorHTTPPort = "collector.http-port"
collectorZipkinHTTPort = "collector.zipkin.http-port"
// CollectorDefaultHealthCheckHTTPPort is the default HTTP Port for health check
CollectorDefaultHealthCheckHTTPPort = 14269
)

// CollectorOptions holds configuration for collector
Expand All @@ -44,8 +45,6 @@ type CollectorOptions struct {
CollectorHTTPPort int
// CollectorZipkinHTTPPort is the port that the Zipkin collector service listens in on for http requests
CollectorZipkinHTTPPort int
// CollectorHealthCheckHTTPPort is the port that the health check service listens in on for http requests
CollectorHealthCheckHTTPPort int
}

// AddFlags adds flags for CollectorOptions
Expand All @@ -55,7 +54,6 @@ func AddFlags(flags *flag.FlagSet) {
flags.Int(collectorPort, 14267, "The tchannel port for the collector service")
flags.Int(collectorHTTPPort, 14268, "The http port for the collector service")
flags.Int(collectorZipkinHTTPort, 0, "The http port for the Zipkin collector service e.g. 9411")
flags.Int(collectorHealthCheckHTTPPort, 14269, "The http port for the health check service")
}

// InitFromViper initializes CollectorOptions with properties from viper
Expand All @@ -65,6 +63,5 @@ func (cOpts *CollectorOptions) InitFromViper(v *viper.Viper) *CollectorOptions {
cOpts.CollectorPort = v.GetInt(collectorPort)
cOpts.CollectorHTTPPort = v.GetInt(collectorHTTPPort)
cOpts.CollectorZipkinHTTPPort = v.GetInt(collectorZipkinHTTPort)
cOpts.CollectorHealthCheckHTTPPort = v.GetInt(collectorHealthCheckHTTPPort)
return cOpts
}
10 changes: 5 additions & 5 deletions cmd/collector/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,13 @@ func main() {
if err != nil {
return err
}

builderOpts := new(builder.CollectorOptions).InitFromViper(v)
hc, err := healthcheck.
New(healthcheck.Unavailable, healthcheck.Logger(logger)).
Serve(builderOpts.CollectorHealthCheckHTTPPort)
hc, err := sFlags.NewHealthCheck(logger)
if err != nil {
logger.Fatal("Could not start the health check server.", zap.Error(err))
}

builderOpts := new(builder.CollectorOptions).InitFromViper(v)

mBldr := new(pMetrics.Builder).InitFromViper(v)
metricsFactory, err := mBldr.CreateMetricsFactory("jaeger-collector")
if err != nil {
Expand Down Expand Up @@ -175,6 +173,8 @@ func main() {
command.AddCommand(version.Command())
command.AddCommand(env.Command())

flags.SetDefaultHealthCheckPort(builder.CollectorDefaultHealthCheckHTTPPort)

config.AddFlags(
v,
command,
Expand Down
32 changes: 29 additions & 3 deletions cmd/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,19 @@ import (
"go.uber.org/zap"
"go.uber.org/zap/zapcore"

hc "github.com/jaegertracing/jaeger/pkg/healthcheck"
"github.com/jaegertracing/jaeger/plugin/storage"
)

const (
spanStorageType = "span-storage.type" // deprecated
logLevel = "log-level"
configFile = "config-file"
spanStorageType = "span-storage.type" // deprecated
logLevel = "log-level"
configFile = "config-file"
healthCheckHTTPPort = "health-check-http-port"
)

var defaultHealthCheckPort int

// 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.")
Expand All @@ -53,21 +57,34 @@ func TryLoadConfigFile(v *viper.Viper) error {
type SharedFlags struct {
// Logging holds logging configuration
Logging logging
// HealthCheck holds health check configuration
HealthCheck healthCheck
}

type logging struct {
Level string
}

type healthCheck struct {
Port int
}

// SetDefaultHealthCheckPort sets the default port for health check. Must be called before AddFlags
func SetDefaultHealthCheckPort(port int) {
defaultHealthCheckPort = port
}

// AddFlags adds flags for SharedFlags
func AddFlags(flagSet *flag.FlagSet) {
flagSet.String(spanStorageType, "", fmt.Sprintf("Deprecated; please use %s environment variable", storage.SpanStorageTypeEnvVar))
flagSet.String(logLevel, "info", "Minimal allowed log Level. For more levels see https://github.com/uber-go/zap")
flagSet.Int(healthCheckHTTPPort, defaultHealthCheckPort, "The http port for the health check service")
}

// InitFromViper initializes SharedFlags with properties from viper
func (flags *SharedFlags) InitFromViper(v *viper.Viper) *SharedFlags {
flags.Logging.Level = v.GetString(logLevel)
flags.HealthCheck.Port = v.GetInt(healthCheckHTTPPort)
return flags
}

Expand All @@ -81,3 +98,12 @@ func (flags *SharedFlags) NewLogger(conf zap.Config, options ...zap.Option) (*za
conf.Level = zap.NewAtomicLevelAt(level)
return conf.Build(options...)
}

// NewHealthCheck returns health check based on configuration in SharedFlags
func (flags *SharedFlags) NewHealthCheck(logger *zap.Logger) (*hc.HealthCheck, error) {
if flags.HealthCheck.Port == 0 {
return nil, errors.New("port not specified")
}
return hc.New(hc.Unavailable, hc.Logger(logger)).
Serve(flags.HealthCheck.Port)
}
15 changes: 6 additions & 9 deletions cmd/query/app/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ import (
)

const (
queryPort = "query.port"
queryBasePath = "query.base-path"
queryStaticFiles = "query.static-files"
queryUIConfig = "query.ui-config"
queryHealthCheckHTTPPort = "query.health-check-http-port"
queryPort = "query.port"
queryBasePath = "query.base-path"
queryStaticFiles = "query.static-files"
queryUIConfig = "query.ui-config"
// QueryDefaultHealthCheckHTTPPort is the default HTTP Port for health check
QueryDefaultHealthCheckHTTPPort = 16687
)

// QueryOptions holds configuration for query service
Expand All @@ -38,8 +39,6 @@ type QueryOptions struct {
StaticAssets string
// UIConfig is the path to a configuration file for the UI
UIConfig string
// HealthCheckHTTPPort is the port that the health check service listens in on for http requests
HealthCheckHTTPPort int
}

// AddFlags adds flags for QueryOptions
Expand All @@ -48,7 +47,6 @@ func AddFlags(flagSet *flag.FlagSet) {
flagSet.String(queryBasePath, "/", "The base path for all HTTP routes, e.g. /jaeger; useful when running behind a reverse proxy")
flagSet.String(queryStaticFiles, "jaeger-ui-build/build/", "The directory path for the static assets for the UI")
flagSet.String(queryUIConfig, "", "The path to the UI configuration file in JSON format")
flagSet.Int(queryHealthCheckHTTPPort, 16687, "The http port for the health check service")
}

// InitFromViper initializes QueryOptions with properties from viper
Expand All @@ -57,6 +55,5 @@ func (qOpts *QueryOptions) InitFromViper(v *viper.Viper) *QueryOptions {
qOpts.BasePath = v.GetString(queryBasePath)
qOpts.StaticAssets = v.GetString(queryStaticFiles)
qOpts.UIConfig = v.GetString(queryUIConfig)
qOpts.HealthCheckHTTPPort = v.GetInt(queryHealthCheckHTTPPort)
return qOpts
}
10 changes: 5 additions & 5 deletions cmd/query/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,13 @@ func main() {
if err != nil {
return err
}

queryOpts := new(app.QueryOptions).InitFromViper(v)
hc, err := healthcheck.
New(healthcheck.Unavailable, healthcheck.Logger(logger)).
Serve(queryOpts.HealthCheckHTTPPort)
hc, err := sFlags.NewHealthCheck(logger)
if err != nil {
logger.Fatal("Could not start the health check server.", zap.Error(err))
}

queryOpts := new(app.QueryOptions).InitFromViper(v)

mBldr := new(pMetrics.Builder).InitFromViper(v)
metricsFactory, err := mBldr.CreateMetricsFactory("jaeger-query")
if err != nil {
Expand Down Expand Up @@ -153,6 +151,8 @@ func main() {
command.AddCommand(version.Command())
command.AddCommand(env.Command())

flags.SetDefaultHealthCheckPort(app.QueryDefaultHealthCheckHTTPPort)

config.AddFlags(
v,
command,
Expand Down
17 changes: 14 additions & 3 deletions cmd/standalone/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import (
"github.com/jaegertracing/jaeger/cmd/flags"
queryApp "github.com/jaegertracing/jaeger/cmd/query/app"
"github.com/jaegertracing/jaeger/pkg/config"
"github.com/jaegertracing/jaeger/pkg/healthcheck"
pMetrics "github.com/jaegertracing/jaeger/pkg/metrics"
"github.com/jaegertracing/jaeger/pkg/recoveryhandler"
"github.com/jaegertracing/jaeger/pkg/version"
Expand Down Expand Up @@ -89,6 +90,10 @@ func main() {
if err != nil {
return err
}
hc, err := sFlags.NewHealthCheck(logger)
if err != nil {
logger.Fatal("Could not start the health check server.", zap.Error(err))
}

mBldr := new(pMetrics.Builder).InitFromViper(v)
metricsFactory, err := mBldr.CreateMetricsFactory("jaeger-standalone")
Expand Down Expand Up @@ -119,8 +124,9 @@ func main() {
qOpts := new(queryApp.QueryOptions).InitFromViper(v)

startAgent(aOpts, cOpts, logger, metricsFactory)
startCollector(cOpts, spanWriter, logger, metricsFactory, samplingHandler)
startQuery(qOpts, spanReader, dependencyReader, logger, metricsFactory, mBldr)
startCollector(cOpts, spanWriter, logger, metricsFactory, samplingHandler, hc)
startQuery(qOpts, spanReader, dependencyReader, logger, metricsFactory, mBldr, hc)
hc.Ready()

select {
case <-signalsChannel:
Expand All @@ -133,6 +139,8 @@ func main() {
command.AddCommand(version.Command())
command.AddCommand(env.Command())

flags.SetDefaultHealthCheckPort(collector.CollectorDefaultHealthCheckHTTPPort)

config.AddFlags(
v,
command,
Expand Down Expand Up @@ -180,6 +188,7 @@ func startCollector(
logger *zap.Logger,
baseFactory metrics.Factory,
samplingHandler sampling.Handler,
hc *healthcheck.HealthCheck,
) {
metricsFactory := baseFactory.Namespace("jaeger-collector", nil)

Expand Down Expand Up @@ -222,6 +231,7 @@ func startCollector(
if err := http.ListenAndServe(httpPortStr, recoveryHandler(r)); err != nil {
logger.Fatal("Could not launch jaeger-collector HTTP server", zap.Error(err))
}
hc.Set(healthcheck.Unavailable)
}()
}

Expand Down Expand Up @@ -251,8 +261,8 @@ func startQuery(
logger *zap.Logger,
baseFactory metrics.Factory,
metricsBuilder *pMetrics.Builder,
hc *healthcheck.HealthCheck,
) {

tracer, closer, err := jaegerClientConfig.Configuration{
Sampler: &jaegerClientConfig.SamplerConfig{
Type: "const",
Expand Down Expand Up @@ -289,6 +299,7 @@ func startQuery(
if err := http.ListenAndServe(portStr, recoveryHandler(r)); err != nil {
logger.Fatal("Could not launch jaeger-query service", zap.Error(err))
}
hc.Set(healthcheck.Unavailable)
}()
}

Expand Down

0 comments on commit fdd4ffc

Please sign in to comment.