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
95ce5d74
Commit
95ce5d74
authored
1 year ago
by
ensiouel
Browse files
Options
Downloads
Patches
Plain Diff
refactor: теперь создание метрик возвращает ошибку вторым параметром
parent
7b56094a
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
pkg/metrics/cache.go
+28
-17
28 additions, 17 deletions
pkg/metrics/cache.go
pkg/metrics/request.go
+31
-18
31 additions, 18 deletions
pkg/metrics/request.go
with
59 additions
and
35 deletions
pkg/metrics/cache.go
+
28
−
17
View file @
95ce5d74
package
metrics
import
(
"git.perx.ru/perxis/perxis-go/pkg/optional"
"go.opentelemetry.io/otel"
metricotel
"go.opentelemetry.io/otel/metric"
)
...
...
@@ -12,21 +11,33 @@ type CacheMetrics struct {
InvalidatesTotal
metricotel
.
Int64Counter
}
func
NewCacheMetrics
(
subsystem
string
)
*
CacheMetrics
{
meter
:=
otel
.
Meter
(
subsystem
)
metrics
:=
&
CacheMetrics
{
HitsTotal
:
optional
.
Must
(
meter
.
Int64Counter
(
"cache_hits_total"
,
func
NewCacheMetrics
(
scope
string
)
(
*
CacheMetrics
,
error
)
{
meter
:=
otel
.
Meter
(
scope
)
hitsTotal
,
err
:=
meter
.
Int64Counter
(
"cache_hits"
,
metricotel
.
WithDescription
(
"Количество найденных в кэше значений"
),
)),
MissesTotal
:
optional
.
Must
(
meter
.
Int64Counter
(
"cache_misses_total"
,
)
if
err
!=
nil
{
return
nil
,
err
}
missesTotal
,
err
:=
meter
.
Int64Counter
(
"cache_misses"
,
metricotel
.
WithDescription
(
"Количество не найденных в кэше значений"
),
)),
InvalidatesTotal
:
optional
.
Must
(
meter
.
Int64Counter
(
"cache_invalidates_total"
,
)
if
err
!=
nil
{
return
nil
,
err
}
invalidatesTotal
,
err
:=
meter
.
Int64Counter
(
"cache_invalidates"
,
metricotel
.
WithDescription
(
"Количество инвалидаций кэша"
),
)),
)
if
err
!=
nil
{
return
nil
,
err
}
return
metrics
return
&
CacheMetrics
{
HitsTotal
:
hitsTotal
,
MissesTotal
:
missesTotal
,
InvalidatesTotal
:
invalidatesTotal
,
},
nil
}
This diff is collapsed.
Click to expand it.
pkg/metrics/request.go
+
31
−
18
View file @
95ce5d74
package
metrics
import
(
"git.perx.ru/perxis/perxis-go/pkg/optional"
"go.opentelemetry.io/otel"
metricotel
"go.opentelemetry.io/otel/metric"
)
...
...
@@ -13,22 +12,36 @@ type RequestMetrics struct {
}
// NewRequestMetrics возвращает метрики для подсчета количества удачных/неудачных запросов, а так же длительности ответов.
func
NewRequestMetrics
(
subsystem
string
)
*
RequestMetrics
{
meter
:=
otel
.
Meter
(
subsystem
)
metrics
:=
&
RequestMetrics
{
Total
:
optional
.
Must
(
meter
.
Int64Counter
(
"requests_total"
,
//
// Для RequestMetrics.DurationMilliseconds значения buckets по умолчанию равно []float64{0, 5, 10, 25, 50, 75, 100, 250, 500, 750, 1000, 2500, 5000, 7500, 10000}
func
NewRequestMetrics
(
scope
string
)
(
*
RequestMetrics
,
error
)
{
meter
:=
otel
.
Meter
(
scope
)
total
,
err
:=
meter
.
Int64Counter
(
"requests"
,
metricotel
.
WithDescription
(
"Количество запросов"
),
)),
FailedTotal
:
optional
.
Must
(
meter
.
Int64Counter
(
"requests_failed_total"
,
)
if
err
!=
nil
{
return
nil
,
err
}
failedTotal
,
err
:=
meter
.
Int64Counter
(
"requests_failed"
,
metricotel
.
WithDescription
(
"Количество запросов, вернувших ошибку"
),
)),
DurationMilliseconds
:
optional
.
Must
(
meter
.
Int64Histogram
(
"request_duration"
,
)
if
err
!=
nil
{
return
nil
,
err
}
durationMilliseconds
,
err
:=
meter
.
Int64Histogram
(
"request_duration"
,
metricotel
.
WithDescription
(
"Длительность обработки запроса"
),
metricotel
.
WithUnit
(
"ms"
),
)),
)
if
err
!=
nil
{
return
nil
,
err
}
return
metrics
return
&
RequestMetrics
{
Total
:
total
,
FailedTotal
:
failedTotal
,
DurationMilliseconds
:
durationMilliseconds
,
},
nil
}
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