Indicate cache hits in HTTP trace log (#29533)
Some checks failed
Release / call-build-workflow (push) Has been cancelled
Release / Publish Docker :release (push) Has been cancelled
Release / Github & APT (push) Has been cancelled
Release / Demo (push) Has been cancelled
Release / Hassio Addon (push) Has been cancelled

This commit is contained in:
andig 2026-05-01 13:56:58 +02:00 • committed by GitHub
parent 9b8f29a6bd
commit 7753d88809
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 10 deletions

View file

@ -11,6 +11,7 @@ import (
"github.com/evcc-io/evcc/util"
"github.com/prometheus/client_golang/prometheus"
"github.com/sandrolain/httpcache"
)
type roundTripper struct {
@ -129,8 +130,6 @@ func dump(r io.ReadCloser, w *strings.Builder) error {
}
func (r *roundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
r.log.TRACE.Printf("%s %s", req.Method, req.URL.String())
// add evcc user agent
if req.Header.Get("User-Agent") == "" {
req = req.Clone(req.Context())
@ -165,6 +164,12 @@ func (r *roundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
reqMetric.WithLabelValues(req.URL.Hostname()).Observe(time.Since(startTime).Seconds())
var cached string
if err == nil && resp.Header.Get(httpcache.XFromCache) != "" {
cached = " CACHED"
}
r.log.TRACE.Printf("%s%s %s", req.Method, cached, req.URL.String())
if err == nil {
resMetric.WithLabelValues(req.URL.Hostname(), strconv.Itoa(resp.StatusCode)).Add(1)