From f58fd5559e3ef5e93b93a770facb34e12856311c Mon Sep 17 00:00:00 2001 From: Jesus Zazueta Date: Fri, 11 Oct 2024 00:46:25 -0400 Subject: [PATCH] - Removing K8S node backend duplicates. - Logging tweaks. - Minor version bump. --- .../src/main/java/io/vacco/a4lb/impl/A4Discover.java | 10 +++++++++- .../main/java/io/vacco/a4lb/impl/A4DiscoverK8s.java | 7 ++++--- build.gradle.kts | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/a4-core/src/main/java/io/vacco/a4lb/impl/A4Discover.java b/a4-core/src/main/java/io/vacco/a4lb/impl/A4Discover.java index f574ecd..5814da9 100644 --- a/a4-core/src/main/java/io/vacco/a4lb/impl/A4Discover.java +++ b/a4-core/src/main/java/io/vacco/a4lb/impl/A4Discover.java @@ -18,11 +18,15 @@ public class A4Discover implements Callable> { + public static Integer MaxDiscoveryErrorLogs = 1024; + public static int LogIntervalMultiplier = 10; + private static final Logger log = LoggerFactory.getLogger(A4Discover.class); private final String serverId; private final A4Match match; private final Gson gson; + private final A4TtlMap errorLogIdx = new A4TtlMap<>(MaxDiscoveryErrorLogs, msg -> {}); private final HttpClient client = HttpClient .newBuilder() .sslContext(SSLCertificates.trustAllContext()) @@ -86,7 +90,11 @@ private int hashOf(List backends) { return bkl; } } catch (Exception e) { - onError(log, "{} - backend discovery error for match [{}]", e, serverId, match); + var msg = String.format("%s - backend discovery error for match [%s]", serverId, match); + if (errorLogIdx.get(msg.hashCode()) == null) { + onError(log, msg, e); + errorLogIdx.put(msg.hashCode(), msg, match.discover.intervalMs * LogIntervalMultiplier); + } } return null; } diff --git a/a4-core/src/main/java/io/vacco/a4lb/impl/A4DiscoverK8s.java b/a4-core/src/main/java/io/vacco/a4lb/impl/A4DiscoverK8s.java index 1da25cb..136baf9 100644 --- a/a4-core/src/main/java/io/vacco/a4lb/impl/A4DiscoverK8s.java +++ b/a4-core/src/main/java/io/vacco/a4lb/impl/A4DiscoverK8s.java @@ -27,7 +27,7 @@ public static List nodesOf(String apiServerUri, String serviceJson, String namespace, String serviceName, int port, Function podJsonFn, Function nodeJsonFn) { - var nodes = new ArrayList(); + var nodes = new HashMap(); var service = JsonParser.parseString(serviceJson).getAsJsonObject(); var spec = service.getAsJsonObject("spec"); @@ -73,7 +73,8 @@ public static List nodesOf(String apiServerUri, String serviceJson, break; } } - nodes.add( + var nodeKey = format("%s-%d", nodeIp, nodePort); + nodes.put(nodeKey, new A4Backend() .state(A4BackendState.Unknown) .addr(new A4Sock().host(nodeIp).port(nodePort)) @@ -83,7 +84,7 @@ public static List nodesOf(String apiServerUri, String serviceJson, } } - return nodes; + return new ArrayList<>(nodes.values()); } private static List nodesOf(HttpClient client, String apiServerUri, String authToken, diff --git a/build.gradle.kts b/build.gradle.kts index 0510eb4..7a2af94 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -3,7 +3,7 @@ plugins { id("io.vacco.oss.gitflow") version "1.0.1" apply(false) } subprojects { apply(plugin = "io.vacco.oss.gitflow") group = "io.vacco.awe4lb" - version = "0.2.4" + version = "0.2.5" configure { addClasspathHell()