Skip to content

Commit

Permalink
[BugFix]Fixed metric overriding issue (#120)
Browse files Browse the repository at this point in the history
* Fixed metric overriding issue

Signed-off-by: iamabhishek-dubey <[email protected]>

* Fixed metric overriding issue

Signed-off-by: iamabhishek-dubey <[email protected]>

* Changed taskID to id

Signed-off-by: iamabhishek-dubey <[email protected]>

* Changed taskID to id

Signed-off-by: iamabhishek-dubey <[email protected]>
  • Loading branch information
iamabhishek-dubey authored Sep 19, 2021
1 parent 0d67373 commit 965c959
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 33 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM golang:1.15 as builder

LABEL VERSION=v0.10.0 \
LABEL VERSION=v0.11.0 \
ARCH=AMD64 \
DESCRIPTION="A monitoring of prometheus for druid" \
MAINTAINER="OpsTree Solutions"
Expand Down
10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Image URL to use all building/pushing image targets
REGISTRY ?= quay.io
REPOSITORY ?= $(REGISTRY)/opstree
IMAGE ?= druid-exporter
VERSION ?= v0.11

get-depends:
go get -v ./...
Expand All @@ -9,7 +11,13 @@ build-code: get-depends
go build -o druid-exporter

build-image:
docker build -t quay.io/opstree/druid-exporter:v0.10 -f Dockerfile .
docker build -t ${REPOSITORY}/${IMAGE}:${VERSION} -f Dockerfile .

push-image:
docker push ${REPOSITORY}/${IMAGE}:${VERSION}

fmt:
go fmt ./...

check-fmt:
test -z "$(shell gofmt -l .)"
Expand Down
2 changes: 1 addition & 1 deletion helm/templates/tests/connection-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ spec:
command: ['wget']
args: ['-qO-', '{{ include "prometheus-druid-exporter.fullname" . }}:{{ .Values.exporterPort }}/metrics']
restartPolicy: Never
{{- end }}
{{- end }}
56 changes: 32 additions & 24 deletions listener/druid_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func DruidHTTPEndpoint(metricsCleanupTTL int, disableHistogram bool, histogram *
service := fmt.Sprintf("%v", data["service"])
hostname := fmt.Sprintf("%v", data["host"])
datasource := data["dataSource"]
id := fmt.Sprintf("%v", data["id"])
value, _ := strconv.ParseFloat(fmt.Sprintf("%v", data["value"]), 64)

// Reverse DNS Lookup
Expand All @@ -61,63 +62,70 @@ func DruidHTTPEndpoint(metricsCleanupTTL int, disableHistogram bool, histogram *
logrus.Tracef(" hostname => (%s -> %s)", hostname, host)
logrus.Tracef(" datasource => %v", datasource)
logrus.Tracef(" value => %v", value)
logrus.Tracef(" id => %v", id)
}

if data["dataSource"] != nil {
if arrDatasource, ok := datasource.([]interface{}); ok { // Array datasource
for _, entryDatasource := range arrDatasource {
if !disableHistogram {
histogram.With(prometheus.Labels{
"metric_name": strings.Replace(metric, "/", "-", 3),
"service": strings.Replace(service, "/", "-", 3),
"datasource": entryDatasource.(string),
"host": host,
}).Observe(value)
}
if !disableHistogram {
histogram.With(prometheus.Labels{
"metric_name": strings.Replace(metric, "/", "-", 3),
"service": strings.Replace(service, "/", "-", 3),
"datasource": entryDatasource.(string),
"host": host,
"id": id,
}).Observe(value)
}

labels := prometheus.Labels{
"metric_name": strings.Replace(metric, "/", "-", 3),
"service": strings.Replace(service, "/", "-", 3),
"datasource": entryDatasource.(string),
"host": host,
"id": id,
}
gaugeCleaner.add(labels)
gauge.With(labels).Set(value)
}
} else { // Single datasource
if !disableHistogram {
histogram.With(prometheus.Labels{
"metric_name": strings.Replace(metric, "/", "-", 3),
"service": strings.Replace(service, "/", "-", 3),
"datasource": datasource.(string),
"host": host,
}).Observe(value)
}
if !disableHistogram {
histogram.With(prometheus.Labels{
"metric_name": strings.Replace(metric, "/", "-", 3),
"service": strings.Replace(service, "/", "-", 3),
"datasource": datasource.(string),
"host": host,
"id": id,
}).Observe(value)
}

labels := prometheus.Labels{
"metric_name": strings.Replace(metric, "/", "-", 3),
"service": strings.Replace(service, "/", "-", 3),
"datasource": datasource.(string),
"host": host,
"id": id,
}
gaugeCleaner.add(labels)
gauge.With(labels).Set(value)
}
} else { // Missing datasource case
if !disableHistogram {
histogram.With(prometheus.Labels{
"metric_name": strings.Replace(metric, "/", "-", 3),
"service": strings.Replace(service, "/", "-", 3),
"datasource": "",
"host": host,
}).Observe(value)
}
if !disableHistogram {
histogram.With(prometheus.Labels{
"metric_name": strings.Replace(metric, "/", "-", 3),
"service": strings.Replace(service, "/", "-", 3),
"datasource": "",
"host": host,
"id": id,
}).Observe(value)
}

labels := prometheus.Labels{
"metric_name": strings.Replace(metric, "/", "-", 3),
"service": strings.Replace(service, "/", "-", 3),
"datasource": "",
"host": host,
"id": id,
}
gaugeCleaner.add(labels)
gauge.With(labels).Set(value)
Expand Down
12 changes: 6 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ var (
"Log format for druid exporter, text or json, EnvVar - LOG_FORMAT. (Default: text)",
).Default("text").OverrideDefaultFromEnvar("LOG_FORMAT").Short('f').String()
disableHistogram = kingpin.Flag(
"no-histogram",
"Flag whether to export histogram metrics or not.",
).Default("false").OverrideDefaultFromEnvar("NO_HISTOGRAM").Bool()
"no-histogram",
"Flag whether to export histogram metrics or not.",
).Default("false").OverrideDefaultFromEnvar("NO_HISTOGRAM").Bool()

metricsCleanupTTL = kingpin.Flag(
"metrics-cleanup-ttl",
"Flag to provide time in minutes for metrics cleanup.",
).Default("5").OverrideDefaultFromEnvar("METRICS_CLEANUP_TTL").Int()
"metrics-cleanup-ttl",
"Flag to provide time in minutes for metrics cleanup.",
).Default("5").OverrideDefaultFromEnvar("METRICS_CLEANUP_TTL").Int()
druidEmittedDataHistogram = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Name: "druid_emitted_metrics_histogram",
Expand Down

0 comments on commit 965c959

Please sign in to comment.