mirror of
https://github.com/prometheus/statsd_exporter.git
synced 2024-11-25 16:51:00 +00:00
Avoid unnecessary initialization of variables
This commit fixes the case when the metric is not present in rm (registered metric) then LastRegisteredAt and TTL are initialized twice. Firstly, LastRegisteredAt is initialized with the time.Time's zero value and then with clock.Now(). Plus, TTL is initialized with the same value twice. Signed-off-by: subham sarkar <subham.sarkar@guavus.com>
This commit is contained in:
parent
b19217a19b
commit
4c0e26bfa1
1 changed files with 7 additions and 5 deletions
|
@ -107,18 +107,20 @@ func (r *Registry) Store(metricName string, hash metrics.LabelHash, labels prome
|
|||
metric.Vectors[hash.Names] = v
|
||||
}
|
||||
|
||||
now := clock.Now()
|
||||
rm, ok := metric.Metrics[hash.Values]
|
||||
if !ok {
|
||||
rm = &metrics.RegisteredMetric{
|
||||
Labels: labels,
|
||||
TTL: ttl,
|
||||
Metric: mh,
|
||||
VecKey: hash.Names,
|
||||
LastRegisteredAt: now,
|
||||
Labels: labels,
|
||||
TTL: ttl,
|
||||
Metric: mh,
|
||||
VecKey: hash.Names,
|
||||
}
|
||||
metric.Metrics[hash.Values] = rm
|
||||
v.RefCount++
|
||||
return
|
||||
}
|
||||
now := clock.Now()
|
||||
rm.LastRegisteredAt = now
|
||||
// Update ttl from mapping
|
||||
rm.TTL = ttl
|
||||
|
|
Loading…
Reference in a new issue