8
8
import com .ctrip .xpipe .redis .core .proxy .monitor .TunnelSocketStatsResult ;
9
9
import com .ctrip .xpipe .redis .core .proxy .monitor .TunnelStatsResult ;
10
10
import com .google .common .collect .Lists ;
11
+ import org .junit .Assert ;
11
12
import org .junit .Test ;
12
13
import org .springframework .beans .factory .annotation .Autowired ;
13
14
14
15
import java .util .List ;
16
+ import java .util .Map ;
15
17
16
18
public class DefaultTunnelSocketStatsAnalyzerManagerTest extends AbstractConsoleIntegrationTest {
17
19
@@ -34,6 +36,36 @@ public void testAnalyze() {
34
36
}
35
37
}
36
38
39
+ @ Test
40
+ public void testAnalyzeTags () {
41
+ List <TunnelSocketStatsAnalyzer .FrontendAndBackendMetrics > result = manager .analyze (new DefaultProxyChain ("FRA-AWS" , "cluster" , "shard" , "sharb" , Lists .newArrayList (
42
+ tunnelInfo3 ()
43
+ )));
44
+ int index = 1 ;
45
+
46
+ List <String > requireTags = Lists .newArrayList ("srcPortReminder" , "srcHostPort" , "dstHostPort" , "dstPortReminder" );
47
+ for (TunnelSocketStatsAnalyzer .FrontendAndBackendMetrics metric : result ) {
48
+
49
+ logger .info ("tunnel-{}" , index ++);
50
+ logger .info ("frontend:" );
51
+ logger .info ("{}: {}" , metric .getFrontend ().getMetricType (), metric .getFrontend ().getValue ());
52
+ Map <String , String > frontendTags = metric .getFrontend ().getTags ();
53
+ for (String tag : requireTags ) {
54
+ Assert .assertTrue (frontendTags .containsKey (tag ));
55
+ }
56
+
57
+ logger .info ("backend:" );
58
+ logger .info ("{}: {}" , metric .getBackend ().getMetricType (), metric .getBackend ().getValue ());
59
+ Map <String , String > backendTags = metric .getBackend ().getTags ();
60
+ for (String tag : requireTags ) {
61
+ Assert .assertTrue (backendTags .containsKey (tag ));
62
+ }
63
+
64
+ }
65
+ }
66
+
67
+
68
+
37
69
private DefaultTunnelInfo tunnelInfo1 () {
38
70
DefaultTunnelInfo info = new DefaultTunnelInfo (new ProxyModel ().setDcName ("oy" ).setHostPort (HostPort .fromString ("10.2.131.201:47082" )),
39
71
"10.2.131.242:55306-R(10.2.131.200:53868)-L(10.2.131.201:47082)->R(10.2.73.170:6389)-TCP://10.2.73.170:6389" );
@@ -53,4 +85,16 @@ private DefaultTunnelInfo tunnelInfo2() {
53
85
info .setTunnelStatsResult (new TunnelStatsResult (info .getTunnelId (), "established" , System .currentTimeMillis (), System .currentTimeMillis (), HostPort .fromString ("10.2.131.201:47082" ), HostPort .fromString ("10.2.131.201:47082" )));
54
86
return info ;
55
87
}
88
+
89
+ private DefaultTunnelInfo tunnelInfo3 () {
90
+ DefaultTunnelInfo info = new DefaultTunnelInfo (new ProxyModel ().setDcName ("fra-aws" ).setHostPort (new HostPort ("10.2.131.200" , 53868 )),
91
+ "10.2.131.242:55306-R(10.2.131.242:55306)-L(10.2.131.200:53868)->R(10.2.131.201:443-TCP://10.2.73.170:6389" );
92
+ info .setTunnelSocketStatsResult (new TunnelSocketStatsResult (info .getTunnelId (),
93
+ new SocketStatsResult (Lists .newArrayList ("ESTAB 0 285 " , "skmem:(r0,rb374400,t0,tb130560,f1251,w2845,o0,bl0) bbr wscale:10,10 rto:459 rtt:258.008/0.348 ato:40 mss:1460 cwnd:11 send 498.0Kbps unacked:2 retrans:0/3119 rcv_rtt:517020 rcv_space:40824" )),
94
+ new SocketStatsResult (Lists .newArrayList ("ESTAB 0 0 ::ffff:10.28.81.65:36190 ::ffff:10.28.97.195:5379 " , "skmem:(r0,rb566888,t0,tb130560,f4096,w0,o0,bl0) bbr wscale:7,10 rto:203 rtt:2.043/3.712 ato:87 mss:1448 cwnd:11 send 62.4Mbps rcv_rtt:1 rcv_space:57729" ))));
95
+ info .setTunnelStatsResult (new TunnelStatsResult (info .getTunnelId (), "established" , System .currentTimeMillis (), System .currentTimeMillis (), HostPort .fromString ("10.2.131.201:47082" ), HostPort .fromString ("10.2.131.201:47082" )));
96
+ return info ;
97
+ }
98
+
99
+
56
100
}
0 commit comments