From 62bf56a7701e183446c3ef1055ac0e751a0d3c55 Mon Sep 17 00:00:00 2001 From: Nathaniel Cook Date: Wed, 21 Oct 2015 17:23:52 -0600 Subject: [PATCH] add circle and .hooks --- .hooks/pre-commit | 15 +++++++++++++++ alert.go | 6 +++--- circle.yml | 16 ++++++++++++++++ cmd/kapacitor/main.go | 2 +- expr.go | 2 +- expr/lex.go | 4 ++-- expr/node.go | 4 ++-- functions.go | 8 ++++---- integrations/helpers_test.go | 2 +- pipeline/map_reduce.go | 4 ++-- pipeline/node.go | 4 ++-- stream.go | 2 +- where.go | 2 +- 13 files changed, 51 insertions(+), 20 deletions(-) create mode 100755 .hooks/pre-commit create mode 100644 circle.yml diff --git a/.hooks/pre-commit b/.hooks/pre-commit new file mode 100755 index 000000000..a12ccac8a --- /dev/null +++ b/.hooks/pre-commit @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +fmtcount=`git ls-files | grep '.go$' | xargs gofmt -l 2>&1 | wc -l` +if [ $fmtcount -gt 0 ]; then + echo "Some files aren't formatted, please run 'go fmt ./...' to format your source code before committing" + exit 1 +fi + +# Due to the way composites work, vet will fail for some of our tests so we ignore it +vetcount=`go tool vet --composites=false ./ 2>&1 | wc -l` +if [ $vetcount -gt 0 ]; then + echo "Some files aren't passing vet heuristics, please run 'go vet ./...' to see the errors it flags and correct your source code before committing" + exit 1 +fi +exit 0 diff --git a/alert.go b/alert.go index bbae4e15d..8adbff56e 100644 --- a/alert.go +++ b/alert.go @@ -98,21 +98,21 @@ func newAlertNode(et *ExecutingTask, n *pipeline.AlertNode) (an *AlertNode, err if err != nil { return nil, err } - an.levels[InfoAlert] = &expr.StatefulExpr{tree, expr.Functions()} + an.levels[InfoAlert] = &expr.StatefulExpr{Tree: tree, Funcs: expr.Functions()} } if n.Warn != "" { tree, err := expr.ParseForType(n.Warn, expr.ReturnBool) if err != nil { return nil, err } - an.levels[WarnAlert] = &expr.StatefulExpr{tree, expr.Functions()} + an.levels[WarnAlert] = &expr.StatefulExpr{Tree: tree, Funcs: expr.Functions()} } if n.Crit != "" { tree, err := expr.ParseForType(n.Crit, expr.ReturnBool) if err != nil { return nil, err } - an.levels[CritAlert] = &expr.StatefulExpr{tree, expr.Functions()} + an.levels[CritAlert] = &expr.StatefulExpr{Tree: tree, Funcs: expr.Functions()} } // Configure flapping if n.UseFlapping { diff --git a/circle.yml b/circle.yml new file mode 100644 index 000000000..a6a203788 --- /dev/null +++ b/circle.yml @@ -0,0 +1,16 @@ +machine: + environment: + IMPORT_PATH: "github.com/influxdb/kapacitor" + +dependencies: + override: + - mkdir -p "$GOPATH/src/$IMPORT_PATH" + - rsync -azC --delete ./ "$GOPATH/src/$IMPORT_PATH/" + +test: + pre: + - go vet ./... + - go get ./... + + override: + - go test ./... diff --git a/cmd/kapacitor/main.go b/cmd/kapacitor/main.go index a9b7f58a0..6f02348f2 100644 --- a/cmd/kapacitor/main.go +++ b/cmd/kapacitor/main.go @@ -289,7 +289,7 @@ Options: func doDefine(args []string) error { - if *dtick == "" || *dname == "" || *dtick == "" { + if *dtick == "" || *dname == "" || *dtype == "" { fmt.Fprintln(os.Stderr, "Must pass name,tick and type options.") defineFlags.Usage() os.Exit(2) diff --git a/expr.go b/expr.go index 52bb9d953..a83c0bf8c 100644 --- a/expr.go +++ b/expr.go @@ -17,7 +17,7 @@ func ExprFunc(field, e string) (TransFunc, error) { } x := &expression{ field: field, - se: &expr.StatefulExpr{t, expr.Functions()}, + se: &expr.StatefulExpr{Tree: t, Funcs: expr.Functions()}, } return TransFunc(x.Eval), nil } diff --git a/expr/lex.go b/expr/lex.go index 3a55516ca..06585cb11 100644 --- a/expr/lex.go +++ b/expr/lex.go @@ -365,7 +365,7 @@ func isValidIdent(r rune) bool { func lexString(l *lexer) stateFn { if n := l.next(); n != '\'' { - return l.errorf(`unexpected "%s" expected "'"`, n) + return l.errorf(`unexpected "%c" expected "'"`, n) } for { switch r := l.next(); { @@ -384,7 +384,7 @@ func lexString(l *lexer) stateFn { func lexRegex(l *lexer) stateFn { if n := l.next(); n != '/' { - return l.errorf(`unexpected "%s" expected "/"`, n) + return l.errorf(`unexpected "%c" expected "/"`, n) } for { switch r := l.next(); { diff --git a/expr/node.go b/expr/node.go index 98b99bf66..3595f05ad 100644 --- a/expr/node.go +++ b/expr/node.go @@ -522,7 +522,7 @@ func compareStrs(l, r string, o tokenType) (b bool, err error) { case tokenRegexNotEqual: b, err = regexp.MatchString(l, r) default: - fmt.Errorf("unsupported operator %v on strings", o) + err = fmt.Errorf("unsupported operator %v on strings", o) } return } @@ -542,7 +542,7 @@ func compareNums(l, r float64, o tokenType) (b bool, err error) { case tokenNotEqual: b = l != r default: - fmt.Errorf("unsupported operator %v on numbers", o) + err = fmt.Errorf("unsupported operator %v on numbers", o) } return } diff --git a/functions.go b/functions.go index 273ee8795..5ca71646b 100644 --- a/functions.go +++ b/functions.go @@ -100,11 +100,11 @@ func (influxqlMapReducers) Bottom(field string, limit int64, fields ...string) p // create MapReduceInfo func mr(field, newField string, m func(*tsdb.MapInput) interface{}, r func([]interface{}) interface{}) pipeline.MapReduceInfo { return pipeline.MapReduceInfo{ - MapInfo{ - field, - m, + Map: MapInfo{ + Field: field, + Func: m, }, - reduce(r, newField), + Reduce: reduce(r, newField), } } diff --git a/integrations/helpers_test.go b/integrations/helpers_test.go index 65aca4cf5..f52a056b6 100644 --- a/integrations/helpers_test.go +++ b/integrations/helpers_test.go @@ -33,7 +33,7 @@ func (m *MockInfluxDBService) NewClient() (*client.Client, error) { func compareResults(exp, got kapacitor.Result) (bool, string) { if (exp.Err == nil && got.Err != nil) || (exp.Err != nil && got.Err == nil) { - return false, fmt.Sprintf("unexpected error: exp %p got %p", exp.Err, got.Err) + return false, fmt.Sprintf("unexpected error: exp %v got %v", exp.Err, got.Err) } if exp.Err != nil && exp.Err.Error() != got.Err.Error() { return false, fmt.Sprintf("unexpected error: exp %v got %v", exp.Err, got.Err) diff --git a/pipeline/map_reduce.go b/pipeline/map_reduce.go index db0760bbc..85ab6ddd7 100644 --- a/pipeline/map_reduce.go +++ b/pipeline/map_reduce.go @@ -2,8 +2,8 @@ package pipeline // tick:ignore type MapReduceInfo struct { - MapI interface{} - ReduceI interface{} + Map interface{} + Reduce interface{} } // Performs a map operation on the data stream. diff --git a/pipeline/node.go b/pipeline/node.go index 3acd298cf..8f9c8d0ab 100644 --- a/pipeline/node.go +++ b/pipeline/node.go @@ -283,8 +283,8 @@ func (n *chainnode) MapReduce(mr MapReduceInfo) *ReduceNode { case StreamEdge: panic("cannot MapReduce stream edge, did you forget to window the data?") case BatchEdge: - m = newMapNode(mr.MapI) - r = newReduceNode(mr.ReduceI) + m = newMapNode(mr.Map) + r = newReduceNode(mr.Reduce) } n.linkChild(m) m.linkChild(r) diff --git a/stream.go b/stream.go index 6593c62ba..5df0348c4 100644 --- a/stream.go +++ b/stream.go @@ -38,7 +38,7 @@ func newStreamNode(et *ExecutingTask, n *pipeline.StreamNode) (*StreamNode, erro if err != nil { return nil, err } - sn.predicate = &expr.StatefulExpr{tree, expr.Functions()} + sn.predicate = &expr.StatefulExpr{Tree: tree, Funcs: expr.Functions()} } return sn, nil } diff --git a/where.go b/where.go index 55df16fd8..3453b6e4c 100644 --- a/where.go +++ b/where.go @@ -30,7 +30,7 @@ func newWhereNode(et *ExecutingTask, n *pipeline.WhereNode) (wn *WhereNode, err if err != nil { return nil, err } - wn.predicate = &expr.StatefulExpr{tree, expr.Functions()} + wn.predicate = &expr.StatefulExpr{Tree: tree, Funcs: expr.Functions()} return }