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

refactor(prov-dev, deps): Add better logging to provisioning device client #746

Merged
merged 2 commits into from
Mar 30, 2020

Conversation

timtay-microsoft
Copy link
Member

Also fixing an issue where provisioning device client didn't propagate up the error code if an http exception was returned from service

Also fixing a bug where if the provisioning device client ignored amqp messages getting rejected from service. Now the sdk responds and throws appropriately

@timtay-microsoft
Copy link
Member Author

/azp run Java Prod

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@timtay-microsoft timtay-microsoft force-pushed the timtay/provisioningLogging branch from 2b05f0d to ff2bae9 Compare March 27, 2020 21:48
@timtay-microsoft
Copy link
Member Author

/azp run Java Prod, SDL, horton-java-gate

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

DeliveryState remoteState = d.getRemoteState();

// Codes_SRS_AMQPSIOTHUBCONNECTION_15_039: [The event handler shall note the remote delivery state and use it and the Delivery (Proton) hash code to inform the AmqpsIotHubConnection of the message receipt.]
boolean messageAcknowledgedAsSuccess = remoteState.equals(Accepted.getInstance());
Copy link
Member Author

Choose a reason for hiding this comment

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

Previously, we ignored if our sent message was accepted or not. Now we fire a callback up to the listener to notify it if any message that was sent was rejected/abandoned/released/etc by the service so that it can stop waiting and propagate up the exception to the user

@@ -18,38 +18,30 @@ public static void verifyHttpResponse(HttpResponse httpResponse) throws Provisio
{
int responseStatus = httpResponse.getStatus();

String errorMessage = ErrorMessageParser.bestErrorMessage(new String(httpResponse.getErrorReason(), StandardCharsets.UTF_8));
Copy link
Member Author

Choose a reason for hiding this comment

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

There is no reason for us to parse the error message considering it will just be a string to the exception we give it to. Parsing this error message may even filter out important information from the service, so we're better off just giving the full error payload string to the user

String errorMessage = ErrorMessageParser.bestErrorMessage(new String(httpResponse.getErrorReason(), StandardCharsets.UTF_8));
byte[] errorReason = httpResponse.getErrorReason();

String errorMessage = httpResponse.getStatus() + " : " + new String(errorReason, StandardCharsets.UTF_8);
Copy link
Member Author

Choose a reason for hiding this comment

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

Previously, we didn't include the status code in this error message, but we should as it helps debug customer issues

case 502:
throw new ProvisioningDeviceHubException(errorMessage);
case 503:
Copy link
Member Author

Choose a reason for hiding this comment

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

This was a strange switch case where almost all cases did the exact same thing. Just using a fall through to simplify it a bit

@timtay-microsoft
Copy link
Member Author

/azp run Java Prod Basic

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@@ -139,6 +130,11 @@ public boolean isConnected() throws Exception
throw this.saslListener.getSavedException();
}

if (this.protonJExceptionParser != null && this.protonJExceptionParser.getError() != null)
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't onConnectionInit() be a better place for this check?

Copy link
Member Author

Choose a reason for hiding this comment

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

isConnected() is called from a user thread whereas onConnectionInit() is a reactor thread. We only want to throw exceptions from a user thread, so I'd prefer to keep this saved exception check here.

Copy link
Member

Choose a reason for hiding this comment

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

I see, maybe add a comment to that effect?

…lient

Also fixing an issue where provisioning device client didn't propagate up the error code if an http exception was returned from service

Also fixing a bug where if the provisioning device client ignored amqp messages getting rejected from service. Now the sdk responds and throws appropriately
@timtay-microsoft timtay-microsoft force-pushed the timtay/provisioningLogging branch from f63dbbb to 0fc4c8b Compare March 30, 2020 17:53
@timtay-microsoft
Copy link
Member Author

/azp run Java Prod, SDL, horton-java-gate

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@timtay-microsoft
Copy link
Member Author

/azp run Java Prod, SDL, horton-java-gate

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@timtay-microsoft
Copy link
Member Author

/azp run Java Prod Basic

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@timtay-microsoft timtay-microsoft merged commit 64ca3e1 into master Mar 30, 2020
@timtay-microsoft timtay-microsoft deleted the timtay/provisioningLogging branch March 30, 2020 19:54
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