From 044a15e569fe674bad0f8190aa31e2c4905c8887 Mon Sep 17 00:00:00 2001 From: Jermy Li Date: Fri, 29 Apr 2022 14:53:28 +0800 Subject: [PATCH] cassandra metrics workaround: translate ipv4 to ipv6 (#1853) * log cassandra probe host * Translate IPv4 to IPv6 to fix issue #1843 * enable cassandra/scylladb metrics test case * resume debug log --- .../store/cassandra/CassandraMetrics.java | 15 +- .../baidu/hugegraph/api/MetricsApiTest.java | 222 +++++++++--------- 2 files changed, 125 insertions(+), 112 deletions(-) diff --git a/hugegraph-cassandra/src/main/java/com/baidu/hugegraph/backend/store/cassandra/CassandraMetrics.java b/hugegraph-cassandra/src/main/java/com/baidu/hugegraph/backend/store/cassandra/CassandraMetrics.java index 15adc8ecda..bc17e207d3 100644 --- a/hugegraph-cassandra/src/main/java/com/baidu/hugegraph/backend/store/cassandra/CassandraMetrics.java +++ b/hugegraph-cassandra/src/main/java/com/baidu/hugegraph/backend/store/cassandra/CassandraMetrics.java @@ -21,6 +21,8 @@ import java.io.IOException; import java.lang.management.MemoryUsage; +import java.net.Inet4Address; +import java.net.Inet6Address; import java.net.InetAddress; import java.util.Collections; import java.util.List; @@ -297,7 +299,18 @@ private Map executeAllHosts(Function func) { Map hostsResults = InsertionOrderUtil.newMap(); for (Host host : hosts) { InetAddress address = host.getAddress(); - String hostAddress = address.getHostAddress(); + String hostAddress; + if (address instanceof Inet4Address) { + hostAddress = host.getAddress().getHostAddress(); + /* + * Translate IPv4 to IPv6 to fix issue #1843 + * TODO: delete this workaround code after fixed CASSANDRA-17581 + */ + hostAddress = "::FFFF:" + hostAddress; + } else { + assert address instanceof Inet6Address; + hostAddress = host.getAddress().getHostAddress(); + } hostsResults.put(hostAddress, func.apply(hostAddress)); } results.put(SERVERS, hostsResults); diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/MetricsApiTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/MetricsApiTest.java index 6b9a4cad1f..aee8d3ccea 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/MetricsApiTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/MetricsApiTest.java @@ -100,61 +100,61 @@ public void testMetricsBackend() { servers = (Map) graph.get("servers"); Assert.assertGte(1, servers.size()); // TODO: Uncomment after fixed #1843 -// for (Map.Entry e : servers.entrySet()) { -// String key = (String) e.getKey(); -// value = e.getValue(); -// Assert.assertTrue(String.format( -// "Expect map value for key %s but got %s", -// key, value), -// value instanceof Map); -// host = (Map) value; -// assertMapContains(host, "mem_max"); -// assertMapContains(host, "mem_committed"); -// assertMapContains(host, "mem_used"); -// assertMapContains(host, "mem_used_readable"); -// assertMapContains(host, "mem_unit"); -// -// assertMapContains(host, "disk_usage"); -// assertMapContains(host, "disk_usage_readable"); -// assertMapContains(host, "disk_usage_details"); -// assertMapContains(host, "disk_unit"); -// -// assertMapContains(host, "uptime"); -// assertMapContains(host, "uptime_readable"); -// assertMapContains(host, "time_unit"); -// -// assertMapContains(host, "estimated_partition_count"); -// assertMapContains(host, "dropped_mutations"); -// assertMapContains(host, "pending_flushes"); -// assertMapContains(host, "key_cache_hit_rate"); -// assertMapContains(host, "bloom_filter_false_ratio"); -// -// assertMapContains(host, "write_latency_hugegraph"); -// assertMapContains(host, "read_latency_hugegraph"); -// assertMapContains(host, "write_latency_*"); -// assertMapContains(host, "read_latency_*"); -// -// assertMapContains(host, "key_cache_size"); -// assertMapContains(host, "key_cache_entries"); -// assertMapContains(host, "row_cache_size"); -// assertMapContains(host, "row_cache_entries"); -// assertMapContains(host, "counter_cache_size"); -// assertMapContains(host, "counter_cache_entries"); -// -// assertMapContains(host, "compaction_completed_tasks"); -// assertMapContains(host, "compaction_pending_tasks"); -// assertMapContains(host, "compaction_bytes_compacted"); -// -// assertMapContains(host, "live_nodes"); -// assertMapContains(host, "joining_nodes"); -// assertMapContains(host, "moving_nodes"); -// assertMapContains(host, "leaving_nodes"); -// assertMapContains(host, "unreachable_nodes"); -// -// assertMapContains(host, "keyspaces"); -// assertMapContains(host, "num_tables"); -// assertMapContains(host, "exception_count"); -// } + for (Map.Entry e : servers.entrySet()) { + String key = (String) e.getKey(); + value = e.getValue(); + Assert.assertTrue(String.format( + "Expect map value for key %s but got %s", + key, value), + value instanceof Map); + host = (Map) value; + assertMapContains(host, "mem_max"); + assertMapContains(host, "mem_committed"); + assertMapContains(host, "mem_used"); + assertMapContains(host, "mem_used_readable"); + assertMapContains(host, "mem_unit"); + + assertMapContains(host, "disk_usage"); + assertMapContains(host, "disk_usage_readable"); + assertMapContains(host, "disk_usage_details"); + assertMapContains(host, "disk_unit"); + + assertMapContains(host, "uptime"); + assertMapContains(host, "uptime_readable"); + assertMapContains(host, "time_unit"); + + assertMapContains(host, "estimated_partition_count"); + assertMapContains(host, "dropped_mutations"); + assertMapContains(host, "pending_flushes"); + assertMapContains(host, "key_cache_hit_rate"); + assertMapContains(host, "bloom_filter_false_ratio"); + + assertMapContains(host, "write_latency_hugegraph"); + assertMapContains(host, "read_latency_hugegraph"); + assertMapContains(host, "write_latency_*"); + assertMapContains(host, "read_latency_*"); + + assertMapContains(host, "key_cache_size"); + assertMapContains(host, "key_cache_entries"); + assertMapContains(host, "row_cache_size"); + assertMapContains(host, "row_cache_entries"); + assertMapContains(host, "counter_cache_size"); + assertMapContains(host, "counter_cache_entries"); + + assertMapContains(host, "compaction_completed_tasks"); + assertMapContains(host, "compaction_pending_tasks"); + assertMapContains(host, "compaction_bytes_compacted"); + + assertMapContains(host, "live_nodes"); + assertMapContains(host, "joining_nodes"); + assertMapContains(host, "moving_nodes"); + assertMapContains(host, "leaving_nodes"); + assertMapContains(host, "unreachable_nodes"); + + assertMapContains(host, "keyspaces"); + assertMapContains(host, "num_tables"); + assertMapContains(host, "exception_count"); + } break; case "scylladb": assertMapContains(graph, "cluster_id"); @@ -162,62 +162,62 @@ public void testMetricsBackend() { servers = (Map) graph.get("servers"); Assert.assertGte(1, servers.size()); - // TODO: Uncomment after fixed #1843 -// for (Map.Entry e : servers.entrySet()) { -// String key = (String) e.getKey(); -// value = e.getValue(); -// Assert.assertTrue(String.format( -// "Expect map value for key %s but got %s", -// key, value), -// value instanceof Map); -// host = (Map) value; -// assertMapContains(host, "mem_max"); -// assertMapContains(host, "mem_committed"); -// assertMapContains(host, "mem_used"); -// assertMapContains(host, "mem_used_readable"); -// assertMapContains(host, "mem_unit"); -// -// assertMapContains(host, "disk_usage"); -// assertMapContains(host, "disk_usage_readable"); -// assertMapContains(host, "disk_usage_details"); -// assertMapContains(host, "disk_unit"); -// -// assertMapContains(host, "uptime"); -// assertMapContains(host, "uptime_readable"); -// assertMapContains(host, "time_unit"); -// -// assertMapContains(host, "estimated_partition_count"); -// assertMapContains(host, "dropped_mutations"); -// assertMapContains(host, "pending_flushes"); -// //assertMapContains(host, "key_cache_hit_rate"); -// assertMapContains(host, "bloom_filter_false_ratio"); -// -// //assertMapContains(host, "write_latency_hugegraph"); -// //assertMapContains(host, "read_latency_hugegraph"); -// //assertMapContains(host, "write_latency_*"); -// //assertMapContains(host, "read_latency_*"); -// -// assertMapContains(host, "key_cache_size"); -// assertMapContains(host, "key_cache_entries"); -// assertMapContains(host, "row_cache_size"); -// assertMapContains(host, "row_cache_entries"); -// assertMapContains(host, "counter_cache_size"); -// assertMapContains(host, "counter_cache_entries"); -// -// assertMapContains(host, "compaction_completed_tasks"); -// assertMapContains(host, "compaction_pending_tasks"); -// //assertMapContains(host, "compaction_bytes_compacted"); -// -// assertMapContains(host, "live_nodes"); -// assertMapContains(host, "joining_nodes"); -// assertMapContains(host, "moving_nodes"); -// assertMapContains(host, "leaving_nodes"); -// assertMapContains(host, "unreachable_nodes"); -// -// assertMapContains(host, "keyspaces"); -// assertMapContains(host, "num_tables"); -// assertMapContains(host, "exception_count"); -// } + + for (Map.Entry e : servers.entrySet()) { + String key = (String) e.getKey(); + value = e.getValue(); + Assert.assertTrue(String.format( + "Expect map value for key %s but got %s", + key, value), + value instanceof Map); + host = (Map) value; + assertMapContains(host, "mem_max"); + assertMapContains(host, "mem_committed"); + assertMapContains(host, "mem_used"); + assertMapContains(host, "mem_used_readable"); + assertMapContains(host, "mem_unit"); + + assertMapContains(host, "disk_usage"); + assertMapContains(host, "disk_usage_readable"); + assertMapContains(host, "disk_usage_details"); + assertMapContains(host, "disk_unit"); + + assertMapContains(host, "uptime"); + assertMapContains(host, "uptime_readable"); + assertMapContains(host, "time_unit"); + + assertMapContains(host, "estimated_partition_count"); + assertMapContains(host, "dropped_mutations"); + assertMapContains(host, "pending_flushes"); + //assertMapContains(host, "key_cache_hit_rate"); + assertMapContains(host, "bloom_filter_false_ratio"); + + //assertMapContains(host, "write_latency_hugegraph"); + //assertMapContains(host, "read_latency_hugegraph"); + //assertMapContains(host, "write_latency_*"); + //assertMapContains(host, "read_latency_*"); + + assertMapContains(host, "key_cache_size"); + assertMapContains(host, "key_cache_entries"); + assertMapContains(host, "row_cache_size"); + assertMapContains(host, "row_cache_entries"); + assertMapContains(host, "counter_cache_size"); + assertMapContains(host, "counter_cache_entries"); + + assertMapContains(host, "compaction_completed_tasks"); + assertMapContains(host, "compaction_pending_tasks"); + //assertMapContains(host, "compaction_bytes_compacted"); + + assertMapContains(host, "live_nodes"); + assertMapContains(host, "joining_nodes"); + assertMapContains(host, "moving_nodes"); + assertMapContains(host, "leaving_nodes"); + assertMapContains(host, "unreachable_nodes"); + + assertMapContains(host, "keyspaces"); + assertMapContains(host, "num_tables"); + assertMapContains(host, "exception_count"); + } break; case "hbase": assertMapContains(graph, "cluster_id");