Skip to content

Commit

Permalink
Unlabel prometheus filter metrics (flyteorg#104)
Browse files Browse the repository at this point in the history
* updated prometheus metric from a labeled counter to unlabeled

Signed-off-by: Daniel Rammer <[email protected]>

* labeled the unused context parameter on lur and oppobloom Contains functions

Signed-off-by: Daniel Rammer <[email protected]>
  • Loading branch information
hamersaw authored Oct 25, 2021
1 parent a625e0c commit ca6c979
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
11 changes: 6 additions & 5 deletions flytestdlib/fastcheck/iface.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package fastcheck
import (
"context"

"github.com/prometheus/client_golang/prometheus"

"github.com/flyteorg/flytestdlib/promutils"
"github.com/flyteorg/flytestdlib/promutils/labeled"
)

// Filter provides an interface to check if a Key of type []byte was ever seen.
Expand All @@ -27,14 +28,14 @@ type Filter interface {
// Every implementation of the Filter Interface provides these metrics
type Metrics struct {
// Indicates if the item was found in the cache
Hit labeled.Counter
Hit prometheus.Counter
// Indicates if the item was not found in the cache
Miss labeled.Counter
Miss prometheus.Counter
}

func newMetrics(scope promutils.Scope) Metrics {
return Metrics{
Hit: labeled.NewCounter("cache_hit", "Indicates that the item was found in the cache", scope),
Miss: labeled.NewCounter("cache_miss", "Indicates that the item was found in the cache", scope),
Hit: scope.MustNewCounter("cache_hit", "Indicates that the item was found in the cache"),
Miss: scope.MustNewCounter("cache_miss", "Indicates that the item was found in the cache"),
}
}
6 changes: 3 additions & 3 deletions flytestdlib/fastcheck/lru.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ type LRUCacheFilter struct {
}

// Simply uses Contains from the LRUCacheFilter
func (l LRUCacheFilter) Contains(ctx context.Context, id []byte) bool {
func (l LRUCacheFilter) Contains(_ context.Context, id []byte) bool {
v := l.lru.Contains(string(id))
if v {
l.metrics.Hit.Inc(ctx)
l.metrics.Hit.Inc()
return true
}
l.metrics.Miss.Inc(ctx)
l.metrics.Miss.Inc()
return false
}

Expand Down
6 changes: 3 additions & 3 deletions flytestdlib/fastcheck/oppobloom.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ func (f *OppoBloomFilter) Add(_ context.Context, id []byte) bool {
return !bytes.Equal(oldID, id)
}

func (f *OppoBloomFilter) Contains(ctx context.Context, id []byte) bool {
func (f *OppoBloomFilter) Contains(_ context.Context, id []byte) bool {
curr := get(f.array, f.getIndex(id))
if curr != nil {
if bytes.Equal(id, *curr) {
f.metrics.Hit.Inc(ctx)
f.metrics.Hit.Inc()
return true
}
}
f.metrics.Miss.Inc(ctx)
f.metrics.Miss.Inc()
return false
}

Expand Down

0 comments on commit ca6c979

Please sign in to comment.