Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: default configs emitter and definition path #85

Merged
merged 3 commits into from
Oct 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
paologallinaharbur marked this conversation as resolved.
Show resolved Hide resolved
}
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