Skip to content

Commit

Permalink
router: add metric to track service instance count (#3918)
Browse files Browse the repository at this point in the history
Add two metrics to track the number of service instances known to the
data plane.

    # HELP router_service_instance_changes_total Number of total service instance changes. Both addition and removal of a service instance is accumulated
    # TYPE router_service_instance_changes_total counter
    router_service_instance_changes_total{isd_as="1-ff00:0:110",service="CS"} 11
    router_service_instance_changes_total{isd_as="1-ff00:0:110",service="DS"} 11
    # HELP router_service_instance_count Number of service instances known by the data plane.
    # TYPE router_service_instance_count gauge
    router_service_instance_count{isd_as="1-ff00:0:110",service="CS"} 3
    router_service_instance_count{isd_as="1-ff00:0:110",service="DS"} 3
  • Loading branch information
oncilla authored Oct 26, 2020
1 parent e87b66d commit 002463e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 11 deletions.
17 changes: 17 additions & 0 deletions go/pkg/router/dataplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,11 @@ func (d *DataPlane) AddSvc(svc addr.HostSVC, a *net.UDPAddr) error {
d.svc = newServices()
}
d.svc.AddSvc(svc, a)
if d.Metrics != nil {
labels := serviceMetricLabels(d.localIA, svc)
d.Metrics.ServiceInstanceChanges.With(labels).Add(1)
d.Metrics.ServiceInstanceCount.With(labels).Add(1)
}
return nil
}

Expand All @@ -343,6 +348,11 @@ func (d *DataPlane) DelSvc(svc addr.HostSVC, a *net.UDPAddr) error {
return nil
}
d.svc.DelSvc(svc, a)
if d.Metrics != nil {
labels := serviceMetricLabels(d.localIA, svc)
d.Metrics.ServiceInstanceChanges.With(labels).Add(1)
d.Metrics.ServiceInstanceCount.With(labels).Add(-1)
}
return nil
}

Expand Down Expand Up @@ -1436,3 +1446,10 @@ func interfaceToMetricLabels(id uint16, localIA addr.IA,
"neighbor_isd_as": neighbors[id].String(),
}
}

func serviceMetricLabels(localIA addr.IA, svc addr.HostSVC) prometheus.Labels {
return prometheus.Labels{
"isd_as": localIA.String(),
"service": svc.BaseString(),
}
}
17 changes: 17 additions & 0 deletions go/pkg/router/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ type Metrics struct {
BFDInterfaceStateChanges *prometheus.CounterVec
BFDPacketsSent *prometheus.CounterVec
BFDPacketsReceived *prometheus.CounterVec
ServiceInstanceCount *prometheus.GaugeVec
ServiceInstanceChanges *prometheus.CounterVec
SiblingReachable *prometheus.GaugeVec
SiblingBFDPacketsSent *prometheus.CounterVec
SiblingBFDPacketsReceived *prometheus.CounterVec
Expand Down Expand Up @@ -104,6 +106,21 @@ func NewMetrics() *Metrics {
},
[]string{"interface", "isd_as", "neighbor_isd_as"},
),
ServiceInstanceCount: promauto.NewGaugeVec(
prometheus.GaugeOpts{
Name: "router_service_instance_count",
Help: "Number of service instances known by the data plane.",
},
[]string{"service", "isd_as"},
),
ServiceInstanceChanges: promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "router_service_instance_changes_total",
Help: "Number of total service instance changes. Both addition and removal of a " +
"service instance is accumulated.",
},
[]string{"service", "isd_as"},
),
SiblingReachable: promauto.NewGaugeVec(
prometheus.GaugeOpts{
Name: "router_sibling_reachable",
Expand Down
22 changes: 11 additions & 11 deletions go/posix-router/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
"github.com/scionproto/scion/go/lib/serrors"
"github.com/scionproto/scion/go/pkg/command"
"github.com/scionproto/scion/go/pkg/router"
brconf "github.com/scionproto/scion/go/pkg/router/config"
"github.com/scionproto/scion/go/pkg/router/config"
"github.com/scionproto/scion/go/pkg/router/control"
"github.com/scionproto/scion/go/pkg/service"
)
Expand All @@ -52,7 +52,7 @@ func main() {
}
cmd.AddCommand(
command.NewCompletion(cmd),
command.NewSample(cmd, command.NewSampleConfig(&brconf.Config{})),
command.NewSample(cmd, command.NewSampleConfig(&config.Config{})),
command.NewVersion(cmd),
)
cmd.Flags().StringVar(&flags.config, "config", "", "Configuration file (required)")
Expand All @@ -72,7 +72,7 @@ func run(file string, metrics *router.Metrics) error {
defer log.Flush()
defer env.LogAppStopped("BR", fileConfig.General.ID)
defer log.HandlePanic()
if err := validateCfg(fileConfig); err != nil {
if err := validateConfig(fileConfig); err != nil {
return err
}
controlConfig, err := loadControlConfig(fileConfig)
Expand Down Expand Up @@ -115,38 +115,38 @@ func run(file string, metrics *router.Metrics) error {
}
}

func setupBasic(file string) (brconf.Config, error) {
var cfg brconf.Config
func setupBasic(file string) (config.Config, error) {
var cfg config.Config
if err := libconfig.LoadFile(file, &cfg); err != nil {
return brconf.Config{}, serrors.WrapStr("loading config from file", err, "file", file)
return config.Config{}, serrors.WrapStr("loading config from file", err, "file", file)
}
cfg.InitDefaults()
if err := log.Setup(cfg.Logging); err != nil {
return brconf.Config{}, serrors.WrapStr("initialize logging", err)
return config.Config{}, serrors.WrapStr("initialize logging", err)
}
prom.ExportElementID(cfg.General.ID)
if err := env.LogAppStarted("BR", cfg.General.ID); err != nil {
return brconf.Config{}, err
return config.Config{}, err
}
return cfg, nil
}

func validateCfg(cfg brconf.Config) error {
func validateConfig(cfg config.Config) error {
if err := cfg.Validate(); err != nil {
return serrors.WrapStr("validating config", err)
}
return nil
}

func loadControlConfig(cfg brconf.Config) (*control.Config, error) {
func loadControlConfig(cfg config.Config) (*control.Config, error) {
newConf, err := control.LoadConfig(cfg.General.ID, cfg.General.ConfigDir)
if err != nil {
return nil, serrors.WrapStr("loading topology", err)
}
return newConf, nil
}

func setupHTTPHandlers(cfg brconf.Config) error {
func setupHTTPHandlers(cfg config.Config) error {
statusPages := service.StatusPages{
"info": service.NewInfoHandler(),
"config": service.NewConfigHandler(cfg),
Expand Down

0 comments on commit 002463e

Please sign in to comment.