diff --git a/filter/filter_impl/metrics_filter.go b/filter/filter_impl/metrics_filter.go index 1e2dc35f2d3f2c39a2273665619d23e35841a475..f4734172b74c8bbcdac5c9a9743acb4df5fcb6b5 100644 --- a/filter/filter_impl/metrics_filter.go +++ b/filter/filter_impl/metrics_filter.go @@ -55,7 +55,7 @@ type metricsFilter struct { reporters []metrics.Reporter } -// using goroutine to report the duration. +// Invoke collect the duration of invocation and then report the duration by using goroutine func (p *metricsFilter) Invoke(ctx context.Context, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result { start := time.Now() res := invoker.Invoke(ctx, invocation) @@ -69,12 +69,12 @@ func (p *metricsFilter) Invoke(ctx context.Context, invoker protocol.Invoker, in return res } -// do nothing and return the result +// OnResponse do nothing and return the result func (p *metricsFilter) OnResponse(ctx context.Context, res protocol.Result, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result { return res } -// the metricsFilter is singleton. +// newMetricsFilter the metricsFilter is singleton. // it's lazy initialization // make sure that the configuration had been loaded before invoking this method. func newMetricsFilter() filter.Filter { diff --git a/metrics/prometheus/reporter.go b/metrics/prometheus/reporter.go index e6dfdb4aeedb2c9c2053dc329bc945a470a9c701..1636b14da2fe5ab714853aa662eaa774ddbc1791 100644 --- a/metrics/prometheus/reporter.go +++ b/metrics/prometheus/reporter.go @@ -68,6 +68,7 @@ func init() { extension.SetMetricReporter(reporterName, newPrometheusReporter) } +// PrometheusReporter // it will collect the data for Prometheus // if you want to use this, you should initialize your prometheus. // https://prometheus.io/docs/guides/go-application/ @@ -84,7 +85,9 @@ type PrometheusReporter struct { consumerHistogramVec *prometheus.HistogramVec } -// report the duration to Prometheus +// Report report the duration to Prometheus +// the role in url must be consumer or provider +// or it will be ignored func (reporter *PrometheusReporter) Report(ctx context.Context, invoker protocol.Invoker, invocation protocol.Invocation, cost time.Duration, res protocol.Result) { url := invoker.GetUrl() var sumVec *prometheus.SummaryVec @@ -139,7 +142,7 @@ func isConsumer(url common.URL) bool { return strings.EqualFold(role, strconv.Itoa(common.CONSUMER)) } -// create SummaryVec, the Namespace is dubbo +// newSummaryVec create SummaryVec, the Namespace is dubbo // the objectives is from my experience. func newSummaryVec(side string) *prometheus.SummaryVec { return prometheus.NewSummaryVec( @@ -161,6 +164,8 @@ func newSummaryVec(side string) *prometheus.SummaryVec { ) } +// newPrometheusReporter create new prometheusReporter +// it will register the metrics into prometheus func newPrometheusReporter() metrics.Reporter { if reporterInstance == nil { reporterInitOnce.Do(func() {