From 644524e8a56a08cd7207f7853e9776d1338d176e Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Fri, 7 Apr 2023 17:58:36 +0300 Subject: [PATCH] [#80] metrics: Make global description unexported Signed-off-by: Denis Kirillov --- metrics/billing.go | 4 ++-- metrics/desc.go | 16 ++++++++-------- metrics/pool.go | 10 +++++----- metrics/state.go | 4 ++-- metrics/stats.go | 12 ++++++------ 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/metrics/billing.go b/metrics/billing.go index 2d75961..7bd3639 100644 --- a/metrics/billing.go +++ b/metrics/billing.go @@ -197,8 +197,8 @@ type billingMetrics struct { func newBillingMetrics() *billingMetrics { return &billingMetrics{ registry: prometheus.NewRegistry(), - userRequestsDesc: NewDesc(AppMetricsDesc[billingSubsystem][userRequestsMetric]), - userTrafficDesc: NewDesc(AppMetricsDesc[billingSubsystem][userTrafficMetric]), + userRequestsDesc: newDesc(appMetricsDesc[billingSubsystem][userRequestsMetric]), + userTrafficDesc: newDesc(appMetricsDesc[billingSubsystem][userTrafficMetric]), apiStat: UsersAPIStats{}, } } diff --git a/metrics/desc.go b/metrics/desc.go index 84f2f53..c3cc9f6 100644 --- a/metrics/desc.go +++ b/metrics/desc.go @@ -6,7 +6,7 @@ import ( "github.com/prometheus/client_golang/prometheus" ) -var AppMetricsDesc = map[string]map[string]Description{ +var appMetricsDesc = map[string]map[string]Description{ poolSubsystem: { overallErrorsMetric: Description{ Namespace: namespace, @@ -161,7 +161,7 @@ func (d *Description) ConstLabelsMap() map[string]string { // DescribeAll returns descriptions for metrics. func DescribeAll() []Description { var list []Description - for _, m := range AppMetricsDesc { + for _, m := range appMetricsDesc { for _, description := range m { list = append(list, description) } @@ -170,7 +170,7 @@ func DescribeAll() []Description { return list } -func NewOpts(description Description) prometheus.Opts { +func newOpts(description Description) prometheus.Opts { return prometheus.Opts{ Namespace: description.Namespace, Subsystem: description.Subsystem, @@ -180,7 +180,7 @@ func NewOpts(description Description) prometheus.Opts { } } -func NewDesc(description Description) *prometheus.Desc { +func newDesc(description Description) *prometheus.Desc { return prometheus.NewDesc( description.BuildFQName(), description.Help, @@ -188,15 +188,15 @@ func NewDesc(description Description) *prometheus.Desc { description.ConstLabelsMap()) } -func NewGauge(description Description) prometheus.Gauge { +func newGauge(description Description) prometheus.Gauge { return prometheus.NewGauge( - prometheus.GaugeOpts(NewOpts(description)), + prometheus.GaugeOpts(newOpts(description)), ) } -func NewGaugeVec(description Description) *prometheus.GaugeVec { +func newGaugeVec(description Description) *prometheus.GaugeVec { return prometheus.NewGaugeVec( - prometheus.GaugeOpts(NewOpts(description)), + prometheus.GaugeOpts(newOpts(description)), description.VariableLabels, ) } diff --git a/metrics/pool.go b/metrics/pool.go index 8392991..b71f479 100644 --- a/metrics/pool.go +++ b/metrics/pool.go @@ -47,11 +47,11 @@ type poolMetricsCollector struct { func newPoolMetricsCollector(scraper StatisticScraper) *poolMetricsCollector { return &poolMetricsCollector{ poolStatScraper: scraper, - overallErrors: NewGauge(AppMetricsDesc[poolSubsystem][overallErrorsMetric]), - overallNodeErrors: NewGaugeVec(AppMetricsDesc[poolSubsystem][overallNodeErrorsMetric]), - overallNodeRequests: NewGaugeVec(AppMetricsDesc[poolSubsystem][overallNodeRequestsMetric]), - currentErrors: NewGaugeVec(AppMetricsDesc[poolSubsystem][currentErrorMetric]), - requestDuration: NewGaugeVec(AppMetricsDesc[poolSubsystem][avgRequestDurationMetric]), + overallErrors: newGauge(appMetricsDesc[poolSubsystem][overallErrorsMetric]), + overallNodeErrors: newGaugeVec(appMetricsDesc[poolSubsystem][overallNodeErrorsMetric]), + overallNodeRequests: newGaugeVec(appMetricsDesc[poolSubsystem][overallNodeRequestsMetric]), + currentErrors: newGaugeVec(appMetricsDesc[poolSubsystem][currentErrorMetric]), + requestDuration: newGaugeVec(appMetricsDesc[poolSubsystem][avgRequestDurationMetric]), } } diff --git a/metrics/state.go b/metrics/state.go index 8aa8624..fe71aaa 100644 --- a/metrics/state.go +++ b/metrics/state.go @@ -28,8 +28,8 @@ type StateMetrics struct { func newStateMetrics() *StateMetrics { return &StateMetrics{ - healthCheck: NewGauge(AppMetricsDesc[stateSubsystem][healthMetric]), - versionInfo: NewGaugeVec(AppMetricsDesc[stateSubsystem][versionInfoMetric]), + healthCheck: newGauge(appMetricsDesc[stateSubsystem][healthMetric]), + versionInfo: newGaugeVec(appMetricsDesc[stateSubsystem][versionInfoMetric]), } } diff --git a/metrics/stats.go b/metrics/stats.go index 462e7d5..2666029 100644 --- a/metrics/stats.go +++ b/metrics/stats.go @@ -52,7 +52,7 @@ const ( ) func newAPIStatMetrics() *APIStatMetrics { - histogramDesc := AppMetricsDesc[statisticSubsystem][requestsSecondsMetric] + histogramDesc := appMetricsDesc[statisticSubsystem][requestsSecondsMetric] return &APIStatMetrics{ stats: newHTTPStats(), @@ -154,11 +154,11 @@ func (a *APIStatMetrics) Collect(ch chan<- prometheus.Metric) { func newHTTPStats() *httpStats { return &httpStats{ - currentS3RequestsDesc: NewDesc(AppMetricsDesc[statisticSubsystem][requestsCurrentMetric]), - totalS3RequestsDesc: NewDesc(AppMetricsDesc[statisticSubsystem][requestsTotalMetric]), - totalS3ErrorsDesc: NewDesc(AppMetricsDesc[statisticSubsystem][errorsTotalMetric]), - txBytesTotalDesc: NewDesc(AppMetricsDesc[statisticSubsystem][txBytesTotalMetric]), - rxBytesTotalDesc: NewDesc(AppMetricsDesc[statisticSubsystem][rxBytesTotalMetric]), + currentS3RequestsDesc: newDesc(appMetricsDesc[statisticSubsystem][requestsCurrentMetric]), + totalS3RequestsDesc: newDesc(appMetricsDesc[statisticSubsystem][requestsTotalMetric]), + totalS3ErrorsDesc: newDesc(appMetricsDesc[statisticSubsystem][errorsTotalMetric]), + txBytesTotalDesc: newDesc(appMetricsDesc[statisticSubsystem][txBytesTotalMetric]), + rxBytesTotalDesc: newDesc(appMetricsDesc[statisticSubsystem][rxBytesTotalMetric]), } }