Skip to content

Commit

Permalink
refactor: file names and method names
Browse files Browse the repository at this point in the history
  • Loading branch information
ev1lQuark committed Jun 28, 2023
1 parent e23b519 commit 38373b5
Show file tree
Hide file tree
Showing 7 changed files with 246 additions and 352 deletions.
54 changes: 0 additions & 54 deletions metrics/prometheus/after_invocation.go

This file was deleted.

40 changes: 0 additions & 40 deletions metrics/prometheus/before_invocation.go

This file was deleted.

12 changes: 5 additions & 7 deletions metrics/prometheus/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,14 @@ const (

requestsField = "requests"
rtField = "rt"
tpsField = "tps"

milliSecondsField = "milliseconds"

minField = "min"
maxField = "max"
sumField = "sum"
avgField = "avg"
lastField = "last"
summaryField = "summary"
minField = "min"
maxField = "max"
sumField = "sum"
avgField = "avg"
lastField = "last"

totalField = "total"
processingField = "processing"
Expand Down
102 changes: 45 additions & 57 deletions metrics/prometheus/metric_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,68 +29,56 @@ import (
"dubbo.apache.org/dubbo-go/v3/metrics"
)

// metricSet is a set of metrics that are reported to prometheus in dubbo go
// metricSet is a set of metrics that are reported to prometheus in dubbo-go
type metricSet struct {
// report the consumer-side's rt gauge data
consumerRTSummaryVec *prometheus.SummaryVec
// report the provider-side's rt gauge data
providerRTSummaryVec *prometheus.SummaryVec
provider providerMetrics
consumer consumerMetrics
}

func (ms *metricSet) init(reporterConfig *metrics.ReporterConfig) {
ms.provider.init(reporterConfig)
ms.consumer.init(reporterConfig)
}

type rpcCommonMetrics struct {
requestsTotal *prometheus.CounterVec
requestsProcessingTotal *prometheus.GaugeVec
requestsSucceedTotal *prometheus.CounterVec
rtMillisecondsMin *GaugeVecWithSyncMap
rtMillisecondsMax *GaugeVecWithSyncMap
rtMillisecondsSum *prometheus.CounterVec
rtMillisecondsAvg *GaugeVecWithSyncMap
rtMillisecondsLast *prometheus.GaugeVec
}

type providerMetrics struct {
rpcCommonMetrics
}

// report the provider-side's request total counter data
providerRequestsTotalCounterVec *prometheus.CounterVec
// report the provider-side's processing request counter data
providerRequestsProcessingTotalGaugeVec *prometheus.GaugeVec
// The number of requests successfully received by the provider
providerRequestsSucceedTotalCounterVec *prometheus.CounterVec
// The minimum response time among all requests processed by the provider
providerRTMillisecondsMinGaugeVecWithSyncMap *GaugeVecWithSyncMap
// The maximum response time among all requests processed by the provider
providerRTMillisecondsMaxGaugeVecWithSyncMap *GaugeVecWithSyncMap
// The total time taken by the provider to process all requests
providerRTMillisecondsSumCounterVec *prometheus.CounterVec
// The average response time of all requests processed by the provider
providerRTMillisecondsAvgGaugeVecWithSyncMap *GaugeVecWithSyncMap
// The current response time in the provider’s processing of requests
providerRTMillisecondsLastGaugeVec *prometheus.GaugeVec
func (pm *providerMetrics) init(reporterConfig *metrics.ReporterConfig) {
pm.requestsTotal = newAutoCounterVec(buildMetricsName(providerField, requestsField, totalField), reporterConfig.Namespace, labelNames)
pm.requestsProcessingTotal = newAutoGaugeVec(buildMetricsName(providerField, requestsField, processingField, totalField), reporterConfig.Namespace, labelNames)
pm.requestsSucceedTotal = newAutoCounterVec(buildMetricsName(providerField, requestsField, succeedField, totalField), reporterConfig.Namespace, labelNames)
pm.rtMillisecondsMin = newAutoGaugeVecWithSyncMap(buildMetricsName(providerField, rtField, milliSecondsField, minField), reporterConfig.Namespace, labelNames)
pm.rtMillisecondsMax = newAutoGaugeVecWithSyncMap(buildMetricsName(providerField, rtField, milliSecondsField, maxField), reporterConfig.Namespace, labelNames)
pm.rtMillisecondsSum = newAutoCounterVec(buildMetricsName(providerField, rtField, milliSecondsField, sumField), reporterConfig.Namespace, labelNames)
pm.rtMillisecondsAvg = newAutoGaugeVecWithSyncMap(buildMetricsName(providerField, rtField, milliSecondsField, avgField), reporterConfig.Namespace, labelNames)
pm.rtMillisecondsLast = newAutoGaugeVec(buildMetricsName(providerField, rtField, milliSecondsField, lastField), reporterConfig.Namespace, labelNames)
}

// report the consumer-side's request total counter data
consumerRequestsTotalCounterVec *prometheus.CounterVec
// report the consumer-side's processing request counter data
consumerRequestsProcessingTotalGaugeVec *prometheus.GaugeVec
// The number of successful requests sent by consumers
consumerRequestsSucceedTotalCounterVec *prometheus.CounterVec
// The minimum response time among all requests processed by the consumer
consumerRTMillisecondsMinGaugeVecWithSyncMap *GaugeVecWithSyncMap
// The maximum response time among all requests processed by the consumer
consumerRTMillisecondsMaxGaugeVecWithSyncMap *GaugeVecWithSyncMap
// The total time taken by the consumer to process all requests
consumerRTMillisecondsSumCounterVec *prometheus.CounterVec
// The average response time of all requests processed by the consumer
consumerRTMillisecondsAvgGaugeVecWithSyncMap *GaugeVecWithSyncMap
// The current response time in the consumer’s processing of requests
consumerRTMillisecondsLastGaugeVec *prometheus.GaugeVec
type consumerMetrics struct {
rpcCommonMetrics
}

// init metric set and register to prometheus
func (ms *metricSet) initAndRegister(reporterConfig *metrics.ReporterConfig) {
ms.consumerRTSummaryVec = newAutoSummaryVec(buildMetricsName(consumerField, rtField, milliSecondsField, summaryField), reporterConfig.Namespace, labelNames, reporterConfig.SummaryMaxAge)
ms.providerRTSummaryVec = newAutoSummaryVec(buildMetricsName(providerField, rtField, milliSecondsField, summaryField), reporterConfig.Namespace, labelNames, reporterConfig.SummaryMaxAge)
ms.consumerRequestsTotalCounterVec = newAutoCounterVec(buildMetricsName(consumerField, requestsField, totalField), reporterConfig.Namespace, labelNames)
ms.providerRequestsTotalCounterVec = newAutoCounterVec(buildMetricsName(providerField, requestsField, totalField), reporterConfig.Namespace, labelNames)
ms.consumerRequestsProcessingTotalGaugeVec = newAutoGaugeVec(buildMetricsName(consumerField, requestsField, processingField, totalField), reporterConfig.Namespace, labelNames)
ms.providerRequestsProcessingTotalGaugeVec = newAutoGaugeVec(buildMetricsName(providerField, requestsField, processingField, totalField), reporterConfig.Namespace, labelNames)
ms.consumerRequestsSucceedTotalCounterVec = newAutoCounterVec(buildMetricsName(consumerField, requestsField, succeedField, totalField), reporterConfig.Namespace, labelNames)
ms.providerRequestsSucceedTotalCounterVec = newAutoCounterVec(buildMetricsName(providerField, requestsField, succeedField, totalField), reporterConfig.Namespace, labelNames)
ms.consumerRTMillisecondsMinGaugeVecWithSyncMap = newAutoGaugeVecWithSyncMap(buildMetricsName(consumerField, rtField, milliSecondsField, minField), reporterConfig.Namespace, labelNames)
ms.providerRTMillisecondsMinGaugeVecWithSyncMap = newAutoGaugeVecWithSyncMap(buildMetricsName(providerField, rtField, milliSecondsField, minField), reporterConfig.Namespace, labelNames)
ms.consumerRTMillisecondsMaxGaugeVecWithSyncMap = newAutoGaugeVecWithSyncMap(buildMetricsName(consumerField, rtField, milliSecondsField, maxField), reporterConfig.Namespace, labelNames)
ms.providerRTMillisecondsMaxGaugeVecWithSyncMap = newAutoGaugeVecWithSyncMap(buildMetricsName(providerField, rtField, milliSecondsField, maxField), reporterConfig.Namespace, labelNames)
ms.consumerRTMillisecondsSumCounterVec = newAutoCounterVec(buildMetricsName(consumerField, rtField, milliSecondsField, sumField), reporterConfig.Namespace, labelNames)
ms.providerRTMillisecondsSumCounterVec = newAutoCounterVec(buildMetricsName(providerField, rtField, milliSecondsField, sumField), reporterConfig.Namespace, labelNames)
ms.consumerRTMillisecondsAvgGaugeVecWithSyncMap = newAutoGaugeVecWithSyncMap(buildMetricsName(consumerField, rtField, milliSecondsField, avgField), reporterConfig.Namespace, labelNames)
ms.providerRTMillisecondsAvgGaugeVecWithSyncMap = newAutoGaugeVecWithSyncMap(buildMetricsName(providerField, rtField, milliSecondsField, avgField), reporterConfig.Namespace, labelNames)
ms.consumerRTMillisecondsLastGaugeVec = newAutoGaugeVec(buildMetricsName(consumerField, rtField, milliSecondsField, lastField), reporterConfig.Namespace, labelNames)
ms.providerRTMillisecondsLastGaugeVec = newAutoGaugeVec(buildMetricsName(providerField, rtField, milliSecondsField, lastField), reporterConfig.Namespace, labelNames)
func (cm *consumerMetrics) init(reporterConfig *metrics.ReporterConfig) {
cm.requestsTotal = newAutoCounterVec(buildMetricsName(consumerField, requestsField, totalField), reporterConfig.Namespace, labelNames)
cm.requestsProcessingTotal = newAutoGaugeVec(buildMetricsName(consumerField, requestsField, processingField, totalField), reporterConfig.Namespace, labelNames)
cm.requestsSucceedTotal = newAutoCounterVec(buildMetricsName(consumerField, requestsField, succeedField, totalField), reporterConfig.Namespace, labelNames)
cm.rtMillisecondsMin = newAutoGaugeVecWithSyncMap(buildMetricsName(consumerField, rtField, milliSecondsField, minField), reporterConfig.Namespace, labelNames)
cm.rtMillisecondsMax = newAutoGaugeVecWithSyncMap(buildMetricsName(consumerField, rtField, milliSecondsField, maxField), reporterConfig.Namespace, labelNames)
cm.rtMillisecondsSum = newAutoCounterVec(buildMetricsName(consumerField, rtField, milliSecondsField, sumField), reporterConfig.Namespace, labelNames)
cm.rtMillisecondsAvg = newAutoGaugeVecWithSyncMap(buildMetricsName(consumerField, rtField, milliSecondsField, avgField), reporterConfig.Namespace, labelNames)
cm.rtMillisecondsLast = newAutoGaugeVec(buildMetricsName(consumerField, rtField, milliSecondsField, lastField), reporterConfig.Namespace, labelNames)
}

func buildMetricsName(args ...string) string {
Expand Down
Loading

0 comments on commit 38373b5

Please sign in to comment.