From 59c8b4a40d6cb27536e43547f0a91a5c3af7fb67 Mon Sep 17 00:00:00 2001 From: iamabhishek-dubey Date: Mon, 22 Jun 2020 13:46:01 +0530 Subject: [PATCH 1/3] Fixed formatting Signed-off-by: iamabhishek-dubey --- collector/druid.go | 5 ++++- main.go | 15 ++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/collector/druid.go b/collector/druid.go index 5089b95..8e0dc1e 100644 --- a/collector/druid.go +++ b/collector/druid.go @@ -10,7 +10,10 @@ import ( ) var ( - druid = kingpin.Flag("druid.uri", "URL of druid router or coordinator, EnvVar - DRUID_URL").Default("http://druid.opstreelabs.in").OverrideDefaultFromEnvar("DRUID_URL").Short('d').String() + druid = kingpin.Flag( + "druid.uri", + "URL of druid router or coordinator, EnvVar - DRUID_URL", + ).Default("http://druid.opstreelabs.in").OverrideDefaultFromEnvar("DRUID_URL").Short('d').String() ) // GetDruidHealthMetrics returns the set of metrics for druid diff --git a/main.go b/main.go index 13ccd5d..bc527b2 100644 --- a/main.go +++ b/main.go @@ -12,9 +12,18 @@ import ( ) var ( - port = kingpin.Flag("port", "Port to listen druid exporter, EnvVar - DRUID_EXPORTER_PORT. (Default - 8080)").Default("8080").OverrideDefaultFromEnvar("DRUID_EXPORTER_PORT").Short('p').String() - logLevel = kingpin.Flag("log.level", "Log level for druid exporter, EnvVar - LOG_LEVEL. (Default: info)").Default("info").OverrideDefaultFromEnvar("LOG_LEVEL").Short('l').String() - logFormat = kingpin.Flag("log.format", "Log format for druid exporter, text or json, EnvVar - LOG_FORMAT. (Default: text)").Default("text").OverrideDefaultFromEnvar("LOG_FORMAT").Short('f').String() + port = kingpin.Flag( + "port", + "Port to listen druid exporter, EnvVar - DRUID_EXPORTER_PORT. (Default - 8080)", + ).Default("8080").OverrideDefaultFromEnvar("DRUID_EXPORTER_PORT").Short('p').String() + logLevel = kingpin.Flag( + "log.level", + "Log level for druid exporter, EnvVar - LOG_LEVEL. (Default: info)", + ).Default("info").OverrideDefaultFromEnvar("LOG_LEVEL").Short('l').String() + logFormat = kingpin.Flag( + "log.format", + "Log format for druid exporter, text or json, EnvVar - LOG_FORMAT. (Default: text)", + ).Default("text").OverrideDefaultFromEnvar("LOG_FORMAT").Short('f').String() druidEmittedData = prometheus.NewGaugeVec( prometheus.GaugeOpts{ Name: "druid_emitted_metrics", From 72eaf9055d5d08eff60f9c570d39a565fbf02a37 Mon Sep 17 00:00:00 2001 From: iamabhishek-dubey Date: Mon, 22 Jun 2020 14:05:10 +0530 Subject: [PATCH 2/3] Fixed duplicate metrics Signed-off-by: iamabhishek-dubey --- main.go | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index bc527b2..3ac1128 100644 --- a/main.go +++ b/main.go @@ -33,8 +33,6 @@ var ( ) func init() { - getDruidAPIdata := collector.Collector() - prometheus.MustRegister(getDruidAPIdata) prometheus.MustRegister(druidEmittedData) } @@ -56,8 +54,10 @@ func main() { }) } router := mux.NewRouter() + getDruidAPIdata := collector.Collector() + handlerFunc := newHandler(*getDruidAPIdata) router.Handle("/druid", listener.DruidHTTPEndpoint(druidEmittedData)) - router.Handle("/metrics", promhttp.Handler()) + router.Handle("/metrics", promhttp.InstrumentMetricHandler(prometheus.DefaultRegisterer, handlerFunc)) router.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte(` Druid Exporter @@ -70,5 +70,19 @@ func main() { logrus.Infof("Druid exporter started listening on: %v", *port) logrus.Infof("Metrics endpoint - http://0.0.0.0:%v/metrics", *port) logrus.Infof("Druid emitter endpoint - http://0.0.0.0:%v/druid", *port) - http.ListenAndServe("0.0.0.0:"+*port, router) + http.ListenAndServe("0.0.0.0:8080", router) +} + +func newHandler(metrics collector.MetricCollector) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + registry := prometheus.NewRegistry() + getDruidAPIdata := collector.Collector() + registry.MustRegister(getDruidAPIdata) + gatherers := prometheus.Gatherers{ + prometheus.DefaultGatherer, + registry, + } + h := promhttp.HandlerFor(gatherers, promhttp.HandlerOpts{}) + h.ServeHTTP(w, r) + } } From 7f4157aff061be28261b954149174b7a5230c784 Mon Sep 17 00:00:00 2001 From: iamabhishek-dubey Date: Mon, 22 Jun 2020 14:21:04 +0530 Subject: [PATCH 3/3] Updated CHANGELOG for v0.7 information Signed-off-by: iamabhishek-dubey --- CHANGELOG.md | 8 ++++++++ main.go | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8892c3..3603522 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +### v0.7 +##### June 22, 2020 + +#### :beetle: Bug Fixes + +- Fixed JSON parser failure issue +- Fixed duplicate task metric's server 500 issue + ### v0.6 ##### June 11, 2020 diff --git a/main.go b/main.go index 3ac1128..7d3fd7a 100644 --- a/main.go +++ b/main.go @@ -70,7 +70,7 @@ func main() { logrus.Infof("Druid exporter started listening on: %v", *port) logrus.Infof("Metrics endpoint - http://0.0.0.0:%v/metrics", *port) logrus.Infof("Druid emitter endpoint - http://0.0.0.0:%v/druid", *port) - http.ListenAndServe("0.0.0.0:8080", router) + http.ListenAndServe("0.0.0.0:"+*port, router) } func newHandler(metrics collector.MetricCollector) http.HandlerFunc {