Skip to content

Log errors when ignoreZeroResult = true #173

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

Merged
merged 2 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,7 @@ func (e *Exporter) scrape(ch chan<- prometheus.Metric, tick *time.Time) {
err = err1
}
errmutex.Unlock()
if !metric.IgnoreZeroResult {
// do not print repetitive error messages for metrics
// with ignoreZeroResult set to true
if shouldLogScrapeError(err, metric.IgnoreZeroResult) {
level.Error(e.logger).Log("msg", "Error scraping metric",
"Context", metric.Context,
"MetricsDesc", fmt.Sprint(metric.MetricsDesc),
Expand Down Expand Up @@ -622,7 +620,9 @@ func (e *Exporter) scrapeGenericValues(db *sql.DB, ch chan<- prometheus.Metric,
return err
}
if !ignoreZeroResult && metricsCount == 0 {
return errors.New("no metrics found while parsing, query returned no rows")
// a zero result error is returned for caller error identification.
// https://github.com/oracle/oracle-db-appdev-monitoring/issues/168
return newZeroResultError()
}
return err
}
Expand Down
25 changes: 25 additions & 0 deletions collector/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) 2024, Oracle and/or its affiliates.
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.

package collector

import "errors"

type zeroResultError struct {
err string
}

func (z *zeroResultError) Error() string {
return z.err
}

func newZeroResultError() error {
return &zeroResultError{
err: "no metrics found while parsing, query returned no rows",
}
}

// shouldLogScrapeError returns false if the error is a zero result error and zero result errors are ignored.
func shouldLogScrapeError(err error, isIgnoreZeroResult bool) bool {
return !isIgnoreZeroResult || !errors.Is(err, newZeroResultError())
}