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

Add support for metrics in stream response handler #738

Merged
merged 4 commits into from
Jan 4, 2024

Conversation

ianbotsf
Copy link
Contributor

@ianbotsf ianbotsf commented Dec 21, 2023

Issue #, if available: smithy-lang/smithy-kotlin#893

Description of changes: This change adds support for getting metrics as part of the Java-level HttpStreamResponseHandler.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

/* Close the Connection if the Java Callback throws an Exception */
aws_http_connection_close(aws_http_stream_get_connection(stream));
}

Copy link
Contributor

Choose a reason for hiding this comment

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

We need to manually delete the local reference created when it's called from a C thread, (*env)->DeleteLocalRef(env, jni_metrics);, otherwise, it will result in a leak. We had the similar leak recently, referring to #734

Comment on lines 350 to 353
if (aws_jni_check_and_clear_exception(env)) {
/* Close the Connection if the Java Callback throws an Exception */
aws_http_connection_close(aws_http_stream_get_connection(stream));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Debatable: I know we have this pattern of error handling from on_complete callback, but I don't really like it. Especially as we introduced http/2, seems like a overkill to kill the whole connection, but, TBH, I don't really have better idea about how to handle this.

I would suggest to at least add a warning-level log here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looking at other callbacks, it seems the common practice is to log at error level (vs warning) and to raise an error as well so I've done that here. Let me know if you'd strongly prefer this be logged at warning level or that the error not be raised.

src/native/http_request_response.c Show resolved Hide resolved
… log and raise an error when an exception occurs in the onMetrics callback
Copy link
Contributor

@TingDaoK TingDaoK left a comment

Choose a reason for hiding this comment

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

Looks good overall, can we also add a small test for it to just make sure we can successfully get the metrics?

Comment on lines +90 to +97
/**
* Called right before stream is complete, whether successful or unsuccessful.
* @param stream The HTTP stream to which the metrics apply
* @param metrics The [HttpStreamMetrics] containing metrics for the given stream
*/
default void onMetrics(HttpStreamBase stream, HttpStreamMetrics metrics) {
/* Optional callback, nothing to do by default */
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: can we move the metrics callback before the complete callback? So, that it's the same order as it gets invoked

ianbotsf and others added 2 commits January 4, 2024 18:38
…rder of onMetrics methods in Java code to match invocation order; clean up clang-format errors
Copy link
Contributor

@TingDaoK TingDaoK left a comment

Choose a reason for hiding this comment

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

:shipit:

@TingDaoK TingDaoK merged commit 3eea28d into awslabs:main Jan 4, 2024
40 checks passed
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.

3 participants