feat(stackdriver_exporter): Add ErrorLogger for promhttp#277
Merged
SuperQ merged 5 commits intoprometheus-community:masterfrom Jul 2, 2024
Merged
Conversation
04af087 to
29e8667
Compare
kgeckhart
approved these changes
Nov 3, 2023
stackdriver_exporter.go
Outdated
| return promhttp.HandlerFor(gatherers, promhttp.HandlerOpts{}) | ||
| opts := promhttp.HandlerOpts{} | ||
| if *monitoringEnablePromHttpCustomLogger { | ||
| h.logger.Log("msg", "Enabling custom logger for promhttp") |
Contributor
There was a problem hiding this comment.
Nit:
Suggested change
| h.logger.Log("msg", "Enabling custom logger for promhttp") | |
| level.Info(h.logger).Log("msg", "Enabling custom logger for promhttp") |
Contributor
There was a problem hiding this comment.
Yes, this needs to be fixed.
Contributor
Author
There was a problem hiding this comment.
@SuperQ I just pushed a change to fix this. Please take a look when you get a chance, thank you!
Contributor
Author
|
@SuperQ when you get a chance, mind providing a review? This would really helpful for us to at least get alerted on when we enter this state. |
SuperQ
requested changes
Mar 7, 2024
stackdriver_exporter.go
Outdated
| return promhttp.HandlerFor(gatherers, promhttp.HandlerOpts{}) | ||
| opts := promhttp.HandlerOpts{} | ||
| if *monitoringEnablePromHttpCustomLogger { | ||
| h.logger.Log("msg", "Enabling custom logger for promhttp") |
Contributor
There was a problem hiding this comment.
Yes, this needs to be fixed.
1e43528 to
c1559c4
Compare
SuperQ
requested changes
Apr 14, 2024
stackdriver_exporter.go
Outdated
|
|
||
| // Delegate http serving to Prometheus client library, which will call collector.Collect. | ||
| return promhttp.HandlerFor(gatherers, promhttp.HandlerOpts{}) | ||
| opts := promhttp.HandlerOpts{} |
Contributor
There was a problem hiding this comment.
This can be simplified to:
Suggested change
| opts := promhttp.HandlerOpts{} | |
| opts := promhttp.HandlerOpts{ErrorLog: stdlog.New(log.NewStdlibAdapter(level.Error(h.logger)), "", 0)} |
There's no need to have a new flag for this, just adding the ErrorLog handler to promhttp is enough.
I had recently experienced prometheus-community#103 and prometheus-community#166 in production and it took quite some time to recognize there was a problem with `stackdriver_exporter` because nothing was logged out to indiciate problems gathering metrics. From my perspective, the pod was healthy and online and I could curl `/metrics` to get results. Grafana Agent however was getting errors when scraping, specifically errors like so: ``` [from Gatherer prometheus-community#2] collected metric "stackdriver_gce_instance_compute_googleapis_com_instance_disk_write_bytes_count" { label:{name:"device_name" value:"REDACTED_FOR_SECURITY"} label:{name:"device_type" value:"permanent"} label:{name:"instance_id" value:"2924941021702260446"} label:{name:"instance_name" value:"REDACTED_FOR_SECURITY"} label:{name:"project_id" value:"REDACTED_FOR_SECURITY"} label:{name:"storage_type" value:"pd-ssd"} label:{name:"unit" value:"By"} label:{name:"zone" value:"us-central1-a"} counter:{value:0} timestamp_ms:1698871080000} was collected before with the same name and label values ``` To help identify the root cause I've added the ability to opt into logging out errors that come from the handler. Specifically, I've created the struct `customPromErrorLogger` that implements the `promhttp.http.Logger` interface. There is a new flag: `monitoring.enable-promhttp-custom-logger` which if it is set to true, then we create an instance of `customPromErrorLogger` and use it as the value for ErrorLogger in `promhttp.Handler{}`. Otherwise, `stackdriver_exporter` works as it did before and does not log out errors collectoing metrics. - refs prometheus-community#103, prometheus-community#166 Signed-off-by: pokom <mark.poko@grafana.com>
Signed-off-by: pokom <mark.poko@grafana.com>
Signed-off-by: pokom <mark.poko@grafana.com>
Signed-off-by: pokom <mark.poko@grafana.com>
e8a6654 to
0e4f42d
Compare
Signed-off-by: pokom <mark.poko@grafana.com>
kgeckhart
approved these changes
Jun 4, 2024
SuperQ
approved these changes
Jul 2, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I had recently experienced #103 and #166 in production and it took quite some time to recognize there was a problem with
stackdriver_exporterbecause nothing was logged out to indiciate problems gathering metrics. From my perspective, the pod was healthy and online and I could curl/metricsto get results. Grafana Agent however was getting errors when scraping, specifically errors like so:To help identify the root cause I've added the ability to opt into logging out errors that come from the handler. Specifically, I've created the struct
customPromErrorLoggerthat implements thepromhttp.http.Loggerinterface. There is a new flag:monitoring.enable-promhttp-custom-loggerwhich if it is set to true, then we create an instance ofcustomPromErrorLoggerand use it as the value for ErrorLogger inpromhttp.Handler{}. Otherwise,stackdriver_exporterworks as it did before and does not log out errors collectoing metrics.