Skip to content
Snippets Groups Projects
Commit ef0fda19 authored by flycash's avatar flycash
Browse files

fix review

parent fb2f8ecc
No related branches found
No related tags found
No related merge requests found
......@@ -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 {
......
......@@ -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() {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment