Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Push NATS error messages to error queue #724

Merged
merged 10 commits into from
Jun 26, 2018
Merged

Push NATS error messages to error queue #724

merged 10 commits into from
Jun 26, 2018

Conversation

Amusement
Copy link
Contributor

@Amusement Amusement commented Jun 5, 2018

Addressed comments -- removed max retries cap, improved error handling.


This change is Reviewable

@life1347 life1347 self-requested a review June 7, 2018 05:47
Copy link
Member

@soamvasani soamvasani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Some very minor comments below, but other than that good to go 👍

if err != nil {
log.Warningf("Request failed: %v", url)
var resp *http.Response
for attempt := -1; attempt < trigger.Spec.MaxRetries; attempt++ {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is entirely subjective but I'd have this loop go attempt := 0; attempt <= trigger.Spec.MaxRetries; ...

var resp *http.Response
for attempt := -1; attempt < trigger.Spec.MaxRetries; attempt++ {
// Make the request
log.Warningf("Request : %v", req)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

}

if resp == nil {
log.Warning("The response was undefined. Quit.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means every retry failed, right? That's probably a better log message.

return
}

// TODO : Sequence
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm?

log.Printf("Request returned failure: %v", resp.StatusCode)
return

// TODO : what if err is not nil, then body is empty. publish either of them, not just body.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't mix those errors into the same queue, simply avoiding publishing when body is empty is probably good enough.

Copy link
Contributor Author

@Amusement Amusement Jun 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment was actually added by @smruthi2187. I can remove this TODO and check if the body is empty before publishing.


// Only the latest error response will be published to error topic
if err != nil || resp.StatusCode != 200 {
if len(trigger.Spec.ErrorTopic) > 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

&& len(body) > 0

@life1347
Copy link
Member

Reviewed 4 of 6 files at r1, 2 of 2 files at r2.
Review status: all files reviewed at latest revision, 6 unresolved discussions, some commit checks failed.


fission/main.go, line 197 at r2 (raw file):

	mqtRespTopicFlag := cli.StringFlag{Name: "resptopic", Usage: "Topic that the function response is sent on (optional; response discarded if unspecified)"}
	mqtErrorTopicFlag := cli.StringFlag{Name: "errortopic", Usage: "Topic that the function error messages are sent to (optional; errors discarded if unspecified"}
	mqtMaxRetries := cli.IntFlag{Name: "maxretries", Usage: "Maximum number of times the function will be retried upon failure (optional; default is 0)"}

Use "Value" to set the default value 0 like

targetcpu := cli.IntFlag{Name: "targetcpu", Value: 80, Usage: "Target average CPU usage percentage across pods for scaling"}

fission/mqtrigger.go, line 163 at r2 (raw file):

	}
	// Default number of max retries is 0
	mqt.Spec.MaxRetries = 0

This line should be removed or it will overwrite previously maxRetries setting if maxRetries has been set.


mqtrigger/messageQueue/nats.go, line 133 at r2 (raw file):

			resp, err = http.DefaultClient.Do(req)
			if err != nil || resp == nil {
				// Retry without referencing status code of nil response on the next line

Print error message if err is not nil


mqtrigger/messageQueue/nats.go, line 139 at r2 (raw file):

				// Success, quit retrying
				break
			}

Suggest using HTTP status const for the status code. (https://golang.org/pkg/net/http/#pkg-constants).


Comments from Reviewable

@life1347
Copy link
Member

life1347 commented Jun 12, 2018

Review status: 3 of 6 files reviewed, 11 unresolved discussions (waiting on @life1347, @soamvasani, and @Amusement)


mqtrigger/messageQueue/nats.go, line 133 at r3 (raw file):

			resp, err = http.DefaultClient.Do(req)
			if err != nil {
				log.Error(err)

We also need to print some useful information for debugging, how about

log.Errorf("Error invoking function for trigger %v: %v", trigger.Metadata.Name, err)

Comments from Reviewable

@smruthi2187 smruthi2187 added this to the 0.9.0 milestone Jun 14, 2018
@Amusement
Copy link
Contributor Author

Review status: 2 of 6 files reviewed, 11 unresolved discussions (waiting on @life1347, @soamvasani, and @Amusement)


fission/mqtrigger.go, line 163 at r2 (raw file):

Previously, life1347 (Ta-Ching Chen) wrote…

This line should be removed or it will overwrite previously maxRetries setting if maxRetries has been set.

Done.


mqtrigger/messageQueue/nats.go, line 129 at r1 (raw file):

Previously, soamvasani (Soam Vasani) wrote…

This is entirely subjective but I'd have this loop go attempt := 0; attempt <= trigger.Spec.MaxRetries; ...

Done.


mqtrigger/messageQueue/nats.go, line 131 at r1 (raw file):

Previously, soamvasani (Soam Vasani) wrote…

remove

Done.


mqtrigger/messageQueue/nats.go, line 144 at r1 (raw file):

Previously, soamvasani (Soam Vasani) wrote…

This means every retry failed, right? That's probably a better log message.

Done.


mqtrigger/messageQueue/nats.go, line 157 at r1 (raw file):

Previously, Amusement (Nafisa Shazia) wrote…

This comment was actually added by @smruthi2187. I can remove this TODO and check if the body is empty before publishing.

Done.


mqtrigger/messageQueue/nats.go, line 161 at r1 (raw file):

Previously, soamvasani (Soam Vasani) wrote…

&& len(body) > 0

Done.


mqtrigger/messageQueue/nats.go, line 133 at r2 (raw file):

Previously, life1347 (Ta-Ching Chen) wrote…

Print error message if err is not nil

Done.


mqtrigger/messageQueue/nats.go, line 139 at r2 (raw file):

Previously, life1347 (Ta-Ching Chen) wrote…

Suggest using HTTP status const for the status code. (https://golang.org/pkg/net/http/#pkg-constants).

Done.


mqtrigger/messageQueue/nats.go, line 133 at r3 (raw file):

Previously, life1347 (Ta-Ching Chen) wrote…

We need to also print some useful information for debugging, how about

log.Errorf("Error invoking function for trigger %v: %v", trigger.Metadata.Name, err)

Done.


Comments from Reviewable

@Amusement
Copy link
Contributor Author

Review status: 2 of 6 files reviewed, 11 unresolved discussions (waiting on @life1347 and @soamvasani)


fission/main.go, line 197 at r2 (raw file):

Previously, life1347 (Ta-Ching Chen) wrote…

Use "Value" to set the default value 0 like

targetcpu := cli.IntFlag{Name: "targetcpu", Value: 80, Usage: "Target average CPU usage percentage across pods for scaling"}

Done.


mqtrigger/messageQueue/nats.go, line 148 at r1 (raw file):

Previously, soamvasani (Soam Vasani) wrote…

Hm?

Done.


Comments from Reviewable

@life1347
Copy link
Member

LGTM

@life1347 life1347 merged commit 1ed59f0 into master Jun 26, 2018
@life1347 life1347 deleted the nats-errors branch June 26, 2018 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants