示例#1
0
func TestParser(t *testing.T) {
	inputs := []string{
		"test > 15 times 3",
		"avg(cpu_util{t1=v1,t2=v2}, 5s) > 30.0 or avg(sum(test)) > 16.0 and sum(test2) < 13",
		"(avg(cpu_util{t1=v1,t2=v2}, 5s) > 30.0 or avg(sum(test)) > 16.0) and sum(test2) < 13",
		"avg(cpu_util{t1=v1,t2=v2}, 5s) > 30.0 or avg(sum(test{t1=v1})) > 16.0 and sum(test2) < 13, t1",
	}
	expected := []alarmDefinition{
		alarmDefinition{
			LeafNode{dagger.StreamID("test"), GT, 15.0, 3},
			"",
		},
		alarmDefinition{
			BinNode{OR,
				LeafNode{dagger.StreamID("avg(cpu_util{t1=v1,t2=v2}, 5s)"), GT, 30.0, 1},
				BinNode{AND,
					LeafNode{dagger.StreamID("avg(sum(test))"), GT, 16.0, 1},
					LeafNode{dagger.StreamID("sum(test2)"), LT, 13.0, 1}},
			},
			"",
		},
		alarmDefinition{
			BinNode{AND,
				BinNode{OR,
					LeafNode{dagger.StreamID("avg(cpu_util{t1=v1,t2=v2}, 5s)"), GT, 30.0, 1},
					LeafNode{dagger.StreamID("avg(sum(test))"), GT, 16.0, 1},
				},
				LeafNode{dagger.StreamID("sum(test2)"), LT, 13.0, 1},
			},
			"",
		},
		alarmDefinition{
			BinNode{OR,
				LeafNode{dagger.StreamID("avg(cpu_util{t1=v1,t2=v2}, 5s)"), GT, 30.0, 1},
				BinNode{AND,
					LeafNode{dagger.StreamID("avg(sum(test{t1=v1}))"), GT, 16.0, 1},
					LeafNode{dagger.StreamID("sum(test2)"), LT, 13.0, 1}},
			},
			"t1",
		},
	}

	for i, input := range inputs {
		tree, err := Parse("alarmDef", []byte(input))
		if err != nil {
			t.Error(err)
		}
		assert.Equal(t, expected[i], tree)
	}
}
示例#2
0
文件: foo.go 项目: nsaje/dagger
func (c *FooComputation) GetInfo(definition string) (dagger.ComputationPluginInfo, error) {
	info := dagger.ComputationPluginInfo{
		Inputs:   []dagger.StreamID{dagger.StreamID(definition)},
		Stateful: true,
	}
	return info, nil
}
示例#3
0
func subscriberAction(c *cli.Context) {
	initLogging(c)
	fmt.Println(c.Args())
	errc := make(chan error)
	persister, err := dagger.NewPersister(persisterConfFromFlags(c))
	if err != nil {
		log.Fatalf("error opening database")
	}
	defer persister.Close()

	prnter := &printer{dataonly: c.Bool("dataonly")}

	coordinator := dagger.NewConsulCoordinator(consulConfFromFlags(c))
	receiver := dagger.NewReceiver(coordinator, receiverConfFromFlags(c))
	go receiver.Listen(errc)

	advertiseAddr := getAdvertiseAddr(c, receiver)
	err = coordinator.Start(advertiseAddr, errc)
	defer coordinator.Stop()
	if err != nil {
		log.Fatalf("Error starting coordinator %s", err)
	}

	topicGlob := dagger.StreamID(c.Args().First())
	lwmTracker := dagger.NewLWMTracker()
	linearizer := dagger.NewLinearizer("test", persister, lwmTracker)
	linearizer.SetProcessor(prnter)
	go linearizer.Run(errc)
	from, err := strconv.ParseInt(c.String("from"), 10, 64)
	if err != nil {
		panic(err)
	}

	if !c.IsSet("groupby") {
		receiver.SubscribeTo(topicGlob, dagger.Timestamp(from), linearizer)
		log.Printf("Subscribed to %s", topicGlob)
	} else {
		matchers := strings.Split(c.String("groupby"), ",")
		varargs := make([]interface{}, len(matchers))
		for i := range matchers {
			matchers[i] = strings.TrimSpace(matchers[i])
			varargs[i] = matchers[i]
		}
		testString := fmt.Sprintf(string(topicGlob), varargs...)
		if strings.Contains(testString, "%!") {
			log.Printf("Group by parameter has too few or too many values")
			return
		}
		// go match(topicGlob, matchers, errc)
	}

	handleSignals(errc)
}
示例#4
0
文件: parser.go 项目: nsaje/dagger
func (c *current) onSubExpr2(streamID, op, thresholdValue, times interface{}) (interface{}, error) {
	periods := 1
	if times != nil {
		periods = times.(int)
	}
	return LeafNode{
		dagger.StreamID(streamID.(string)),
		op.(RelationalOperator),
		thresholdValue.(float64),
		periods,
	}, nil
}