Skip to content

Commit

Permalink
- Removing K8S node backend duplicates.
Browse files Browse the repository at this point in the history
- Logging tweaks.
- Minor version bump.
  • Loading branch information
jjzazuet committed Oct 11, 2024
1 parent 44174d1 commit f58fd55
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
10 changes: 9 additions & 1 deletion a4-core/src/main/java/io/vacco/a4lb/impl/A4Discover.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@

public class A4Discover implements Callable<List<A4Backend>> {

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<Integer, String> errorLogIdx = new A4TtlMap<>(MaxDiscoveryErrorLogs, msg -> {});
private final HttpClient client = HttpClient
.newBuilder()
.sslContext(SSLCertificates.trustAllContext())
Expand Down Expand Up @@ -86,7 +90,11 @@ private int hashOf(List<A4Backend> 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;
}
Expand Down
7 changes: 4 additions & 3 deletions a4-core/src/main/java/io/vacco/a4lb/impl/A4DiscoverK8s.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static List<A4Backend> nodesOf(String apiServerUri, String serviceJson,
String namespace, String serviceName, int port,
Function<String, String> podJsonFn,
Function<String, String> nodeJsonFn) {
var nodes = new ArrayList<A4Backend>();
var nodes = new HashMap<String, A4Backend>();
var service = JsonParser.parseString(serviceJson).getAsJsonObject();
var spec = service.getAsJsonObject("spec");

Expand Down Expand Up @@ -73,7 +73,8 @@ public static List<A4Backend> 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))
Expand All @@ -83,7 +84,7 @@ public static List<A4Backend> nodesOf(String apiServerUri, String serviceJson,
}
}

return nodes;
return new ArrayList<>(nodes.values());
}

private static List<A4Backend> nodesOf(HttpClient client, String apiServerUri, String authToken,
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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<io.vacco.oss.gitflow.GsPluginProfileExtension> {
addClasspathHell()
Expand Down

0 comments on commit f58fd55

Please sign in to comment.