Indicate cache hits in HTTP trace log (#29533)
Some checks failed
Some checks failed
This commit is contained in:
parent
9b8f29a6bd
commit
7753d88809
2 changed files with 20 additions and 10 deletions
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue