From d0077ef223d1d9f471c5a06317f8fbf297678381 Mon Sep 17 00:00:00 2001 From: davidnewhall2 Date: Mon, 15 Jun 2020 04:38:00 -0700 Subject: [PATCH 1/4] Deprecate role param --- integrations/promunifi/collector.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/integrations/promunifi/collector.go b/integrations/promunifi/collector.go index 8bdff576..727e7c68 100644 --- a/integrations/promunifi/collector.go +++ b/integrations/promunifi/collector.go @@ -150,15 +150,20 @@ func (u *promUnifi) ScrapeHandler(w http.ResponseWriter, r *http.Request) { }} if t.Name == "" { - u.Collector.LogErrorf("input parameter missing on scrape from %v", r.RemoteAddr) - http.Error(w, `'input' parameter must be specified (try "unifi")`, 400) - - return + t.Name = "unifi" // the default } - if t.Role == "" && t.Path == "" { - u.Collector.LogErrorf("role and path parameters missing on scrape from %v", r.RemoteAddr) - http.Error(w, "'role' OR 'path' parameter must be specified: configured role OR unconfigured url", 400) + if t.Role != "" { + u.Collector.LogErrorf("deprecated 'role' parameter used; update your config to use 'path'") + + if t.Path == "" { + t.Path = t.Role + } + } + + if t.Path == "" { + u.Collector.LogErrorf("path parameter missing on scrape from %v", r.RemoteAddr) + http.Error(w, "'path' parameter must be specified: configured OR unconfigured url", 400) return } From 51814bf1955490730cef6e60e594eab3ca5408bb Mon Sep 17 00:00:00 2001 From: davidnewhall2 Date: Mon, 15 Jun 2020 04:55:28 -0700 Subject: [PATCH 2/4] same thing --- integrations/promunifi/collector.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/integrations/promunifi/collector.go b/integrations/promunifi/collector.go index 727e7c68..d6b655df 100644 --- a/integrations/promunifi/collector.go +++ b/integrations/promunifi/collector.go @@ -225,12 +225,7 @@ func (u *promUnifi) collect(ch chan<- prometheus.Metric, filter *poller.Filter) ok := false - if filter == nil { - r.Metrics, ok, err = u.Collector.Metrics() - } else { - r.Metrics, ok, err = u.Collector.MetricsFrom(filter) - } - + r.Metrics, ok, err = u.Collector.MetricsFrom(filter) r.Fetch = time.Since(r.Start) if err != nil { From 378466472cb96d8ae6d8edcfe010ac7464381ee7 Mon Sep 17 00:00:00 2001 From: davidnewhall2 Date: Mon, 15 Jun 2020 05:06:14 -0700 Subject: [PATCH 3/4] deprecate path too --- integrations/promunifi/collector.go | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/integrations/promunifi/collector.go b/integrations/promunifi/collector.go index d6b655df..b4e5df19 100644 --- a/integrations/promunifi/collector.go +++ b/integrations/promunifi/collector.go @@ -144,26 +144,33 @@ func (u *promUnifi) Run(c poller.Collect) error { // ScrapeHandler allows prometheus to scrape a single source, instead of all sources. func (u *promUnifi) ScrapeHandler(w http.ResponseWriter, r *http.Request) { t := &target{u: u, Filter: &poller.Filter{ - Name: r.URL.Query().Get("input"), // "unifi" - Path: r.URL.Query().Get("path"), // url: "https://127.0.0.1:8443" - Role: r.URL.Query().Get("role"), // configured role in up.conf. + Name: r.URL.Query().Get("input"), // "unifi" + Path: r.URL.Query().Get("target"), // NEW (target): "https://127.0.0.1:8443" }} if t.Name == "" { t.Name = "unifi" // the default } - if t.Role != "" { - u.Collector.LogErrorf("deprecated 'role' parameter used; update your config to use 'path'") + if pathOld := r.URL.Query().Get("path"); pathOld != "" { + u.Collector.LogErrorf("deprecated 'path' parameter used; update your config to use 'target'") if t.Path == "" { - t.Path = t.Role + t.Path = pathOld + } + } + + if roleOld := r.URL.Query().Get("role"); roleOld != "" { + u.Collector.LogErrorf("deprecated 'role' parameter used; update your config to use 'target'") + + if t.Path == "" { + t.Path = roleOld } } if t.Path == "" { - u.Collector.LogErrorf("path parameter missing on scrape from %v", r.RemoteAddr) - http.Error(w, "'path' parameter must be specified: configured OR unconfigured url", 400) + u.Collector.LogErrorf("'target' parameter missing on scrape from %v", r.RemoteAddr) + http.Error(w, "'target' parameter must be specified: configured OR unconfigured url", 400) return } From a4db0c38927d5b9a106f6e2d53ed386d7684766f Mon Sep 17 00:00:00 2001 From: davidnewhall2 Date: Mon, 15 Jun 2020 05:09:18 -0700 Subject: [PATCH 4/4] comment change --- integrations/promunifi/collector.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integrations/promunifi/collector.go b/integrations/promunifi/collector.go index b4e5df19..e76517bb 100644 --- a/integrations/promunifi/collector.go +++ b/integrations/promunifi/collector.go @@ -145,7 +145,7 @@ func (u *promUnifi) Run(c poller.Collect) error { func (u *promUnifi) ScrapeHandler(w http.ResponseWriter, r *http.Request) { t := &target{u: u, Filter: &poller.Filter{ Name: r.URL.Query().Get("input"), // "unifi" - Path: r.URL.Query().Get("target"), // NEW (target): "https://127.0.0.1:8443" + Path: r.URL.Query().Get("target"), // url: "https://127.0.0.1:8443" }} if t.Name == "" {