Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
perxis-go
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Package registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
perxis
perxis-go
Commits
53852ae2
Commit
53852ae2
authored
1 year ago
by
ensiouel
Browse files
Options
Downloads
Patches
Plain Diff
refactor(RequestMetrics): убрана метрика запросов, вернувших ошибку
parent
5662db2e
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
assets/templates/middleware/metrics
+0
-3
0 additions, 3 deletions
assets/templates/middleware/metrics
pkg/items/middleware/metrics_middleware.go
+0
-54
0 additions, 54 deletions
pkg/items/middleware/metrics_middleware.go
pkg/metrics/request.go
+0
-6
0 additions, 6 deletions
pkg/metrics/request.go
with
0 additions
and
63 deletions
assets/templates/middleware/metrics
+
0
−
3
View file @
53852ae2
...
...
@@ -30,9 +30,6 @@ func {{ $funcName }} (requestMetrics *metrics.RequestMetrics) Middleware {
defer func() {
timer.ObserveDuration()
m.requestMetrics.Total.WithLabelValues("{{ $.Interface.Name }}", "{{ $method.Name }}").Inc()
if err != nil {
m.requestMetrics.FailedTotal.WithLabelValues("{{ $.Interface.Name }}", "{{ $method.Name }}", "???").Inc()
}
}()
{{ $method.Pass "m.next." }}
}
...
...
This diff is collapsed.
Click to expand it.
pkg/items/middleware/metrics_middleware.go
+
0
−
54
View file @
53852ae2
...
...
@@ -37,9 +37,6 @@ func (m metricsMiddleware) Aggregate(ctx context.Context, spaceId string, envId
defer
func
()
{
timer
.
ObserveDuration
()
m
.
requestMetrics
.
Total
.
WithLabelValues
(
"Items"
,
"Aggregate"
)
.
Inc
()
if
err
!=
nil
{
m
.
requestMetrics
.
FailedTotal
.
WithLabelValues
(
"Items"
,
"Aggregate"
,
"???"
)
.
Inc
()
}
}()
return
m
.
next
.
Aggregate
(
ctx
,
spaceId
,
envId
,
collectionId
,
filter
,
options
...
)
}
...
...
@@ -50,9 +47,6 @@ func (m metricsMiddleware) AggregatePublished(ctx context.Context, spaceId strin
defer
func
()
{
timer
.
ObserveDuration
()
m
.
requestMetrics
.
Total
.
WithLabelValues
(
"Items"
,
"AggregatePublished"
)
.
Inc
()
if
err
!=
nil
{
m
.
requestMetrics
.
FailedTotal
.
WithLabelValues
(
"Items"
,
"AggregatePublished"
,
"???"
)
.
Inc
()
}
}()
return
m
.
next
.
AggregatePublished
(
ctx
,
spaceId
,
envId
,
collectionId
,
filter
,
options
...
)
}
...
...
@@ -63,9 +57,6 @@ func (m metricsMiddleware) Archive(ctx context.Context, item *items.Item, option
defer
func
()
{
timer
.
ObserveDuration
()
m
.
requestMetrics
.
Total
.
WithLabelValues
(
"Items"
,
"Archive"
)
.
Inc
()
if
err
!=
nil
{
m
.
requestMetrics
.
FailedTotal
.
WithLabelValues
(
"Items"
,
"Archive"
,
"???"
)
.
Inc
()
}
}()
return
m
.
next
.
Archive
(
ctx
,
item
,
options
...
)
}
...
...
@@ -76,9 +67,6 @@ func (m metricsMiddleware) Create(ctx context.Context, item *items.Item, opts ..
defer
func
()
{
timer
.
ObserveDuration
()
m
.
requestMetrics
.
Total
.
WithLabelValues
(
"Items"
,
"Create"
)
.
Inc
()
if
err
!=
nil
{
m
.
requestMetrics
.
FailedTotal
.
WithLabelValues
(
"Items"
,
"Create"
,
"???"
)
.
Inc
()
}
}()
return
m
.
next
.
Create
(
ctx
,
item
,
opts
...
)
}
...
...
@@ -89,9 +77,6 @@ func (m metricsMiddleware) Delete(ctx context.Context, item *items.Item, options
defer
func
()
{
timer
.
ObserveDuration
()
m
.
requestMetrics
.
Total
.
WithLabelValues
(
"Items"
,
"Delete"
)
.
Inc
()
if
err
!=
nil
{
m
.
requestMetrics
.
FailedTotal
.
WithLabelValues
(
"Items"
,
"Delete"
,
"???"
)
.
Inc
()
}
}()
return
m
.
next
.
Delete
(
ctx
,
item
,
options
...
)
}
...
...
@@ -102,9 +87,6 @@ func (m metricsMiddleware) Find(ctx context.Context, spaceId string, envId strin
defer
func
()
{
timer
.
ObserveDuration
()
m
.
requestMetrics
.
Total
.
WithLabelValues
(
"Items"
,
"Find"
)
.
Inc
()
if
err
!=
nil
{
m
.
requestMetrics
.
FailedTotal
.
WithLabelValues
(
"Items"
,
"Find"
,
"???"
)
.
Inc
()
}
}()
return
m
.
next
.
Find
(
ctx
,
spaceId
,
envId
,
collectionId
,
filter
,
options
...
)
}
...
...
@@ -115,9 +97,6 @@ func (m metricsMiddleware) FindArchived(ctx context.Context, spaceId string, env
defer
func
()
{
timer
.
ObserveDuration
()
m
.
requestMetrics
.
Total
.
WithLabelValues
(
"Items"
,
"FindArchived"
)
.
Inc
()
if
err
!=
nil
{
m
.
requestMetrics
.
FailedTotal
.
WithLabelValues
(
"Items"
,
"FindArchived"
,
"???"
)
.
Inc
()
}
}()
return
m
.
next
.
FindArchived
(
ctx
,
spaceId
,
envId
,
collectionId
,
filter
,
options
...
)
}
...
...
@@ -128,9 +107,6 @@ func (m metricsMiddleware) FindPublished(ctx context.Context, spaceId string, en
defer
func
()
{
timer
.
ObserveDuration
()
m
.
requestMetrics
.
Total
.
WithLabelValues
(
"Items"
,
"FindPublished"
)
.
Inc
()
if
err
!=
nil
{
m
.
requestMetrics
.
FailedTotal
.
WithLabelValues
(
"Items"
,
"FindPublished"
,
"???"
)
.
Inc
()
}
}()
return
m
.
next
.
FindPublished
(
ctx
,
spaceId
,
envId
,
collectionId
,
filter
,
options
...
)
}
...
...
@@ -141,9 +117,6 @@ func (m metricsMiddleware) Get(ctx context.Context, spaceId string, envId string
defer
func
()
{
timer
.
ObserveDuration
()
m
.
requestMetrics
.
Total
.
WithLabelValues
(
"Items"
,
"Get"
)
.
Inc
()
if
err
!=
nil
{
m
.
requestMetrics
.
FailedTotal
.
WithLabelValues
(
"Items"
,
"Get"
,
"???"
)
.
Inc
()
}
}()
return
m
.
next
.
Get
(
ctx
,
spaceId
,
envId
,
collectionId
,
itemId
,
options
...
)
}
...
...
@@ -154,9 +127,6 @@ func (m metricsMiddleware) GetPublished(ctx context.Context, spaceId string, env
defer
func
()
{
timer
.
ObserveDuration
()
m
.
requestMetrics
.
Total
.
WithLabelValues
(
"Items"
,
"GetPublished"
)
.
Inc
()
if
err
!=
nil
{
m
.
requestMetrics
.
FailedTotal
.
WithLabelValues
(
"Items"
,
"GetPublished"
,
"???"
)
.
Inc
()
}
}()
return
m
.
next
.
GetPublished
(
ctx
,
spaceId
,
envId
,
collectionId
,
itemId
,
options
...
)
}
...
...
@@ -167,9 +137,6 @@ func (m metricsMiddleware) GetRevision(ctx context.Context, spaceId string, envI
defer
func
()
{
timer
.
ObserveDuration
()
m
.
requestMetrics
.
Total
.
WithLabelValues
(
"Items"
,
"GetRevision"
)
.
Inc
()
if
err
!=
nil
{
m
.
requestMetrics
.
FailedTotal
.
WithLabelValues
(
"Items"
,
"GetRevision"
,
"???"
)
.
Inc
()
}
}()
return
m
.
next
.
GetRevision
(
ctx
,
spaceId
,
envId
,
collectionId
,
itemId
,
revisionId
,
options
...
)
}
...
...
@@ -180,9 +147,6 @@ func (m metricsMiddleware) Introspect(ctx context.Context, item *items.Item, opt
defer
func
()
{
timer
.
ObserveDuration
()
m
.
requestMetrics
.
Total
.
WithLabelValues
(
"Items"
,
"Introspect"
)
.
Inc
()
if
err
!=
nil
{
m
.
requestMetrics
.
FailedTotal
.
WithLabelValues
(
"Items"
,
"Introspect"
,
"???"
)
.
Inc
()
}
}()
return
m
.
next
.
Introspect
(
ctx
,
item
,
opts
...
)
}
...
...
@@ -193,9 +157,6 @@ func (m metricsMiddleware) ListRevisions(ctx context.Context, spaceId string, en
defer
func
()
{
timer
.
ObserveDuration
()
m
.
requestMetrics
.
Total
.
WithLabelValues
(
"Items"
,
"ListRevisions"
)
.
Inc
()
if
err
!=
nil
{
m
.
requestMetrics
.
FailedTotal
.
WithLabelValues
(
"Items"
,
"ListRevisions"
,
"???"
)
.
Inc
()
}
}()
return
m
.
next
.
ListRevisions
(
ctx
,
spaceId
,
envId
,
collectionId
,
itemId
,
options
...
)
}
...
...
@@ -206,9 +167,6 @@ func (m metricsMiddleware) Publish(ctx context.Context, item *items.Item, option
defer
func
()
{
timer
.
ObserveDuration
()
m
.
requestMetrics
.
Total
.
WithLabelValues
(
"Items"
,
"Publish"
)
.
Inc
()
if
err
!=
nil
{
m
.
requestMetrics
.
FailedTotal
.
WithLabelValues
(
"Items"
,
"Publish"
,
"???"
)
.
Inc
()
}
}()
return
m
.
next
.
Publish
(
ctx
,
item
,
options
...
)
}
...
...
@@ -219,9 +177,6 @@ func (m metricsMiddleware) Unarchive(ctx context.Context, item *items.Item, opti
defer
func
()
{
timer
.
ObserveDuration
()
m
.
requestMetrics
.
Total
.
WithLabelValues
(
"Items"
,
"Unarchive"
)
.
Inc
()
if
err
!=
nil
{
m
.
requestMetrics
.
FailedTotal
.
WithLabelValues
(
"Items"
,
"Unarchive"
,
"???"
)
.
Inc
()
}
}()
return
m
.
next
.
Unarchive
(
ctx
,
item
,
options
...
)
}
...
...
@@ -232,9 +187,6 @@ func (m metricsMiddleware) Undelete(ctx context.Context, item *items.Item, optio
defer
func
()
{
timer
.
ObserveDuration
()
m
.
requestMetrics
.
Total
.
WithLabelValues
(
"Items"
,
"Undelete"
)
.
Inc
()
if
err
!=
nil
{
m
.
requestMetrics
.
FailedTotal
.
WithLabelValues
(
"Items"
,
"Undelete"
,
"???"
)
.
Inc
()
}
}()
return
m
.
next
.
Undelete
(
ctx
,
item
,
options
...
)
}
...
...
@@ -245,9 +197,6 @@ func (m metricsMiddleware) Unpublish(ctx context.Context, item *items.Item, opti
defer
func
()
{
timer
.
ObserveDuration
()
m
.
requestMetrics
.
Total
.
WithLabelValues
(
"Items"
,
"Unpublish"
)
.
Inc
()
if
err
!=
nil
{
m
.
requestMetrics
.
FailedTotal
.
WithLabelValues
(
"Items"
,
"Unpublish"
,
"???"
)
.
Inc
()
}
}()
return
m
.
next
.
Unpublish
(
ctx
,
item
,
options
...
)
}
...
...
@@ -258,9 +207,6 @@ func (m metricsMiddleware) Update(ctx context.Context, item *items.Item, options
defer
func
()
{
timer
.
ObserveDuration
()
m
.
requestMetrics
.
Total
.
WithLabelValues
(
"Items"
,
"Update"
)
.
Inc
()
if
err
!=
nil
{
m
.
requestMetrics
.
FailedTotal
.
WithLabelValues
(
"Items"
,
"Update"
,
"???"
)
.
Inc
()
}
}()
return
m
.
next
.
Update
(
ctx
,
item
,
options
...
)
}
This diff is collapsed.
Click to expand it.
pkg/metrics/request.go
+
0
−
6
View file @
53852ae2
...
...
@@ -7,7 +7,6 @@ import (
type
RequestMetrics
struct
{
Total
*
prometheus
.
CounterVec
FailedTotal
*
prometheus
.
CounterVec
DurationSeconds
*
prometheus
.
HistogramVec
}
...
...
@@ -21,17 +20,12 @@ type RequestMetrics struct {
//
// svc_request_duration_seconds_count{service="Collections",method="Get"} 2
//
// svc_requests_failed_total{service="Collections",method="Get",error="not found"} 1
//
// svc_requests_total{service="Collections",method="Get"} 2
func
NewRequestMetrics
(
registry
prometheus
.
Registerer
,
buckets
[]
float64
)
*
RequestMetrics
{
return
&
RequestMetrics
{
Total
:
promauto
.
With
(
registry
)
.
NewCounterVec
(
prometheus
.
CounterOpts
{
Name
:
"svc_requests_total"
,
},
[]
string
{
"service"
,
"method"
}),
FailedTotal
:
promauto
.
With
(
registry
)
.
NewCounterVec
(
prometheus
.
CounterOpts
{
Name
:
"svc_requests_failed_total"
,
},
[]
string
{
"service"
,
"method"
,
"error"
}),
DurationSeconds
:
promauto
.
With
(
registry
)
.
NewHistogramVec
(
prometheus
.
HistogramOpts
{
Name
:
"svc_request_duration_seconds"
,
Buckets
:
buckets
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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