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

Fix for iamseth/oracledb_exporter#459 #460

Merged
merged 2 commits into from
Jul 29, 2024
Merged
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
11 changes: 9 additions & 2 deletions collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,11 @@
wg.Wait()
}

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

Check failure on line 241 in collector/collector.go

View workflow job for this annotation

GitHub Actions / build

cognitive complexity 34 of func `(*Exporter).scrape` is high (> 30) (gocognit)

Check failure on line 241 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
var errmutex sync.Mutex

defer func(begun time.Time) {
e.duration.Set(time.Since(begun).Seconds())
if err == nil {
Expand Down Expand Up @@ -277,7 +279,7 @@

for _, metric := range e.metricsToScrape.Metric {
wg.Add(1)
metric := metric //https://golang.org/doc/faq#closures_and_goroutines

Check failure on line 282 in collector/collector.go

View workflow job for this annotation

GitHub Actions / build

File is not `gofumpt`-ed with `-extra` (gofumpt)

Check failure on line 282 in collector/collector.go

View workflow job for this annotation

GitHub Actions / build

File is not `gofumpt`-ed with `-extra` (gofumpt)

f := func() {
defer wg.Done()
Expand All @@ -303,7 +305,7 @@
}

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

Check failure on line 308 in collector/collector.go

View workflow job for this annotation

GitHub Actions / build

string `histogram` has 3 occurrences, make it a constant (goconst)

Check failure on line 308 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 All @@ -313,8 +315,13 @@
}

scrapeStart := time.Now()
if err = e.ScrapeMetric(e.db, ch, metric); err != nil {
level.Error(e.logger).Log("scrapeMetricContext", metric.Context, "ScrapeDuration", time.Since(scrapeStart), "msg", err.Error())
if err1 := e.ScrapeMetric(e.db, ch, metric); err1 != nil {
errmutex.Lock()
{
err = err1
}
errmutex.Unlock()
level.Error(e.logger).Log("scrapeMetricContext", metric.Context, "ScrapeDuration", time.Since(scrapeStart), "msg", err1.Error())
e.scrapeErrors.WithLabelValues(metric.Context).Inc()
} else {
level.Debug(e.logger).Log("successfully scraped metric: ", metric.Context, metric.MetricsDesc, time.Since(scrapeStart))
Expand Down Expand Up @@ -436,8 +443,8 @@
}

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

Check failure on line 446 in collector/collector.go

View workflow job for this annotation

GitHub Actions / build

cognitive complexity 63 of func `(*Exporter).scrapeGenericValues` is high (> 30) (gocognit)

Check failure on line 446 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 {

Check failure on line 447 in collector/collector.go

View workflow job for this annotation

GitHub Actions / build

File is not `gofumpt`-ed with `-extra` (gofumpt)

Check failure on line 447 in collector/collector.go

View workflow job for this annotation

GitHub Actions / build

File is not `gofumpt`-ed with `-extra` (gofumpt)
metricsCount := 0
genericParser := func(row map[string]string) error {
// Construct labels value
Expand Down
Loading