Skip to content

Commit

Permalink
prom: Remove custom registry (#3161)
Browse files Browse the repository at this point in the history
This change renames namespaces and removes the `elem_id` label from all metrics.
The element ID configured in the config is exposed through `scion_elem_id`.

namespace renames:
- `beacon_srv` -> `bs`
- `border` -> `br`
- `cert_srv` -> `cs`
- `dispatcher` -> `disp`
- `path_srv` -> `ps`
- `sciond` -> `sd`


fixes #3160
  • Loading branch information
oncilla authored Sep 18, 2019
1 parent fba6b8c commit afb63c0
Show file tree
Hide file tree
Showing 36 changed files with 72 additions and 142 deletions.
2 changes: 1 addition & 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 All @@ -31,6 +30,7 @@ go_library(
"//go/lib/keyconf:go_default_library",
"//go/lib/log:go_default_library",
"//go/lib/periodic:go_default_library",
"//go/lib/prom:go_default_library",
"//go/lib/scrypto:go_default_library",
"//go/lib/snet:go_default_library",
"//go/lib/sock/reliable: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"
4 changes: 2 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 All @@ -54,6 +53,7 @@ import (
"github.com/scionproto/scion/go/lib/keyconf"
"github.com/scionproto/scion/go/lib/log"
"github.com/scionproto/scion/go/lib/periodic"
"github.com/scionproto/scion/go/lib/prom"
"github.com/scionproto/scion/go/lib/scrypto"
"github.com/scionproto/scion/go/lib/snet"
"github.com/scionproto/scion/go/lib/sock/reliable"
Expand Down Expand Up @@ -544,7 +544,7 @@ func setupBasic() error {
if err := env.InitLogging(&cfg.Logging); err != nil {
return err
}
metrics.Init(cfg.General.ID)
prom.ExportElementID(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
2 changes: 2 additions & 0 deletions go/border/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/scionproto/scion/go/lib/fatal"
"github.com/scionproto/scion/go/lib/log"
"github.com/scionproto/scion/go/lib/profile"
"github.com/scionproto/scion/go/lib/prom"
)

var (
Expand Down Expand Up @@ -104,6 +105,7 @@ func setupBasic() error {
if err := env.InitLogging(&cfg.Logging); err != nil {
return err
}
prom.ExportElementID(cfg.General.ID)
return env.LogAppStarted(common.BR, cfg.General.ID)
}

Expand Down
18 changes: 9 additions & 9 deletions go/border/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ import (
"github.com/scionproto/scion/go/lib/ringbuf"
)

// Namespace is the metrics namespace for the border router.
const Namespace = "br"

// Declare prometheus metrics to export.
var (
// High-level input stats
Expand Down Expand Up @@ -55,26 +58,23 @@ var (
IFState *prometheus.GaugeVec
)

// Init ensures all metrics are registered.
func Init(elem string) {
namespace := "border"
func init() {
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)
return prom.NewCounterVec(Namespace, "", name, help, lNames)
}
newG := func(name, help string) prometheus.Gauge {
return prom.NewGauge(namespace, "", name, help)
return prom.NewGauge(Namespace, "", name, help)
}
newGVec := func(name, help string, lNames []string) *prometheus.GaugeVec {
return prom.NewGaugeVec(namespace, "", name, help, lNames)
return prom.NewGaugeVec(Namespace, "", name, help, lNames)
}
newHVec := func(name, help string,
lNames []string, buckets []float64) *prometheus.HistogramVec {

return prom.NewHistogramVec(namespace, "", name, help, lNames, buckets)
return prom.NewHistogramVec(Namespace, "", name, help, lNames, buckets)
}

InputPkts = newCVec("input_pkts_total", "Total number of input packets received.", sockLabels)
Expand Down Expand Up @@ -116,5 +116,5 @@ func Init(elem string) {
IFState = newGVec("interface_active", "Interface is active.", sockLabels)

// Initialize ringbuf metrics.
ringbuf.InitMetrics("border", []string{"ringId"})
ringbuf.InitMetrics(Namespace, []string{"ringId"})
}
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
2 changes: 1 addition & 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 All @@ -27,6 +26,7 @@ go_library(
"//go/lib/infra/modules/trust/trustdb:go_default_library",
"//go/lib/log:go_default_library",
"//go/lib/periodic:go_default_library",
"//go/lib/prom:go_default_library",
"//go/lib/snet:go_default_library",
"//go/lib/topology:go_default_library",
"//go/proto: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"
4 changes: 2 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 All @@ -34,6 +33,7 @@ import (
"github.com/scionproto/scion/go/lib/infra/modules/trust"
"github.com/scionproto/scion/go/lib/infra/modules/trust/trustdb"
"github.com/scionproto/scion/go/lib/log"
"github.com/scionproto/scion/go/lib/prom"
"github.com/scionproto/scion/go/lib/snet"
"github.com/scionproto/scion/go/lib/topology"
"github.com/scionproto/scion/go/proto"
Expand All @@ -57,7 +57,7 @@ func setupBasic() error {
if err := env.InitLogging(&cfg.Logging); err != nil {
return err
}
metrics.Init(cfg.General.ID)
prom.ExportElementID(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
31 changes: 9 additions & 22 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 = "disp"

// 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)
ringbuf.InitMetrics("dispatcher", nil)
OutgoingBytesTotal = prom.NewCounter(namespace, "", "outgoing_bytes_total",
func init() {
ringbuf.InitMetrics(Namespace, nil)
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
Loading

0 comments on commit afb63c0

Please sign in to comment.