Skip to content

Fix adding label matchers for groups if label not in query #735

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

Merged
merged 1 commit into from
May 17, 2023
Merged
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
51 changes: 42 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,46 +590,79 @@ func (s *objectiveServer) List(ctx context.Context, req *connect.Request[objecti

// If specific grouping was selected we need to merge the label matchers for the queries.
if len(groupingMatchers) > 0 {
if oi.Indicator.Ratio != nil {
switch oi.IndicatorType() {
case slo.Ratio:
groupingMatchersErrors := make(map[string]*labels.Matcher, len(groupingMatchers))
groupingMatchersTotal := make(map[string]*labels.Matcher, len(groupingMatchers))
for _, matcher := range groupingMatchers {
// We need to copy the matchers to avoid modifying the original later on.
groupingMatchersErrors[matcher.Name] = &labels.Matcher{Type: matcher.Type, Name: matcher.Name, Value: matcher.Value}
groupingMatchersTotal[matcher.Name] = &labels.Matcher{Type: matcher.Type, Name: matcher.Name, Value: matcher.Value}
}

for _, m := range oi.Indicator.Ratio.Errors.LabelMatchers {
if rm, replace := groupingMatchers[m.Name]; replace {
m.Type = rm.Type
m.Value = rm.Value
delete(groupingMatchersErrors, m.Name)
}
}
for _, m := range oi.Indicator.Ratio.Total.LabelMatchers {
if rm, replace := groupingMatchers[m.Name]; replace {
m.Type = rm.Type
m.Value = rm.Value
delete(groupingMatchersTotal, m.Name)
}
}
}
if oi.Indicator.Latency != nil {

// Now add the remaining matchers we didn't find before.
for _, m := range groupingMatchersErrors {
oi.Indicator.Ratio.Errors.LabelMatchers = append(oi.Indicator.Ratio.Errors.LabelMatchers, m)
}
for _, m := range groupingMatchersTotal {
oi.Indicator.Ratio.Total.LabelMatchers = append(oi.Indicator.Ratio.Total.LabelMatchers, m)
}
case slo.Latency:
groupingMatchersSuccess := make(map[string]*labels.Matcher, len(groupingMatchers))
groupingMatchersTotal := make(map[string]*labels.Matcher, len(groupingMatchers))
for _, matcher := range groupingMatchers {
// We need to copy the matchers to avoid modifying the original later on.
groupingMatchersSuccess[matcher.Name] = &labels.Matcher{Type: matcher.Type, Name: matcher.Name, Value: matcher.Value}
groupingMatchersTotal[matcher.Name] = &labels.Matcher{Type: matcher.Type, Name: matcher.Name, Value: matcher.Value}
}

for _, m := range oi.Indicator.Latency.Success.LabelMatchers {
if rm, replace := groupingMatchers[m.Name]; replace {
m.Type = rm.Type
m.Value = rm.Value
delete(groupingMatchersSuccess, m.Name)
}
}
for _, m := range oi.Indicator.Latency.Total.LabelMatchers {
if rm, replace := groupingMatchers[m.Name]; replace {
m.Type = rm.Type
m.Value = rm.Value
delete(groupingMatchersTotal, m.Name)
}
}
}
if oi.Indicator.BoolGauge != nil {

// Now add the remaining matchers we didn't find before.
for _, m := range groupingMatchersSuccess {
oi.Indicator.Latency.Success.LabelMatchers = append(oi.Indicator.Latency.Success.LabelMatchers, m)
}
for _, m := range groupingMatchersTotal {
oi.Indicator.Latency.Total.LabelMatchers = append(oi.Indicator.Latency.Total.LabelMatchers, m)
}
case slo.BoolGauge:
for _, m := range oi.Indicator.BoolGauge.LabelMatchers {
if rm, replace := groupingMatchers[m.Name]; replace {
m.Type = rm.Type
m.Value = rm.Value
delete(groupingMatchers, m.Name)
}
}
if len(groupingMatchers) > 0 {
for _, m := range groupingMatchers {
oi.Indicator.BoolGauge.LabelMatchers = append(oi.Indicator.BoolGauge.LabelMatchers, m)
}
for _, m := range groupingMatchers {
oi.Indicator.BoolGauge.LabelMatchers = append(oi.Indicator.BoolGauge.LabelMatchers, m)
}
}
}
Expand Down