Skip to content

Commit

Permalink
Feat/listening address (#371)
Browse files Browse the repository at this point in the history
* feat(selfMetrics): address should be configurable
  • Loading branch information
paologallinaharbur authored Dec 7, 2022
1 parent 392ed8c commit f1aecab
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 33 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ 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/).

## v2.17.0
## Changed
- Exposed `self_metrics_listening_address` to set listening address for self-metrics, having as default `:8080`.
- Several dependencies updated

## v2.16.7
## Changed
- Several dependencies updated
Expand Down
14 changes: 1 addition & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,9 @@ bin/$(BINARY_NAME):

compile: compile-deps bin/$(BINARY_NAME)

clean-test:
@echo "=== $(INTEGRATION) === [ compile ]: cleanup test dependencies..."
@go mod tidy

test-deps: compile-deps
@echo "=== $(INTEGRATION) === [ test-deps ]: installing testing dependencies..."
@go get -v $(TEST_DEPS)

test-only:
test:
@echo "=== $(INTEGRATION) === [ test ]: running unit tests..."
@go test ./...
@echo "=== $(INTEGRATION) === [ install ]: installing bin/$(BINARY_NAME)..."
@sudo install -D --mode=755 --owner=root --strip $(ROOT)bin/$(BINARY_NAME) $(INTEGRATIONS_DIR)/bin/$(BINARY_NAME)
@sudo install -D --mode=644 --owner=root $(ROOT)$(INTEGRATION)-definition.yml $(INTEGRATIONS_DIR)/$(INTEGRATION)-definition.yml
@sudo install -D --mode=644 --owner=root $(ROOT)$(INTEGRATION)-config.yml.sample $(CONFIG_DIR)/$(INTEGRATION)-config.yml.sample

# Include thematic Makefiles
include $(CURDIR)/build/ci.mk
Expand Down
1 change: 1 addition & 0 deletions cmd/nri-prometheus/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ func setViperDefaults(viper *viper.Viper) {
viper.SetDefault("scrape_endpoints", false)
viper.SetDefault("percentiles", []float64{50.0, 95.0, 99.0})
viper.SetDefault("worker_threads", 4)
viper.SetDefault("self_metrics_listening_address", ":8080")
}

