func (s Synthesizer) getMatchingRule(metricName string, attributes labels.Set) (rule EntityRule, found bool) {
	var match *conditionGroup
	for i, cg := range s.conditionList {
		value := metricName
		if cg.condition.Attribute != "metricName" {
			val, ok := attributes[cg.condition.Attribute]
			if !ok {
				continue
			}
			value, _ = val.(string)
		}
		if cg.condition.match(value) && (match == nil || len(cg.condition.Prefix) > len(match.condition.Prefix)) {  
			match = &s.conditionList[i]
		}
	}
	if match != nil {
		return match.rule, true
	}
	return
}
getMatchingRule iterates over all conditions to check if m satisfy returning the associated rule.
package synthesis
import (
	"strings"
	sdk_metadata "github.com/newrelic/infra-integrations-sdk/v4/data/metadata"
	"github.com/newrelic/nri-prometheus/internal/pkg/labels"
)
type Synthesizer struct {
	conditionList []conditionGroup  
}
type conditionGroup struct {
	condition Condition
	rule      EntityRule
}
func NewSynthesizer(entitySynthesisDefinitions []Definition) Synthesizer {
	s := Synthesizer{}
	for _, definition := range entitySynthesisDefinitions {
		definition.tagRules = definition.Tags.getTagRules()
		s.addConditions(definition.EntityRule)
		for _, rule := range definition.Rules {
			rule.EntityType = definition.EntityType
			rule.tagRules = append(rule.Tags.getTagRules(), definition.EntityRule.tagRules...)
			s.addConditions(rule)
		}
	}
	return s
}
func (s *Synthesizer) addConditions(rule EntityRule) {
	if !rule.isValid() {
		return
	}
	for _, c := range rule.Conditions {
		s.conditionList = append(s.conditionList, conditionGroup{c, rule})
	}
}
type Definition struct {
	EntityRule `mapstructure:",squash"`
	Rules      []EntityRule `mapstructure:"rules"`
}
type EntityRule struct {
	EntityType string      `mapstructure:"type"`
	Identifier string      `mapstructure:"identifier"`  
	Name       string      `mapstructure:"name"`        
	Conditions []Condition `mapstructure:"conditions"`  
	Tags       Tags        `mapstructure:"tags"`        
	tagRules   []tagRule    
}
func (rule EntityRule) isValid() bool {
	return rule.Identifier != "" && rule.Name != "" && rule.EntityType != ""
}
type Condition struct {
	Attribute string `mapstructure:"attribute"`
	Prefix    string `mapstructure:"prefix"`
	Value     string `mapstructure:"value"`
}
func (c Condition) match(attribute string) bool {
	if c.Value != "" {
		return c.Value == attribute
	}
	return strings.HasPrefix(attribute, c.Prefix)
}
type Tags map[string]map[string]interface{}
type tagRule struct {
	sourceAttribute string  
	entityTagName   string  
}
func (t Tags) getTagRules() []tagRule {
	var tagRules []tagRule
	for attributeName, rules := range t {
		if rules == nil {
			tagRules = append(tagRules, tagRule{sourceAttribute: attributeName, entityTagName: attributeName})
			continue
		}
		if newName, ok := rules["entityTagName"]; ok {
			newNameS, _ := newName.(string)
			tagRules = append(tagRules, tagRule{sourceAttribute: attributeName, entityTagName: newNameS})
		}
	}
	return tagRules
}
func (s Synthesizer) GetEntityMetadata(metricName string, attributes labels.Set) (sdk_metadata.Metadata, bool) {
	rule, found := s.getMatchingRule(metricName, attributes)
	if !found {
		return sdk_metadata.Metadata{}, false
	}
	entityName := getEntityAttribute(attributes, rule.Identifier)
	entityDisplayName := getEntityAttribute(attributes, rule.Name)
	if entityName == "" || entityDisplayName == "" {
		return sdk_metadata.Metadata{}, false
	}
	entityName = rule.EntityType + ":" + entityName
	md := sdk_metadata.New(entityName, rule.EntityType, entityDisplayName)
	for _, t := range rule.tagRules {
		if tagVal, ok := attributes[t.sourceAttribute]; ok {
			md.AddTag(t.entityTagName, tagVal)
		}
	}
	return *md, true
}