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

Give better feedback on synchronous zipdeploy #2641

Closed

Conversation

nikolaia
Copy link

@nikolaia nikolaia commented Dec 4, 2017

As mentioned in #2630 it would be nice to know if the deployment succeeded or failed when running a synchronous zipdeploy

@davidebbo
Copy link
Member

@nickwalkmsft can you review this change to zip push deploy?

response.Content = new StringContent("Succeeded");
break;
case FetchDeploymentRequestResult.RanSynchronouslyFailed:
response.StatusCode = HttpStatusCode.OK;
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like this should be BadRequest or something similar?

Copy link
Contributor

Choose a reason for hiding this comment

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

Along with error text?

Copy link
Author

Choose a reason for hiding this comment

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

I changed FetchDeploymentRequestResult to include a StatusText and renamed the enum. Don't know if you approve of the pattern, let me know. Changed to BadRequest, agree it's better.

@@ -118,6 +118,7 @@ public class FetchHandler : HttpTaskAsyncHandler
context.ApplicationInstance.CompleteRequest();
break;
case FetchDeploymentRequestResult.RanSynchronously:
case FetchDeploymentRequestResult.RanSynchronouslyFailed:
Copy link
Contributor

Choose a reason for hiding this comment

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

This is actually the reason I left the feature in question out of Zipdeploy - because synchronous fetch deployment didn't do it. I didn't just want to add it and change the expected behavior, and it made more sense (to me, at the time) to keep the behavior the same between fetch and zip/push, so I did. @davidebbo what's your take on this?

Copy link
Member

Choose a reason for hiding this comment

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

So is the /api/zip behavior today that if something goes wrong on the server, the request doesn't fail? If so, that doesn't seem good, and I wouldn't make push zip behave the same way (ideally we'd fix both).

Copy link
Author

Choose a reason for hiding this comment

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

I changed fetch to act the same way as push on RanSynchronously, but I'm not 100% sure of the consequences here so feedback is appreciated. Tests seems to run fine at least 💯

Copy link
Contributor

@nickwalkmsft nickwalkmsft Dec 5, 2017

Choose a reason for hiding this comment

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

Not /api/zip, but /deploy (fetch deployment), which zipdeploy has the most in common with (a zip deployment just pushes the zip to the server and then does a "fetch" deployment with a custom fetch action that unzips the local file and sets the deployment source to the extract directory).

In DeploymentManager.Build(), the call to builder.Build() (which does most of the actual work of the deployment) is wrapped in a try/catch that doesn't rethrow. See https://github.com/projectkudu/kudu/blob/master/Kudu.Core/Deployment/DeploymentManager.cs#L651-L675. Everything further up the call stack relies on exceptions and doesn't actually check the status, so the caller gets a 200 back if an exception occurs there, even though the deployment failed. It's always been this way.

Copy link
Member

Choose a reason for hiding this comment

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

Ah I see. I guess the reason is that in those scenarios, the http call normally comes from GitHub/BitBucket, and the error is less relevant. Instead, the deployment status shows it. But for Zip, I can see how not having an error becomes more quirky.

@ghost ghost deleted a comment from dnfclas Dec 5, 2017
@ghost ghost deleted a comment from dnfclas Dec 5, 2017
@ghost ghost removed the cla-signed label Dec 5, 2017
@nickwalkmsft
Copy link
Contributor

Okey doke - overall I think this is a good idea and would like to merge it. Could you make a couple of revisions? I am adding a couple comments now.

Thanks for the contrib!

context.Response.StatusCode = (int)HttpStatusCode.Conflict;
context.Response.Write(Resources.Error_DeploymentInProgress);
context.ApplicationInstance.CompleteRequest();
break;
case FetchDeploymentRequestResult.RanSynchronously:
case FetchDeploymentRequestResultStatus.RanSynchronously:
Copy link
Contributor

Choose a reason for hiding this comment

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

This new behavior is good for PushDeploymentController since it's new and likely to be used interactively, but here for FetchHandler, please put this bit back how it was (have RanSynchronously fall through to the default case), and have RanSynchronouslyFailed fall through to the default case as well. I'm hesitant to change the behavior here, since this is generally called by webhooks from many different CI services and I don't want to break expectations related to how they react to the response. A short comment to acknowledge the RanSynchronouslyFailed case and explaining that we're avoiding a behavior change would be good also.

Copy link
Author

Choose a reason for hiding this comment

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

Reverted to default case

response.StatusCode = HttpStatusCode.OK;
break;
case FetchDeploymentRequestResult.ConflictDeploymentInProgress:
case FetchDeploymentRequestResultStatus.RanSynchronouslyFailed:
response.StatusCode = HttpStatusCode.BadRequest;
Copy link
Contributor

Choose a reason for hiding this comment

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

I misspoke on this earlier; it should probably be a 500 instead of a 400.

Copy link
Author

Choose a reason for hiding this comment

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

Fixed

}

await PerformDeployment(deployInfo);
return FetchDeploymentRequestResult.RanSynchronously;
var result = _deploymentManager.GetResults().FirstOrDefault();
Copy link
Contributor

Choose a reason for hiding this comment

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

GetResults() is not a good idea here (it hits the filesystem to enumerate all the existing results, does locking stuff, and has the side effect of purging old deployment records, none of which I want to incur here) but unfortunately there's no other option the way things are factored now.

DeploymentManager.DeployAsync() currently doesn't return anything. Given the functionality it would make sense to return the DeployResult, and in turn that could be returned up through PerformDeployment() and checked here. Please give that a go; if it's not looking great let me know and I'll take a swing at it or something similar.

Copy link
Author

@nikolaia nikolaia Dec 8, 2017

Choose a reason for hiding this comment

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

Now using GetResult(id) to return the DeployResult from DeployAsync. Does that solve the lockingissues?

@@ -274,6 +274,8 @@ public void Delete(string id)
{
throw new DeploymentFailedException(exception);
}

return GetResult(id);
Copy link
Author

Choose a reason for hiding this comment

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

Is this safe?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry for the delay, I'll get to this soon...

Copy link
Author

Choose a reason for hiding this comment

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

Bump! Don't wanna nag, but thought I'd remind you about this in case it's been forgotten ⏳

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks @nikolaia, have been working on other priorities but will get to this as soon as I can, it's still on my radar.

Choose a reason for hiding this comment

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

Any updates here? :)

@nikolaia nikolaia force-pushed the f_zipdeploy_failed_sync_example branch from de572eb to f32d0f0 Compare March 21, 2018 09:38
@honorew
Copy link

honorew commented Jan 23, 2019

when isAsync=true,could return the deploy id ?

@nikolaia
Copy link
Author

I'm gonna close this. Ended up just using the Azure CLI to deploy. (Example: https://github.com/nikolaia/weather-in-harstad/blob/master/provision.fsx#L82)

@nikolaia nikolaia closed this Feb 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants