Skip to content

Commit

Permalink
fix: error type conversion (#353)
Browse files Browse the repository at this point in the history
  • Loading branch information
burningalchemist authored Oct 8, 2023
1 parent 0875aea commit 7f9f26b
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions cmd/sql_exporter/promhttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,23 @@ func ExporterHandlerFor(exporter sql_exporter.Exporter) http.Handler {
gatherer := prometheus.Gatherers{exporter.WithContext(ctx)}
mfs, err := gatherer.Gather()
if err != nil {
switch t := err.(type) {
case prometheus.MultiError:
for _, err := range t {
if errors.Is(err, context.DeadlineExceeded) {
klog.Errorf("%s: timeout collecting metrics", err)
} else {
klog.Errorf("Error gathering metrics: %s", err)
}
}
default:
klog.Errorf("Error gathering metrics: %s", err)
}
if len(mfs) == 0 {
klog.Errorf("%s: %s", noMetricsGathered, err)
http.Error(w, noMetricsGathered+", "+err.Error(), http.StatusInternalServerError)
return
}
multierr := err.(prometheus.MultiError)
for _, err := range multierr {
if errors.Is(err, context.DeadlineExceeded) {
klog.Errorf("%s: timeout collecting metrics", err)
} else {
klog.Errorf("Error gathering metrics: %s", err)
}
}
}

contentType := expfmt.Negotiate(req.Header)
Expand Down

0 comments on commit 7f9f26b

Please sign in to comment.