Skip to content

Commit 62d0969

Browse files
committed
master pull
1 parent 9ade38a commit 62d0969

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,8 @@ public Attributes filterTransport(Attributes attributes) {
588588
@Override
589589
public void transportReady() {
590590
channelLogger.log(ChannelLogLevel.INFO, "READY");
591+
subchannelMetrics.recordConnectionAttemptSucceeded(
592+
buildLabelSet(null, extractSecurityLevel()));
591593
syncContext.execute(new Runnable() {
592594
@Override
593595
public void run() {
@@ -624,6 +626,7 @@ public void transportShutdown(final Status s) {
624626
channelLogger.log(
625627
ChannelLogLevel.INFO, "{0} SHUTDOWN with {1}", transport.getLogId(), printShortStatus(s));
626628
shutdownInitiated = true;
629+
subchannelMetrics.recordConnectionAttemptFailed(buildLabelSet("Peer Pressure", null));
627630
syncContext.execute(new Runnable() {
628631
@Override
629632
public void run() {
@@ -678,6 +681,8 @@ public void transportTerminated() {
678681
for (ClientTransportFilter filter : transportFilters) {
679682
filter.transportTerminated(transport.getAttributes());
680683
}
684+
subchannelMetrics.recordDisconnection(buildLabelSet("Peer Pressure",
685+
null));
681686
syncContext.execute(new Runnable() {
682687
@Override
683688
public void run() {
@@ -868,6 +873,17 @@ private String printShortStatus(Status status) {
868873
return buffer.toString();
869874
}
870875

876+
private OtelMetricsAttributes buildLabelSet(String disconnectError, String secLevel) {
877+
return new OtelMetricsAttributes(
878+
target,
879+
backendService,
880+
locality,
881+
disconnectError,
882+
secLevel != null ? secLevel : securityLevel
883+
);
884+
}
885+
886+
871887
@VisibleForTesting
872888
static final class TransportLogger extends ChannelLogger {
873889
// Changed just after construction to break a cyclic dependency.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright 2025 The gRPC Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.grpc.internal;
18+
19+
20+
import io.grpc.Attributes;
21+
22+
class OtelMetricsAttributes {
23+
final String target;
24+
final String backendService;
25+
final String locality;
26+
final String disconnectError;
27+
final String securityLevel;
28+
29+
public OtelMetricsAttributes(String target, String backendService, String locality,
30+
String disconnectError, String securityLevel) {
31+
this.target = target;
32+
this.backendService = backendService;
33+
this.locality = locality;
34+
this.disconnectError = disconnectError;
35+
this.securityLevel = securityLevel;
36+
}
37+
38+
public Attributes toOtelMetricsAttributes() {
39+
Attributes attributes =
40+
Attributes.EMPTY;
41+
42+
if (target != null) {
43+
attributes.toBuilder()
44+
.set(Attributes.Key.create("grpc.target"), target)
45+
.build();
46+
}
47+
if (backendService != null) {
48+
attributes.toBuilder()
49+
.set(Attributes.Key.create("grpc.lb.backend_service"), backendService)
50+
.build();
51+
}
52+
if (locality != null) {
53+
attributes.toBuilder()
54+
.set(Attributes.Key.create("grpc.lb.locality"), locality)
55+
.build();
56+
}
57+
if (disconnectError != null) {
58+
attributes.toBuilder()
59+
.set(Attributes.Key.create("grpc.disconnect_error"), disconnectError)
60+
.build();
61+
}
62+
if (securityLevel != null) {
63+
attributes.toBuilder()
64+
.set(Attributes.Key.create("grpc.security_level"), securityLevel)
65+
.build();
66+
}
67+
return attributes;
68+
}
69+
}

0 commit comments

Comments
 (0)