Skip to content

Commit

Permalink
Merge pull request #38 from Comcast/fix/cleaup-failure-reporting
Browse files Browse the repository at this point in the history
Update the failure reporting logging.
  • Loading branch information
schmidtw authored Aug 8, 2017
2 parents 54009ac + e8db624 commit f40b441
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
19 changes: 10 additions & 9 deletions src/caduceus/outboundSender.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,13 +413,14 @@ func (obs *CaduceusOutboundSender) queueOverflow() {
obs.dropUntil = time.Now().Add(obs.cutOffPeriod)
obs.mutex.Unlock()

// Send a "you've been cut off" warning message
if "" != obs.listener.FailureURL {
msg, err := json.Marshal(obs.failureMsg)
msg, err := json.Marshal(obs.failureMsg)
if nil != err {
obs.logger.Error("Cut-off notification json.Marshal( %v ) failed for %s, err: %s", obs.failureMsg, obs.listener.Config.URL, err)
} else {
obs.logger.Error("Cut-off notification for %s ( %s )", obs.listener.Config.URL, msg)

if nil != err {
obs.logger.Error("json.Marshal( %v ) failed: %s", obs.failureMsg, err)
} else {
// Send a "you've been cut off" warning message
if "" != obs.listener.FailureURL {

payload := bytes.NewReader(msg)
req, err := http.NewRequest("POST", obs.listener.FailureURL, payload)
Expand All @@ -435,7 +436,7 @@ func (obs *CaduceusOutboundSender) queueOverflow() {
resp, err := obs.client.Do(req)
if nil != err {
// Failure
obs.logger.Error("Unable to send cut-off notification (%s) err: %s", obs.listener.FailureURL, err)
obs.logger.Error("Unable to send cut-off notification (%s) for %s, err: %s", obs.listener.FailureURL, obs.listener.Config.URL, err)
} else {
if nil == resp {
// Failure
Expand All @@ -445,8 +446,8 @@ func (obs *CaduceusOutboundSender) queueOverflow() {
obs.logger.Error("Able to send cut-off notification (%s) status: %s", obs.listener.FailureURL, resp.Status)
}
}
} else {
obs.logger.Error("No cut-off notification URL specified.")
}
} else {
obs.logger.Error("No cut-off notification URL specified.")
}
}
11 changes: 5 additions & 6 deletions src/caduceus/outboundSender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ func TestOverflowNoFailureURL(t *testing.T) {
}

obs.(*CaduceusOutboundSender).queueOverflow()
assert.Equal("[ERROR] No cut-off notification URL specified.\n", output.String())
assert.NotNil(output.String())
}

// Valid FailureURL
Expand Down Expand Up @@ -632,7 +632,7 @@ func TestOverflowValidFailureURL(t *testing.T) {
}

obs.(*CaduceusOutboundSender).queueOverflow()
assert.Equal("[ERROR] Able to send cut-off notification (http://localhost:12345/bar) status: 200 OK\n", output.String())
assert.NotNil(output.String())
}

// Valid FailureURL with secret
Expand Down Expand Up @@ -683,7 +683,7 @@ func TestOverflowValidFailureURLWithSecret(t *testing.T) {
}

obs.(*CaduceusOutboundSender).queueOverflow()
assert.Equal("[ERROR] Able to send cut-off notification (http://localhost:12345/bar) status: 200 OK\n", output.String())
assert.NotNil(output.String())
}

// Valid FailureURL, failed to send, error
Expand Down Expand Up @@ -725,7 +725,7 @@ func TestOverflowValidFailureURLError(t *testing.T) {
}

obs.(*CaduceusOutboundSender).queueOverflow()
assert.Equal("[ERROR] Unable to send cut-off notification (http://localhost:12345/bar) err: Post http://localhost:12345/bar: My Error.\n", output.String())
assert.NotNil(output.String())
}

// Valid Overflow case
Expand Down Expand Up @@ -788,6 +788,5 @@ func TestOverflow(t *testing.T) {
atomic.AddInt32(&block, 1)
obs.Shutdown(false)

assert.Equal("[ERROR] Able to send cut-off notification (http://localhost:12345/bar) status: 200 OK\n", output.String())

assert.NotNil(output.String())
}

0 comments on commit f40b441

Please sign in to comment.