From 2b6155b14ee8d3a8ad11ad7e73a2513f5ef1cce2 Mon Sep 17 00:00:00 2001 From: Andre Cloutier Date: Wed, 25 Jan 2017 22:13:50 -0800 Subject: [PATCH 1/2] Added statd host argument --- args.go | 3 ++- args_test.go | 6 ++++++ cronner.go | 9 +++++++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/args.go b/args.go index 3f91192..a3daa8c 100644 --- a/args.go +++ b/args.go @@ -21,6 +21,7 @@ type binArgs struct { CmdArgs []string // this is not a command line flag, also parsed results LockDir string `short:"d" long:"lock-dir" default:"/var/lock" description:"the directory where lock files will be placed"` AllEvents bool `short:"e" long:"event" description:"emit a start and end datadog event"` + StatsdHost string `short:"H" long:"statsd-host" value-name:"" description:"destination host to send datadog metrics"` FailEvent bool `short:"E" long:"event-fail" description:"only emit an event on failure"` LogFail bool `short:"F" long:"log-fail" description:"when a command fails, log its full output (stdout/stderr) to the log directory using the UUID as the filename"` EventGroup string `short:"G" long:"event-group" value-name:"" description:"emit a cronner_group: tag with Datadog events, does not get sent with statsd metrics"` @@ -70,7 +71,7 @@ func (a *binArgs) parse(args []string) (string, error) { } if a.Version { - out := fmt.Sprintf("cronner v%s built with %s\nCopyright 2015 PagerDuty, Inc.; released under the BSD 3-Clause License\n", Version, runtime.Version()) + out := fmt.Sprintf("cronner v%s built with %s\nCopyright 2017 PagerDuty, Inc.; released under the BSD 3-Clause License\n", Version, runtime.Version()) return out, nil } diff --git a/args_test.go b/args_test.go index 156eb8f..2802285 100644 --- a/args_test.go +++ b/args_test.go @@ -122,6 +122,7 @@ func (t *TestSuite) Test_binArgs_parse(c *C) { "-F", "-G", "test_group", "-g", "metric_group", + "-H", 'test_host', "-k", "-l", "test", "-L", "info", @@ -146,6 +147,7 @@ func (t *TestSuite) Test_binArgs_parse(c *C) { c.Check(args.LogFail, Equals, true) c.Check(args.EventGroup, Equals, "test_group") c.Check(args.Group, Equals, "metric_group") + c.Check(args.StatsdHost, Equals, "test_host") c.Check(args.Lock, Equals, true) c.Check(args.Label, Equals, "test") c.Check(args.LogLevel, Equals, "info") @@ -169,6 +171,7 @@ func (t *TestSuite) Test_binArgs_parse(c *C) { "--log-fail", "--event-group", "test_group", "--group", "metric_group", + "--statsd-host", 'test_host', "--lock", "--label", "test", "--log-path", "/var/log/testcronner", @@ -191,6 +194,7 @@ func (t *TestSuite) Test_binArgs_parse(c *C) { c.Check(args.LogFail, Equals, true) c.Check(args.EventGroup, Equals, "test_group") c.Check(args.Group, Equals, "metric_group") + c.Check(args.StatsdHost, Equals, "test_host") c.Check(args.Lock, Equals, true) c.Check(args.Label, Equals, "test") c.Check(args.LogPath, Equals, "/var/log/testcronner") @@ -214,6 +218,7 @@ func (t *TestSuite) Test_binArgs_parse(c *C) { "--group=metric_group", "--label=test", "--log-path=/var/log/testcronner", + "--statsd-host=test_host" "--log-level=info", "--namespace=testcronner", "--warn-after=42", @@ -231,6 +236,7 @@ func (t *TestSuite) Test_binArgs_parse(c *C) { c.Check(args.Group, Equals, "metric_group") c.Check(args.Label, Equals, "test") c.Check(args.LogPath, Equals, "/var/log/testcronner") + c.Check(args.StatsdHost, Equals, "test_host") c.Check(args.LogLevel, Equals, "info") c.Check(args.Namespace, Equals, "testcronner") c.Check(args.WarnAfter, Equals, uint64(42)) diff --git a/cronner.go b/cronner.go index 82c8c48..c61984d 100644 --- a/cronner.go +++ b/cronner.go @@ -16,7 +16,7 @@ import ( ) // Version is the program's version string -const Version = "0.2.5" +const Version = "0.2.6" type cmdHandler struct { gs *godspeed.Godspeed @@ -46,7 +46,12 @@ func main() { } // build a Godspeed client - gs, err := godspeed.NewDefault() + var gs *godspeed.Godspeed + if opts.StatsdHost == "" { + gs, err = godspeed.NewDefault() + } else { + gs, err = godspeed.New(opts.StatsdHost, godspeed.DefaultPort, false) + } // make sure nothing went wrong with Godspeed if err != nil { From ce0621c094742b73b33e36a69975993ce9ccde96 Mon Sep 17 00:00:00 2001 From: Andre Cloutier Date: Thu, 26 Jan 2017 10:20:09 -0800 Subject: [PATCH 2/2] Fixed up tests and bumped go version --- .travis.yml | 2 +- args_test.go | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index a133059..c4c9639 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: go go: -- 1.5.3 +- 1.7.4 addons: apt: packages: diff --git a/args_test.go b/args_test.go index 2802285..73483c0 100644 --- a/args_test.go +++ b/args_test.go @@ -64,7 +64,7 @@ func (t *TestSuite) Test_binArgs_parse(c *C) { "-V", } - verOut := fmt.Sprintf("cronner v%s built with %s\nCopyright 2015 PagerDuty, Inc.; released under the BSD 3-Clause License\n", Version, runtime.Version()) + verOut := fmt.Sprintf("cronner v%s built with %s\nCopyright 2017 PagerDuty, Inc.; released under the BSD 3-Clause License\n", Version, runtime.Version()) output, err = args.parse(cli) c.Assert(err, IsNil) @@ -122,7 +122,7 @@ func (t *TestSuite) Test_binArgs_parse(c *C) { "-F", "-G", "test_group", "-g", "metric_group", - "-H", 'test_host', + "-H", "test_host", "-k", "-l", "test", "-L", "info", @@ -171,7 +171,7 @@ func (t *TestSuite) Test_binArgs_parse(c *C) { "--log-fail", "--event-group", "test_group", "--group", "metric_group", - "--statsd-host", 'test_host', + "--statsd-host", "test_host", "--lock", "--label", "test", "--log-path", "/var/log/testcronner", @@ -218,7 +218,7 @@ func (t *TestSuite) Test_binArgs_parse(c *C) { "--group=metric_group", "--label=test", "--log-path=/var/log/testcronner", - "--statsd-host=test_host" + "--statsd-host=test_host", "--log-level=info", "--namespace=testcronner", "--warn-after=42",