示例#1
0
func NewVectorAggregation(aggrTypeStr string, vector ast.Node, groupBy []model.LabelName) (*ast.VectorAggregation, error) {
	if vector.Type() != ast.VECTOR {
		return nil, rulesError("Operand of %v aggregation must be of vector type", aggrTypeStr)
	}
	var aggrTypes = map[string]ast.AggrType{
		"SUM": ast.SUM,
		"MAX": ast.MAX,
		"MIN": ast.MIN,
		"AVG": ast.AVG,
	}
	aggrType, ok := aggrTypes[aggrTypeStr]
	if !ok {
		return nil, rulesError("Unknown aggregation type '%v'", aggrTypeStr)
	}
	return ast.NewVectorAggregation(aggrType, vector.(ast.VectorNode), groupBy), nil
}
示例#2
0
func CreateRule(name string, labels model.LabelSet, root ast.Node, permanent bool) (*Rule, error) {
	if root.Type() != ast.VECTOR {
		return nil, rulesError("Rule %v does not evaluate to vector type", name)
	}
	return NewRule(name, labels, root.(ast.VectorNode), permanent), nil
}