Skip to content

Commit

Permalink
feat(config): added config option to enable/disable autodiscovery (#69)
Browse files Browse the repository at this point in the history
* feat(config): added config option to disable autodiscovery

* fix(variableName): enable_autodiscovery changed to disable_autodiscovery
  • Loading branch information
paologallinaharbur authored Aug 31, 2020
1 parent 8368d86 commit 9099e99
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions cmd/nri-prometheus/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func setViperDefaults(viper *viper.Viper) {
viper.SetDefault("auto_decorate", false)
viper.SetDefault("insecure_skip_verify", false)
viper.SetDefault("standalone", true)
viper.SetDefault("disable_autodiscovery", false)
viper.SetDefault("percentiles", []float64{50.0, 95.0, 99.0})
}

Expand Down
3 changes: 3 additions & 0 deletions deploy/local.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ data:
insecure_skip_verify: false
# The label used to identify scrapable targets. Defaults to "prometheus.io/scrape".
scrape_enabled_label: "prometheus.io/scrape"
# Set to true in order to stop autodiscovery in the k8s cluster. It can be useful when running the Pod with a service account
# having limited privileges. Defaults to false.
# disable_autodiscovery: false
# Wether k8s nodes needs to be labelled to be scraped or not. Defaults to false.
require_scrape_enabled_label_for_nodes: true
#targets:
Expand Down
4 changes: 4 additions & 0 deletions deploy/nri-prometheus.tmpl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ data:
# If left empty, TLS uses the host's root CA set.
# emitter_ca_file: "/path/to/cert/server.pem"
# Set to true in order to stop autodiscovery in the k8s cluster. It can be useful when running the Pod with a service account
# having limited privileges. Defaults to false.
# disable_autodiscovery: false
# Whether the emitter should skip TLS verification when submitting data.
# Defaults to false.
# emitter_insecure_skip_verify: false
Expand Down
13 changes: 8 additions & 5 deletions internal/cmd/scraper/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type Config struct {
RequireScrapeEnabledLabelForNodes bool `mapstructure:"require_scrape_enabled_label_for_nodes"`
ScrapeTimeout time.Duration `mapstructure:"scrape_timeout"`
Standalone bool `mapstructure:"standalone"`
DisableAutodiscovery bool `mapstructure:"disable_autodiscovery"`
ScrapeDuration string `mapstructure:"scrape_duration"`
EmitterHarvestPeriod string `mapstructure:"emitter_harvest_period"`
TargetConfigs []endpoints.TargetConfig `mapstructure:"targets"`
Expand Down Expand Up @@ -119,11 +120,13 @@ func RunWithEmitters(cfg *Config, emitters []integration.Emitter) error {
}
retrievers = append(retrievers, fixedRetriever)

kubernetesRetriever, err := endpoints.NewKubernetesTargetRetriever(cfg.ScrapeEnabledLabel, cfg.RequireScrapeEnabledLabelForNodes, endpoints.WithInClusterConfig())
if err != nil {
logrus.WithError(err).Errorf("not possible to get a Kubernetes client. If you aren't running this integration in a Kubernetes cluster, you can ignore this error")
} else {
retrievers = append(retrievers, kubernetesRetriever)
if !cfg.DisableAutodiscovery {
kubernetesRetriever, err := endpoints.NewKubernetesTargetRetriever(cfg.ScrapeEnabledLabel, cfg.RequireScrapeEnabledLabelForNodes, endpoints.WithInClusterConfig())
if err != nil {
logrus.WithError(err).Errorf("not possible to get a Kubernetes client. If you aren't running this integration in a Kubernetes cluster, you can ignore this error")
} else {
retrievers = append(retrievers, kubernetesRetriever)
}
}
defaultTransformations := integration.ProcessingRule{
Description: "Default transformation rules",
Expand Down

0 comments on commit 9099e99

Please sign in to comment.