fix: change timedValue to return the previously cached value (#15169)

fix: change timedvalue to return previous cached value

caller can interpret the underlying error and decide
accordingly, places where we do not interpret the
errors upon timedValue.Get() - we should simply use
the previously cached value instead of returning "empty".

Bonus: remove some unused code
This commit is contained in:
Harshavardhana
2022-06-25 08:50:16 -07:00
committed by GitHub
parent baf257adcb
commit bd099f5e71
5 changed files with 44 additions and 106 deletions

View File

@@ -264,18 +264,7 @@ func (m *Metric) copyMetric() Metric {
// once the TTL expires "read()" registered function is called
// to return the new values and updated.
func (g *MetricsGroup) Get() (metrics []Metric) {
var c interface{}
var err error
if g.cacheInterval <= 0 {
c, err = g.metricsCache.Update()
} else {
c, err = g.metricsCache.Get()
}
if err != nil {
return []Metric{}
}
c, _ := g.metricsCache.Get()
m, ok := c.([]Metric)
if !ok {
return []Metric{}