otel: fixes NPE

This commit is contained in:
AgraVator 2025-07-09 15:16:27 +05:30
parent a664b2fd92
commit 2ce087eebb
1 changed files with 16 additions and 7 deletions

View File

@ -589,8 +589,10 @@ final class InternalSubchannel implements InternalInstrumented<ChannelStats>, Tr
public void transportReady() { public void transportReady() {
channelLogger.log(ChannelLogLevel.INFO, "READY"); channelLogger.log(ChannelLogLevel.INFO, "READY");
subchannelMetrics.recordConnectionAttemptSucceeded(buildLabelSet( subchannelMetrics.recordConnectionAttemptSucceeded(buildLabelSet(
addressIndex.getCurrentEagAttributes().get(NameResolver.ATTR_BACKEND_SERVICE), getAttributeOrDefault(
addressIndex.getCurrentEagAttributes().get(LoadBalancer.ATTR_LOCALITY_NAME), addressIndex.getCurrentEagAttributes(), NameResolver.ATTR_BACKEND_SERVICE),
getAttributeOrDefault(
addressIndex.getCurrentEagAttributes(), LoadBalancer.ATTR_LOCALITY_NAME),
null, null,
extractSecurityLevel( extractSecurityLevel(
addressIndex.getCurrentEagAttributes().get(GrpcAttributes.ATTR_SECURITY_LEVEL)) addressIndex.getCurrentEagAttributes().get(GrpcAttributes.ATTR_SECURITY_LEVEL))
@ -625,8 +627,8 @@ final class InternalSubchannel implements InternalInstrumented<ChannelStats>, Tr
ChannelLogLevel.INFO, "{0} SHUTDOWN with {1}", transport.getLogId(), printShortStatus(s)); ChannelLogLevel.INFO, "{0} SHUTDOWN with {1}", transport.getLogId(), printShortStatus(s));
shutdownInitiated = true; shutdownInitiated = true;
subchannelMetrics.recordConnectionAttemptFailed(buildLabelSet( subchannelMetrics.recordConnectionAttemptFailed(buildLabelSet(
addressIndex.getCurrentEagAttributes().get(NameResolver.ATTR_BACKEND_SERVICE), getAttributeOrDefault(addressIndex.getCurrentEagAttributes(), NameResolver.ATTR_BACKEND_SERVICE),
addressIndex.getCurrentEagAttributes().get(LoadBalancer.ATTR_LOCALITY_NAME), getAttributeOrDefault(addressIndex.getCurrentEagAttributes(), LoadBalancer.ATTR_LOCALITY_NAME),
null, null null, null
)); ));
syncContext.execute(new Runnable() { syncContext.execute(new Runnable() {
@ -670,8 +672,10 @@ final class InternalSubchannel implements InternalInstrumented<ChannelStats>, Tr
filter.transportTerminated(transport.getAttributes()); filter.transportTerminated(transport.getAttributes());
} }
subchannelMetrics.recordDisconnection(buildLabelSet( subchannelMetrics.recordDisconnection(buildLabelSet(
addressIndex.getCurrentEagAttributes().get(NameResolver.ATTR_BACKEND_SERVICE), getAttributeOrDefault(
addressIndex.getCurrentEagAttributes().get(LoadBalancer.ATTR_LOCALITY_NAME), addressIndex.getCurrentEagAttributes(), NameResolver.ATTR_BACKEND_SERVICE),
getAttributeOrDefault(
addressIndex.getCurrentEagAttributes(), LoadBalancer.ATTR_LOCALITY_NAME),
"Peer Pressure", "Peer Pressure",
extractSecurityLevel( extractSecurityLevel(
addressIndex.getCurrentEagAttributes().get(GrpcAttributes.ATTR_SECURITY_LEVEL)) addressIndex.getCurrentEagAttributes().get(GrpcAttributes.ATTR_SECURITY_LEVEL))
@ -702,6 +706,11 @@ final class InternalSubchannel implements InternalInstrumented<ChannelStats>, Tr
throw new IllegalArgumentException("Unknown SecurityLevel: " + securityLevel); throw new IllegalArgumentException("Unknown SecurityLevel: " + securityLevel);
} }
} }
private String getAttributeOrDefault(Attributes attributes, Attributes.Key<String> key) {
String value = attributes.get(key);
return value == null ? "" : value;
}
} }
// All methods are called in syncContext // All methods are called in syncContext