Skip to content

Commit

Permalink
fix: default configs emitter and definition path (#85)
Browse files Browse the repository at this point in the history
* fix: default configs emitter and definition path

* log error instead of fatal when LoadSpecFiles fail
  • Loading branch information
gsanchezgavier authored Oct 6, 2020
1 parent c4be94e commit f84e4bf
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
24 changes: 23 additions & 1 deletion cmd/nri-prometheus/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"path/filepath"
"reflect"
"regexp"
"runtime"
"strings"
"time"

Expand All @@ -22,6 +23,11 @@ type ArgumentList struct {
Configfile string `default:"" help:"Deprecated. --config_path takes precedence if both are set"`
}

const (
windowsDefinitionPath = "C:\\Program Files\\New Relic\\newrelic-infra\\definition-files"
linuxDefinitionPath = "/etc/newrelic-infra/definition-files"
)

func loadConfig() (*scraper.Config, error) {

c := ArgumentList{}
Expand Down Expand Up @@ -61,6 +67,23 @@ func loadConfig() (*scraper.Config, error) {
return nil, errors.Wrap(err, "could not parse configuration file")
}

// Set emitter default according to standalone mode.
if len(scraperCfg.Emitters) == 0 {
if scraperCfg.Standalone {
scraperCfg.Emitters = append(scraperCfg.Emitters, "telemetry")
} else {
scraperCfg.Emitters = append(scraperCfg.Emitters, "infra-sdk")
}
}

if scraperCfg.DefinitionFilesPath == "" {
if runtime.GOOS == "windows" {
scraperCfg.DefinitionFilesPath = windowsDefinitionPath
} else {
scraperCfg.DefinitionFilesPath = linuxDefinitionPath
}
}

if scraperCfg.MetricAPIURL == "" {
scraperCfg.MetricAPIURL = determineMetricAPIURL(string(scraperCfg.LicenseKey))
}
Expand All @@ -72,7 +95,6 @@ func loadConfig() (*scraper.Config, error) {
func setViperDefaults(viper *viper.Viper) {
viper.SetDefault("debug", false)
viper.SetDefault("verbose", false)
viper.SetDefault("emitters", []string{"telemetry"})
viper.SetDefault("scrape_enabled_label", "prometheus.io/scrape")
viper.SetDefault("require_scrape_enabled_label_for_nodes", true)
viper.SetDefault("scrape_timeout", 5*time.Second)
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/scraper/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ func Run(cfg *Config) error {
case "infra-sdk":
specs, err := integration.LoadSpecFiles(cfg.DefinitionFilesPath)
if err != nil {
return err
logrus.Errorf("error loading definition files: %s", err)
}
emitter := integration.NewInfraSdkEmitter(specs)
emitters = append(emitters, emitter)
Expand Down
3 changes: 2 additions & 1 deletion internal/integration/infra_sdk_emitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ func (e *InfraSdkEmitter) Emit(metrics []Metric) error {
logrus.WithError(err).Errorf("failed to create metric from '%s'", me.name)
}
}
logrus.Debugf("%d metrics processed", len(metrics))
logrus.Debugf("%d metrics not found in definition file and added to the Host Entity", len(i.HostEntity.Metrics))

return i.Publish()
}
Expand Down Expand Up @@ -127,7 +129,6 @@ func (e *InfraSdkEmitter) addMetricToEntity(i *sdk.Integration, metric Metric, m
entityProps, err := e.definitions.getEntity(metric)
// if we can't find an entity for the metric, add it to the "host" entity
if err != nil {
logrus.WithError(err).Debugf("failed to map metric to entity. using 'host' entity")
i.HostEntity.AddMetric(m)
return nil
}
Expand Down

0 comments on commit f84e4bf

Please sign in to comment.