Merge pull request #335 from shmsr/dup-init-vars

Avoid double initialization of variables
This commit is contained in:
Matthias Rampke 2020-09-07 09:38:12 +02:00 committed by GitHub
commit da85f9d207
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -107,18 +107,20 @@ func (r *Registry) Store(metricName string, hash metrics.LabelHash, labels prome
metric.Vectors[hash.Names] = v metric.Vectors[hash.Names] = v
} }
now := clock.Now()
rm, ok := metric.Metrics[hash.Values] rm, ok := metric.Metrics[hash.Values]
if !ok { if !ok {
rm = &metrics.RegisteredMetric{ rm = &metrics.RegisteredMetric{
Labels: labels, LastRegisteredAt: now,
TTL: ttl, Labels: labels,
Metric: mh, TTL: ttl,
VecKey: hash.Names, Metric: mh,
VecKey: hash.Names,
} }
metric.Metrics[hash.Values] = rm metric.Metrics[hash.Values] = rm
v.RefCount++ v.RefCount++
return
} }
now := clock.Now()
rm.LastRegisteredAt = now rm.LastRegisteredAt = now
// Update ttl from mapping // Update ttl from mapping
rm.TTL = ttl rm.TTL = ttl