Skip to content

Commit

Permalink
[#11267] Add netty ByteBufAllocator metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
intr3p1d committed Aug 6, 2024
1 parent da395b1 commit 0900974
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@
import io.micrometer.core.instrument.Counter;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Timer;
import io.micrometer.core.instrument.binder.MeterBinder;
import io.micrometer.core.instrument.binder.grpc.MetricCollectingServerInterceptor;
import io.micrometer.core.instrument.binder.netty4.NettyAllocatorMetrics;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.ByteBufAllocatorMetricProvider;
import io.netty.buffer.PooledByteBufAllocator;
import io.netty.channel.EventLoopGroup;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Qualifier;
Expand Down Expand Up @@ -100,4 +106,12 @@ private Timer.Builder addTimerTag(Timer.Builder builder, String tagValue) {
return builder;
}

@Bean
public ByteBufAllocator byteBufAllocator(MeterRegistry meterRegistry){
ByteBufAllocator allocator = PooledByteBufAllocator.DEFAULT;

Check warning on line 111 in collector/src/main/java/com/navercorp/pinpoint/collector/monitor/config/MicrometerConfiguration.java

View check run for this annotation

Codecov / codecov/patch

collector/src/main/java/com/navercorp/pinpoint/collector/monitor/config/MicrometerConfiguration.java#L111

Added line #L111 was not covered by tests
if (allocator != null) {
new NettyAllocatorMetrics((ByteBufAllocatorMetricProvider) allocator).bindTo(meterRegistry);

Check warning on line 113 in collector/src/main/java/com/navercorp/pinpoint/collector/monitor/config/MicrometerConfiguration.java

View check run for this annotation

Codecov / codecov/patch

collector/src/main/java/com/navercorp/pinpoint/collector/monitor/config/MicrometerConfiguration.java#L113

Added line #L113 was not covered by tests
}
return allocator;

Check warning on line 115 in collector/src/main/java/com/navercorp/pinpoint/collector/monitor/config/MicrometerConfiguration.java

View check run for this annotation

Codecov / codecov/patch

collector/src/main/java/com/navercorp/pinpoint/collector/monitor/config/MicrometerConfiguration.java#L115

Added line #L115 was not covered by tests
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ private void setupServerOption(NettyServerBuilder builder) {
builder.withChildOption(ChannelOption.SO_RCVBUF, this.serverOption.getReceiveBufferSize());
final WriteBufferWaterMark disabledWriteBufferWaterMark = new WriteBufferWaterMark(0, Integer.MAX_VALUE);
builder.withChildOption(ChannelOption.WRITE_BUFFER_WATER_MARK, disabledWriteBufferWaterMark);
builder.withChildOption(ChannelOption.ALLOCATOR, this.serverOption.getAllocator());

builder.handshakeTimeout(this.serverOption.getHandshakeTimeout(), TimeUnit.MILLISECONDS);
builder.flowControlWindow(this.serverOption.getFlowControlWindow());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.navercorp.pinpoint.common.util.Assert;
import com.navercorp.pinpoint.grpc.ChannelTypeEnum;
import io.netty.buffer.ByteBufAllocator;

import java.util.Objects;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -78,14 +79,17 @@ public class ServerOption {
// ChannelOption
private final int receiveBufferSize;

private final ByteBufAllocator allocator;

private final long grpcMaxTermWaitTimeMillis;

public final ChannelTypeEnum channelTypeEnum;

ServerOption(long keepAliveTime, long keepAliveTimeout, long permitKeepAliveTime,
long maxConnectionIdle, long maxConnectionAge, long maxConnectionAgeGrace,
int maxConcurrentCallsPerConnection, int maxInboundMessageSize, int maxHeaderListSize,
long handshakeTimeout, int flowControlWindow, int receiveBufferSize, long grpcMaxTermWaitTimeMillis,
long handshakeTimeout, int flowControlWindow, int receiveBufferSize,
ByteBufAllocator allocator, long grpcMaxTermWaitTimeMillis,
ChannelTypeEnum channelTypeEnum) {
this.keepAliveTime = keepAliveTime;
this.keepAliveTimeout = keepAliveTimeout;
Expand All @@ -101,6 +105,7 @@ public class ServerOption {
this.handshakeTimeout = handshakeTimeout;
this.flowControlWindow = flowControlWindow;
this.receiveBufferSize = receiveBufferSize;
this.allocator = allocator;
this.grpcMaxTermWaitTimeMillis = grpcMaxTermWaitTimeMillis;
this.channelTypeEnum = Objects.requireNonNull(channelTypeEnum, "channelTypeEnum");
}
Expand Down Expand Up @@ -157,6 +162,10 @@ public int getReceiveBufferSize() {
return receiveBufferSize;
}

public ByteBufAllocator getAllocator() {
return allocator;
}

public long getGrpcMaxTermWaitTimeMillis() {
return grpcMaxTermWaitTimeMillis;
}
Expand Down Expand Up @@ -217,6 +226,8 @@ public static class Builder {

private int receiveBufferSize = DEFAULT_RECEIVE_BUFFER_SIZE;

private ByteBufAllocator allocator;

private long grpcMaxTermWaitTimeMillis = DEFAULT_GRPC_MAX_TERM_WAIT_TIME_MILLIS;

private ChannelTypeEnum channelTypeEnum = ChannelTypeEnum.valueOf(DEFAULT_CHANNEL_TYPE);
Expand All @@ -228,7 +239,8 @@ public ServerOption build() {
return new ServerOption(keepAliveTime, keepAliveTimeout, permitKeepAliveTime,
maxConnectionIdle, maxConnectionAge, maxConnectionAgeGrace,
maxConcurrentCallsPerConnection, maxInboundMessageSize,
maxHeaderListSize, handshakeTimeout, flowControlWindow, receiveBufferSize, grpcMaxTermWaitTimeMillis, channelTypeEnum);
maxHeaderListSize, handshakeTimeout, flowControlWindow, receiveBufferSize, allocator,
grpcMaxTermWaitTimeMillis, channelTypeEnum);
}

public void setKeepAliveTime(long keepAliveTime) {
Expand Down

0 comments on commit 0900974

Please sign in to comment.