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

Register the allocator memory metric polled gauge only once #1084

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 13 additions & 9 deletions zuul-core/src/main/java/com/netflix/zuul/netty/server/Server.java
Expand Up @@ -203,6 +203,19 @@ public void start()
addressesToChannels.put(requestedNamedAddr.withNewSocket(chan.localAddress()), chan);
allBindFutures.add(nettyServerFuture);
}

// All channels should share a single ByteBufAllocator instance.
// Add metrics to monitor that allocator's memory usage.
if (!allBindFutures.isEmpty()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this conditional be inverted?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We want to check here that the allbindFutures list is not empty because in line 201 we fetch the first entry. The conditional looks correct to me.

ByteBufAllocator alloc = allBindFutures.get(0).channel().alloc();
if (alloc instanceof ByteBufAllocatorMetricProvider) {
ByteBufAllocatorMetric metrics = ((ByteBufAllocatorMetricProvider) alloc).metric();
PolledMeter.using(registry).withId(registry.createId("zuul.nettybuffermem.live", "type", "heap"))
.monitorValue(metrics, ByteBufAllocatorMetric::usedHeapMemory);
PolledMeter.using(registry).withId(registry.createId("zuul.nettybuffermem.live", "type", "direct"))
.monitorValue(metrics, ByteBufAllocatorMetric::usedDirectMemory);
}
}
}
catch (InterruptedException e) {
Thread.currentThread().interrupt();
Expand Down Expand Up @@ -277,15 +290,6 @@ private ChannelFuture setupServerBootstrap(
// Bind and start to accept incoming connections.
ChannelFuture bindFuture = serverBootstrap.bind(listenAddress.unwrap());

ByteBufAllocator alloc = bindFuture.channel().alloc();
if (alloc instanceof ByteBufAllocatorMetricProvider) {
ByteBufAllocatorMetric metrics = ((ByteBufAllocatorMetricProvider) alloc).metric();
PolledMeter.using(registry).withId(registry.createId("zuul.nettybuffermem.live", "type", "heap"))
.monitorValue(metrics, ByteBufAllocatorMetric::usedHeapMemory);
PolledMeter.using(registry).withId(registry.createId("zuul.nettybuffermem.live", "type", "direct"))
.monitorValue(metrics, ByteBufAllocatorMetric::usedDirectMemory);
}

try {
return bindFuture.sync();
} catch (Exception e) {
Expand Down