Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2
22a7f0099
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Summer2022
22a7f0099
Commits
ef0fda19
Commit
ef0fda19
authored
5 years ago
by
flycash
Browse files
Options
Downloads
Patches
Plain Diff
fix review
parent
fb2f8ecc
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
filter/filter_impl/metrics_filter.go
+3
-3
3 additions, 3 deletions
filter/filter_impl/metrics_filter.go
metrics/prometheus/reporter.go
+7
-2
7 additions, 2 deletions
metrics/prometheus/reporter.go
with
10 additions
and
5 deletions
filter/filter_impl/metrics_filter.go
+
3
−
3
View file @
ef0fda19
...
...
@@ -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
{
...
...
This diff is collapsed.
Click to expand it.
metrics/prometheus/reporter.go
+
7
−
2
View file @
ef0fda19
...
...
@@ -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
()
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment