Skip to content

Commit

Permalink
Pull new version of tally with registry changes (#1867)
Browse files Browse the repository at this point in the history
* Use latest tally library
* Use new tally config options to create prom reporter
  • Loading branch information
shreyassrivatsan committed May 17, 2019
1 parent 2aa943b commit 8f12e6d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 72 deletions.
6 changes: 3 additions & 3 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions Gopkg.toml
Expand Up @@ -88,7 +88,7 @@ ignored = ["github.com/uber/cadence/.gen"]

[[constraint]]
name = "github.com/uber-go/tally"
version = "3.3.7"
version = "3.3.9"

[[constraint]]
name = "github.com/uber/ringpop-go"
Expand Down Expand Up @@ -150,7 +150,3 @@ ignored = ["github.com/uber/cadence/.gen"]
[[constraint]]
name = "github.com/valyala/fastjson"
version = "1.4.1"

[[override]]
name = "github.com/m3db/prometheus_client_golang"
revision = "8ae269d24972b8695572fa6b2e3718b5ea82d6b4"
66 changes: 2 additions & 64 deletions common/service/config/metrics.go
Expand Up @@ -21,13 +21,10 @@
package config

import (
"net/http"
"strings"
"time"

"github.com/cactus/go-statsd-client/statsd"
prom "github.com/m3db/prometheus_client_golang/prometheus"
"github.com/m3db/prometheus_client_golang/prometheus/promhttp"
"github.com/uber-go/tally"
"github.com/uber-go/tally/prometheus"
tallystatsdreporter "github.com/uber-go/tally/statsd"
Expand Down Expand Up @@ -123,9 +120,9 @@ func (c *Metrics) newStatsdScope(logger log.Logger) tally.Scope {
// newPrometheusScope returns a new prometheus scope with
// a default reporting interval of a second
func (c *Metrics) newPrometheusScope(logger log.Logger) tally.Scope {
reporter, err := NewPrometheusReporter(
c.Prometheus,
reporter, err := c.Prometheus.NewReporter(
prometheus.ConfigurationOptions{
Registry: prom.NewRegistry(),
OnError: func(err error) {
logger.Warn("error in prometheus reporter", tag.Error(err))
},
Expand All @@ -142,62 +139,3 @@ func (c *Metrics) newPrometheusScope(logger log.Logger) tally.Scope {
scope, _ := tally.NewRootScope(scopeOpts, time.Second)
return scope
}

// NewPrometheusReporter - creates a prometheus reporter
// N.B - copy of the NewReporter method in tally - https://github.com/uber-go/tally/blob/master/prometheus/config.go#L77
// as the above method does not allow setting a separate registry per root
// which is necessary when we are running multiple roles within a same process
func NewPrometheusReporter(
config *prometheus.Configuration,
configOpts prometheus.ConfigurationOptions,
) (prometheus.Reporter, error) {
var opts prometheus.Options
opts.OnRegisterError = configOpts.OnError

switch config.TimerType {
case "summary":
opts.DefaultTimerType = prometheus.SummaryTimerType
case "histogram":
opts.DefaultTimerType = prometheus.HistogramTimerType
}

if len(config.DefaultHistogramBuckets) > 0 {
var values []float64
for _, value := range config.DefaultHistogramBuckets {
values = append(values, value.Upper)
}
opts.DefaultHistogramBuckets = values
}

if len(config.DefaultSummaryObjectives) > 0 {
values := make(map[float64]float64)
for _, value := range config.DefaultSummaryObjectives {
values[value.Percentile] = value.AllowedError
}
opts.DefaultSummaryObjectives = values
}

registry := prom.NewRegistry()
opts.Registerer = registry

reporter := prometheus.NewReporter(opts)

path := "/metrics"
if handlerPath := strings.TrimSpace(config.HandlerPath); handlerPath != "" {
path = handlerPath
}

if addr := strings.TrimSpace(config.ListenAddress); addr == "" {
http.Handle(path, promhttp.HandlerFor(registry, promhttp.HandlerOpts{}))
} else {
mux := http.NewServeMux()
mux.Handle(path, promhttp.HandlerFor(registry, promhttp.HandlerOpts{}))
go func() {
if err := http.ListenAndServe(addr, mux); err != nil {
configOpts.OnError(err)
}
}()
}

return reporter, nil
}

0 comments on commit 8f12e6d

Please sign in to comment.