Skip to content
This repository has been archived by the owner on Feb 13, 2025. It is now read-only.

support labels when using fieldtoappend feature #422

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
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
6 changes: 3 additions & 3 deletions collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@
wg.Wait()
}

func (e *Exporter) scrape(ch chan<- prometheus.Metric) {

Check failure on line 239 in collector/collector.go

View workflow job for this annotation

GitHub Actions / build

cognitive complexity 34 of func `(*Exporter).scrape` is high (> 30) (gocognit)
e.totalScrapes.Inc()
var err error
defer func(begun time.Time) {
Expand All @@ -250,16 +250,16 @@

if err = e.db.Ping(); err != nil {
if strings.Contains(err.Error(), "sql: database is closed") {
level.Info(e.logger).Log("Reconnecting to DB")

Check failure on line 253 in collector/collector.go

View workflow job for this annotation

GitHub Actions / build

Error return value of `(github.com/go-kit/log.Logger).Log` is not checked (errcheck)
err = e.connect()
if err != nil {
level.Error(e.logger).Log("error reconnecting to DB", err.Error())

Check failure on line 256 in collector/collector.go

View workflow job for this annotation

GitHub Actions / build

Error return value of `(github.com/go-kit/log.Logger).Log` is not checked (errcheck)
}
}
}

if err = e.db.Ping(); err != nil {
level.Error(e.logger).Log("error pinging oracle:", err.Error())

Check failure on line 262 in collector/collector.go

View workflow job for this annotation

GitHub Actions / build

Error return value of `(github.com/go-kit/log.Logger).Log` is not checked (errcheck)
e.up.Set(0)
return
}
Expand Down Expand Up @@ -301,7 +301,7 @@
}

for column, metricType := range metric.MetricsType {
if metricType == "histogram" {

Check failure on line 304 in collector/collector.go

View workflow job for this annotation

GitHub Actions / build

string `histogram` has 3 occurrences, make it a constant (goconst)
_, ok := metric.MetricsBuckets[column]
if !ok {
level.Error(e.logger).Log("Unable to find MetricsBuckets configuration key for metric. (metric=" + column + ")")
Expand Down Expand Up @@ -406,7 +406,7 @@
}

// generic method for retrieving metrics.
func (e *Exporter) scrapeGenericValues(db *sql.DB, ch chan<- prometheus.Metric, context string, labels []string,

Check failure on line 409 in collector/collector.go

View workflow job for this annotation

GitHub Actions / build

cognitive complexity 63 of func `(*Exporter).scrapeGenericValues` is high (> 30) (gocognit)
metricsDesc map[string]string, metricsType map[string]string, metricsBuckets map[string]map[string]string, fieldToAppend string, ignoreZeroResult bool, request string) error {
metricsCount := 0
genericParser := func(row map[string]string) error {
Expand All @@ -432,7 +432,7 @@
metricHelp,
labels, nil,
)
if metricsType[strings.ToLower(metric)] == "histogram" {

Check failure on line 435 in collector/collector.go

View workflow job for this annotation

GitHub Actions / build

435-461 lines are duplicate of `collector/collector.go:469-495` (dupl)
count, err := strconv.ParseUint(strings.TrimSpace(row["count"]), 10, 64)
if err != nil {
level.Error(e.logger).Log("Unable to convert count value to int (metric=" + metric +
Expand Down Expand Up @@ -464,9 +464,9 @@
desc := prometheus.NewDesc(
prometheus.BuildFQName(namespace, context, cleanName(row[fieldToAppend])),
metricHelp,
nil, nil,
labels, nil,
)
if metricsType[strings.ToLower(metric)] == "histogram" {

Check failure on line 469 in collector/collector.go

View workflow job for this annotation

GitHub Actions / build

469-495 lines are duplicate of `collector/collector.go:435-461` (dupl)
count, err := strconv.ParseUint(strings.TrimSpace(row["count"]), 10, 64)
if err != nil {
level.Error(e.logger).Log("Unable to convert count value to int (metric=" + metric +
Expand All @@ -489,9 +489,9 @@
}
buckets[lelimit] = counter
}
ch <- prometheus.MustNewConstHistogram(desc, count, value, buckets)
ch <- prometheus.MustNewConstHistogram(desc, count, value, buckets, labelsValues...)
} else {
ch <- prometheus.MustNewConstMetric(desc, getMetricType(metric, metricsType), value)
ch <- prometheus.MustNewConstMetric(desc, getMetricType(metric, metricsType), value, labelsValues...)
}
}
metricsCount++
Expand Down
Loading