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

Post the response from the endpoint when log file posting succeed or failed #2771

Merged
merged 2 commits into from Jan 29, 2024

Conversation

shaopeng-gh
Copy link
Collaborator

The response from the endpoint is useful for troubleshooting.

@@ -101,8 +101,20 @@ public static SarifLog Load(Stream source, bool deferred = false)
return false;
}

await Post(postUri, new MemoryStream(fileBytes), httpClient);
Console.WriteLine($"Posted log file successfully to: {postUri}");
HttpResponseMessage response = await Post(postUri, new MemoryStream(fileBytes), httpClient);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

copied the code section,
but made some changes to the message, please review.
I used generic form: "Endpoint provided message"

await Post(postUri, new MemoryStream(fileBytes), httpClient);
Console.WriteLine($"Posted log file successfully to: {postUri}");
HttpResponseMessage response = await Post(postUri, new MemoryStream(fileBytes), httpClient);
string responseText = response.Content.ReadAsStringAsync().Result;
Copy link
Collaborator

@scottoneil-ms scottoneil-ms Jan 29, 2024

Choose a reason for hiding this comment

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

This method is actually async, so you can await this Task instead of doing .Result. (And that is better.) #Resolved

Console.WriteLine($"Error Posting log file to: {postUri}. Endpoint provided message: {responseText}");
return false;
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems better to check response.IsSuccessStatusCode. #Closed

Copy link
Collaborator

Choose a reason for hiding this comment

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

That is, as opposed to doing a try/catch here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

And I also think status code is useful to user, I think we should add it to the output as well

return false;
}

Console.WriteLine($"Posted log file successfully to: {postUri}. Endpoint provided message: {responseText}");
return true;
Copy link
Collaborator

@scottoneil-ms scottoneil-ms Jan 29, 2024

Choose a reason for hiding this comment

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

I'm not sure what the format of the responseText is going to be and what it contains. Is it possible to run this locally and provide a sample in the PR description? #Resolved

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is generic,
the server that takes the SARIF file is to be set by the user,
and that server could be with any design by the user.
It can returns anything, e.g. correlation id.

Copy link

@stacywray stacywray left a comment

Choose a reason for hiding this comment

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

:shipit:

return false;
}

Console.WriteLine($"Posted log file successfully to: {postUri}. Endpoint provided status code {response.StatusCode} and message: {responseText}");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks. I'm realizing we should revisit this code soon. We probably shouldn't be writing directly to the Console, and instead refactor the APIs at this layer and a few more up above to pass a Context down, so we can access a proper logger. I'll leave it for Michael to decide if we need that in this change. I can see cases in both directions.

Copy link
Collaborator

@scottoneil-ms scottoneil-ms left a comment

Choose a reason for hiding this comment

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

:shipit:

@scottoneil-ms scottoneil-ms merged commit 07912cf into main Jan 29, 2024
7 of 8 checks passed
@scottoneil-ms scottoneil-ms deleted the users/shaopeng-gh/responselogresponse branch January 29, 2024 23:11
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.

None yet

3 participants