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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
perxis
perxis-go
Commits
6e34c3bb
Commit
6e34c3bb
authored
1 year ago
by
ensiouel
Browse files
Options
Downloads
Patches
Plain Diff
refactor: убрана обертка для сбора метрик кэша
parent
c8093a14
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pkg/cache/metrics_cache.go
+0
-54
0 additions, 54 deletions
pkg/cache/metrics_cache.go
with
0 additions
and
54 deletions
pkg/cache/metrics_cache.go
deleted
100644 → 0
+
0
−
54
View file @
c8093a14
package
cache
import
(
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
var
(
cacheHitsTotal
=
promauto
.
With
(
prometheus
.
DefaultRegisterer
)
.
NewCounterVec
(
prometheus
.
CounterOpts
{
Name
:
"cache_hits_total"
,
Help
:
"Количество попаданий в кэш."
,
},
[]
string
{
"cache_id"
})
cacheMissesTotal
=
promauto
.
With
(
prometheus
.
DefaultRegisterer
)
.
NewCounterVec
(
prometheus
.
CounterOpts
{
Name
:
"cache_misses_total"
,
Help
:
"Количество пропусков в кэш."
,
},
[]
string
{
"cache_id"
})
)
type
metricsCache
struct
{
cache
Cache
cacheID
string
}
// WithMetrics возвращает обертку над кэшем, которая используется для отслеживания количества хитов и промахов в кэше.
// Помимо этого, в функцию WithMetrics передается параметр cacheID, который используется в метке метрик для идентификации конкретного кэша.
//
// Метрики записываются в prometheus.DefaultRegisterer
func
WithMetrics
(
cache
Cache
,
cacheID
string
)
Cache
{
if
cache
==
nil
{
panic
(
"cannot wrap metrics in cache, cache is nil"
)
}
return
&
metricsCache
{
cacheID
:
cacheID
,
cache
:
cache
,
}
}
func
(
c
*
metricsCache
)
Set
(
key
,
value
any
)
error
{
return
c
.
cache
.
Set
(
key
,
value
)
}
func
(
c
*
metricsCache
)
Get
(
key
any
)
(
any
,
error
)
{
value
,
err
:=
c
.
cache
.
Get
(
key
)
if
err
!=
nil
{
cacheMissesTotal
.
WithLabelValues
(
c
.
cacheID
)
.
Inc
()
return
nil
,
err
}
cacheHitsTotal
.
WithLabelValues
(
c
.
cacheID
)
.
Inc
()
return
value
,
nil
}
func
(
c
*
metricsCache
)
Remove
(
key
any
)
error
{
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