Skip to content

Commit

Permalink
prom: Remove custom registry
Browse files Browse the repository at this point in the history
  • Loading branch information
oncilla committed Sep 17, 2019
1 parent fba6b8c commit ad9c36a
Show file tree
Hide file tree
Showing 34 changed files with 42 additions and 129 deletions.
1 change: 0 additions & 1 deletion go/beacon_srv/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ go_library(
"//go/beacon_srv/internal/config:go_default_library",
"//go/beacon_srv/internal/ifstate:go_default_library",
"//go/beacon_srv/internal/keepalive:go_default_library",
"//go/beacon_srv/internal/metrics:go_default_library",
"//go/beacon_srv/internal/onehop:go_default_library",
"//go/beacon_srv/internal/revocation:go_default_library",
"//go/lib/addr:go_default_library",
Expand Down
1 change: 0 additions & 1 deletion go/beacon_srv/internal/metrics/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ go_library(
srcs = ["metrics.go"],
importpath = "github.com/scionproto/scion/go/beacon_srv/internal/metrics",
visibility = ["//go/beacon_srv:__subpackages__"],
deps = ["//go/lib/prom:go_default_library"],
)
14 changes: 2 additions & 12 deletions go/beacon_srv/internal/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,5 @@

package metrics

import (
"github.com/scionproto/scion/go/lib/prom"
)

const (
namespace = "beacon_srv"
)

// Init initializes the metrics for the beacon server.
func Init(elem string) {
prom.UseDefaultRegWithElem(elem)
}
// Namespace is the metrics namespace for the beacon server.
const namespace = "bs"
2 changes: 0 additions & 2 deletions go/beacon_srv/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import (
"github.com/scionproto/scion/go/beacon_srv/internal/config"
"github.com/scionproto/scion/go/beacon_srv/internal/ifstate"
"github.com/scionproto/scion/go/beacon_srv/internal/keepalive"
"github.com/scionproto/scion/go/beacon_srv/internal/metrics"
"github.com/scionproto/scion/go/beacon_srv/internal/onehop"
"github.com/scionproto/scion/go/beacon_srv/internal/revocation"
"github.com/scionproto/scion/go/lib/addr"
Expand Down Expand Up @@ -544,7 +543,6 @@ func setupBasic() error {
if err := env.InitLogging(&cfg.Logging); err != nil {
return err
}
metrics.Init(cfg.General.ID)
return env.LogAppStarted(common.BS, cfg.General.ID)
}

Expand Down
1 change: 0 additions & 1 deletion go/border/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ go_test(
embed = [":go_default_library"],
deps = [
"//go/border/brconf:go_default_library",
"//go/border/metrics:go_default_library",
"//go/border/rctx:go_default_library",
"//go/border/rpkt:go_default_library",
"//go/lib/addr:go_default_library",
Expand Down
6 changes: 2 additions & 4 deletions go/border/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,10 @@ var (
IFState *prometheus.GaugeVec
)

// Init ensures all metrics are registered.
func Init(elem string) {
namespace := "border"
func init() {
namespace := "br"
sockLabels := []string{"sock"}

prom.UseDefaultRegWithElem(elem)
// Some closures to reduce boiler-plate.
newCVec := func(name, help string, lNames []string) *prometheus.CounterVec {
return prom.NewCounterVec(namespace, "", name, help, lNames)
Expand Down
2 changes: 0 additions & 2 deletions go/border/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"sync"

"github.com/scionproto/scion/go/border/brconf"
"github.com/scionproto/scion/go/border/metrics"
"github.com/scionproto/scion/go/border/rcmn"
"github.com/scionproto/scion/go/border/rctrl"
"github.com/scionproto/scion/go/border/rctx"
Expand Down Expand Up @@ -55,7 +54,6 @@ type Router struct {
}

func NewRouter(id, confDir string) (*Router, error) {
metrics.Init(id)
r := &Router{Id: id, confDir: confDir}
if err := r.setup(); err != nil {
return nil, err
Expand Down
2 changes: 0 additions & 2 deletions go/border/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
. "github.com/smartystreets/goconvey/convey"

"github.com/scionproto/scion/go/border/brconf"
"github.com/scionproto/scion/go/border/metrics"
"github.com/scionproto/scion/go/border/rctx"
"github.com/scionproto/scion/go/border/rpkt"
"github.com/scionproto/scion/go/lib/common"
Expand Down Expand Up @@ -304,7 +303,6 @@ func setupTestRouter(t *testing.T) (*Router, *rctx.Ctx) {
func initTestRouter(maxNumPosixInput int) *Router {
// Init metrics.
testInitOnce.Do(func() {
metrics.Init("br1-ff00_0_111-1")
// Reduce output displayed in goconvey.
log.Root().SetHandler(log.DiscardHandler())
})
Expand Down
1 change: 0 additions & 1 deletion go/cert_srv/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ go_library(
visibility = ["//visibility:private"],
deps = [
"//go/cert_srv/internal/config:go_default_library",
"//go/cert_srv/internal/metrics:go_default_library",
"//go/cert_srv/internal/reiss:go_default_library",
"//go/lib/addr:go_default_library",
"//go/lib/common:go_default_library",
Expand Down
1 change: 0 additions & 1 deletion go/cert_srv/internal/metrics/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ go_library(
srcs = ["metrics.go"],
importpath = "github.com/scionproto/scion/go/cert_srv/internal/metrics",
visibility = ["//go/cert_srv:__subpackages__"],
deps = ["//go/lib/prom:go_default_library"],
)
14 changes: 2 additions & 12 deletions go/cert_srv/internal/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,5 @@

package metrics

import (
"github.com/scionproto/scion/go/lib/prom"
)

const (
namespace = "cert_srv"
)

// Init initializes the metrics for the CS.
func Init(elem string) {
prom.UseDefaultRegWithElem(elem)
}
// Namespace is the metrics namespace for the certificate server.
const namespace = "cs"
2 changes: 0 additions & 2 deletions go/cert_srv/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/BurntSushi/toml"

"github.com/scionproto/scion/go/cert_srv/internal/config"
"github.com/scionproto/scion/go/cert_srv/internal/metrics"
"github.com/scionproto/scion/go/cert_srv/internal/reiss"
"github.com/scionproto/scion/go/lib/addr"
"github.com/scionproto/scion/go/lib/common"
Expand Down Expand Up @@ -57,7 +56,6 @@ func setupBasic() error {
if err := env.InitLogging(&cfg.Logging); err != nil {
return err
}
metrics.Init(cfg.General.ID)
return env.LogAppStarted(common.CS, cfg.General.ID)
}

Expand Down
2 changes: 0 additions & 2 deletions go/godispatcher/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ go_library(
visibility = ["//visibility:private"],
deps = [
"//go/godispatcher/internal/config:go_default_library",
"//go/godispatcher/internal/metrics:go_default_library",
"//go/godispatcher/network:go_default_library",
"//go/lib/common:go_default_library",
"//go/lib/env:go_default_library",
Expand All @@ -30,7 +29,6 @@ go_test(
srcs = ["main_test.go"],
embed = [":go_default_library"],
deps = [
"//go/godispatcher/internal/metrics:go_default_library",
"//go/lib/addr:go_default_library",
"//go/lib/common:go_default_library",
"//go/lib/hpkt:go_default_library",
Expand Down
29 changes: 8 additions & 21 deletions go/godispatcher/internal/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,15 @@
package metrics

import (
"sync"

"github.com/prometheus/client_golang/prometheus"

"github.com/scionproto/scion/go/lib/addr"
"github.com/scionproto/scion/go/lib/prom"
"github.com/scionproto/scion/go/lib/ringbuf"
)

const (
namespace = "dispatcher"
)
// Namespace is the metrics namespace for the dispatcher.
const Namespace = "dispatcher"

// Label descriptions
const (
Expand Down Expand Up @@ -58,26 +55,16 @@ func GetOpenConnectionLabel(svc addr.HostSVC) string {
return svc.BaseString()
}

var initSentinel sync.Once

// Init initializes the metrics for the dispatcher.
func Init(elem string) {
initSentinel.Do(func() {
initMetrics(elem)
})
}

func initMetrics(elem string) {
prom.UseDefaultRegWithElem(elem)
func init() {
ringbuf.InitMetrics("dispatcher", nil)
OutgoingBytesTotal = prom.NewCounter(namespace, "", "outgoing_bytes_total",
OutgoingBytesTotal = prom.NewCounter(Namespace, "", "outgoing_bytes_total",
"Total bytes sent on the network.")
OutgoingPacketsTotal = prom.NewCounter(namespace, "", "outgoing_packets_total",
OutgoingPacketsTotal = prom.NewCounter(Namespace, "", "outgoing_packets_total",
"Total packets sent on the network.")
IncomingBytesTotal = prom.NewCounter(namespace, "", "incoming_bytes_total",
IncomingBytesTotal = prom.NewCounter(Namespace, "", "incoming_bytes_total",
"Total bytes received from the network irrespective of packet outcome.")
IncomingPackets = prom.NewCounterVec(namespace, "", "incoming_packets_total",
IncomingPackets = prom.NewCounterVec(Namespace, "", "incoming_packets_total",
"Total packets received from the network.", []string{IncomingPacketOutcome})
OpenSockets = prom.NewGaugeVec(namespace, "", "open_application_connections",
OpenSockets = prom.NewGaugeVec(Namespace, "", "open_application_connections",
"Number of sockets currently opened by applications.", []string{OpenConnectionType})
}
2 changes: 0 additions & 2 deletions go/godispatcher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/BurntSushi/toml"

"github.com/scionproto/scion/go/godispatcher/internal/config"
"github.com/scionproto/scion/go/godispatcher/internal/metrics"
"github.com/scionproto/scion/go/godispatcher/network"
"github.com/scionproto/scion/go/lib/common"
"github.com/scionproto/scion/go/lib/env"
Expand Down Expand Up @@ -124,7 +123,6 @@ func setupBasic() error {
if err := env.InitLogging(&cfg.Logging); err != nil {
return err
}
metrics.Init(cfg.Dispatcher.ID)
return env.LogAppStarted("Dispatcher", cfg.Dispatcher.ID)
}

Expand Down
4 changes: 0 additions & 4 deletions go/godispatcher/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"testing"
"time"

"github.com/scionproto/scion/go/godispatcher/internal/metrics"
"github.com/scionproto/scion/go/lib/addr"
"github.com/scionproto/scion/go/lib/common"
"github.com/scionproto/scion/go/lib/hpkt"
Expand Down Expand Up @@ -519,9 +518,6 @@ func MustPackQuotedSCMPL4Header(header *scmp.Hdr, meta *scmp.Meta, info scmp.Inf
}

func TestMain(m *testing.M) {
// If the prometheus package is not initialized, dispatcher internals panic
// because the counters are nil.
metrics.Init("dispatcher")
log.Root().SetHandler(log.DiscardHandler())
os.Exit(m.Run())
}
2 changes: 1 addition & 1 deletion go/lib/infra/messenger/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func errorToResultLabel(ctx context.Context, err error) string {
// TODO(lukedirtwalker): categorize error better.
switch {
case err == nil:
return prom.ResultOk
return prom.Success
case common.IsTimeoutErr(err):
return prom.ErrTimeout
default:
Expand Down
2 changes: 1 addition & 1 deletion go/lib/infra/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ var (
metricsErrRevCache = &HandlerResult{Result: "err_revcache", Status: prom.StatusErr}
metricsErrRevCacheTo = &HandlerResult{Result: "err_revcache_to", Status: prom.StatusTimeout}

MetricsResultOk = &HandlerResult{Result: prom.ResultOk, Status: prom.StatusOk}
MetricsResultOk = &HandlerResult{Result: prom.Success, Status: prom.StatusOk}
)

func MetricsErrTrustDB(err error) *HandlerResult {
Expand Down
2 changes: 1 addition & 1 deletion go/lib/infra/modules/db/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
func ErrToMetricLabel(err error) string {
switch {
case err == nil:
return prom.ResultOk
return prom.Success
case common.IsTimeoutErr(err):
return prom.ErrTimeout
default:
Expand Down
25 changes: 15 additions & 10 deletions go/lib/prom/prom.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,34 @@ import (
"github.com/prometheus/client_golang/prometheus/promauto"
)

// Common label values.
const (
// LabelResult is the label for result classifications.
LabelResult = "result"
// LabelStatus for latency status classifications, possible values are prefixed with Status*.
LabelStatus = "status"
// LabelElem is the label for the element id that is added to all metrics.
LabelElem = "elem"
// LabelOperation is the label for the name of an executed operation.
LabelOperation = "op"
// LabelSrc is the label for the src of a request.
LabelSrc = "src"
)

// ResultOk is no error.
ResultOk = "ok"
// Common result values.
const (
// Success is no error.
Success = "success"
// ErrNotClassified is an error that is not further classified.
ErrNotClassified = "err_not_classified"
// ErrTimeout is a timeout error.
ErrTimeout = "err_timeout"
// ErrInternal is an internal error.
ErrInternal = "err_internal"
// ErrInvalidReq is an invalid request.
ErrInvalidReq = "err_invalid_request"
)

// FIXME(roosd): remove when moving messenger to new metrics style.
const (
StatusOk = "ok"
StatusErr = "err"
StatusTimeout = "err_timeout"
Expand All @@ -52,6 +61,7 @@ var (
1.28, 2.56, 5.12, 10.24}
)

// FIXME(roosd): remove.
func CopyLabels(labels prometheus.Labels) prometheus.Labels {
l := make(prometheus.Labels)
for k, v := range labels {
Expand All @@ -65,12 +75,7 @@ func CopyLabels(labels prometheus.Labels) prometheus.Labels {
// Note this should be called before any other interaction with prometheus.
// See also: https://github.com/prometheus/client_golang/issues/515
func UseDefaultRegWithElem(elemId string) {
labels := prometheus.Labels{LabelElem: elemId}
reg := prometheus.NewRegistry()
prometheus.DefaultRegisterer = prometheus.WrapRegistererWith(labels, reg)
prometheus.DefaultGatherer = reg
prometheus.MustRegister(prometheus.NewProcessCollector(prometheus.ProcessCollectorOpts{}))
prometheus.MustRegister(prometheus.NewGoCollector())

}

// NewCounter creates a new prometheus counter that is registered with the default registry.
Expand Down
1 change: 0 additions & 1 deletion go/path_srv/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ go_library(
"//go/path_srv/internal/config:go_default_library",
"//go/path_srv/internal/cryptosyncer:go_default_library",
"//go/path_srv/internal/handlers:go_default_library",
"//go/path_srv/internal/metrics:go_default_library",
"//go/path_srv/internal/segreq:go_default_library",
"//go/path_srv/internal/segsyncer:go_default_library",
"//go/proto:go_default_library",
Expand Down
1 change: 0 additions & 1 deletion go/path_srv/internal/metrics/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ go_library(
srcs = ["metrics.go"],
importpath = "github.com/scionproto/scion/go/path_srv/internal/metrics",
visibility = ["//go/path_srv:__subpackages__"],
deps = ["//go/lib/prom:go_default_library"],
)
14 changes: 2 additions & 12 deletions go/path_srv/internal/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,5 @@

package metrics

import (
"github.com/scionproto/scion/go/lib/prom"
)

const (
namespace = "path_srv"
)

// Init initializes the metrics for the PS.
func Init(elem string) {
prom.UseDefaultRegWithElem(elem)
}
// Namespace is the metrics namespace for the path server.
const Namespace = "ps"
2 changes: 0 additions & 2 deletions go/path_srv/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ import (
"github.com/scionproto/scion/go/path_srv/internal/config"
"github.com/scionproto/scion/go/path_srv/internal/cryptosyncer"
"github.com/scionproto/scion/go/path_srv/internal/handlers"
"github.com/scionproto/scion/go/path_srv/internal/metrics"
"github.com/scionproto/scion/go/path_srv/internal/segreq"
"github.com/scionproto/scion/go/path_srv/internal/segsyncer"
"github.com/scionproto/scion/go/proto"
Expand Down Expand Up @@ -264,7 +263,6 @@ func setupBasic() error {
if err := env.InitLogging(&cfg.Logging); err != nil {
return err
}
metrics.Init(cfg.General.ID)
return env.LogAppStarted(common.PS, cfg.General.ID)
}

Expand Down
1 change: 0 additions & 1 deletion go/sciond/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ go_library(
"//go/proto:go_default_library",
"//go/sciond/internal/config:go_default_library",
"//go/sciond/internal/fetcher:go_default_library",
"//go/sciond/internal/metrics:go_default_library",
"//go/sciond/internal/servers:go_default_library",
"@com_github_burntsushi_toml//:go_default_library",
"@com_github_opentracing_opentracing_go//:go_default_library",
Expand Down
Loading

0 comments on commit ad9c36a

Please sign in to comment.