Skip to content
This repository was archived by the owner on May 8, 2026. It is now read-only.

Commit 7290306

Browse files
committed
fix
1 parent bea4f02 commit 7290306

4 files changed

Lines changed: 27 additions & 334 deletions

File tree

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/dp/DirectAccessInvestigator.java

Lines changed: 27 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -18,124 +18,58 @@
1818

1919
import com.google.api.core.InternalApi;
2020
import com.google.cloud.bigtable.data.v2.internal.csm.tracers.DirectPathCompatibleTracer;
21-
import java.net.InetAddress;
2221
import java.util.logging.Level;
2322
import java.util.logging.Logger;
2423

2524
@InternalApi
2625
public class DirectAccessInvestigator {
2726
private static final Logger LOG = Logger.getLogger(DirectAccessInvestigator.class.getName());
2827

29-
// Telemetry metric reason codes
30-
private static final String REASON_NOT_IN_GCP = "not_in_gcp";
31-
private static final String REASON_METADATA_UNREACHABLE = "metadata_unreachable";
32-
private static final String REASON_NO_IP_ASSIGNED = "no_ip_assigned";
33-
private static final String REASON_LOOPBACK_DOWN = "loopback_misconfigured";
34-
private static final String REASON_LOOPBACK_V4_MISSING = "loopback_misconfigured_ipv4";
35-
private static final String REASON_LOOPBACK_V6_MISSING = "loopback_misconfigured_ipv6";
36-
private static final String REASON_UNKNOWN = "";
28+
/** Metric reason codes for Direct Access failures. */
29+
public enum FailureReason {
30+
NOT_IN_GCP("not_in_gcp"),
31+
METADATA_UNREACHABLE("metadata_unreachable"),
32+
NO_IP_ASSIGNED("no_ip_assigned"),
33+
LOOPBACK_DOWN("loopback_misconfigured"),
34+
LOOPBACK_V4_MISSING("loopback_misconfigured_ipv4"),
35+
LOOPBACK_V6_MISSING("loopback_misconfigured_ipv6"),
36+
USER_DISABLED("user_disabled"),
37+
UNKNOWN("");
38+
39+
private final String value;
40+
41+
FailureReason(String value) {
42+
this.value = value;
43+
}
44+
45+
public String getValue() {
46+
return value;
47+
}
48+
}
3749

3850
public static void investigateAndReport(
3951
DirectPathCompatibleTracer tracer, Throwable originalError) {
4052
try {
41-
if (!GCECheck.isRunningOnGCP()) {
42-
recordAndLog(
43-
tracer, REASON_NOT_IN_GCP, "Direct Access investigation: not in GCP.", originalError);
44-
return;
45-
}
46-
47-
if (!MetadataServer.isReachable()) {
48-
recordAndLog(
49-
tracer,
50-
REASON_METADATA_UNREACHABLE,
51-
"Direct Access investigation: Metadata unreachable.",
52-
null);
53-
return;
54-
}
55-
56-
InetAddress ipv4 = MetadataServer.getIPv4();
57-
InetAddress ipv6 = MetadataServer.getIPv6();
58-
59-
if (ipv4 == null && ipv6 == null) {
60-
recordAndLog(
61-
tracer,
62-
REASON_NO_IP_ASSIGNED,
63-
"Direct Access investigation: Neither IPv4 nor IPv6 assigned.",
64-
null);
65-
return;
66-
}
67-
68-
if (!LoopBackInterface.isUp()) {
69-
recordAndLog(
70-
tracer,
71-
REASON_LOOPBACK_DOWN,
72-
"Direct Access investigation: Loopback interface down.",
73-
null);
74-
return;
75-
}
76-
77-
// ONLY check for IPv4 loopback if we are using an IPv4 address
78-
if (ipv4 != null && !LoopBackInterface.hasLocalIpv4Loopback()) {
79-
recordAndLog(
80-
tracer,
81-
REASON_LOOPBACK_V4_MISSING,
82-
"Direct Access investigation: IPv4 loopback missing.",
83-
null);
84-
return;
85-
}
86-
87-
// ONLY check for IPv6 loopback if we are using an IPv6 address
88-
if (ipv6 != null && !LoopBackInterface.hasLocalIpv6Loopback()) {
89-
recordAndLog(
90-
tracer,
91-
REASON_LOOPBACK_V6_MISSING,
92-
"Direct Access investigation: IPv6 loopback missing.",
93-
null);
94-
return;
95-
}
96-
97-
boolean v4Plumbed = ipv4 != null && LoopBackInterface.isIpPlumbed(ipv4);
98-
if (ipv4 != null && !v4Plumbed) {
99-
LOG.log(
100-
Level.FINE,
101-
"Direct Access investigation: IPv4 assigned by metadata but not found on NIC.");
102-
}
103-
104-
boolean v6Plumbed = ipv6 != null && LoopBackInterface.isIpPlumbed(ipv6);
105-
if (ipv6 != null && !v6Plumbed) {
106-
LOG.log(
107-
Level.FINE,
108-
"Direct Access investigation: IPv6 assigned by metadata but not found on NIC.");
109-
}
110-
111-
// If the metadata server assigned IPs, but the guest OS hasn't configured any of them on an
112-
// interface.
113-
// Do NOT return early here, because this is how GKE pods work (relying on default kernel
114-
// routing).
115-
if (!v4Plumbed && !v6Plumbed) {
116-
LOG.log(
117-
Level.FINE,
118-
"Direct Access investigation: Metadata IPs are not plumbed to local interfaces (likely containerized). Relying on kernel default routing.");
119-
}
53+
// TODO: Implement checks in a future PR.
54+
// For now, default to returning "unknown".
12055
recordAndLog(
12156
tracer,
122-
REASON_UNKNOWN,
123-
"Direct Access investigation: Running on GCP, metadata reachable, IPs assigned and plumbed, but Direct Access still failed.",
57+
FailureReason.UNKNOWN,
58+
"Direct Access investigation: Defaulting to unknown failure reason for now.",
12459
originalError);
125-
12660
} catch (Exception e) {
12761
LOG.log(Level.WARNING, "Failed to complete Direct Access investigation", e);
12862
}
12963
}
13064

13165
/** Helper method to consistently log the failure reason and record it to the tracer. */
13266
private static void recordAndLog(
133-
DirectPathCompatibleTracer tracer, String reasonCode, String logMessage, Throwable error) {
67+
DirectPathCompatibleTracer tracer, FailureReason reason, String logMessage, Throwable error) {
13468
if (error != null) {
13569
LOG.log(Level.FINE, logMessage, error);
13670
} else {
13771
LOG.log(Level.FINE, logMessage);
13872
}
139-
tracer.recordFailure(reasonCode);
73+
tracer.recordFailure(reason.getValue());
14074
}
14175
}

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/dp/GCECheck.java

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

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/dp/LoopBackInterface.java

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

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/dp/MetadataServer.java

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

0 commit comments

Comments
 (0)