Skip to content

Commit

Permalink
Regex set optimisation when looking series in ingester (grafana#2475)
Browse files Browse the repository at this point in the history
* Regex set optimisation when looking series in ingester

Similar to cortexproject/cortex#2446

Super useful for templated grafana dashboards which send matchers such
as =~"a|b|c|d|e"

Signed-off-by: Goutham Veeramachaneni <gouthamve@gmail.com>

* Add CHANGELOG entry

Signed-off-by: Goutham Veeramachaneni <gouthamve@gmail.com>

* Add benchmark for set optimisation

Signed-off-by: Goutham Veeramachaneni <gouthamve@gmail.com>
  • Loading branch information
gouthamve committed Apr 17, 2020
1 parent 5dc91ea commit 4a5cbd2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions chunk_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,8 @@ func (c *baseStore) lookupIdsByMetricNameMatcher(ctx context.Context, from, thro
} else if matcher.Type == labels.MatchEqual {
labelName = matcher.Name
queries, err = c.schema.GetReadQueriesForMetricLabelValue(from, through, userID, metricName, matcher.Name, matcher.Value)
} else if matcher.Type == labels.MatchRegexp && len(findSetMatches(matcher.Value)) > 0 {
set := findSetMatches(matcher.Value)
} else if matcher.Type == labels.MatchRegexp && len(FindSetMatches(matcher.Value)) > 0 {
set := FindSetMatches(matcher.Value)
for _, v := range set {
var qs []IndexQuery
qs, err = c.schema.GetReadQueriesForMetricLabelValue(from, through, userID, metricName, matcher.Name, v)
Expand Down
4 changes: 2 additions & 2 deletions opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ func init() {
}
}

// FindSetMatches returns list of values that can be equality matched on.
// copied from Prometheus querier.go, removed check for Prometheus wrapper.
// Returns list of values that can regex matches.
func findSetMatches(pattern string) []string {
func FindSetMatches(pattern string) []string {
escaped := false
sets := []*strings.Builder{{}}
for i := 0; i < len(pattern); i++ {
Expand Down
2 changes: 1 addition & 1 deletion opts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestFindSetMatches(t *testing.T) {
}

for _, c := range cases {
matches := findSetMatches(c.pattern)
matches := FindSetMatches(c.pattern)
require.Equal(t, c.exp, matches)
}
}

0 comments on commit 4a5cbd2

Please sign in to comment.