diff --git a/CHANGELOG.md b/CHANGELOG.md index 13a1ba9a7b..6ab0be698a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ * [BUGFIX] Ingester: Fix `user` and `type` labels for the `cortex_ingester_tsdb_head_samples_appended_total` TSDB metric. #5952 * [BUGFIX] Querier: Enforce max query length check for `/api/v1/series` API even though `ignoreMaxQueryLength` is set to true. #6018 * [BUGFIX] Ingester: Fix issue with the minimize token generator where it was not taking in consideration the current ownerhip of an instance when generating extra tokens. #6062 +* [ENHANCEMENT] Ruler: Add support for filtering by `state` and `health` field on Rules API. #6040 ## 1.17.1 2024-05-20 diff --git a/pkg/ruler/api.go b/pkg/ruler/api.go index f535e737ae..64d4e67626 100644 --- a/pkg/ruler/api.go +++ b/pkg/ruler/api.go @@ -135,11 +135,25 @@ func (a *API) PrometheusRules(w http.ResponseWriter, req *http.Request) { return } + state := strings.ToLower(req.URL.Query().Get("state")) + if state != "" && state != firingStateFilter && state != pendingStateFilter && state != inactiveStateFilter { + util_api.RespondError(logger, w, v1.ErrBadData, fmt.Sprintf("unsupported state value %q", state), http.StatusBadRequest) + return + } + + health := strings.ToLower(req.URL.Query().Get("health")) + if health != "" && health != unknownHealthFilter && health != okHealthFilter && health != errHealthFilter { + util_api.RespondError(logger, w, v1.ErrBadData, fmt.Sprintf("unsupported health value %q", health), http.StatusBadRequest) + return + } + rulesRequest := RulesRequest{ RuleNames: req.Form["rule_name[]"], RuleGroupNames: req.Form["rule_group[]"], Files: req.Form["file[]"], Type: typ, + State: state, + Health: health, } w.Header().Set("Content-Type", "application/json") diff --git a/pkg/ruler/ruler.go b/pkg/ruler/ruler.go index 3e72fa1629..d07cd86033 100644 --- a/pkg/ruler/ruler.go +++ b/pkg/ruler/ruler.go @@ -73,6 +73,14 @@ const ( alertingRuleFilter string = "alert" recordingRuleFilter string = "record" + + firingStateFilter string = "firing" + pendingStateFilter string = "pending" + inactiveStateFilter string = "inactive" + + unknownHealthFilter string = "unknown" + okHealthFilter string = "ok" + errHealthFilter string = "err" ) type DisabledRuleGroupErr struct { @@ -874,9 +882,11 @@ func (r *Ruler) getLocalRules(userID string, rulesRequest RulesRequest, includeB ruleGroupNameSet := sliceToSet(rulesRequest.RuleGroupNames) fileSet := sliceToSet(rulesRequest.Files) ruleType := rulesRequest.Type + alertState := rulesRequest.State + health := rulesRequest.Health returnAlerts := ruleType == "" || ruleType == alertingRuleFilter - returnRecording := ruleType == "" || ruleType == recordingRuleFilter + returnRecording := (ruleType == "" || ruleType == recordingRuleFilter) && alertState == "" for _, group := range groups { // The mapped filename is url path escaped encoded to make handling `/` characters easier @@ -915,6 +925,9 @@ func (r *Ruler) getLocalRules(userID string, rulesRequest RulesRequest, includeB continue } } + if !returnByHealth(health, string(r.Health())) { + continue + } lastError := "" if r.LastError() != nil { lastError = r.LastError().Error() @@ -926,6 +939,9 @@ func (r *Ruler) getLocalRules(userID string, rulesRequest RulesRequest, includeB if !returnAlerts { continue } + if !returnByState(alertState, rule.State().String()) { + continue + } alerts := []*AlertStateDesc{} for _, a := range rule.ActiveAlerts() { alerts = append(alerts, &AlertStateDesc{ @@ -1296,3 +1312,11 @@ func (r *Ruler) ListAllRules(w http.ResponseWriter, req *http.Request) { close(iter) <-done } + +func returnByState(requestState string, alertState string) bool { + return requestState == "" || requestState == alertState +} + +func returnByHealth(requestHealth string, ruleHealth string) bool { + return requestHealth == "" || requestHealth == ruleHealth +} diff --git a/pkg/ruler/ruler.pb.go b/pkg/ruler/ruler.pb.go index 412fe757f2..192c8f3e25 100644 --- a/pkg/ruler/ruler.pb.go +++ b/pkg/ruler/ruler.pb.go @@ -43,6 +43,8 @@ type RulesRequest struct { RuleGroupNames []string `protobuf:"bytes,2,rep,name=ruleGroupNames,proto3" json:"ruleGroupNames,omitempty"` Files []string `protobuf:"bytes,3,rep,name=files,proto3" json:"files,omitempty"` Type string `protobuf:"bytes,4,opt,name=type,proto3" json:"type,omitempty"` + State string `protobuf:"bytes,5,opt,name=state,proto3" json:"state,omitempty"` + Health string `protobuf:"bytes,6,opt,name=health,proto3" json:"health,omitempty"` } func (m *RulesRequest) Reset() { *m = RulesRequest{} } @@ -105,6 +107,20 @@ func (m *RulesRequest) GetType() string { return "" } +func (m *RulesRequest) GetState() string { + if m != nil { + return m.State + } + return "" +} + +func (m *RulesRequest) GetHealth() string { + if m != nil { + return m.Health + } + return "" +} + type RulesResponse struct { Groups []*GroupStateDesc `protobuf:"bytes,1,rep,name=groups,proto3" json:"groups,omitempty"` } @@ -420,54 +436,55 @@ func init() { func init() { proto.RegisterFile("ruler.proto", fileDescriptor_9ecbec0a4cfddea6) } var fileDescriptor_9ecbec0a4cfddea6 = []byte{ - // 750 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x55, 0x4f, 0x6b, 0x13, 0x4f, - 0x18, 0xde, 0x49, 0x9b, 0x34, 0x99, 0xf4, 0xd7, 0xf2, 0x9b, 0x46, 0x59, 0x83, 0x4c, 0x4a, 0x04, - 0x29, 0x82, 0x1b, 0x88, 0x05, 0xf1, 0x50, 0x25, 0xa5, 0xad, 0x17, 0x91, 0xb2, 0x51, 0xaf, 0x61, - 0x92, 0x4c, 0xb6, 0x6b, 0x37, 0x3b, 0xeb, 0xcc, 0x6c, 0xa8, 0x17, 0xf1, 0x23, 0xf4, 0xe8, 0xd9, - 0x93, 0x1f, 0xa5, 0xc7, 0xe2, 0xa9, 0x88, 0x54, 0x9b, 0x5e, 0x3c, 0xf6, 0x23, 0xc8, 0xcc, 0xec, - 0x9a, 0xa4, 0x56, 0x70, 0x91, 0x5e, 0x92, 0x79, 0xff, 0x3c, 0xcf, 0x3b, 0xef, 0xfb, 0xcc, 0xcc, - 0xc2, 0x32, 0x8f, 0x03, 0xca, 0x9d, 0x88, 0x33, 0xc9, 0x50, 0x5e, 0x1b, 0xd5, 0x8a, 0xc7, 0x3c, - 0xa6, 0x3d, 0x0d, 0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x05, 0x6e, 0x6e, 0xc0, 0xbc, 0x7a, 0x0e, 0x38, 0x5a, 0x37, 0x0b, 0x81, - 0x56, 0xa6, 0x5e, 0xc5, 0xf4, 0x7b, 0x51, 0xad, 0xcc, 0x3a, 0xcd, 0x23, 0x5e, 0xb7, 0x36, 0xd7, - 0x8f, 0xcf, 0xb0, 0x75, 0x72, 0x86, 0xad, 0x8b, 0x33, 0x0c, 0xde, 0x8f, 0x31, 0xf8, 0x34, 0xc6, - 0xe0, 0x68, 0x8c, 0xc1, 0xf1, 0x18, 0x83, 0xef, 0x63, 0x0c, 0x7e, 0x8c, 0xb1, 0x75, 0x31, 0xc6, - 0xe0, 0xf0, 0x1c, 0x5b, 0xc7, 0xe7, 0xd8, 0x3a, 0x39, 0xc7, 0x56, 0xb7, 0xa0, 0xf7, 0xf8, 0xe0, - 0x67, 0x00, 0x00, 0x00, 0xff, 0xff, 0x77, 0xf3, 0x36, 0x0c, 0x7b, 0x07, 0x00, 0x00, + // 759 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x55, 0x4f, 0x4f, 0x13, 0x41, + 0x14, 0xdf, 0x69, 0x69, 0x69, 0xa7, 0x08, 0x71, 0xa8, 0x66, 0x6d, 0xcc, 0x94, 0xd4, 0xc4, 0x10, + 0x13, 0xb7, 0x49, 0x25, 0x31, 0x1e, 0xd0, 0x94, 0x00, 0x5e, 0x8c, 0x21, 0x5b, 0xf5, 0xda, 0x4c, + 0xdb, 0xe9, 0xb2, 0xb2, 0xdd, 0x59, 0x67, 0x66, 0x1b, 0xbc, 0xf9, 0x11, 0x38, 0x7a, 0xf6, 0xe4, + 0xc1, 0x0f, 0xc2, 0x91, 0x78, 0x22, 0xc6, 0xa0, 0x94, 0x8b, 0x47, 0x3e, 0x82, 0x99, 0x99, 0x5d, + 0xdb, 0x22, 0x26, 0x34, 0x86, 0x0b, 0xcc, 0xfb, 0xf3, 0x7b, 0x7f, 0x7e, 0xef, 0xed, 0x2b, 0x2c, + 0xf1, 0x38, 0xa0, 0xdc, 0x89, 0x38, 0x93, 0x0c, 0xe5, 0xb4, 0x50, 0x29, 0x7b, 0xcc, 0x63, 0x5a, + 0x53, 0x57, 0x2f, 0x63, 0xac, 0x60, 0x8f, 0x31, 0x2f, 0xa0, 0x75, 0x2d, 0x75, 0xe2, 0x7e, 0xbd, + 0x17, 0x73, 0x22, 0x7d, 0x16, 0x26, 0xf6, 0xea, 0x45, 0xbb, 0xf4, 0x07, 0x54, 0x48, 0x32, 0x88, + 0x12, 0x87, 0x27, 0x9e, 0x2f, 0x77, 0xe3, 0x8e, 0xd3, 0x65, 0x83, 0x7a, 0x97, 0x71, 0x49, 0xf7, + 0x23, 0xce, 0xde, 0xd2, 0xae, 0x4c, 0xa4, 0x7a, 0xb4, 0xe7, 0xa5, 0x86, 0x4e, 0xf2, 0x48, 0xa0, + 0xeb, 0x57, 0x81, 0xea, 0xe2, 0xf5, 0x5f, 0x11, 0x75, 0xcc, 0x7f, 0x03, 0xaf, 0x7d, 0x01, 0x70, + 0xc1, 0x55, 0xb2, 0x4b, 0xdf, 0xc5, 0x54, 0x48, 0x74, 0x17, 0x16, 0x95, 0xfd, 0x25, 0x19, 0x50, + 0x61, 0x83, 0x95, 0xec, 0x6a, 0xd1, 0x1d, 0x2b, 0xd0, 0x7d, 0xb8, 0xa8, 0x84, 0xe7, 0x9c, 0xc5, + 0x91, 0x71, 0xc9, 0x68, 0x97, 0x0b, 0x5a, 0x54, 0x86, 0xb9, 0xbe, 0x1f, 0x50, 0x61, 0x67, 0xb5, + 0xd9, 0x08, 0x08, 0xc1, 0x39, 0xf9, 0x3e, 0xa2, 0xf6, 0xdc, 0x0a, 0x58, 0x2d, 0xba, 0xfa, 0xad, + 0x3c, 0x85, 0x24, 0x92, 0xda, 0x39, 0xad, 0x34, 0x02, 0xba, 0x0d, 0xf3, 0xbb, 0x94, 0x04, 0x72, + 0xd7, 0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x2e, 0xce, 0x12, 0x46, + 0x03, 0x5f, 0x2b, 0x1c, 0xda, 0x81, 0x37, 0xf7, 0x28, 0x8d, 0xda, 0x7d, 0x9f, 0xfb, 0xa1, 0xd7, + 0x16, 0x7e, 0xd8, 0xa5, 0x36, 0x9c, 0x21, 0xd8, 0x92, 0x82, 0x6f, 0x6b, 0x74, 0x4b, 0x81, 0x1b, + 0xeb, 0x30, 0xa7, 0xce, 0x01, 0x47, 0x6b, 0xe6, 0x21, 0xd0, 0xf2, 0xc4, 0x55, 0x4c, 0x7f, 0x5d, + 0x2a, 0xe5, 0x69, 0xa5, 0x39, 0xe2, 0x35, 0x6b, 0x63, 0xed, 0xe8, 0x14, 0x5b, 0xc7, 0xa7, 0xd8, + 0x3a, 0x3f, 0xc5, 0xe0, 0xc3, 0x08, 0x83, 0xcf, 0x23, 0x0c, 0x0e, 0x47, 0x18, 0x1c, 0x8d, 0x30, + 0xf8, 0x39, 0xc2, 0xe0, 0xd7, 0x08, 0x5b, 0xe7, 0x23, 0x0c, 0x0e, 0xce, 0xb0, 0x75, 0x74, 0x86, + 0xad, 0xe3, 0x33, 0x6c, 0x75, 0xf2, 0xba, 0xc6, 0x47, 0xbf, 0x03, 0x00, 0x00, 0xff, 0xff, 0x7c, + 0x42, 0x1b, 0x9b, 0xaa, 0x07, 0x00, 0x00, } func (this *RulesRequest) Equal(that interface{}) bool { @@ -516,6 +533,12 @@ func (this *RulesRequest) Equal(that interface{}) bool { if this.Type != that1.Type { return false } + if this.State != that1.State { + return false + } + if this.Health != that1.Health { + return false + } return true } func (this *RulesResponse) Equal(that interface{}) bool { @@ -697,12 +720,14 @@ func (this *RulesRequest) GoString() string { if this == nil { return "nil" } - s := make([]string, 0, 8) + s := make([]string, 0, 10) s = append(s, "&ruler.RulesRequest{") s = append(s, "RuleNames: "+fmt.Sprintf("%#v", this.RuleNames)+",\n") s = append(s, "RuleGroupNames: "+fmt.Sprintf("%#v", this.RuleGroupNames)+",\n") s = append(s, "Files: "+fmt.Sprintf("%#v", this.Files)+",\n") s = append(s, "Type: "+fmt.Sprintf("%#v", this.Type)+",\n") + s = append(s, "State: "+fmt.Sprintf("%#v", this.State)+",\n") + s = append(s, "Health: "+fmt.Sprintf("%#v", this.Health)+",\n") s = append(s, "}") return strings.Join(s, "") } @@ -883,6 +908,20 @@ func (m *RulesRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.Health) > 0 { + i -= len(m.Health) + copy(dAtA[i:], m.Health) + i = encodeVarintRuler(dAtA, i, uint64(len(m.Health))) + i-- + dAtA[i] = 0x32 + } + if len(m.State) > 0 { + i -= len(m.State) + copy(dAtA[i:], m.State) + i = encodeVarintRuler(dAtA, i, uint64(len(m.State))) + i-- + dAtA[i] = 0x2a + } if len(m.Type) > 0 { i -= len(m.Type) copy(dAtA[i:], m.Type) @@ -1259,6 +1298,14 @@ func (m *RulesRequest) Size() (n int) { if l > 0 { n += 1 + l + sovRuler(uint64(l)) } + l = len(m.State) + if l > 0 { + n += 1 + l + sovRuler(uint64(l)) + } + l = len(m.Health) + if l > 0 { + n += 1 + l + sovRuler(uint64(l)) + } return n } @@ -1390,6 +1437,8 @@ func (this *RulesRequest) String() string { `RuleGroupNames:` + fmt.Sprintf("%v", this.RuleGroupNames) + `,`, `Files:` + fmt.Sprintf("%v", this.Files) + `,`, `Type:` + fmt.Sprintf("%v", this.Type) + `,`, + `State:` + fmt.Sprintf("%v", this.State) + `,`, + `Health:` + fmt.Sprintf("%v", this.Health) + `,`, `}`, }, "") return s @@ -1632,6 +1681,70 @@ func (m *RulesRequest) Unmarshal(dAtA []byte) error { } m.Type = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field State", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowRuler + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthRuler + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthRuler + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.State = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Health", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowRuler + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthRuler + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthRuler + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Health = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipRuler(dAtA[iNdEx:]) diff --git a/pkg/ruler/ruler.proto b/pkg/ruler/ruler.proto index da653b8651..15f3b0bccb 100644 --- a/pkg/ruler/ruler.proto +++ b/pkg/ruler/ruler.proto @@ -24,6 +24,8 @@ message RulesRequest { repeated string ruleGroupNames = 2; repeated string files = 3; string type = 4; + string state = 5; + string health = 6; } message RulesResponse { diff --git a/pkg/ruler/ruler_test.go b/pkg/ruler/ruler_test.go index f04d02d6d4..937e2d1b01 100644 --- a/pkg/ruler/ruler_test.go +++ b/pkg/ruler/ruler_test.go @@ -526,6 +526,54 @@ func TestGetRules(t *testing.T) { }, expectedClientCallCount: len(expectedRules), }, + "No Sharding with Alert state filter for firing alerts": { + sharding: false, + rulesRequest: RulesRequest{ + State: firingStateFilter, + }, + rulerStateMap: rulerStateMapAllActive, + expectedCount: map[string]int{ + "user1": 0, + "user2": 0, + "user3": 0, + }, + }, + "No Sharding with Alert state filter for inactive alerts": { + sharding: false, + rulesRequest: RulesRequest{ + State: inactiveStateFilter, + }, + rulerStateMap: rulerStateMapAllActive, + expectedCount: map[string]int{ + "user1": 2, + "user2": 4, + "user3": 2, + }, + }, + "No Sharding with health filter for OK alerts": { + sharding: false, + rulesRequest: RulesRequest{ + Health: okHealthFilter, + }, + rulerStateMap: rulerStateMapAllActive, + expectedCount: map[string]int{ + "user1": 0, + "user2": 0, + "user3": 0, + }, + }, + "No Sharding with health filter for unknown alerts": { + sharding: false, + rulesRequest: RulesRequest{ + Health: unknownHealthFilter, + }, + rulerStateMap: rulerStateMapAllActive, + expectedCount: map[string]int{ + "user1": 5, + "user2": 9, + "user3": 3, + }, + }, "Default Sharding with No Filter": { sharding: true, shardingStrategy: util.ShardingStrategyDefault,