Skip to content

Commit

Permalink
fix: metrics NPE
Browse files Browse the repository at this point in the history
Signed-off-by: Valery Piashchynski <piashchynski.valery@gmail.com>
  • Loading branch information
rustatian committed Sep 9, 2022
1 parent b569da9 commit 63d35af
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
17 changes: 10 additions & 7 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,18 @@ func (c *Config) InitDefault() error {

switch c.Metrics.Driver {
case driverPrometheus:
if c.Metrics.Prometheus != nil {
if c.Metrics.Prometheus.Type == "" {
c.Metrics.Prometheus.Type = MetricsTypeSummary
}
if c.Metrics.Prometheus == nil {
c.Metrics.Prometheus = &Prometheus{}
}

if c.Metrics.Prometheus.Address == "" {
c.Metrics.Prometheus.Address = "127.0.0.1:9091"
}
if c.Metrics.Prometheus.Type == "" {
c.Metrics.Prometheus.Type = MetricsTypeSummary
}

if c.Metrics.Prometheus.Address == "" {
c.Metrics.Prometheus.Address = "127.0.0.1:9091"
}

case driverStatsd:
if c.Metrics.Statsd != nil {
if c.Metrics.Statsd.HostPort == "" {
Expand Down
29 changes: 29 additions & 0 deletions plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
const (
// PluginName defines public service name.
PluginName string = "temporal"
metricsKey string = "temporal.metrics"

// RrMode env variable key
RrMode string = "RR_MODE"
Expand Down Expand Up @@ -101,6 +102,30 @@ func (p *Plugin) Init(cfg config.Configurer, log *zap.Logger, server server.Serv
return errors.E(op, err)
}

/*
Parse metrics configuration
default (no BC): prometheus
*/
if p.config.Metrics != nil {
switch p.config.Metrics.Driver {
case driverPrometheus:
err = cfg.UnmarshalKey(metricsKey, &p.config.Metrics.Prometheus)
if err != nil {
return errors.E(op, err)
}
case driverStatsd:
err = cfg.UnmarshalKey(metricsKey, &p.config.Metrics.Statsd)
if err != nil {
return errors.E(op, err)
}
default:
err = cfg.UnmarshalKey(metricsKey, &p.config.Metrics.Prometheus)
if err != nil {
return errors.E(op, err)
}
}
}

err = p.config.InitDefault()
if err != nil {
return errors.E(op, err)
Expand Down Expand Up @@ -158,6 +183,10 @@ func (p *Plugin) Serve() chan error {
}
}

/*
TODO(rustatian): simplify
set up metrics handler
*/
if p.config.Metrics != nil {
switch p.config.Metrics.Driver {
case driverPrometheus:
Expand Down

0 comments on commit 63d35af

Please sign in to comment.