Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log SQL error message #344

Merged
merged 1 commit into from
Sep 18, 2023
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
2 changes: 1 addition & 1 deletion 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)

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)

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 All @@ -275,7 +275,7 @@

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

Check failure on line 278 in collector/collector.go

View workflow job for this annotation

GitHub Actions / build

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

go func() {
defer wg.Done()
Expand All @@ -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 All @@ -312,7 +312,7 @@

scrapeStart := time.Now()
if err = e.ScrapeMetric(e.db, ch, metric); err != nil {
level.Error(e.logger).Log("Error scraping for", metric.Context, "_", metric.MetricsDesc, time.Since(scrapeStart), ":", err)
level.Error(e.logger).Log("Error scraping for", metric.Context, "_", metric.MetricsDesc, time.Since(scrapeStart), ":", err.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 @@ -405,8 +405,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 408 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 409 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 Expand Up @@ -556,7 +556,7 @@
}

func getMetricType(metricType string, metricsType map[string]string) prometheus.ValueType {
var strToPromType = map[string]prometheus.ValueType{

Check failure on line 559 in collector/collector.go

View workflow job for this annotation

GitHub Actions / build

File is not `gofumpt`-ed with `-extra` (gofumpt)
"gauge": prometheus.GaugeValue,
"counter": prometheus.CounterValue,
"histogram": prometheus.UntypedValue,
Expand Down
Loading