Skip to content

Commit 9073cd4

Browse files
committed
suggested changes
1 parent d6bb6ec commit 9073cd4

File tree

5 files changed

+158
-87
lines changed

5 files changed

+158
-87
lines changed

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,6 @@ 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-
144138
/**
145139
* A picker that always returns an erring pick.
146140
*

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -868,18 +868,6 @@ private String printShortStatus(Status status) {
868868
return buffer.toString();
869869
}
870870

871-
private OtelMetricsAttributes buildLabelSet(String backendService, String locality,
872-
String disconnectError, String securityLevel) {
873-
return new OtelMetricsAttributes(
874-
target,
875-
backendService,
876-
locality,
877-
disconnectError,
878-
securityLevel
879-
);
880-
}
881-
882-
883871
@VisibleForTesting
884872
static final class TransportLogger extends ChannelLogger {
885873
// Changed just after construction to break a cyclic dependency.
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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+
class MetricsAttributes {
20+
final String target;
21+
final String backendService;
22+
final String locality;
23+
final String disconnectError;
24+
final String securityLevel;
25+
26+
// Constructor is private, only the Builder can call it
27+
private MetricsAttributes(Builder builder) {
28+
this.target = builder.target;
29+
this.backendService = builder.backendService;
30+
this.locality = builder.locality;
31+
this.disconnectError = builder.disconnectError;
32+
this.securityLevel = builder.securityLevel;
33+
}
34+
35+
// Public static method to get a new builder instance
36+
public static Builder newBuilder(String target) {
37+
return new Builder(target);
38+
}
39+
40+
public static class Builder {
41+
// Required parameter
42+
private final String target;
43+
44+
// Optional parameters - initialized to default values
45+
private String backendService = null;
46+
private String locality = null;
47+
private String disconnectError = null;
48+
private String securityLevel = null;
49+
50+
public Builder(String target) {
51+
this.target = target;
52+
}
53+
54+
public Builder backendService(String val) {
55+
this.backendService = val;
56+
return this;
57+
}
58+
59+
public Builder locality(String val) {
60+
this.locality = val;
61+
return this;
62+
}
63+
64+
public Builder disconnectError(String val) {
65+
this.disconnectError = val;
66+
return this;
67+
}
68+
69+
public Builder securityLevel(String val) {
70+
this.securityLevel = val;
71+
return this;
72+
}
73+
74+
public MetricsAttributes build() {
75+
return new MetricsAttributes(this);
76+
}
77+
}
78+
}

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

Lines changed: 0 additions & 69 deletions
This file was deleted.

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

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,84 @@ public String getErrorString(@Nullable String goawayErrorCode) {
186186
return this.errorTag;
187187
}
188188
}
189+
190+
/**
191+
* Represents the reason for a subchannel failure.
192+
*/
193+
public enum DisconnectError {
194+
195+
/**
196+
* Represents an HTTP/2 GOAWAY frame. The specific error code
197+
* (e.g., "NO_ERROR", "PROTOCOL_ERROR") should be handled separately
198+
* as it is a dynamic part of the error.
199+
* See RFC 9113 for error codes: https://www.rfc-editor.org/rfc/rfc9113.html#name-error-codes
200+
*/
201+
GOAWAY("goaway"),
202+
203+
/**
204+
* The subchannel was shut down for various reasons like parent channel shutdown,
205+
* idleness, or load balancing policy changes.
206+
*/
207+
SUBCHANNEL_SHUTDOWN("subchannel shutdown"),
208+
209+
/**
210+
* Connection was reset (e.g., ECONNRESET, WSAECONNERESET).
211+
*/
212+
CONNECTION_RESET("connection reset"),
213+
214+
/**
215+
* Connection timed out (e.g., ETIMEDOUT, WSAETIMEDOUT), including closures
216+
* from gRPC keepalives.
217+
*/
218+
CONNECTION_TIMED_OUT("connection timed out"),
219+
220+
/**
221+
* Connection was aborted (e.g., ECONNABORTED, WSAECONNABORTED).
222+
*/
223+
CONNECTION_ABORTED("connection aborted"),
224+
225+
/**
226+
* Any socket error not covered by other specific disconnect errors.
227+
*/
228+
SOCKET_ERROR("socket error"),
229+
230+
/**
231+
* A catch-all for any other unclassified reason.
232+
*/
233+
UNKNOWN("unknown");
234+
235+
private final String errorTag;
236+
237+
/**
238+
* Private constructor to associate a description with each enum constant.
239+
*
240+
* @param errorTag The detailed explanation of the error.
241+
*/
242+
DisconnectError(String errorTag) {
243+
this.errorTag = errorTag;
244+
}
245+
246+
/**
247+
* Gets the error string suitable for use as a metric tag.
248+
*
249+
* <p>If the reason is {@code GOAWAY}, this method requires the specific
250+
* HTTP/2 error code to create the complete tag (e.g., "goaway PROTOCOL_ERROR").
251+
* For all other reasons, the parameter is ignored.</p>
252+
*
253+
* @param goawayErrorCode The specific HTTP/2 error code. This is only
254+
* used if the reason is GOAWAY and should not be null in that case.
255+
* @return The formatted error string.
256+
*/
257+
public String getErrorString(@Nullable String goawayErrorCode) {
258+
if (this == GOAWAY) {
259+
if (goawayErrorCode == null || goawayErrorCode.isEmpty()) {
260+
// Return the base tag if the code is missing, or consider throwing an exception
261+
// throw new IllegalArgumentException("goawayErrorCode is required for GOAWAY reason.");
262+
return this.errorTag;
263+
}
264+
return this.errorTag + " " + goawayErrorCode;
265+
}
266+
return this.errorTag;
267+
}
268+
}
189269
}

0 commit comments

Comments
 (0)