Skip to content

Commit

Permalink
[7.17] [GCE Discovery] Correcly handle large zones with 500 or more i…
Browse files Browse the repository at this point in the history
…nstances (#83785) (#83981)

Backports the following commits to 7.17:
 - [GCE Discovery] Correcly handle large zones with 500 or more instances (#83785)

Co-authored-by: Claudio Marins <cdmbr@users.noreply.github.com>
  • Loading branch information
arteam and cdmbr committed Feb 15, 2022
1 parent 53ed187 commit dbb5c95
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 8 deletions.
6 changes: 6 additions & 0 deletions docs/changelog/83785.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 83785
summary: '[GCE Discovery] Correcly handle large zones with 500 or more instances'
area: Distributed
type: bug
issues:
- 83783
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,19 @@ public Collection<Instance> instances() {
try {
// hack around code messiness in GCE code
// TODO: get this fixed
InstanceList instanceList = Access.doPrivilegedIOException(() -> {
Compute.Instances.List list = client().instances().list(project, zoneId);
return list.execute();
return Access.doPrivilegedIOException(() -> {
String nextPageToken = null;
List<Instance> zoneInstances = new ArrayList<>();
do {
Compute.Instances.List list = client().instances().list(project, zoneId).setPageToken(nextPageToken);
InstanceList instanceList = list.execute();
nextPageToken = instanceList.getNextPageToken();
if (instanceList.isEmpty() == false && instanceList.getItems() != null) {
zoneInstances.addAll(instanceList.getItems());
}
} while (nextPageToken != null);
return zoneInstances;
});
// assist type inference
return instanceList.isEmpty() || instanceList.getItems() == null
? Collections.<Instance>emptyList()
: instanceList.getItems();
} catch (IOException e) {
logger.warn((Supplier<?>) () -> new ParameterizedMessage("Problem fetching instance list for zone {}", zoneId), e);
logger.debug("Full exception:", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,4 +272,17 @@ public void testMetadataServerValues() {
List<TransportAddress> dynamicHosts = buildDynamicNodes(mock, nodeSettings);
assertThat(dynamicHosts, hasSize(1));
}

public void testNodesWithPagination() {
Settings nodeSettings = Settings.builder()
.put(GceInstancesServiceImpl.PROJECT_SETTING.getKey(), projectName)
.put(GceInstancesServiceImpl.ZONE_SETTING.getKey(), "europe-west1-b")
.putList(GceSeedHostsProvider.TAGS_SETTING.getKey(), "elasticsearch", "dev")
.build();
mock = new GceInstancesServiceMock(nodeSettings);
List<TransportAddress> dynamicHosts = buildDynamicNodes(mock, nodeSettings);
assertThat(dynamicHosts, hasSize(2));
assertEquals("10.240.79.59", dynamicHosts.get(0).getAddress());
assertEquals("10.240.79.60", dynamicHosts.get(1).getAddress());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static String readGoogleApiJsonResponse(String url) throws IOException {

private static String readJsonResponse(String url, String urlRoot) throws IOException {
// We extract from the url the mock file path we want to use
String mockFileName = Strings.replace(url, urlRoot, "");
String mockFileName = Strings.replace(url, urlRoot, "").replace("?", "%3F");

URL resource = GceMockUtils.class.getResource(mockFileName);
if (resource == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"id": "dummy",
"items":[
{
"description": "ES Node 1",
"id": "9309873766428965105",
"kind": "compute#instance",
"machineType": "n1-standard-1",
"name": "test1",
"networkInterfaces": [
{
"accessConfigs": [
{
"kind": "compute#accessConfig",
"name": "External NAT",
"natIP": "104.155.13.147",
"type": "ONE_TO_ONE_NAT"
}
],
"name": "nic0",
"network": "default",
"networkIP": "10.240.79.59"
}
],
"status": "RUNNING",
"tags": {
"fingerprint": "xA6QJb-rGtg=",
"items": [
"elasticsearch",
"dev"
]
},
"zone": "europe-west1-b"
}
],
"nextPageToken": "next-token"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"id": "dummy",
"items":[
{
"description": "ES Node 2",
"id": "9309873766428965105",
"kind": "compute#instance",
"machineType": "n1-standard-1",
"name": "test2",
"networkInterfaces": [
{
"accessConfigs": [
{
"kind": "compute#accessConfig",
"name": "External NAT",
"natIP": "104.155.13.147",
"type": "ONE_TO_ONE_NAT"
}
],
"name": "nic0",
"network": "default",
"networkIP": "10.240.79.60"
}
],
"status": "RUNNING",
"tags": {
"fingerprint": "xA6QJb-rGtg=",
"items": [
"elasticsearch",
"dev"
]
},
"zone": "europe-west1-b"
}
]
}

0 comments on commit dbb5c95

Please sign in to comment.