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 ServerMetrics to collect metrics related server #5627

Merged
merged 20 commits into from
Jun 10, 2024

Conversation

seongbeenkim
Copy link
Contributor

@seongbeenkim seongbeenkim commented Apr 22, 2024

Motivation:

Add ServerMetrics to collect metrics related server. #4992

Modifications:

  • Add ServerMetrics.increasePendingHttp1Requests()
    in Http1RequestDecoder#channelRead before fireChannelRead()
  • Add ServerMetrics.increasePendingHttp2Requests()
    in Http2RequestDecoder#onHeadersRead before fireChannelRead()
  • Add ServerMetrics.decreasePendingHttp1Requests(), ServerMetrics.decreasePendingHttp2Requests(), ServerMetrics.increaseActiveHttp1WebSocketRequests(), ServerMetrics.increaseActiveHttp1Requests() and ServerMetrics.increaseActiveHttp2Requests()
    in HttpServerHandler#serve0 before service.serve(reqCtx, req)
  • Add ServerMetrics.decreaseActiveHttp1WebSocketRequests(), ServerMetrics.decreaseActiveHttp1Requests() and ServerMetrics.decreaseActiveHttp2Requests()
    in AbstractHttpResponseHandler#tryComplete
  • Add ServerMetrics.increaseActiveConnectionsAndGet() and ServerMetrics.decreaseActiveConnections()
    in ConnectionLimitingHandler#channelRead

Result:

@CLAassistant
Copy link

CLAassistant commented Apr 22, 2024

CLA assistant check
All committers have signed the CLA.

@minwoox minwoox added this to the 1.29.0 milestone Apr 22, 2024
Copy link
Member

@minwoox minwoox left a comment

Choose a reason for hiding this comment

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

Looks great, @seongbeenkim! Left some suggestions. 😉

@@ -574,14 +575,19 @@ private ChannelFuture doStart(ServerPort port) {
}

private void setupServerMetrics() {
final MeterRegistry meterRegistry = config().meterRegistry();
final MeterRegistry meterRegistry = config.meterRegistry();
final ServerMetrics serverMetrics = config.serverMetrics();
final GracefulShutdownSupport gracefulShutdownSupport = this.gracefulShutdownSupport;
assert gracefulShutdownSupport != null;

meterRegistry.gauge("armeria.server.pending.responses", gracefulShutdownSupport,
GracefulShutdownSupport::pendingResponses);
Copy link
Member

Choose a reason for hiding this comment

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

@seongbeenkim is going to add the metric to the ServerMetrics in the follow-up PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Question) Could "armeria.server.pending.responses" be deprecated?
I guess ServerMetric. activeRequests() == GracefulShutdownSupport.pendingResponses().

Copy link
Member

@minwoox minwoox Jun 5, 2024

Choose a reason for hiding this comment

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

pendingResponses does not include the transient service requests, meanwhile activeRequests include them.
If we make activeRequests do not contain the transient service requests, we can deprecate pendingResponses. But I wasn't sure if it was okay. 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

It is hard to notice from the metric name that the difference between the two metrics is the existence of transient services.
We may add an API and a new tag to explicitly expose the number of transient service requests in the f/u work.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, that's a good suggestion. 👍

Copy link
Contributor

@jrhee17 jrhee17 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! Left some minor comments

@minwoox
Copy link
Member

minwoox commented May 21, 2024

Let me resolve the conflict. 😉

@jrhee17
Copy link
Contributor

jrhee17 commented May 29, 2024

Gentle ping 🙏

@minwoox
Copy link
Member

minwoox commented May 30, 2024

I've pushed commits because we are about to release the next version.
There are also some failing tests that will be resolved after #5680 gets merged.

Copy link
Member

@minwoox minwoox left a comment

Choose a reason for hiding this comment

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

@seongbeenkim Thanks for the all your work! 😄

Copy link
Contributor

@ikhoon ikhoon left a comment

Choose a reason for hiding this comment

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

It looks like a useful feature. ServerMetric may be used to implement a graceful shutdown logic.
Thanks, @seongbeenkim and @minwoox.

@@ -574,14 +575,19 @@ private ChannelFuture doStart(ServerPort port) {
}

private void setupServerMetrics() {
final MeterRegistry meterRegistry = config().meterRegistry();
final MeterRegistry meterRegistry = config.meterRegistry();
final ServerMetrics serverMetrics = config.serverMetrics();
final GracefulShutdownSupport gracefulShutdownSupport = this.gracefulShutdownSupport;
assert gracefulShutdownSupport != null;

meterRegistry.gauge("armeria.server.pending.responses", gracefulShutdownSupport,
GracefulShutdownSupport::pendingResponses);
Copy link
Contributor

Choose a reason for hiding this comment

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

Question) Could "armeria.server.pending.responses" be deprecated?
I guess ServerMetric. activeRequests() == GracefulShutdownSupport.pendingResponses().

Copy link
Contributor

@jrhee17 jrhee17 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 👍 Pushed a small commit which cleans up dead code and tests.
Also left a comment which I'm not how to handle at the moment 🤔

Copy link
Member

@trustin trustin left a comment

Choose a reason for hiding this comment

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

Thank very much, @seongbeenkim and @minwoox! 🙇

Comment on lines +264 to +265
System.nanoTime(), SystemInfo.currentTimeMicros(), true, false
);
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps we can revert this cosmetic change?

Suggested change
System.nanoTime(), SystemInfo.currentTimeMicros(), true, false
);
System.nanoTime(), SystemInfo.currentTimeMicros(), true, false);

Copy link
Member

Choose a reason for hiding this comment

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

Thanks addressed. 😉

Copy link
Contributor

@jrhee17 jrhee17 left a comment

Choose a reason for hiding this comment

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

👍 👍 👍

@minwoox minwoox merged commit 8dd819c into line:main Jun 10, 2024
14 of 15 checks passed
@minwoox
Copy link
Member

minwoox commented Jun 10, 2024

Thanks a lot, @seongbeenkim! 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expose the server-side metrics programmatically
6 participants