Skip to content

Commit

Permalink
Remove remote store attributes from DiscoveryNode toString() (#10810)
Browse files Browse the repository at this point in the history
Signed-off-by: Dhwanil Patel <[email protected]>
(cherry picked from commit 911afc4)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
github-actions[bot] committed Oct 22, 2023
1 parent 2dee554 commit a3a5512
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,13 @@ public String toString() {
sb.append('}');
}
if (!attributes.isEmpty()) {
sb.append(attributes);
sb.append(
attributes.entrySet()
.stream()
.filter(entry -> !entry.getKey().startsWith(REMOTE_STORE_NODE_ATTRIBUTE_KEY_PREFIX)) // filter remote_store attributes
// from logging to reduce noise.
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))
);
}
return sb.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,16 @@
import org.opensearch.common.settings.Settings;
import org.opensearch.core.common.io.stream.StreamInput;
import org.opensearch.core.common.transport.TransportAddress;
import org.opensearch.node.remotestore.RemoteStoreNodeAttribute;
import org.opensearch.test.NodeRoles;
import org.opensearch.test.OpenSearchTestCase;

import java.net.InetAddress;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -82,6 +85,22 @@ public void testRolesAreSorted() {

}

public void testRemoteStoreRedactionInToString() {
final Set<DiscoveryNodeRole> roles = new HashSet<>(randomSubsetOf(DiscoveryNodeRole.BUILT_IN_ROLES));
Map<String, String> attributes = new HashMap<>();
attributes.put(RemoteStoreNodeAttribute.REMOTE_STORE_SEGMENT_REPOSITORY_NAME_ATTRIBUTE_KEY, "test-repo");
attributes.put(RemoteStoreNodeAttribute.REMOTE_STORE_CLUSTER_STATE_REPOSITORY_NAME_ATTRIBUTE_KEY, "test-repo");
final DiscoveryNode node = new DiscoveryNode(
"name",
"id",
new TransportAddress(TransportAddress.META_ADDRESS, 9200),
attributes,
roles,
Version.CURRENT
);
assertFalse(node.toString().contains(RemoteStoreNodeAttribute.REMOTE_STORE_NODE_ATTRIBUTE_KEY_PREFIX));
}

public void testDiscoveryNodeIsCreatedWithHostFromInetAddress() throws Exception {
InetAddress inetAddress = randomBoolean()
? InetAddress.getByName("192.0.2.1")
Expand Down

0 comments on commit a3a5512

Please sign in to comment.