Skip to content

Commit

Permalink
Improve logging for cache (#11453)
Browse files Browse the repository at this point in the history
* Include ServerURL in cache logging

* Add additional cache tracing

* TEMP - DO NOT MERGE THIS - promote Trace=>Debug cache logging

* Log if call was cached or not

* Revert "TEMP - DO NOT MERGE THIS - promote Trace=>Debug cache logging"

This reverts commit f0f3f07a59c8d310ac74849519d46ea9b53495c1.
  • Loading branch information
samsondav authored Dec 6, 2023
1 parent c17067b commit 47d0690
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
7 changes: 6 additions & 1 deletion core/services/relay/evm/mercury/wsrpc/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,14 @@ func (m *memCache) LatestReport(ctx context.Context, req *pb.LatestReportRequest
if time.Now().Before(v.expiresAt) {
// CACHE HIT
promCacheHitCount.WithLabelValues(m.client.ServerURL(), feedIDHex).Inc()
m.lggr.Tracew("LatestReport CACHE HIT (hot path)", "feedID", feedIDHex)

defer v.RUnlock()
return v.val, nil
} else if v.fetching {
// CACHE WAIT
promCacheWaitCount.WithLabelValues(m.client.ServerURL(), feedIDHex).Inc()
m.lggr.Tracew("LatestReport CACHE WAIT (hot path)", "feedID", feedIDHex)
// if someone else is fetching then wait for the fetch to complete
ch := v.fetchCh
v.RUnlock()
Expand All @@ -234,18 +236,21 @@ func (m *memCache) LatestReport(ctx context.Context, req *pb.LatestReportRequest
if time.Now().Before(v.expiresAt) {
// CACHE HIT
promCacheHitCount.WithLabelValues(m.client.ServerURL(), feedIDHex).Inc()
m.lggr.Tracew("LatestReport CACHE HIT (cold path)", "feedID", feedIDHex)
defer v.RUnlock()
return v.val, nil
} else if v.fetching {
// CACHE WAIT
promCacheWaitCount.WithLabelValues(m.client.ServerURL(), feedIDHex).Inc()
m.lggr.Tracew("LatestReport CACHE WAIT (cold path)", "feedID", feedIDHex)
// if someone else is fetching then wait for the fetch to complete
ch := v.fetchCh
v.Unlock()
return v.waitForResult(ctx, ch, m.chStop)
}
// CACHE MISS
promCacheMissCount.WithLabelValues(m.client.ServerURL(), feedIDHex).Inc()
m.lggr.Tracew("LatestReport CACHE MISS (cold path)", "feedID", feedIDHex)
// initiate the fetch and wait for result
ch := v.initiateFetch()
v.Unlock()
Expand Down Expand Up @@ -328,7 +333,7 @@ func (m *memCache) fetch(req *pb.LatestReportRequest, v *cacheVal) {

func (m *memCache) Start(context.Context) error {
return m.StartOnce(m.Name(), func() error {
m.lggr.Debugw("MemCache starting", "config", m.cfg)
m.lggr.Debugw("MemCache starting", "config", m.cfg, "serverURL", m.client.ServerURL())
m.wg.Add(1)
go m.runloop()
return nil
Expand Down
10 changes: 7 additions & 3 deletions core/services/relay/evm/mercury/wsrpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,17 +303,21 @@ func (w *client) LatestReport(ctx context.Context, req *pb.LatestReportRequest)
if err = w.waitForReady(ctx); err != nil {
return nil, errors.Wrap(err, "LatestReport failed")
}
var cached bool
if w.cache == nil {
resp, err = w.rawClient.LatestReport(ctx, req)
} else {
cached = true
resp, err = w.cache.LatestReport(ctx, req)
}
if err != nil {
lggr.Errorw("LatestReport failed", "err", err, "resp", resp)
lggr.Errorw("LatestReport failed", "err", err, "resp", resp, "cached", cached)
} else if resp.Error != "" {
lggr.Errorw("LatestReport failed; mercury server returned error", "err", resp.Error, "resp", resp)
lggr.Errorw("LatestReport failed; mercury server returned error", "err", resp.Error, "resp", resp, "cached", cached)
} else if !cached {
lggr.Debugw("LatestReport succeeded", "resp", resp, "cached", cached)
} else {
lggr.Debugw("LatestReport succeeded", "resp", resp)
lggr.Tracew("LatestReport succeeded", "resp", resp, "cached", cached)
}
return
}
Expand Down

0 comments on commit 47d0690

Please sign in to comment.