Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use summary type to observe p99 #1875

Merged
merged 6 commits into from
May 8, 2022
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions metrics/prometheus/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ func init() {
// https://prometheus.io/docs/guides/go-application/
type PrometheusReporter struct {
// report the consumer-side's rt gauge data
consumerRTGaugeVec *prometheus.GaugeVec
consumerRTSummaryVec *prometheus.SummaryVec
// report the provider-side's rt gauge data
providerRTGaugeVec *prometheus.GaugeVec
providerRTSummaryVec *prometheus.SummaryVec
// todo tps support
// report the consumer-side's tps gauge data
consumerTPSGaugeVec *prometheus.GaugeVec
Expand All @@ -102,11 +102,11 @@ type PrometheusReporter struct {
// 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 rtVec *prometheus.GaugeVec
var rtVec *prometheus.SummaryVec
if isProvider(url) {
rtVec = reporter.providerRTGaugeVec
rtVec = reporter.providerRTSummaryVec
} else if isConsumer(url) {
rtVec = reporter.consumerRTGaugeVec
rtVec = reporter.consumerRTSummaryVec
} else {
logger.Warnf("The url belongs neither the consumer nor the provider, "+
"so the invocation will be ignored. url: %s", url.String())
Expand All @@ -121,7 +121,7 @@ func (reporter *PrometheusReporter) Report(ctx context.Context, invoker protocol
timeoutKey: url.GetParam(timeoutKey, ""),
}
costMs := cost.Nanoseconds()
rtVec.With(labels).Set(float64(costMs))
rtVec.With(labels).Observe(float64(costMs))
}

func newHistogramVec(name, namespace string, labels []string) *prometheus.HistogramVec {
Expand Down Expand Up @@ -212,12 +212,12 @@ func newPrometheusReporter(reporterConfig *metrics.ReporterConfig) metrics.Repor
if reporterInstance == nil {
reporterInitOnce.Do(func() {
reporterInstance = &PrometheusReporter{
namespace: reporterConfig.Namespace,
consumerRTGaugeVec: newGaugeVec(consumerPrefix+serviceKey+rtSuffix, reporterConfig.Namespace, labelNames),
providerRTGaugeVec: newGaugeVec(providerPrefix+serviceKey+rtSuffix, reporterConfig.Namespace, labelNames),
namespace: reporterConfig.Namespace,
consumerRTSummaryVec: newSummaryVec(consumerPrefix+serviceKey+rtSuffix, reporterConfig.Namespace, labelNames),
providerRTSummaryVec: newSummaryVec(providerPrefix+serviceKey+rtSuffix, reporterConfig.Namespace, labelNames),
}

prom.DefaultRegisterer.MustRegister(reporterInstance.consumerRTGaugeVec, reporterInstance.providerRTGaugeVec)
prom.DefaultRegisterer.MustRegister(reporterInstance.consumerRTSummaryVec, reporterInstance.providerRTSummaryVec)
metricsExporter, err := ocprom.NewExporter(ocprom.Options{
Registry: prom.DefaultRegisterer.(*prom.Registry),
})
Expand Down