// bindViperEnv automatically binds the variables in given configuration struct to environment variables.
Expand Down
1 change: 1 addition & 0 deletions cmd/nri-prometheus/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func TestLoadConfig(t *testing.T) {
EmitterHarvestPeriod: "1s",
MinEmitterHarvestPeriod: "200ms",
MaxStoredMetrics: 10000,
SelfMetricsListeningAddress: ":8080",
TargetConfigs: []endpoints.TargetConfig{
{
Description: "AAA",
Expand Down
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ require (
github.com/newrelic/infra-integrations-sdk/v4 v4.2.1
github.com/newrelic/newrelic-telemetry-sdk-go v0.8.1
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.13.1
github.com/prometheus/client_model v0.2.0
github.com/prometheus/client_golang v1.14.0
github.com/prometheus/client_model v0.3.0
github.com/prometheus/common v0.37.0
github.com/sirupsen/logrus v1.9.0
github.com/spf13/viper v1.14.0
github.com/stretchr/testify v1.8.1
k8s.io/api v0.25.3
k8s.io/apimachinery v0.25.3
k8s.io/client-go v0.25.3
k8s.io/api v0.25.4
k8s.io/apimachinery v0.25.4
k8s.io/client-go v0.25.4
)

require (
Expand Down
19 changes: 10 additions & 9 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -280,13 +280,14 @@ github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5Fsn
github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M=
github.com/prometheus/client_golang v1.11.0/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0=
github.com/prometheus/client_golang v1.12.1/go.mod h1:3Z9XVyYiZYEO+YQWt3RD2R3jrbd179Rt297l4aS6nDY=
github.com/prometheus/client_golang v1.13.1 h1:3gMjIY2+/hzmqhtUC/aQNYldJA6DtH3CgQvwS+02K1c=
github.com/prometheus/client_golang v1.13.1/go.mod h1:vTeo+zgvILHsnnj/39Ou/1fPN5nJFOEMgftOUOmlvYQ=
github.com/prometheus/client_golang v1.14.0 h1:nJdhIvne2eSX/XRAFV9PcvFFRbrjbcTUj0VP62TMhnw=
github.com/prometheus/client_golang v1.14.0/go.mod h1:8vpkKitgIVNcqrRBWh1C4TIUQgYNtG/XQE4E/Zae36Y=
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/prometheus/client_model v0.2.0 h1:uq5h0d+GuxiXLJLNABMgp2qUWDPiLvgCzz2dUR+/W/M=
github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/prometheus/client_model v0.3.0 h1:UBgGFHqYdG/TPFD1B1ogZywDqEkwp3fBMvqdiQ7Xew4=
github.com/prometheus/client_model v0.3.0/go.mod h1:LDGWKZIo7rky3hgvBe+caln+Dr3dPggB5dvjtD7w9+w=
github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo=
github.com/prometheus/common v0.26.0/go.mod h1:M7rCNAaPfAosfx8veZJCuw84e35h3Cfd9VFqTh1DIvc=
Expand Down Expand Up @@ -706,12 +707,12 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
k8s.io/api v0.25.3 h1:Q1v5UFfYe87vi5H7NU0p4RXC26PPMT8KOpr1TLQbCMQ=
k8s.io/api v0.25.3/go.mod h1:o42gKscFrEVjHdQnyRenACrMtbuJsVdP+WVjqejfzmI=
k8s.io/apimachinery v0.25.3 h1:7o9ium4uyUOM76t6aunP0nZuex7gDf8VGwkR5RcJnQc=
k8s.io/apimachinery v0.25.3/go.mod h1:jaF9C/iPNM1FuLl7Zuy5b9v+n35HGSh6AQ4HYRkCqwo=
k8s.io/client-go v0.25.3 h1:oB4Dyl8d6UbfDHD8Bv8evKylzs3BXzzufLiO27xuPs0=
k8s.io/client-go v0.25.3/go.mod h1:t39LPczAIMwycjcXkVc+CB+PZV69jQuNx4um5ORDjQA=
k8s.io/api v0.25.4 h1:3YO8J4RtmG7elEgaWMb4HgmpS2CfY1QlaOz9nwB+ZSs=
k8s.io/api v0.25.4/go.mod h1:IG2+RzyPQLllQxnhzD8KQNEu4c4YvyDTpSMztf4A0OQ=
k8s.io/apimachinery v0.25.4 h1:CtXsuaitMESSu339tfhVXhQrPET+EiWnIY1rcurKnAc=
k8s.io/apimachinery v0.25.4/go.mod h1:jaF9C/iPNM1FuLl7Zuy5b9v+n35HGSh6AQ4HYRkCqwo=
k8s.io/client-go v0.25.4 h1:3RNRDffAkNU56M/a7gUfXaEzdhZlYhoW8dgViGy5fn8=
k8s.io/client-go v0.25.4/go.mod h1:8trHCAC83XKY0wsBIpbirZU4NTUpbuhc2JnI7OruGZw=
k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE=
k8s.io/klog/v2 v2.70.1 h1:7aaoSdahviPmR+XkS7FyxlkkXs6tHISSG03RxleQAVQ=
k8s.io/klog/v2 v2.70.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0=
Expand Down
14 changes: 8 additions & 6 deletions internal/cmd/scraper/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type Config struct {
BearerTokenFile string `mapstructure:"bearer_token_file"`
InsecureSkipVerify bool `mapstructure:"insecure_skip_verify" default:"false"`
ProcessingRules []integration.ProcessingRule `mapstructure:"transformations"`
SelfMetricsListeningAddress string `mapstructure:"self_metrics_listening_address"`
DecorateFile bool
EmitterProxy string `mapstructure:"emitter_proxy"`
// Parsed version of `EmitterProxy`
Expand Down Expand Up @@ -161,11 +162,7 @@ func RunWithEmitters(cfg *Config, emitters []integration.Emitter) error {

scrapeDuration, err := time.ParseDuration(cfg.ScrapeDuration)
if err != nil {
return fmt.Errorf(
"parsing scrape_duration value (%v): %w",
cfg.ScrapeDuration,
err,
)
return fmt.Errorf("parsing scrape_duration value (%v): %w", cfg.ScrapeDuration, err)
}

go integration.Execute(
Expand All @@ -185,7 +182,12 @@ func RunWithEmitters(cfg *Config, emitters []integration.Emitter) error {
r.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
r.HandleFunc("/debug/pprof/trace", pprof.Trace)
}
return http.ListenAndServe(":8080", r)
err = http.ListenAndServe(cfg.SelfMetricsListeningAddress, r)
if err != nil {
return fmt.Errorf("listening on %q for metrics: %w", cfg.SelfMetricsListeningAddress, err)
}

return nil
}

// RunOnceWithEmitters runs the scraper with preselected emitters once.
Expand Down

0 comments on commit f1aecab

Please sign in to comment.