Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 committed Nov 25, 2024
1 parent 61c46bc commit a381442
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions internal/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func init() {
prometheus.MustRegister(RequestCount)
prometheus.MustRegister(RequestHistogram)
prometheus.MustRegister(SQLHistogram)

}

Check failure on line 27 in internal/metrics/metrics.go

View workflow job for this annotation

GitHub Actions / lint

unnecessary trailing newline (whitespace)

var RequestCount = prometheus.NewCounter(prometheus.CounterOpts{
Expand Down
24 changes: 24 additions & 0 deletions internal/tag/cache_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"time"

"github.com/prometheus/client_golang/prometheus"
"github.com/samber/lo"
"github.com/trim21/errgo"
"go.uber.org/zap"
Expand All @@ -44,6 +45,25 @@ type cachedTags struct {
Tags []Tag
}

var CacheCount = prometheus.NewCounter(prometheus.CounterOpts{

Check failure on line 48 in internal/tag/cache_repo.go

View workflow job for this annotation

GitHub Actions / lint

Metric: chii_request_cached_count Error: counter metrics should have "_total" suffix (promlinter)
Subsystem: "chii",
Name: "request_cached_count",
Help: "",
ConstLabels: map[string]string{"repo": "meta_tags"},
})

var NotCacheCount = prometheus.NewCounter(prometheus.CounterOpts{

Check failure on line 55 in internal/tag/cache_repo.go

View workflow job for this annotation

GitHub Actions / lint

Metric: chii_request_not_cached_count Error: counter metrics should have "_total" suffix (promlinter)
Subsystem: "chii",
Name: "request_not_cached_count",
Help: "",
ConstLabels: map[string]string{"repo": "meta_tags"},
})

func init() {

Check failure on line 62 in internal/tag/cache_repo.go

View workflow job for this annotation

GitHub Actions / lint

don't use `init` function (gochecknoinits)
prometheus.MustRegister(CacheCount)
prometheus.MustRegister(NotCacheCount)
}

func (r cacheRepo) Get(ctx context.Context, id model.SubjectID) ([]Tag, error) {
var key = cachekey.SubjectMetaTag(id)

Expand All @@ -54,8 +74,10 @@ func (r cacheRepo) Get(ctx context.Context, id model.SubjectID) ([]Tag, error) {
}

if ok {
CacheCount.Add(1)
return s.Tags, nil
}
NotCacheCount.Add(1)

tags, err := r.repo.Get(ctx, id)
if err != nil {
Expand Down Expand Up @@ -86,6 +108,7 @@ func (r cacheRepo) GetByIDs(ctx context.Context, ids []model.SubjectID) (map[mod
return nil, errgo.Wrap(err, "cache.MGet")
}

CacheCount.Add(float64(len(tags)))
for _, tag := range tags {
result[tag.ID] = tag.Tags
}
Expand All @@ -97,6 +120,7 @@ func (r cacheRepo) GetByIDs(ctx context.Context, ids []model.SubjectID) (map[mod
}
}

NotCacheCount.Add(float64(len(missing)))
missingFromCache, err := r.repo.GetByIDs(ctx, missing)
if err != nil {
return nil, err
Expand Down

0 comments on commit a381442

Please sign in to comment.