Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
Signed-off-by: Pavel Okhlopkov <[email protected]>
  • Loading branch information
Pavel Okhlopkov committed Nov 5, 2024
1 parent 631a27b commit 86fe6d8
Showing 1 changed file with 11 additions and 21 deletions.
32 changes: 11 additions & 21 deletions pkg/metric_storage/metric_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func NewMetricStorage(ctx context.Context, prefix string, newRegistry bool, logg
Gatherer: prometheus.DefaultGatherer,
Registerer: prometheus.DefaultRegisterer,

logger: logger,
logger: logger.With("operator.component", "metricsStorage"),
}
m.groupedVault = vault.NewGroupedVault(m.resolveMetricName)
m.groupedVault.SetRegisterer(m.Registerer)
Expand Down Expand Up @@ -94,8 +94,7 @@ func (m *MetricStorage) GaugeSet(metric string, value float64, labels map[string
}
defer func() {
if r := recover(); r != nil {
m.logger.With("operator.component", "metricsStorage").
Errorf("Metric gauge set %s %v with %v: %v", m.resolveMetricName(metric), LabelNames(labels), labels, r)
m.logger.Errorf("Metric gauge set %s %v with %v: %v", m.resolveMetricName(metric), LabelNames(labels), labels, r)
}
}()

Expand All @@ -108,8 +107,7 @@ func (m *MetricStorage) GaugeAdd(metric string, value float64, labels map[string
}
defer func() {
if r := recover(); r != nil {
m.logger.With("operator.component", "metricsStorage").
Errorf("Metric gauge add %s %v with %v: %v", m.resolveMetricName(metric), LabelNames(labels), labels, r)
m.logger.Errorf("Metric gauge add %s %v with %v: %v", m.resolveMetricName(metric), LabelNames(labels), labels, r)
}
}()

Expand All @@ -134,8 +132,7 @@ func (m *MetricStorage) RegisterGauge(metric string, labels map[string]string) *

defer func() {
if r := recover(); r != nil {
m.logger.With("operator.component", "metricStorage").
Errorf("Create metric gauge %s %v with %v: %v", metricName, LabelNames(labels), labels, r)
m.logger.Errorf("Create metric gauge %s %v with %v: %v", metricName, LabelNames(labels), labels, r)
}
}()

Expand All @@ -147,8 +144,7 @@ func (m *MetricStorage) RegisterGauge(metric string, labels map[string]string) *
return vec
}

m.logger.With("operator.component", "metricStorage").
Infof("Create metric gauge %s", metricName)
m.logger.Infof("Create metric gauge %s", metricName)
vec = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: metricName,
Expand All @@ -169,8 +165,7 @@ func (m *MetricStorage) CounterAdd(metric string, value float64, labels map[stri
}
defer func() {
if r := recover(); r != nil {
m.logger.With("operator.component", "metricsStorage").
Errorf("Metric counter add %s %v with %v: %v", m.resolveMetricName(metric), LabelNames(labels), labels, r)
m.logger.Errorf("Metric counter add %s %v with %v: %v", m.resolveMetricName(metric), LabelNames(labels), labels, r)
}
}()
m.Counter(metric, labels).With(labels).Add(value)
Expand All @@ -194,8 +189,7 @@ func (m *MetricStorage) RegisterCounter(metric string, labels map[string]string)

defer func() {
if r := recover(); r != nil {
m.logger.With("operator.component", "metricStorage").
Errorf("Create metric counter %s %v with %v: %v", metricName, LabelNames(labels), labels, r)
m.logger.Errorf("Create metric counter %s %v with %v: %v", metricName, LabelNames(labels), labels, r)
}
}()

Expand All @@ -207,8 +201,7 @@ func (m *MetricStorage) RegisterCounter(metric string, labels map[string]string)
return vec
}

m.logger.With("operator.component", "metricStorage").
Infof("Create metric counter %s", metricName)
m.logger.Infof("Create metric counter %s", metricName)
vec = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: metricName,
Expand All @@ -228,8 +221,7 @@ func (m *MetricStorage) HistogramObserve(metric string, value float64, labels ma
}
defer func() {
if r := recover(); r != nil {
m.logger.With("operator.component", "metricsStorage").
Errorf("Metric histogram observe %s %v with %v: %v", m.resolveMetricName(metric), LabelNames(labels), labels, r)
m.logger.Errorf("Metric histogram observe %s %v with %v: %v", m.resolveMetricName(metric), LabelNames(labels), labels, r)
}
}()
m.Histogram(metric, labels, buckets).With(labels).Observe(value)
Expand All @@ -250,8 +242,7 @@ func (m *MetricStorage) RegisterHistogram(metric string, labels map[string]strin

defer func() {
if r := recover(); r != nil {
m.logger.With("operator.component", "metricsStorage").
Errorf("Create metric histogram %s %v with %v: %v", metricName, LabelNames(labels), labels, r)
m.logger.Errorf("Create metric histogram %s %v with %v: %v", metricName, LabelNames(labels), labels, r)
}
}()

Expand All @@ -263,8 +254,7 @@ func (m *MetricStorage) RegisterHistogram(metric string, labels map[string]strin
return vec
}

m.logger.With("operator.component", "metricsStorage").
Infof("Create metric histogram %s", metricName)
m.logger.Infof("Create metric histogram %s", metricName)
b, has := m.HistogramBuckets[metric]
// This shouldn't happen except when entering this concurrently
// If there are buckets for this histogram about to be registered, keep them
Expand Down

0 comments on commit 86fe6d8

Please sign in to comment.