|
14 | 14 | import org.elasticsearch.cluster.metadata.ProjectId; |
15 | 15 | import org.elasticsearch.cluster.metadata.ProjectMetadata; |
16 | 16 | import org.elasticsearch.common.CheckedBiFunction; |
17 | | -import org.elasticsearch.common.Strings; |
18 | 17 | import org.elasticsearch.common.settings.ProjectSecrets; |
19 | 18 | import org.elasticsearch.common.settings.Settings; |
20 | 19 | import org.elasticsearch.common.util.Maps; |
21 | 20 | import org.elasticsearch.common.util.concurrent.ConcurrentCollections; |
| 21 | +import org.elasticsearch.common.util.set.Sets; |
22 | 22 | import org.elasticsearch.logging.LogManager; |
23 | 23 | import org.elasticsearch.logging.Logger; |
24 | 24 |
|
@@ -89,20 +89,25 @@ public void applyClusterState(ClusterChangedEvent event) { |
89 | 89 | .put(nodeGcsSettings) |
90 | 90 | .setSecureSettings(projectSecrets.getSettings()) |
91 | 91 | .build(); |
92 | | - final Map<String, GoogleCloudStorageClientSettings> clientSettings = GoogleCloudStorageClientSettings.load(currentSettings) |
93 | | - .entrySet() |
| 92 | + |
| 93 | + final var allClientSettings = GoogleCloudStorageClientSettings.load(currentSettings); |
| 94 | + assert allClientSettings.isEmpty() == false; |
| 95 | + // Skip project clients that have no credentials configured. This should not happen in serverless. |
| 96 | + // But it is safer to skip them and is also a more consistent behaviour with the cases when |
| 97 | + // project secrets are not present. |
| 98 | + final var clientSettings = allClientSettings.entrySet() |
94 | 99 | .stream() |
95 | | - // Skip project clients that have no credentials configured. This should not happen in serverless. |
96 | | - // But it is safer to skip them and is also a more consistent behaviour with the cases when |
97 | | - // project secrets are not present. |
98 | 100 | .filter(entry -> entry.getValue().getCredential() != null) |
99 | 101 | .collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, Map.Entry::getValue)); |
100 | 102 |
|
101 | | - if (clientSettings.isEmpty()) { |
102 | | - // clientSettings should not be empty, i.e. there should be at least one client configured. |
103 | | - // But if it does somehow happen, log a warning and continue. The project will not have usable client but that is ok. |
104 | | - logger.warn("Skipping project [{}] with no client settings", project.id()); |
105 | | - continue; |
| 103 | + if (allClientSettings.size() != clientSettings.size()) { |
| 104 | + logger.warn( |
| 105 | + "Project [{}] has [{}] GCS client settings, but [{}] is usable due to missing credentials for clients {}", |
| 106 | + project.id(), |
| 107 | + allClientSettings.size(), |
| 108 | + clientSettings.size(), |
| 109 | + Sets.difference(allClientSettings.keySet(), clientSettings.keySet()) |
| 110 | + ); |
106 | 111 | } |
107 | 112 |
|
108 | 113 | // TODO: If performance is an issue, we may consider comparing just the relevant project secrets for new or updated clients |
@@ -221,10 +226,7 @@ MeteredStorage client(final String clientName, final String repositoryName, fina |
221 | 226 |
|
222 | 227 | if (settings == null) { |
223 | 228 | throw new IllegalArgumentException( |
224 | | - "Unknown client name [" |
225 | | - + clientName |
226 | | - + "]. Existing client configs: " |
227 | | - + Strings.collectionToDelimitedString(allClientSettings().keySet(), ",") |
| 229 | + "Unknown client name [" + clientName + "]. Existing client configs: " + allClientSettings().keySet() |
228 | 230 | ); |
229 | 231 | } |
230 | 232 |
|
|
0 commit comments