Skip to content

Commit

Permalink
Allow selectively turn off prometheus metrics and/or stats poller
Browse files Browse the repository at this point in the history
Signed-off-by: Vladimir Lavor <vlavor@cisco.com>
  • Loading branch information
VladoLavor committed Oct 21, 2019
1 parent 69d622d commit 8467888
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 31 deletions.
6 changes: 4 additions & 2 deletions plugins/telemetry/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ const (
type Config struct {
// Custom polling interval, default value is 30s
PollingInterval time.Duration `json:"polling-interval"`
// Allows to disable plugin
Disabled bool `json:"disabled"`
// Allows to disable prometheus in telemetry plugin
PrometheusDisabled bool `json:"prometheus-disabled"`
// Allows to disable stats poller in telemetry plugin
StatsPollerDisabled bool `json:"stats-poller-disabled"`
// Skip collecting some of the metrics:
// runtime, memory, buffers, nodes, interfaces
Skipped []string `json:"skipped"`
Expand Down
7 changes: 5 additions & 2 deletions plugins/telemetry/telemetry.conf
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# Interval of data read procedure from the vpp. Default value is 30 seconds.
polling-interval: 30s

# If set to true, telemetry plugin is disabled.
disabled: false
# If set to true, prometheus in telemetry plugin is disabled.
prometheus-disabled: false

# If set to true, stats poller in telemetry plugin is disabled.
stats-poller-disabled: false

# Skip collecting some of the metrics.
# runtime, memory, buffers, nodes, interfaces
Expand Down
56 changes: 29 additions & 27 deletions plugins/telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ type Plugin struct {
prometheusMetrics

// From config file
updatePeriod time.Duration
disabled bool
skipped map[string]bool
updatePeriod time.Duration
prometheusDisabled bool
statsPollerDisabled bool
skipped map[string]bool

wg sync.WaitGroup
quit chan struct{}
Expand All @@ -83,13 +84,14 @@ func (p *Plugin) Init() error {
if err != nil {
return err
}
if config != nil {
// If telemetry is not enabled, skip plugin initialization
if config.Disabled {
p.Log.Info("Telemetry plugin disabled via config file")
p.disabled = true
return nil
}

// Prometheus metrics
if config == nil {
p.updatePeriod = defaultUpdatePeriod
} else if config.PrometheusDisabled {
p.prometheusDisabled = true
p.Log.Infof("Prometheus metrics disabled")
} else {
// This prevents setting the update period to less than 5 seconds,
// which can have significant performance hit.
if config.PollingInterval > minimumUpdatePeriod {
Expand All @@ -103,23 +105,25 @@ func (p *Plugin) Init() error {
for _, skip := range config.Skipped {
p.skipped[skip] = true
}
}
// This serves as fallback if the config was not found or if the value is not set in config.
if p.updatePeriod == 0 {
p.updatePeriod = defaultUpdatePeriod
}

if err := p.registerPrometheus(); err != nil {
return err
}
if err := p.registerPrometheus(); err != nil {
return err
}

p.statsPollerServer.log = p.Log.NewLogger("stats-poller")
if err := p.setupStatsPoller(); err != nil {
return err
if p.HTTPHandlers != nil {
p.HTTPHandlers.RegisterHTTPHandler("/metrics/{metric}", metricsHandler, "GET")
}
}

if p.HTTPHandlers != nil {
p.HTTPHandlers.RegisterHTTPHandler("/metrics/{metric}", metricsHandler, "GET")
// Stats poller
if config == nil || !config.StatsPollerDisabled {
p.statsPollerServer.log = p.Log.NewLogger("stats-poller")
if err := p.setupStatsPoller(); err != nil {
return err
}
} else {
p.statsPollerDisabled = true
p.Log.Infof("Stats poller disabled")
}

return nil
Expand All @@ -128,12 +132,10 @@ func (p *Plugin) Init() error {
// AfterInit executes after initializion of Telemetry Plugin
func (p *Plugin) AfterInit() error {
// Do not start polling if telemetry is disabled
if p.disabled {
return nil
if !p.prometheusDisabled {
p.startPeriodicUpdates()
}

p.startPeriodicUpdates()

return nil
}

Expand Down

0 comments on commit 8467888

Please sign in to comment.