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

feat(config): added config option to enable/disable autodiscovery #69

Merged
merged 3 commits into from
Aug 31, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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("enable_autodiscovery", true)
paologallinaharbur marked this conversation as resolved.
Show resolved Hide resolved
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 false in order to stop autodiscovery in the k8s cluster. It can be useful when running the Pod with a service account
# having limited privileges
# enable_autodiscovery: true
# 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 false in order to stop autodiscovery in the k8s cluster. It can be useful when running the Pod with a service account
# having limited privileges
# enable_autodiscovery: true

# 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"`
EnableAutodiscovery bool `mapstructure:"enable_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.EnableAutodiscovery {
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