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

[ORCA-4531] Improve pre workflow hook error handling #228

Merged

Conversation

msarvar
Copy link

@msarvar msarvar commented Mar 30, 2022

Updating our pre workflow hooks logic to fail the workflow execution when hook return an error. This will provide better user experience and will allow us to debug issue related to pre-workflow-hook failures.

Additionally added instrumentation to pre workflow hooks to allow us to create alarms when pre workflow hooks fail.

@msarvar msarvar force-pushed the improve-pre-workflow-hook-error-handling branch from 7fd0a3c to a105dc3 Compare March 30, 2022 22:55
@msarvar msarvar changed the title Improve pre workflow hook error handling [ORCA-4531] Improve pre workflow hook error handling Mar 31, 2022
@@ -179,7 +179,11 @@ func (c *DefaultCommandRunner) RunAutoplanCommand(logger logging.SimpleLogging,
err = c.PreWorkflowHooksCommandRunner.RunPreHooks(ctx)

if err != nil {
ctx.Log.Errorf("Error running pre-workflow hooks %s. Proceeding with %s command.", err, command.Plan)
ctx.Log.Errorf("Error running pre-workflow hooks %s. Aborting %s command.", err, command.Plan.String())
Copy link
Contributor

Choose a reason for hiding this comment

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

can you use my new logger here pls.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also no formatting allowed in logs anymore.

Copy link
Author

Choose a reason for hiding this comment

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

Are you talking about logging.Logger interface and do I need to thread it into command runner?

Comment on lines 183 to 185
if err := c.VCSClient.CreateComment(ctx.Pull.BaseRepo, ctx.Pull.Num, fmt.Sprintf("Encountered an error during pre-workflow-hook execution: %s", err), command.Plan.String()); err != nil {
ctx.Log.Errorf("unable to comment: %s", err)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd like to move away from this paradigm of commenting logging errors on the PR since its just noise that the customer won't understand and just pollutes our codebase all over the place.

The ideal UX in my mind is to mark the status/checks as fail and have some details as to why they failed when you click into it. For now i think just failing the statuses is enough since customers will need our help anyways at that point.

server/instrumentation/pre_workflow_hook.go Show resolved Hide resolved
}

func (r *PreWorkflowHookRunner) RunPreHooks(ctx *command.Context) error {
scope := ctx.Scope.SubScope("pre-workflow-hook")
Copy link
Contributor

Choose a reason for hiding this comment

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

i think we've been using underscores for metric names instead of dashes.

@msarvar msarvar force-pushed the improve-pre-workflow-hook-error-handling branch from 9601e54 to 09714de Compare March 31, 2022 19:26
User models.User
Log logging.SimpleLogging
User models.User
Log logging.SimpleLogging
Copy link
Contributor

Choose a reason for hiding this comment

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

can you remove this? Why have both? We're gonna need to do this for the whole codebase at some point anyways, might as well do it per file as we come across it.

ctx.Log.Errorf("Error running pre-workflow hooks %s. Proceeding with %s command.", err, command.Plan)
if err := c.PreWorkflowHooksCommandRunner.RunPreHooks(context.TODO(), ctx); err != nil {
c.Logger.ErrorContext(context.TODO(), "Error running pre-workflow hooks", map[string]interface{}{
"err": err,
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add repository and pull num here? similar to here:
https://github.com/lyft/atlantis/blob/release-v0.17.3-lyft.1/server/events/vcs/instrumented_client.go#L346-L348

Eventually this can be added to ctx and ripped out from there automatically but for now we need this.

Copy link
Author

Choose a reason for hiding this comment

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

yeah, my thinking was that it will be covered by the context, but you're right in the meantime we need a workaround.

return err
}

r.Logger.InfoContext(ctx, "pre-workflow-hook success", logHelpers.PullRequest(cmdCtx.Pull))
Copy link
Contributor

Choose a reason for hiding this comment

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

not a fan of helpers, handlers, util, common etc. it's not descriptive and becomes a dumping ground.

here, it could make sense to just use fields as the package. so it would be fields.PullRequest(..)

Again this should hopefully go away soon. Can we add a //TODO here to remove that

Copy link
Author

Choose a reason for hiding this comment

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

done, also added todo to the package

// writes them. Used for testing.
func NewNoopCtxLogger(t *testing.T) Logger {
return &logger{
LoggerFacade: logur.NoopLogger{},
Copy link
Contributor

Choose a reason for hiding this comment

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

What does this NoopLogger do btw? The noop logger we have is nice because it logs all the output to t so you can at least debug failing tests.

Copy link
Author

Choose a reason for hiding this comment

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

It literally did nothing, changed to mimic our NoopLogger

use our NoopLogger instead of logur.NoopLogger
@msarvar msarvar force-pushed the improve-pre-workflow-hook-error-handling branch from 902fc6f to d522a3a Compare April 1, 2022 18:53
Copy link
Contributor

@nishkrishnan nishkrishnan left a comment

Choose a reason for hiding this comment

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

💯

@msarvar msarvar merged commit 048001d into release-v0.17.3-lyft.1 Apr 1, 2022
@msarvar msarvar deleted the improve-pre-workflow-hook-error-handling branch April 1, 2022 19:02
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.

2 participants