Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query: Skip formatting strings if debug logging is disabled #7678

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 28 additions & 10 deletions pkg/store/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -562,26 +562,32 @@ func (s *ProxyStore) matchingStores(ctx context.Context, minTime, maxTime int64,
)
for _, st := range s.stores() {
// We might be able to skip the store if its meta information indicates it cannot have series matching our query.
if ok, reason := storeMatches(ctx, st, minTime, maxTime, matchers...); !ok {
storeDebugMsgs = append(storeDebugMsgs, fmt.Sprintf("Store %s filtered out due to: %v", st, reason))
if ok, reason := storeMatches(ctx, s.debugLogging, st, minTime, maxTime, matchers...); !ok {
if s.debugLogging {
storeDebugMsgs = append(storeDebugMsgs, fmt.Sprintf("Store %s filtered out due to: %v", st, reason))
}
continue
}
matches, extraMatchers := s.tsdbSelector.MatchLabelSets(st.LabelSets()...)
if !matches {
storeDebugMsgs = append(storeDebugMsgs, fmt.Sprintf("Store %s filtered out due to: %v", st, "tsdb selector"))
if s.debugLogging {
storeDebugMsgs = append(storeDebugMsgs, fmt.Sprintf("Store %s filtered out due to: %v", st, "tsdb selector"))
}
continue
}
storeLabelSets = append(storeLabelSets, extraMatchers...)

stores = append(stores, st)
storeDebugMsgs = append(storeDebugMsgs, fmt.Sprintf("Store %s queried", st))
if s.debugLogging {
storeDebugMsgs = append(storeDebugMsgs, fmt.Sprintf("Store %s queried", st))
}
}

return stores, storeLabelSets, storeDebugMsgs
}

// storeMatches returns boolean if the given store may hold data for the given label matchers, time ranges and debug store matches gathered from context.
func storeMatches(ctx context.Context, s Client, mint, maxt int64, matchers ...*labels.Matcher) (ok bool, reason string) {
func storeMatches(ctx context.Context, debugLogging bool, s Client, mint, maxt int64, matchers ...*labels.Matcher) (ok bool, reason string) {
var storeDebugMatcher [][]*labels.Matcher
if ctxVal := ctx.Value(StoreMatcherKey); ctxVal != nil {
if value, ok := ctxVal.([][]*labels.Matcher); ok {
Expand All @@ -591,22 +597,30 @@ func storeMatches(ctx context.Context, s Client, mint, maxt int64, matchers ...*

storeMinTime, storeMaxTime := s.TimeRange()
if mint > storeMaxTime || maxt < storeMinTime {
return false, fmt.Sprintf("does not have data within this time period: [%v,%v]. Store time ranges: [%v,%v]", mint, maxt, storeMinTime, storeMaxTime)
const s string = "does not have data within this time period"
if debugLogging {
return false, fmt.Sprintf("%s: [%v,%v]. Store time ranges: [%v,%v]", s, mint, maxt, storeMinTime, storeMaxTime)
}
return false, s
}

if ok, reason := storeMatchDebugMetadata(s, storeDebugMatcher); !ok {
if ok, reason := storeMatchDebugMetadata(s, debugLogging, storeDebugMatcher); !ok {
return false, reason
}

extLset := s.LabelSets()
if !LabelSetsMatch(matchers, extLset...) {
return false, fmt.Sprintf("external labels %v does not match request label matchers: %v", extLset, matchers)
const s string = "external labels does not match request label matchers"
if debugLogging {
return false, fmt.Sprintf("external labels %v does not match request label matchers: %v", extLset, matchers)
}
return false, s
}
return true, ""
}

// storeMatchDebugMetadata return true if the store's address match the storeDebugMatchers.
func storeMatchDebugMetadata(s Client, storeDebugMatchers [][]*labels.Matcher) (ok bool, reason string) {
func storeMatchDebugMetadata(s Client, debugLogging bool, storeDebugMatchers [][]*labels.Matcher) (ok bool, reason string) {
if len(storeDebugMatchers) == 0 {
return true, ""
}
Expand All @@ -621,7 +635,11 @@ func storeMatchDebugMetadata(s Client, storeDebugMatchers [][]*labels.Matcher) (
match = match || LabelSetsMatch(sm, labels.FromStrings("__address__", addr))
}
if !match {
return false, fmt.Sprintf("__address__ %v does not match debug store metadata matchers: %v", addr, storeDebugMatchers)
const s string = "__address__ does not match debug store metadata matchers"
if debugLogging {
return false, fmt.Sprintf("__address__ %v does not match debug store metadata matchers: %v", addr, storeDebugMatchers)
}
return false, s
}
return true, ""
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/store/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1927,7 +1927,7 @@ func TestStoreMatches(t *testing.T) {
},
} {
t.Run("", func(t *testing.T) {
ok, reason := storeMatches(context.TODO(), c.s, c.mint, c.maxt, c.ms...)
ok, reason := storeMatches(context.TODO(), true, c.s, c.mint, c.maxt, c.ms...)
testutil.Equals(t, c.expectedMatch, ok)
testutil.Equals(t, c.expectedReason, reason)

Expand Down Expand Up @@ -2257,18 +2257,18 @@ func TestProxyStore_storeMatchMetadata(t *testing.T) {
c := storetestutil.TestClient{Name: "testaddr"}
c.IsLocalStore = true

ok, reason := storeMatchDebugMetadata(c, [][]*labels.Matcher{{}})
ok, reason := storeMatchDebugMetadata(c, true, [][]*labels.Matcher{{}})
testutil.Assert(t, !ok)
testutil.Equals(t, "the store is not remote, cannot match __address__", reason)

// Change client to remote.
c.IsLocalStore = false

ok, reason = storeMatchDebugMetadata(c, [][]*labels.Matcher{{labels.MustNewMatcher(labels.MatchEqual, "__address__", "wrong")}})
ok, reason = storeMatchDebugMetadata(c, true, [][]*labels.Matcher{{labels.MustNewMatcher(labels.MatchEqual, "__address__", "wrong")}})
testutil.Assert(t, !ok)
testutil.Equals(t, "__address__ testaddr does not match debug store metadata matchers: [[__address__=\"wrong\"]]", reason)

ok, reason = storeMatchDebugMetadata(c, [][]*labels.Matcher{{labels.MustNewMatcher(labels.MatchEqual, "__address__", "testaddr")}})
ok, reason = storeMatchDebugMetadata(c, true, [][]*labels.Matcher{{labels.MustNewMatcher(labels.MatchEqual, "__address__", "testaddr")}})
testutil.Assert(t, ok)
testutil.Equals(t, "", reason)
}
Expand Down
Loading