From ad9c36aada9b318e9bddfd261e8a217a470d5bd7 Mon Sep 17 00:00:00 2001 From: roos Date: Tue, 17 Sep 2019 18:32:07 +0200 Subject: [PATCH] prom: Remove custom registry fixes #3160 --- go/beacon_srv/BUILD.bazel | 1 - go/beacon_srv/internal/metrics/BUILD.bazel | 1 - go/beacon_srv/internal/metrics/metrics.go | 14 ++-------- go/beacon_srv/main.go | 2 -- go/border/BUILD.bazel | 1 - go/border/metrics/metrics.go | 6 ++--- go/border/router.go | 2 -- go/border/setup_test.go | 2 -- go/cert_srv/BUILD.bazel | 1 - go/cert_srv/internal/metrics/BUILD.bazel | 1 - go/cert_srv/internal/metrics/metrics.go | 14 ++-------- go/cert_srv/setup.go | 2 -- go/godispatcher/BUILD.bazel | 2 -- go/godispatcher/internal/metrics/metrics.go | 29 ++++++--------------- go/godispatcher/main.go | 2 -- go/godispatcher/main_test.go | 4 --- go/lib/infra/messenger/metrics.go | 2 +- go/lib/infra/metrics.go | 2 +- go/lib/infra/modules/db/metrics.go | 2 +- go/lib/prom/prom.go | 25 +++++++++++------- go/path_srv/BUILD.bazel | 1 - go/path_srv/internal/metrics/BUILD.bazel | 1 - go/path_srv/internal/metrics/metrics.go | 14 ++-------- go/path_srv/main.go | 2 -- go/sciond/BUILD.bazel | 1 - go/sciond/internal/metrics/BUILD.bazel | 1 - go/sciond/internal/metrics/metrics.go | 14 ++-------- go/sciond/main.go | 2 -- go/sig/egress/worker/BUILD.bazel | 1 - go/sig/egress/worker/worker_test.go | 2 -- go/sig/ingress/BUILD.bazel | 1 - go/sig/ingress/worker_test.go | 2 -- go/sig/main.go | 2 -- go/sig/metrics/metrics.go | 12 ++++----- 34 files changed, 42 insertions(+), 129 deletions(-) diff --git a/go/beacon_srv/BUILD.bazel b/go/beacon_srv/BUILD.bazel index c6eaaf95cf..8f9a49c107 100644 --- a/go/beacon_srv/BUILD.bazel +++ b/go/beacon_srv/BUILD.bazel @@ -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", diff --git a/go/beacon_srv/internal/metrics/BUILD.bazel b/go/beacon_srv/internal/metrics/BUILD.bazel index 310d00255b..634f6791f6 100644 --- a/go/beacon_srv/internal/metrics/BUILD.bazel +++ b/go/beacon_srv/internal/metrics/BUILD.bazel @@ -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"], ) diff --git a/go/beacon_srv/internal/metrics/metrics.go b/go/beacon_srv/internal/metrics/metrics.go index bc7f163947..34eed90f54 100644 --- a/go/beacon_srv/internal/metrics/metrics.go +++ b/go/beacon_srv/internal/metrics/metrics.go @@ -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" diff --git a/go/beacon_srv/main.go b/go/beacon_srv/main.go index e8d6762567..9670424264 100644 --- a/go/beacon_srv/main.go +++ b/go/beacon_srv/main.go @@ -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" @@ -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) } diff --git a/go/border/BUILD.bazel b/go/border/BUILD.bazel index 34073fac09..9a32270291 100644 --- a/go/border/BUILD.bazel +++ b/go/border/BUILD.bazel @@ -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", diff --git a/go/border/metrics/metrics.go b/go/border/metrics/metrics.go index 4592d803ba..7409a437a3 100644 --- a/go/border/metrics/metrics.go +++ b/go/border/metrics/metrics.go @@ -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) diff --git a/go/border/router.go b/go/border/router.go index 6f54d3731b..6d4ad75aa2 100644 --- a/go/border/router.go +++ b/go/border/router.go @@ -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" @@ -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 diff --git a/go/border/setup_test.go b/go/border/setup_test.go index b657af9734..569a5397c9 100644 --- a/go/border/setup_test.go +++ b/go/border/setup_test.go @@ -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" @@ -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()) }) diff --git a/go/cert_srv/BUILD.bazel b/go/cert_srv/BUILD.bazel index e06671fcbf..4448bf8a99 100644 --- a/go/cert_srv/BUILD.bazel +++ b/go/cert_srv/BUILD.bazel @@ -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", diff --git a/go/cert_srv/internal/metrics/BUILD.bazel b/go/cert_srv/internal/metrics/BUILD.bazel index 0092d061dc..8718235700 100644 --- a/go/cert_srv/internal/metrics/BUILD.bazel +++ b/go/cert_srv/internal/metrics/BUILD.bazel @@ -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"], ) diff --git a/go/cert_srv/internal/metrics/metrics.go b/go/cert_srv/internal/metrics/metrics.go index ccad8b9607..043abbfbae 100644 --- a/go/cert_srv/internal/metrics/metrics.go +++ b/go/cert_srv/internal/metrics/metrics.go @@ -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" diff --git a/go/cert_srv/setup.go b/go/cert_srv/setup.go index 01a2bcdc10..ca71bac4bb 100644 --- a/go/cert_srv/setup.go +++ b/go/cert_srv/setup.go @@ -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" @@ -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) } diff --git a/go/godispatcher/BUILD.bazel b/go/godispatcher/BUILD.bazel index 62753f093b..ceb4b573ce 100644 --- a/go/godispatcher/BUILD.bazel +++ b/go/godispatcher/BUILD.bazel @@ -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", @@ -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", diff --git a/go/godispatcher/internal/metrics/metrics.go b/go/godispatcher/internal/metrics/metrics.go index 5a4b36554d..ca968edf19 100644 --- a/go/godispatcher/internal/metrics/metrics.go +++ b/go/godispatcher/internal/metrics/metrics.go @@ -15,8 +15,6 @@ package metrics import ( - "sync" - "github.com/prometheus/client_golang/prometheus" "github.com/scionproto/scion/go/lib/addr" @@ -24,9 +22,8 @@ import ( "github.com/scionproto/scion/go/lib/ringbuf" ) -const ( - namespace = "dispatcher" -) +// Namespace is the metrics namespace for the dispatcher. +const Namespace = "dispatcher" // Label descriptions const ( @@ -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}) } diff --git a/go/godispatcher/main.go b/go/godispatcher/main.go index e228be220d..b7fd645408 100644 --- a/go/godispatcher/main.go +++ b/go/godispatcher/main.go @@ -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" @@ -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) } diff --git a/go/godispatcher/main_test.go b/go/godispatcher/main_test.go index bd2178aab8..754695733e 100644 --- a/go/godispatcher/main_test.go +++ b/go/godispatcher/main_test.go @@ -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" @@ -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()) } diff --git a/go/lib/infra/messenger/metrics.go b/go/lib/infra/messenger/metrics.go index 508b9ec638..fdd066c9ee 100644 --- a/go/lib/infra/messenger/metrics.go +++ b/go/lib/infra/messenger/metrics.go @@ -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: diff --git a/go/lib/infra/metrics.go b/go/lib/infra/metrics.go index 0bf82f3d68..745e27d751 100644 --- a/go/lib/infra/metrics.go +++ b/go/lib/infra/metrics.go @@ -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 { diff --git a/go/lib/infra/modules/db/metrics.go b/go/lib/infra/modules/db/metrics.go index 350c629c06..0d1d0c7d05 100644 --- a/go/lib/infra/modules/db/metrics.go +++ b/go/lib/infra/modules/db/metrics.go @@ -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: diff --git a/go/lib/prom/prom.go b/go/lib/prom/prom.go index fca0cd6253..1791441cce 100644 --- a/go/lib/prom/prom.go +++ b/go/lib/prom/prom.go @@ -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" @@ -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 { @@ -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. diff --git a/go/path_srv/BUILD.bazel b/go/path_srv/BUILD.bazel index 633618caa8..02786694fb 100644 --- a/go/path_srv/BUILD.bazel +++ b/go/path_srv/BUILD.bazel @@ -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", diff --git a/go/path_srv/internal/metrics/BUILD.bazel b/go/path_srv/internal/metrics/BUILD.bazel index 7d9c228e74..c761bb301f 100644 --- a/go/path_srv/internal/metrics/BUILD.bazel +++ b/go/path_srv/internal/metrics/BUILD.bazel @@ -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"], ) diff --git a/go/path_srv/internal/metrics/metrics.go b/go/path_srv/internal/metrics/metrics.go index 9d7931b257..dcbee3a5c3 100644 --- a/go/path_srv/internal/metrics/metrics.go +++ b/go/path_srv/internal/metrics/metrics.go @@ -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" diff --git a/go/path_srv/main.go b/go/path_srv/main.go index e30c79bdda..78eb92bc16 100644 --- a/go/path_srv/main.go +++ b/go/path_srv/main.go @@ -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" @@ -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) } diff --git a/go/sciond/BUILD.bazel b/go/sciond/BUILD.bazel index b05432a449..d5cf451b46 100644 --- a/go/sciond/BUILD.bazel +++ b/go/sciond/BUILD.bazel @@ -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", diff --git a/go/sciond/internal/metrics/BUILD.bazel b/go/sciond/internal/metrics/BUILD.bazel index 84e1eea304..ab58ad2913 100644 --- a/go/sciond/internal/metrics/BUILD.bazel +++ b/go/sciond/internal/metrics/BUILD.bazel @@ -5,5 +5,4 @@ go_library( srcs = ["metrics.go"], importpath = "github.com/scionproto/scion/go/sciond/internal/metrics", visibility = ["//go/sciond:__subpackages__"], - deps = ["//go/lib/prom:go_default_library"], ) diff --git a/go/sciond/internal/metrics/metrics.go b/go/sciond/internal/metrics/metrics.go index cf12170cfe..1840f3fa88 100644 --- a/go/sciond/internal/metrics/metrics.go +++ b/go/sciond/internal/metrics/metrics.go @@ -14,15 +14,5 @@ package metrics -import ( - "github.com/scionproto/scion/go/lib/prom" -) - -const ( - namespace = "sciond" -) - -// Init initializes the metrics for sciond. -func Init(elem string) { - prom.UseDefaultRegWithElem(elem) -} +// Namespace is the metrics namespace for sciond. +const Namespace = "sciond" diff --git a/go/sciond/main.go b/go/sciond/main.go index 3910851ea9..b58c59e8b2 100644 --- a/go/sciond/main.go +++ b/go/sciond/main.go @@ -46,7 +46,6 @@ import ( "github.com/scionproto/scion/go/proto" "github.com/scionproto/scion/go/sciond/internal/config" "github.com/scionproto/scion/go/sciond/internal/fetcher" - "github.com/scionproto/scion/go/sciond/internal/metrics" "github.com/scionproto/scion/go/sciond/internal/servers" ) @@ -192,7 +191,6 @@ func setupBasic() error { if err := env.InitLogging(&cfg.Logging); err != nil { return err } - metrics.Init(cfg.General.ID) return env.LogAppStarted("SD", cfg.General.ID) } diff --git a/go/sig/egress/worker/BUILD.bazel b/go/sig/egress/worker/BUILD.bazel index adbf0a82f8..2e7dcfb87e 100644 --- a/go/sig/egress/worker/BUILD.bazel +++ b/go/sig/egress/worker/BUILD.bazel @@ -36,7 +36,6 @@ go_test( "//go/sig/egress/iface:go_default_library", "//go/sig/egress/iface/mock_iface:go_default_library", "//go/sig/egress/worker/mock_worker:go_default_library", - "//go/sig/metrics:go_default_library", "//go/sig/mgmt:go_default_library", "@com_github_golang_mock//gomock:go_default_library", "@com_github_prometheus_client_golang//prometheus:go_default_library", diff --git a/go/sig/egress/worker/worker_test.go b/go/sig/egress/worker/worker_test.go index 91c71719a5..2fa05061ad 100644 --- a/go/sig/egress/worker/worker_test.go +++ b/go/sig/egress/worker/worker_test.go @@ -31,7 +31,6 @@ import ( "github.com/scionproto/scion/go/sig/egress/iface" "github.com/scionproto/scion/go/sig/egress/iface/mock_iface" "github.com/scionproto/scion/go/sig/egress/worker/mock_worker" - "github.com/scionproto/scion/go/sig/metrics" "github.com/scionproto/scion/go/sig/mgmt" ) @@ -127,7 +126,6 @@ func (wt *WorkerTester) Finish() { } func TestParsing(t *testing.T) { - metrics.Init("") iface.Init() t.Run("simple packet", func(t *testing.T) { diff --git a/go/sig/ingress/BUILD.bazel b/go/sig/ingress/BUILD.bazel index 2e6550660e..312501596d 100644 --- a/go/sig/ingress/BUILD.bazel +++ b/go/sig/ingress/BUILD.bazel @@ -34,7 +34,6 @@ go_test( deps = [ "//go/lib/ringbuf:go_default_library", "//go/lib/snet:go_default_library", - "//go/sig/metrics:go_default_library", "@com_github_stretchr_testify//assert:go_default_library", ], ) diff --git a/go/sig/ingress/worker_test.go b/go/sig/ingress/worker_test.go index 5736ecd1b7..8fdb7958f0 100644 --- a/go/sig/ingress/worker_test.go +++ b/go/sig/ingress/worker_test.go @@ -21,7 +21,6 @@ import ( "github.com/scionproto/scion/go/lib/ringbuf" "github.com/scionproto/scion/go/lib/snet" - "github.com/scionproto/scion/go/sig/metrics" ) type MockTun struct { @@ -62,7 +61,6 @@ func SendFrame(t *testing.T, w *Worker, data []byte) { } func TestParsing(t *testing.T) { - metrics.Init("") addr, err := snet.AddrFromString("1-ff00:0:300,[192.168.1.1]:80") assert.NoError(t, err) mt := &MockTun{} diff --git a/go/sig/main.go b/go/sig/main.go index c77ec04a1e..170ec95eb8 100644 --- a/go/sig/main.go +++ b/go/sig/main.go @@ -78,8 +78,6 @@ func realMain() int { log.Crit("Unable to create & configure TUN device", "err", err) return 1 } - // Export prometheus metrics. - metrics.Init(cfg.Sig.ID) if err := sigcmn.Init(cfg.Sig, cfg.Sciond); err != nil { log.Crit("Error during initialization", err) return 1 diff --git a/go/sig/metrics/metrics.go b/go/sig/metrics/metrics.go index 4e55014128..d41c71c09d 100644 --- a/go/sig/metrics/metrics.go +++ b/go/sig/metrics/metrics.go @@ -30,6 +30,9 @@ import ( "github.com/scionproto/scion/go/sig/mgmt" ) +// Namespace is the metrics namespace for the SIG. +const Namespace = "sig" + // Declare prometheus metrics to export. var ( PktsRecv *prometheus.CounterVec @@ -54,18 +57,15 @@ var ( // Version number of loaded config, atomic var ConfigVersion uint64 -// Ensure all metrics are registered. -func Init(elem string) { - namespace := "sig" +func init() { iaLabels := []string{"IA", "sessId"} - prom.UseDefaultRegWithElem(elem) // Some closures to reduce boiler-plate. newC := func(name, help string) prometheus.Counter { - return prom.NewCounter(namespace, "", name, help) + return prom.NewCounter(Namespace, "", name, help) } newCVec := func(name, help string, lNames []string) *prometheus.CounterVec { - return prom.NewCounterVec(namespace, "", name, help, lNames) + return prom.NewCounterVec(Namespace, "", name, help, lNames) } // FIXME(kormat): these metrics should probably have more informative labels PktsRecv = newCVec("pkts_recv_total", "Number of packets received.", iaLabels)