Skip to content
This repository has been archived by the owner on Aug 12, 2024. It is now read-only.

Commit

Permalink
Add a datadog event when the file isn't long enough on in. Closes #62.
Browse files Browse the repository at this point in the history
Also added metrics for checksum and length failures on `out`.
  • Loading branch information
darron committed Dec 23, 2015
1 parent 010a9e4 commit 6325c68
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
37 changes: 37 additions & 0 deletions commands/datadog.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,30 @@ func StatsdLocked(file string) {
}
}

// StatsdLength sends metrics to Dogstatsd on a `kvexpress out` operation
// where the file isn't long enough.
func StatsdLength(key string) {
if DogStatsd {
Log(fmt.Sprintf("dogstatsd='true' key='%s' stats='not_long_enough'", key), "debug")
statsd, _ := godspeed.NewDefault()
defer statsd.Conn.Close()
tags := makeTags(key, "not_long_enough")
statsd.Incr("kvexpress.not_long_enough", tags)
}
}

// StatsdChecksum sends metrics to Dogstatsd on a `kvexpress out` operation
// where the checksum doesn't match.
func StatsdChecksum(key string) {
if DogStatsd {
Log(fmt.Sprintf("dogstatsd='true' key='%s' stats='checksum_mismatch'", key), "debug")
statsd, _ := godspeed.NewDefault()
defer statsd.Conn.Close()
tags := makeTags(key, "checksum_mismatch")
statsd.Incr("kvexpress.checksum_mismatch", tags)
}
}

// StatsdLock sends metrics to Dogstatsd on a `kvexpress lock` operation.
func StatsdLock(key string) {
if DogStatsd {
Expand Down Expand Up @@ -141,6 +165,19 @@ func DDStopEvent(dd *datadog.Client, key, value string) {
}
}

// DDLengthEvent sends a Datadog event to the API when the file/url is too short.
func DDLengthEvent(dd *datadog.Client, key, value string) {
Log(fmt.Sprintf("datadog='true' DDLengthEvent='true' key='%s'", key), "debug")
tags := makeTags(key, "not_long_enough")
tags = append(tags, "kvexpress:length")
title := fmt.Sprintf("Not long enough: %s. Stopping.", key)
event := datadog.Event{Title: title, Text: value, AlertType: "error", Tags: tags}
post, _ := dd.PostEvent(&event)
if post != nil {

}
}

// DDSaveDataEvent sends a Datadog event to the API when we have updated a Consul key.
func DDSaveDataEvent(dd *datadog.Client, key, value string) {
Log(fmt.Sprintf("datadog='true' DDSaveDataEvent='true' key='%s'", key), "debug")
Expand Down
4 changes: 3 additions & 1 deletion commands/in.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ func inRun(cmd *cobra.Command, args []string) {

if !longEnough {
Log("File is NOT long enough. Stopping.", "info")
// TODO: Add Datadog Event here.
if DatadogAPIKey != "" && DatadogAPPKey != "" {
DDLengthEvent(dog, KeyInLocation, FileString)
}
RunTime(start, KeyInLocation, "not_long_enough")
os.Exit(1)
}
Expand Down
9 changes: 8 additions & 1 deletion commands/out.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,14 @@ func outRun(cmd *cobra.Command, args []string) {
WriteFile(KVData, FiletoWrite, FilePermissions, Owner)
StatsdOut(KeyOutLocation)
} else {
Log("longEnough='no'", "info")
if !longEnough {
Log("longEnough='no'", "info")
StatsdLength(KeyOutLocation)
}
if !checksumMatch {
Log("checksumMismatch='yes'", "info")
StatsdChecksum(KeyOutLocation)
}
os.Exit(0)
}

Expand Down

0 comments on commit 6325c68

Please sign in to comment.