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
1cd9f9a8
Commit
1cd9f9a8
authored
1 year ago
by
ensiouel
Browse files
Options
Downloads
Patches
Plain Diff
убрана метрика cache_requests_total
parent
d5f1daad
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
pkg/cache/metrics_cache.go
+14
-18
14 additions, 18 deletions
pkg/cache/metrics_cache.go
with
14 additions
and
18 deletions
pkg/cache/metrics_cache.go
+
14
−
18
View file @
1cd9f9a8
...
@@ -6,52 +6,48 @@ import (
...
@@ -6,52 +6,48 @@ import (
)
)
var
(
var
(
cacheRequestsTotal
=
promauto
.
With
(
prometheus
.
DefaultRegisterer
)
.
NewCounterVec
(
prometheus
.
CounterOpts
{
Name
:
"cache_requests_total"
,
Help
:
"Количество обращений к кэшу"
,
},
[]
string
{
"cache_id"
})
cacheHitsTotal
=
promauto
.
With
(
prometheus
.
DefaultRegisterer
)
.
NewCounterVec
(
prometheus
.
CounterOpts
{
cacheHitsTotal
=
promauto
.
With
(
prometheus
.
DefaultRegisterer
)
.
NewCounterVec
(
prometheus
.
CounterOpts
{
Name
:
"cache_hits_total"
,
Name
:
"cache_hits_total"
,
Help
:
"Количество попаданий в кэш"
,
Help
:
"Количество попаданий в кэш
.
"
,
},
[]
string
{
"cache_id"
})
},
[]
string
{
"cache_id"
})
cacheMissesTotal
=
promauto
.
With
(
prometheus
.
DefaultRegisterer
)
.
NewCounterVec
(
prometheus
.
CounterOpts
{
cacheMissesTotal
=
promauto
.
With
(
prometheus
.
DefaultRegisterer
)
.
NewCounterVec
(
prometheus
.
CounterOpts
{
Name
:
"cache_misses_total"
,
Name
:
"cache_misses_total"
,
Help
:
"Количество пропусков в кэш"
,
Help
:
"Количество пропусков в кэш
.
"
,
},
[]
string
{
"cache_id"
})
},
[]
string
{
"cache_id"
})
)
)
var
_
Cache
=
&
M
etricsCache
{}
var
_
Cache
=
&
m
etricsCache
{}
type
MetricsCache
struct
{
type
metricsCache
struct
{
cacheID
string
cache
Cache
cache
Cache
cacheID
string
}
}
func
WrapMetrics
(
cacheID
string
,
cache
Cache
)
*
MetricsCache
{
// WithMetrics возвращает обертку над кэшем, которая используется для отслеживания количества хитов и промахов в кэше.
return
&
MetricsCache
{
// Помимо этого, в функцию WithMetrics передается параметр cacheID, который используется в метке метрик для идентификации конкретного кэша.
//
// Метрики записываются в prometheus.DefaultRegisterer
func
WithMetrics
(
cache
Cache
,
cacheID
string
)
Cache
{
return
&
metricsCache
{
cacheID
:
cacheID
,
cacheID
:
cacheID
,
cache
:
cache
,
cache
:
cache
,
}
}
}
}
func
(
c
*
M
etricsCache
)
Set
(
key
,
value
any
)
error
{
func
(
c
*
m
etricsCache
)
Set
(
key
,
value
any
)
error
{
return
c
.
cache
.
Set
(
key
,
value
)
return
c
.
cache
.
Set
(
key
,
value
)
}
}
func
(
c
*
MetricsCache
)
Get
(
key
any
)
(
any
,
error
)
{
func
(
c
*
metricsCache
)
Get
(
key
any
)
(
any
,
error
)
{
cacheRequestsTotal
.
WithLabelValues
(
c
.
cacheID
)
.
Inc
()
value
,
err
:=
c
.
cache
.
Get
(
key
)
value
,
err
:=
c
.
cache
.
Get
(
key
)
if
err
!=
nil
{
if
err
!=
nil
{
cacheMissesTotal
.
WithLabelValues
(
c
.
cacheID
)
.
Inc
()
cacheMissesTotal
.
WithLabelValues
(
c
.
cacheID
)
.
Inc
()
return
nil
,
err
return
nil
,
err
}
}
cacheHitsTotal
.
WithLabelValues
(
c
.
cacheID
)
.
Inc
()
cacheHitsTotal
.
WithLabelValues
(
c
.
cacheID
)
.
Inc
()
return
value
,
nil
return
value
,
nil
}
}
func
(
c
*
M
etricsCache
)
Remove
(
key
any
)
error
{
func
(
c
*
m
etricsCache
)
Remove
(
key
any
)
error
{
return
c
.
cache
.
Remove
(
key
)
return
c
.
cache
.
Remove
(
key
)
}
}
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