[#80] metrics: Make global description unexported

Signed-off-by: Denis Kirillov <d.kirillov@yadro.com>
pull/82/head
Denis Kirillov 2023-04-07 17:58:36 +03:00
parent ee6118c3d7
commit 644524e8a5
5 changed files with 23 additions and 23 deletions

View File

@ -197,8 +197,8 @@ type billingMetrics struct {
func newBillingMetrics() *billingMetrics { func newBillingMetrics() *billingMetrics {
return &billingMetrics{ return &billingMetrics{
registry: prometheus.NewRegistry(), registry: prometheus.NewRegistry(),
userRequestsDesc: NewDesc(AppMetricsDesc[billingSubsystem][userRequestsMetric]), userRequestsDesc: newDesc(appMetricsDesc[billingSubsystem][userRequestsMetric]),
userTrafficDesc: NewDesc(AppMetricsDesc[billingSubsystem][userTrafficMetric]), userTrafficDesc: newDesc(appMetricsDesc[billingSubsystem][userTrafficMetric]),
apiStat: UsersAPIStats{}, apiStat: UsersAPIStats{},
} }
} }

View File

@ -6,7 +6,7 @@ import (
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
) )
var AppMetricsDesc = map[string]map[string]Description{ var appMetricsDesc = map[string]map[string]Description{
poolSubsystem: { poolSubsystem: {
overallErrorsMetric: Description{ overallErrorsMetric: Description{
Namespace: namespace, Namespace: namespace,
@ -161,7 +161,7 @@ func (d *Description) ConstLabelsMap() map[string]string {
// DescribeAll returns descriptions for metrics. // DescribeAll returns descriptions for metrics.
func DescribeAll() []Description { func DescribeAll() []Description {
var list []Description var list []Description
for _, m := range AppMetricsDesc { for _, m := range appMetricsDesc {
for _, description := range m { for _, description := range m {
list = append(list, description) list = append(list, description)
} }
@ -170,7 +170,7 @@ func DescribeAll() []Description {
return list return list
} }
func NewOpts(description Description) prometheus.Opts { func newOpts(description Description) prometheus.Opts {
return prometheus.Opts{ return prometheus.Opts{
Namespace: description.Namespace, Namespace: description.Namespace,
Subsystem: description.Subsystem, 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( return prometheus.NewDesc(
description.BuildFQName(), description.BuildFQName(),
description.Help, description.Help,
@ -188,15 +188,15 @@ func NewDesc(description Description) *prometheus.Desc {
description.ConstLabelsMap()) description.ConstLabelsMap())
} }
func NewGauge(description Description) prometheus.Gauge { func newGauge(description Description) prometheus.Gauge {
return prometheus.NewGauge( 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( return prometheus.NewGaugeVec(
prometheus.GaugeOpts(NewOpts(description)), prometheus.GaugeOpts(newOpts(description)),
description.VariableLabels, description.VariableLabels,
) )
} }

View File

@ -47,11 +47,11 @@ type poolMetricsCollector struct {
func newPoolMetricsCollector(scraper StatisticScraper) *poolMetricsCollector { func newPoolMetricsCollector(scraper StatisticScraper) *poolMetricsCollector {
return &poolMetricsCollector{ return &poolMetricsCollector{
poolStatScraper: scraper, poolStatScraper: scraper,
overallErrors: NewGauge(AppMetricsDesc[poolSubsystem][overallErrorsMetric]), overallErrors: newGauge(appMetricsDesc[poolSubsystem][overallErrorsMetric]),
overallNodeErrors: NewGaugeVec(AppMetricsDesc[poolSubsystem][overallNodeErrorsMetric]), overallNodeErrors: newGaugeVec(appMetricsDesc[poolSubsystem][overallNodeErrorsMetric]),
overallNodeRequests: NewGaugeVec(AppMetricsDesc[poolSubsystem][overallNodeRequestsMetric]), overallNodeRequests: newGaugeVec(appMetricsDesc[poolSubsystem][overallNodeRequestsMetric]),
currentErrors: NewGaugeVec(AppMetricsDesc[poolSubsystem][currentErrorMetric]), currentErrors: newGaugeVec(appMetricsDesc[poolSubsystem][currentErrorMetric]),
requestDuration: NewGaugeVec(AppMetricsDesc[poolSubsystem][avgRequestDurationMetric]), requestDuration: newGaugeVec(appMetricsDesc[poolSubsystem][avgRequestDurationMetric]),
} }
} }

View File

@ -28,8 +28,8 @@ type StateMetrics struct {
func newStateMetrics() *StateMetrics { func newStateMetrics() *StateMetrics {
return &StateMetrics{ return &StateMetrics{
healthCheck: NewGauge(AppMetricsDesc[stateSubsystem][healthMetric]), healthCheck: newGauge(appMetricsDesc[stateSubsystem][healthMetric]),
versionInfo: NewGaugeVec(AppMetricsDesc[stateSubsystem][versionInfoMetric]), versionInfo: newGaugeVec(appMetricsDesc[stateSubsystem][versionInfoMetric]),
} }
} }

View File

@ -52,7 +52,7 @@ const (
) )
func newAPIStatMetrics() *APIStatMetrics { func newAPIStatMetrics() *APIStatMetrics {
histogramDesc := AppMetricsDesc[statisticSubsystem][requestsSecondsMetric] histogramDesc := appMetricsDesc[statisticSubsystem][requestsSecondsMetric]
return &APIStatMetrics{ return &APIStatMetrics{
stats: newHTTPStats(), stats: newHTTPStats(),
@ -154,11 +154,11 @@ func (a *APIStatMetrics) Collect(ch chan<- prometheus.Metric) {
func newHTTPStats() *httpStats { func newHTTPStats() *httpStats {
return &httpStats{ return &httpStats{
currentS3RequestsDesc: NewDesc(AppMetricsDesc[statisticSubsystem][requestsCurrentMetric]), currentS3RequestsDesc: newDesc(appMetricsDesc[statisticSubsystem][requestsCurrentMetric]),
totalS3RequestsDesc: NewDesc(AppMetricsDesc[statisticSubsystem][requestsTotalMetric]), totalS3RequestsDesc: newDesc(appMetricsDesc[statisticSubsystem][requestsTotalMetric]),
totalS3ErrorsDesc: NewDesc(AppMetricsDesc[statisticSubsystem][errorsTotalMetric]), totalS3ErrorsDesc: newDesc(appMetricsDesc[statisticSubsystem][errorsTotalMetric]),
txBytesTotalDesc: NewDesc(AppMetricsDesc[statisticSubsystem][txBytesTotalMetric]), txBytesTotalDesc: newDesc(appMetricsDesc[statisticSubsystem][txBytesTotalMetric]),
rxBytesTotalDesc: NewDesc(AppMetricsDesc[statisticSubsystem][rxBytesTotalMetric]), rxBytesTotalDesc: newDesc(appMetricsDesc[statisticSubsystem][rxBytesTotalMetric]),
} }
} }