github.com/muhammadn/cortex@v1.9.1-0.20220510110439-46bb7000d03d/pkg/ruler/rulespb/custom.go (about)

     1  package rulespb
     2  
     3  import "github.com/prometheus/prometheus/pkg/rulefmt"
     4  
     5  // RuleGroupList contains a set of rule groups
     6  type RuleGroupList []*RuleGroupDesc
     7  
     8  // Formatted returns the rule group list as a set of formatted rule groups mapped
     9  // by namespace
    10  func (l RuleGroupList) Formatted() map[string][]rulefmt.RuleGroup {
    11  	ruleMap := map[string][]rulefmt.RuleGroup{}
    12  	for _, g := range l {
    13  		if _, exists := ruleMap[g.Namespace]; !exists {
    14  			ruleMap[g.Namespace] = []rulefmt.RuleGroup{FromProto(g)}
    15  			continue
    16  		}
    17  		ruleMap[g.Namespace] = append(ruleMap[g.Namespace], FromProto(g))
    18  
    19  	}
    20  	return ruleMap
    21  }