func (m *Manager) LoadGroups(
	interval time.Duration, externalLabels labels.Labels, filenames ...string,
) (map[string]*Group, []error) {
	groups := make(map[string]*Group)

	shouldRestore := !m.restored

	for _, fn := range filenames {
		rgs, errs := rulefmt.ParseFile(fn)
		if errs != nil {
			return nil, errs
		}

		for _, rg := range rgs.Groups {
			itv := interval
			if rg.Interval != 0 {
				itv = time.Duration(rg.Interval)
			}

			rules := make([]Rule, 0, len(rg.Rules))
			for _, r := range rg.Rules {
				expr, err := promql.ParseExpr(r.Expr)
				if err != nil {
					return nil, []error{err}
				}

				if r.Alert != "" {
					rules = append(rules, NewAlertingRule(
						r.Alert,
						expr,
						time.Duration(r.For),
						labels.FromMap(r.Labels),
						labels.FromMap(r.Annotations),
						externalLabels,
						m.restored,
						log.With(m.logger, "alert", r.Alert),
					))
					continue
				}
				rules = append(rules, NewRecordingRule(
					r.Record,
					expr,
					labels.FromMap(r.Labels),
				))
			}

			groups[groupKey(rg.Name, fn)] = NewGroup(rg.Name, fn, itv, rules, shouldRestore, m.opts)
		}
	}

	return groups, nil
}
func (m *Manager) LoadGroups(
	interval time.Duration, externalLabels labels.Labels, filenames ...string,
) (map[string]*Group, []error) {
	groups := make(map[string]*Group)

	shouldRestore := !m.restored

	for _, fn := range filenames {
		rgs, errs := rulefmt.ParseFile(fn)
		if errs != nil {
			return nil, errs
		}

		for _, rg := range rgs.Groups {
			itv := interval
			if rg.Interval != 0 {
				itv = time.Duration(rg.Interval)
			}

			rules := make([]Rule, 0, len(rg.Rules))
			for _, r := range rg.Rules {
				expr, err := promql.ParseExpr(r.Expr)
				if err != nil {
					return nil, []error{err}
				}

				if r.Alert != "" {
					rules = append(rules, NewAlertingRule(
						r.Alert,
						expr,
						time.Duration(r.For),
						labels.FromMap(r.Labels),
						labels.FromMap(r.Annotations),
						externalLabels,
						m.restored,
						log.With(m.logger, "alert", r.Alert),
					))
					continue
				}
				rules = append(rules, NewRecordingRule(
					r.Record,
					expr,
					labels.FromMap(r.Labels),
				))
			}

			groups[groupKey(rg.Name, fn)] = NewGroup(rg.Name, fn, itv, rules, shouldRestore, m.opts)
		}
	}

	return groups, nil
}
func ( m * Manager ) LoadGroups ( interval time . Duration , externalLabels labels . Labels , filenames ... string , ) ( map [ string ] * Group , [ ] error ) { groups := make ( map [ string ] * Group ) shouldRestore := ! m . restored for _ , fn := range filenames { rgs , errs := rulefmt . ParseFile ( fn ) if errs != nil { return nil , errs } for _ , rg := range rgs . Groups { itv := interval if rg . Interval != 0 { itv = time . Duration ( rg . Interval ) } rules := make ( [ ] Rule , 0 , len ( rg . Rules ) ) for _ , r := range rg . Rules { expr , err := promql . ParseExpr ( r . Expr ) if err != nil { return nil , [ ] error { err } } if r . Alert != " " { rules = append ( rules , NewAlertingRule ( r . Alert , expr , time . Duration ( r . For ) , labels . FromMap ( r . Labels ) , labels . FromMap ( r . Annotations ) , externalLabels , m . restored , log . With ( m . logger , " " , r . Alert ) , ) ) continue } rules = append ( rules , NewRecordingRule ( r . Record , expr , labels . FromMap ( r . Labels ) , ) ) } groups [ groupKey ( rg . Name , fn ) ] = NewGroup ( rg . Name , fn , itv , rules , shouldRestore , m . opts ) } } return groups , nil }
// LoadGroups reads groups from a list of files.
LoadGroups reads groups from a list of files .