forked from thanos-io/thanos
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #112 from vinted/cuckoofilter_thanos
receive/multitsdb: add cuckoo filter on metric names
- Loading branch information
Showing
11 changed files
with
133 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
github.com/Songmu/gotesplit v0.2.1 h1:qJFvR75nJpeKyMQFwyDtFrcc6zDWhrHAkks7DvM8oLo= | ||
github.com/Songmu/gotesplit v0.2.1/go.mod h1:sVBfmLT26b1H5VhUpq8cRhCVK75GAmW9c8r2NiK0gzk= | ||
github.com/jstemmer/go-junit-report v1.0.0 h1:8X1gzZpR+nVQLAht+L/foqOeX2l9DTZoaIPbEQHxsds= | ||
github.com/jstemmer/go-junit-report v1.0.0/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= | ||
golang.org/x/sync v0.0.0-20220513210516-0976fa681c29 h1:w8s32wxx3sY+OjLlv9qltkLU5yvJzxjjgiHWLjdIcw4= | ||
golang.org/x/sync v0.0.0-20220513210516-0976fa681c29/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright (c) The Thanos Authors. | ||
// Licensed under the Apache License 2.0. | ||
|
||
package filter | ||
|
||
import ( | ||
"sync" | ||
|
||
cuckoo "github.com/seiflotfy/cuckoofilter" | ||
) | ||
|
||
type MetricNameFilter interface { | ||
MatchesMetricName(metricName string) bool | ||
ResetAddMetricName(metricNames ...string) | ||
} | ||
|
||
type AllowAllMetricNameFilter struct{} | ||
|
||
func (f AllowAllMetricNameFilter) MatchesMetricName(metricName string) bool { | ||
return true | ||
} | ||
|
||
func (f AllowAllMetricNameFilter) ResetAddMetricName(metricNames ...string) {} | ||
|
||
type CuckooFilterMetricNameFilter struct { | ||
filter *cuckoo.Filter | ||
mtx sync.RWMutex | ||
} | ||
|
||
func NewCuckooFilterMetricNameFilter(capacity uint) *CuckooFilterMetricNameFilter { | ||
return &CuckooFilterMetricNameFilter{ | ||
filter: cuckoo.NewFilter(capacity), | ||
} | ||
} | ||
|
||
func (f *CuckooFilterMetricNameFilter) MatchesMetricName(metricName string) bool { | ||
f.mtx.RLock() | ||
defer f.mtx.RUnlock() | ||
return f.filter.Lookup([]byte(metricName)) | ||
} | ||
|
||
func (f *CuckooFilterMetricNameFilter) ResetAddMetricName(metricNames ...string) { | ||
f.mtx.Lock() | ||
defer f.mtx.Unlock() | ||
f.filter.Reset() | ||
for _, metricName := range metricNames { | ||
f.filter.Insert([]byte(metricName)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters