Skip to content

Commit

Permalink
Change delta calcaulator defaults (#52)
Browse files Browse the repository at this point in the history
Changes the values for the telemetry emitter delta calculator expiration
age and expiration check interval from 30 seconds to 5 minutes. Also
adds the following configuration options for setting each setting:

- telemetry_emitter_delta_expiration_age
- telemetry_emitter_delta_expiration_check_interval

This fixes the issue of missing datapoints for counters when the scrape
interval was taking longer than the delta expiration check interval and age.
  • Loading branch information
alejandrodnm authored Jun 10, 2020
1 parent 46b4310 commit f37fb89
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 19 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## NEXT RELEASE
### Changed
- Change the default for the New Relic telemetry emitter delta calculator
expiration age and expiration check interval to 5 minutes. These values can
now be configured with the following options
`telemetry_emitter_delta_expiration_age` and
`telemetry_emitter_delta_expiration_check_interval`. This solves the issue
with missing counters when the scrape interval takes more than the hard-coded
30 minutes values that we had previously.
- Use go modules instead of govendor for managing project dependencies.

## 1.4.0
### Changed
- Redact the password from URLs using simple authentication when storing target metadata.
Expand Down
8 changes: 8 additions & 0 deletions deploy/nri-prometheus.tmpl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ data:
# The HTTP client timeout when fetching data from endpoints. Defaults to 5s.
# scrape_timeout: "5s"
# How old must the entries used for calculating the counters delta be
# before the telemetry emitter expires them. Defaults to 5m.
# telemetry_emitter_delta_expiration_age: "5m"
# How often must the telemetry emitter check for expired delta entries.
# Defaults to 5m.
# telemetry_emitter_delta_expiration_check_interval: "5m"
# Wether the integration should run in verbose mode or not. Defaults to false.
verbose: false
Expand Down
20 changes: 12 additions & 8 deletions internal/cmd/scraper/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ type Config struct {
DecorateFile bool
EmitterProxy string `mapstructure:"emitter_proxy"`
// Parsed version of `EmitterProxy`
EmitterProxyURL *url.URL
EmitterCAFile string `mapstructure:"emitter_ca_file"`
EmitterInsecureSkipVerify bool `mapstructure:"emitter_insecure_skip_verify" default:"false"`
EmitterProxyURL *url.URL
EmitterCAFile string `mapstructure:"emitter_ca_file"`
EmitterInsecureSkipVerify bool `mapstructure:"emitter_insecure_skip_verify" default:"false"`
TelemetryEmitterDeltaExpirationAge time.Duration `mapstructure:"telemetry_emitter_delta_expiration_age"`
TelemetryEmitterDeltaExpirationCheckInterval time.Duration `mapstructure:"telemetry_emitter_delta_expiration_check_interval"`
}

const maskedLicenseKey = "****"
Expand Down Expand Up @@ -108,9 +110,6 @@ func validateConfig(cfg *Config) error {
// RunWithEmitters runs the scraper with preselected emitters.
func RunWithEmitters(cfg *Config, emitters []integration.Emitter) error {
logrus.Infof("Starting New Relic's Prometheus OpenMetrics Integration version %s", integration.Version)
if cfg.Verbose {
logrus.SetLevel(logrus.DebugLevel)
}
logrus.Debugf("Config: %#v", cfg)

if len(emitters) == 0 {
Expand Down Expand Up @@ -185,6 +184,9 @@ func Run(cfg *Config) error {
if err != nil {
return fmt.Errorf("while getting configuration options: %w", err)
}
if cfg.Verbose {
logrus.SetLevel(logrus.DebugLevel)
}

var emitters []integration.Emitter
for _, e := range cfg.Emitters {
Expand Down Expand Up @@ -242,8 +244,10 @@ func Run(cfg *Config) error {
}

c := integration.TelemetryEmitterConfig{
Percentiles: cfg.Percentiles,
HarvesterOpts: harvesterOpts,
Percentiles: cfg.Percentiles,
HarvesterOpts: harvesterOpts,
DeltaExpirationAge: cfg.TelemetryEmitterDeltaExpirationAge,
DeltaExpirationCheckInternval: cfg.TelemetryEmitterDeltaExpirationCheckInterval,
}

emitter, err := integration.NewTelemetryEmitter(c)
Expand Down
21 changes: 10 additions & 11 deletions internal/integration/emitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ import (
)

const (
// Ideally these 2 values should be configurable as integer multiples of the scrape interval.
defaultDeltaExpirationAge = 30 * time.Second
defaultDeltaExpirationCheckInterval = 30 * time.Second
defaultDeltaExpirationAge = 5 * time.Minute
defaultDeltaExpirationCheckInterval = 5 * time.Minute
)

// Emitter is an interface representing the ability to emit metrics.
Expand Down Expand Up @@ -147,24 +146,24 @@ func TelemetryHarvesterWithProxy(proxyURL *url.URL) TelemetryHarvesterOpt {
func NewTelemetryEmitter(cfg TelemetryEmitterConfig) (*TelemetryEmitter, error) {
dc := cumulative.NewDeltaCalculator()

deltaExpirationAge := defaultDeltaExpirationAge
if cfg.DeltaExpirationAge != 0 {
dc.SetExpirationAge(cfg.DeltaExpirationAge)
} else {
dc.SetExpirationAge(defaultDeltaExpirationAge)
deltaExpirationAge = cfg.DeltaExpirationAge
}
dc.SetExpirationAge(deltaExpirationAge)
logrus.Debugf(
"telemetry emitter configured with delta counter expiration age: %s",
cfg.DeltaExpirationAge,
deltaExpirationAge,
)

deltaExpirationCheckInterval := defaultDeltaExpirationCheckInterval
if cfg.DeltaExpirationCheckInternval != 0 {
dc.SetExpirationCheckInterval(cfg.DeltaExpirationCheckInternval)
} else {
dc.SetExpirationCheckInterval(defaultDeltaExpirationCheckInterval)
deltaExpirationCheckInterval = cfg.DeltaExpirationCheckInternval
}
dc.SetExpirationCheckInterval(deltaExpirationCheckInterval)
logrus.Debugf(
"telemetry emitter configured with delta counter expiration check interval: %s",
cfg.DeltaExpirationAge,
deltaExpirationCheckInterval,
)

harvester, err := telemetry.NewHarvester(cfg.HarvesterOpts...)
Expand Down

0 comments on commit f37fb89

Please sign in to comment.