|
12 | 12 | import org.elasticsearch.action.admin.cluster.node.stats.NodeStats;
|
13 | 13 | import org.elasticsearch.action.admin.cluster.node.stats.NodeStatsTests;
|
14 | 14 | import org.elasticsearch.cluster.node.DiscoveryNode;
|
| 15 | +import org.elasticsearch.common.network.InetAddresses; |
15 | 16 | import org.elasticsearch.common.network.NetworkModule;
|
16 | 17 | import org.elasticsearch.common.settings.Settings;
|
| 18 | +import org.elasticsearch.monitor.fs.FsInfo; |
17 | 19 | import org.elasticsearch.test.ESTestCase;
|
18 | 20 | import org.elasticsearch.xcontent.XContentType;
|
19 | 21 |
|
| 22 | +import java.net.InetAddress; |
20 | 23 | import java.util.Arrays;
|
21 | 24 | import java.util.Collections;
|
22 | 25 | import java.util.Iterator;
|
@@ -121,6 +124,128 @@ public void testIngestStats() throws Exception {
|
121 | 124 | );
|
122 | 125 | }
|
123 | 126 |
|
| 127 | + public void testClusterFsStatsDeduplicator() { |
| 128 | + { |
| 129 | + // single node, multiple data paths, different devices |
| 130 | + InetAddress address1 = InetAddresses.forString("192.168.0.1"); |
| 131 | + FsInfo.Path path1 = new FsInfo.Path("/a", "/dev/sda", 3, 2, 1); |
| 132 | + FsInfo.Path path2 = new FsInfo.Path("/b", "/dev/sdb", 3, 2, 1); |
| 133 | + ClusterStatsNodes.ClusterFsStatsDeduplicator deduplicator = new ClusterStatsNodes.ClusterFsStatsDeduplicator(1); |
| 134 | + deduplicator.add(address1, newFsInfo(path1, path2)); |
| 135 | + FsInfo.Path total = deduplicator.getTotal(); |
| 136 | + |
| 137 | + // since they're different devices, they sum |
| 138 | + assertThat(total.getTotal().getBytes(), equalTo(6L)); |
| 139 | + assertThat(total.getFree().getBytes(), equalTo(4L)); |
| 140 | + assertThat(total.getAvailable().getBytes(), equalTo(2L)); |
| 141 | + } |
| 142 | + |
| 143 | + { |
| 144 | + // single node, multiple data paths, same device |
| 145 | + InetAddress address1 = InetAddresses.forString("192.168.0.1"); |
| 146 | + FsInfo.Path path1 = new FsInfo.Path("/data/a", "/dev/sda", 3, 2, 1); |
| 147 | + FsInfo.Path path2 = new FsInfo.Path("/data/b", "/dev/sda", 3, 2, 1); |
| 148 | + ClusterStatsNodes.ClusterFsStatsDeduplicator deduplicator = new ClusterStatsNodes.ClusterFsStatsDeduplicator(1); |
| 149 | + deduplicator.add(address1, newFsInfo(path1, path2)); |
| 150 | + FsInfo.Path total = deduplicator.getTotal(); |
| 151 | + |
| 152 | + // since it's the same device, they don't sum, we just see the one |
| 153 | + assertThat(total.getTotal().getBytes(), equalTo(3L)); |
| 154 | + assertThat(total.getFree().getBytes(), equalTo(2L)); |
| 155 | + assertThat(total.getAvailable().getBytes(), equalTo(1L)); |
| 156 | + } |
| 157 | + |
| 158 | + { |
| 159 | + // two nodes, same ip address, but different data paths on different devices |
| 160 | + InetAddress address1 = InetAddresses.forString("192.168.0.1"); |
| 161 | + FsInfo.Path path1 = new FsInfo.Path("/data/a", "/dev/sda", 3, 2, 1); |
| 162 | + InetAddress address2 = InetAddresses.forString("192.168.0.1"); |
| 163 | + FsInfo.Path path2 = new FsInfo.Path("/data/b", "/dev/sdb", 3, 2, 1); |
| 164 | + ClusterStatsNodes.ClusterFsStatsDeduplicator deduplicator = new ClusterStatsNodes.ClusterFsStatsDeduplicator(1); |
| 165 | + deduplicator.add(address1, newFsInfo(path1)); |
| 166 | + deduplicator.add(address2, newFsInfo(path2)); |
| 167 | + FsInfo.Path total = deduplicator.getTotal(); |
| 168 | + |
| 169 | + // since they're different devices, they sum |
| 170 | + assertThat(total.getTotal().getBytes(), equalTo(6L)); |
| 171 | + assertThat(total.getFree().getBytes(), equalTo(4L)); |
| 172 | + assertThat(total.getAvailable().getBytes(), equalTo(2L)); |
| 173 | + } |
| 174 | + |
| 175 | + { |
| 176 | + // two nodes, different ip addresses, different data paths, same device |
| 177 | + InetAddress address1 = InetAddresses.forString("192.168.0.1"); |
| 178 | + FsInfo.Path path1 = new FsInfo.Path("/data/a", "/dev/sda", 3, 2, 1); |
| 179 | + InetAddress address2 = InetAddresses.forString("192.168.0.2"); |
| 180 | + FsInfo.Path path2 = new FsInfo.Path("/data/b", "/dev/sda", 3, 2, 1); |
| 181 | + ClusterStatsNodes.ClusterFsStatsDeduplicator deduplicator = new ClusterStatsNodes.ClusterFsStatsDeduplicator(1); |
| 182 | + deduplicator.add(address1, newFsInfo(path1)); |
| 183 | + deduplicator.add(address2, newFsInfo(path2)); |
| 184 | + FsInfo.Path total = deduplicator.getTotal(); |
| 185 | + |
| 186 | + // it's the same device, yeah, but on entirely different machines, so they sum |
| 187 | + assertThat(total.getTotal().getBytes(), equalTo(6L)); |
| 188 | + assertThat(total.getFree().getBytes(), equalTo(4L)); |
| 189 | + assertThat(total.getAvailable().getBytes(), equalTo(2L)); |
| 190 | + } |
| 191 | + |
| 192 | + { |
| 193 | + // two nodes, same ip address, same data path, same device |
| 194 | + InetAddress address1 = InetAddresses.forString("192.168.0.1"); |
| 195 | + FsInfo.Path path1 = new FsInfo.Path("/app/data", "/app (/dev/mapper/lxc-data)", 3, 2, 1); |
| 196 | + InetAddress address2 = InetAddresses.forString("192.168.0.1"); |
| 197 | + FsInfo.Path path2 = new FsInfo.Path("/app/data", "/app (/dev/mapper/lxc-data)", 3, 2, 1); |
| 198 | + ClusterStatsNodes.ClusterFsStatsDeduplicator deduplicator = new ClusterStatsNodes.ClusterFsStatsDeduplicator(1); |
| 199 | + deduplicator.add(address1, newFsInfo(path1)); |
| 200 | + deduplicator.add(address2, newFsInfo(path2)); |
| 201 | + FsInfo.Path total = deduplicator.getTotal(); |
| 202 | + |
| 203 | + // wait a second, this is the super-special case -- you can't actually have two nodes doing this unless something |
| 204 | + // very interesting is happening, so they sum (i.e. we assume the operator is doing smart things) |
| 205 | + assertThat(total.getTotal().getBytes(), equalTo(6L)); |
| 206 | + assertThat(total.getFree().getBytes(), equalTo(4L)); |
| 207 | + assertThat(total.getAvailable().getBytes(), equalTo(2L)); |
| 208 | + } |
| 209 | + |
| 210 | + { |
| 211 | + // two nodes, same ip address, different data paths, same device |
| 212 | + InetAddress address1 = InetAddresses.forString("192.168.0.1"); |
| 213 | + FsInfo.Path path1 = new FsInfo.Path("/app/data1", "/dev/sda", 3, 2, 1); |
| 214 | + InetAddress address2 = InetAddresses.forString("192.168.0.1"); |
| 215 | + FsInfo.Path path2 = new FsInfo.Path("/app/data2", "/dev/sda", 3, 2, 1); |
| 216 | + ClusterStatsNodes.ClusterFsStatsDeduplicator deduplicator = new ClusterStatsNodes.ClusterFsStatsDeduplicator(1); |
| 217 | + deduplicator.add(address1, newFsInfo(path1)); |
| 218 | + deduplicator.add(address2, newFsInfo(path2)); |
| 219 | + FsInfo.Path total = deduplicator.getTotal(); |
| 220 | + |
| 221 | + // since the paths aren't the same, it doesn't trigger the special case -- it's just the same device and doesn't sum |
| 222 | + assertThat(total.getTotal().getBytes(), equalTo(3L)); |
| 223 | + assertThat(total.getFree().getBytes(), equalTo(2L)); |
| 224 | + assertThat(total.getAvailable().getBytes(), equalTo(1L)); |
| 225 | + } |
| 226 | + |
| 227 | + { |
| 228 | + // two nodes, same ip address, same data path, different devices |
| 229 | + InetAddress address1 = InetAddresses.forString("192.168.0.1"); |
| 230 | + FsInfo.Path path1 = new FsInfo.Path("/app/data", "/dev/sda", 3, 2, 1); |
| 231 | + InetAddress address2 = InetAddresses.forString("192.168.0.1"); |
| 232 | + FsInfo.Path path2 = new FsInfo.Path("/app/data", "/dev/sdb", 3, 2, 1); |
| 233 | + ClusterStatsNodes.ClusterFsStatsDeduplicator deduplicator = new ClusterStatsNodes.ClusterFsStatsDeduplicator(1); |
| 234 | + deduplicator.add(address1, newFsInfo(path1)); |
| 235 | + deduplicator.add(address2, newFsInfo(path2)); |
| 236 | + FsInfo.Path total = deduplicator.getTotal(); |
| 237 | + |
| 238 | + // having the same path isn't special in this case, it's just unique ip/mount pairs, so they sum |
| 239 | + assertThat(total.getTotal().getBytes(), equalTo(6L)); |
| 240 | + assertThat(total.getFree().getBytes(), equalTo(4L)); |
| 241 | + assertThat(total.getAvailable().getBytes(), equalTo(2L)); |
| 242 | + } |
| 243 | + } |
| 244 | + |
| 245 | + private static FsInfo newFsInfo(FsInfo.Path... paths) { |
| 246 | + return new FsInfo(-1, null, paths); |
| 247 | + } |
| 248 | + |
124 | 249 | private static NodeInfo createNodeInfo(String nodeId, String transportType, String httpType) {
|
125 | 250 | Settings.Builder settings = Settings.builder();
|
126 | 251 | if (transportType != null) {
|
|
0 commit comments