-
Notifications
You must be signed in to change notification settings - Fork 954
Introduce XdsClusterManager
to cache Cluster
s
#6261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/* | ||
* Copyright 2024 LINE Corporation | ||
* Copyright 2025 LY Corporation | ||
* | ||
* LINE Corporation licenses this file to you under the Apache License, | ||
* LY Corporation licenses this file to you under the Apache License, | ||
* version 2.0 (the "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at: | ||
* | ||
|
@@ -22,43 +22,54 @@ | |
import com.linecorp.armeria.common.annotation.Nullable; | ||
|
||
import io.envoyproxy.envoy.config.bootstrap.v3.Bootstrap; | ||
import io.envoyproxy.envoy.config.bootstrap.v3.Bootstrap.StaticResources; | ||
import io.envoyproxy.envoy.config.cluster.v3.Cluster; | ||
import io.grpc.Status; | ||
import io.netty.util.concurrent.EventExecutor; | ||
|
||
final class BootstrapClusters implements SnapshotWatcher<ClusterSnapshot> { | ||
|
||
private final Map<String, ClusterSnapshot> clusterSnapshots = new HashMap<>(); | ||
private final Map<String, Cluster> clusters = new HashMap<>(); | ||
private final Bootstrap bootstrap; | ||
private final EventExecutor eventLoop; | ||
private final XdsClusterManager clusterManager; | ||
|
||
BootstrapClusters(Bootstrap bootstrap, XdsBootstrapImpl xdsBootstrap) { | ||
if (bootstrap.hasStaticResources()) { | ||
final StaticResources staticResources = bootstrap.getStaticResources(); | ||
for (Cluster cluster : staticResources.getClustersList()) { | ||
if (cluster.hasLoadAssignment()) { | ||
// no need to clean this cluster up since it is fully static | ||
StaticResourceUtils.staticCluster(xdsBootstrap, cluster.getName(), this, cluster); | ||
} | ||
clusters.put(cluster.getName(), cluster); | ||
BootstrapClusters(Bootstrap bootstrap, EventExecutor eventLoop, XdsClusterManager clusterManager) { | ||
this.bootstrap = bootstrap; | ||
this.eventLoop = eventLoop; | ||
this.clusterManager = clusterManager; | ||
initializePrimary(bootstrap); | ||
} | ||
|
||
private void initializePrimary(Bootstrap bootstrap) { | ||
final StaticSubscriptionContext context = new StaticSubscriptionContext(eventLoop); | ||
for (Cluster cluster: bootstrap.getStaticResources().getClustersList()) { | ||
if (!cluster.hasLoadAssignment()) { | ||
continue; | ||
} | ||
clusterManager.register(cluster, context, this); | ||
} | ||
} | ||
|
||
void initializeSecondary(SubscriptionContext context) { | ||
for (Cluster cluster: bootstrap.getStaticResources().getClustersList()) { | ||
if (!cluster.hasEdsClusterConfig()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer to keep the naming secondary as it is a widely used term upstream. (ref) Let me know if you feel strongly about this though There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Didn't know about it. Let's use the term secondary, then. |
||
continue; | ||
} | ||
clusterManager.register(cluster, context, this); | ||
} | ||
} | ||
|
||
@Override | ||
public void snapshotUpdated(ClusterSnapshot newSnapshot) { | ||
clusterSnapshots.put(newSnapshot.xdsResource().name(), newSnapshot); | ||
final String name = newSnapshot.xdsResource().name(); | ||
clusterSnapshots.put(name, newSnapshot); | ||
} | ||
|
||
@Nullable | ||
ClusterSnapshot clusterSnapshot(String clusterName) { | ||
return clusterSnapshots.get(clusterName); | ||
} | ||
|
||
@Nullable | ||
Cluster cluster(String clusterName) { | ||
return clusters.get(clusterName); | ||
} | ||
|
||
@Override | ||
public void onMissing(XdsType type, String resourceName) { | ||
throw new IllegalArgumentException("Bootstrap cluster not found for type: '" + | ||
|
Uh oh!
There was an error while loading. Please reload this page.