Skip to content

Commit bf7255e

Browse files
committed
otel: plumb optional labels other than disconnect_error
1 parent 62d0969 commit bf7255e

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

api/src/main/java/io/grpc/LoadBalancer.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ public abstract class LoadBalancer {
135135
public static final Attributes.Key<Boolean> IS_PETIOLE_POLICY =
136136
Attributes.Key.create("io.grpc.IS_PETIOLE_POLICY");
137137

138+
/**
139+
* The name of the locality that this EquivalentAddressGroup is in.
140+
*/
141+
public static final Attributes.Key<String> ATTR_LOCALITY_NAME =
142+
Attributes.Key.create("io.grpc.lb.locality");
143+
138144
/**
139145
* A picker that always returns an erring pick.
140146
*

core/src/main/java/io/grpc/internal/InternalSubchannel.java

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -588,8 +588,13 @@ public Attributes filterTransport(Attributes attributes) {
588588
@Override
589589
public void transportReady() {
590590
channelLogger.log(ChannelLogLevel.INFO, "READY");
591-
subchannelMetrics.recordConnectionAttemptSucceeded(
592-
buildLabelSet(null, extractSecurityLevel()));
591+
subchannelMetrics.recordConnectionAttemptSucceeded(buildLabelSet(
592+
addressIndex.getCurrentEagAttributes().get(NameResolver.ATTR_BACKEND_SERVICE),
593+
addressIndex.getCurrentEagAttributes().get(LoadBalancer.ATTR_LOCALITY_NAME),
594+
null,
595+
extractSecurityLevel(
596+
addressIndex.getCurrentEagAttributes().get(GrpcAttributes.ATTR_SECURITY_LEVEL))
597+
));
593598
syncContext.execute(new Runnable() {
594599
@Override
595600
public void run() {
@@ -626,7 +631,11 @@ public void transportShutdown(final Status s) {
626631
channelLogger.log(
627632
ChannelLogLevel.INFO, "{0} SHUTDOWN with {1}", transport.getLogId(), printShortStatus(s));
628633
shutdownInitiated = true;
629-
subchannelMetrics.recordConnectionAttemptFailed(buildLabelSet("Peer Pressure", null));
634+
subchannelMetrics.recordConnectionAttemptFailed(buildLabelSet(
635+
addressIndex.getCurrentEagAttributes().get(NameResolver.ATTR_BACKEND_SERVICE),
636+
addressIndex.getCurrentEagAttributes().get(LoadBalancer.ATTR_LOCALITY_NAME),
637+
null, null
638+
));
630639
syncContext.execute(new Runnable() {
631640
@Override
632641
public void run() {
@@ -681,8 +690,13 @@ public void transportTerminated() {
681690
for (ClientTransportFilter filter : transportFilters) {
682691
filter.transportTerminated(transport.getAttributes());
683692
}
684-
subchannelMetrics.recordDisconnection(buildLabelSet("Peer Pressure",
685-
null));
693+
subchannelMetrics.recordDisconnection(buildLabelSet(
694+
addressIndex.getCurrentEagAttributes().get(NameResolver.ATTR_BACKEND_SERVICE),
695+
addressIndex.getCurrentEagAttributes().get(LoadBalancer.ATTR_LOCALITY_NAME),
696+
"Peer Pressure",
697+
extractSecurityLevel(
698+
addressIndex.getCurrentEagAttributes().get(GrpcAttributes.ATTR_SECURITY_LEVEL))
699+
));
686700
syncContext.execute(new Runnable() {
687701
@Override
688702
public void run() {
@@ -873,13 +887,14 @@ private String printShortStatus(Status status) {
873887
return buffer.toString();
874888
}
875889

876-
private OtelMetricsAttributes buildLabelSet(String disconnectError, String secLevel) {
890+
private OtelMetricsAttributes buildLabelSet(String backendService, String locality,
891+
String disconnectError, String securityLevel) {
877892
return new OtelMetricsAttributes(
878893
target,
879894
backendService,
880895
locality,
881896
disconnectError,
882-
secLevel != null ? secLevel : securityLevel
897+
securityLevel
883898
);
884899
}
885900

0 commit comments

Comments
 (0)