Beispiel #1
0
func NewVectorAggregation(aggrTypeStr string, vector ast.Node, groupBy []model.LabelName) (*ast.VectorAggregation, error) {
	if vector.Type() != ast.VECTOR {
		return nil, fmt.Errorf("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, fmt.Errorf("Unknown aggregation type '%v'", aggrTypeStr)
	}
	return ast.NewVectorAggregation(aggrType, vector.(ast.VectorNode), groupBy), nil
}
Beispiel #2
0
func CreateRule(name string, labels model.LabelSet, root ast.Node, permanent bool) (*Rule, error) {
	if root.Type() != ast.VECTOR {
		return nil, fmt.Errorf("Rule %v does not evaluate to vector type", name)
	}
	return NewRule(name, labels, root.(ast.VectorNode), permanent), nil
}