changeset 1060:efe41a7d7272

Metrics bugfixes
author Devel 2
date Thu, 16 Apr 2020 14:14:53 +0200
parents 1d47e67bad78
children b79ecce8df37
files stress-tester/src/main/java/com/passus/st/client/AbstractFlowHandler.java stress-tester/src/main/java/com/passus/st/client/DbMetric.java stress-tester/src/main/java/com/passus/st/client/GenericMetric.java stress-tester/src/main/java/com/passus/st/client/SynchFlowWorker.java stress-tester/src/main/java/com/passus/st/client/http/HttpFlowHandler.java stress-tester/src/test/java/com/passus/st/source/NcEventSourceTest.java
diffstat 6 files changed, 16 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/client/AbstractFlowHandler.java	Thu Apr 16 12:52:37 2020 +0200
+++ b/stress-tester/src/main/java/com/passus/st/client/AbstractFlowHandler.java	Thu Apr 16 14:14:53 2020 +0200
@@ -42,7 +42,7 @@
             synchronized (metric) {
                 metric.activate();
             }
-        } else {
+        } else if (metric != null) {
             synchronized (metric) {
                 metric.deactivate();
             }
--- a/stress-tester/src/main/java/com/passus/st/client/DbMetric.java	Thu Apr 16 12:52:37 2020 +0200
+++ b/stress-tester/src/main/java/com/passus/st/client/DbMetric.java	Thu Apr 16 14:14:53 2020 +0200
@@ -9,7 +9,7 @@
 
 public abstract class DbMetric extends GenericMetric {
 
-    private HashMap<String, MutableInt> queryTypeCount;
+    private HashMap<String, MutableInt> queryTypeCount = new HashMap<>();
 
     public DbMetric(String name) {
         super(name);
@@ -30,19 +30,6 @@
     }
 
     @Override
-    protected void doActivate() {
-        super.doActivate();
-        queryTypeCount = new HashMap<>();
-    }
-
-    @Override
-    protected void doDeactivate() {
-        super.doDeactivate();
-        reset();
-        queryTypeCount = null;
-    }
-
-    @Override
     public void update(Metric metric) {
         DbMetric dbMetric = (DbMetric) metric;
         Metric.updateCountMap(queryTypeCount, dbMetric.queryTypeCount);
--- a/stress-tester/src/main/java/com/passus/st/client/GenericMetric.java	Thu Apr 16 12:52:37 2020 +0200
+++ b/stress-tester/src/main/java/com/passus/st/client/GenericMetric.java	Thu Apr 16 14:14:53 2020 +0200
@@ -24,7 +24,6 @@
         this.name = name;
     }
 
-
     @Override
     public String getName() {
         return name;
--- a/stress-tester/src/main/java/com/passus/st/client/SynchFlowWorker.java	Thu Apr 16 12:52:37 2020 +0200
+++ b/stress-tester/src/main/java/com/passus/st/client/SynchFlowWorker.java	Thu Apr 16 14:14:53 2020 +0200
@@ -5,6 +5,7 @@
 import com.passus.st.emitter.ChannelContext;
 import com.passus.st.emitter.Emitter;
 import com.passus.st.emitter.SessionInfo;
+import com.passus.st.metric.MetricsContainer;
 import com.passus.st.plugin.PluginConstants;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
@@ -77,6 +78,17 @@
         return count;
     }
 
+    @Override
+    public void writeMetrics(MetricsContainer container) {
+        super.writeMetrics(container);
+
+        sessions.forEach((s, f) -> {
+            if (f.client != null) {
+                f.client.writeMetrics(container);
+            }
+        });
+    }
+
     protected FlowContext register(SessionEvent sessionEvent) {
         return register(sessionEvent.getSessionInfo());
     }
@@ -89,9 +101,9 @@
 
         FlowContext flowContext = new FlowContext(session, eventsQueue);
         flowContext.createLock();
-
         FlowHandler client = clientFactory.create(session.getProtocolId());
         client.init(flowContext);
+        client.setCollectMetrics(collectMetric);
         flowContext.client(client);
         sessions.put(session, flowContext);
         return flowContext;
--- a/stress-tester/src/main/java/com/passus/st/client/http/HttpFlowHandler.java	Thu Apr 16 12:52:37 2020 +0200
+++ b/stress-tester/src/main/java/com/passus/st/client/http/HttpFlowHandler.java	Thu Apr 16 14:14:53 2020 +0200
@@ -77,7 +77,7 @@
             synchronized (metric) {
                 metric.activate();
             }
-        } else {
+        } else if (metric != null) {
             synchronized (metric) {
                 metric.deactivate();
             }
--- a/stress-tester/src/test/java/com/passus/st/source/NcEventSourceTest.java	Thu Apr 16 12:52:37 2020 +0200
+++ b/stress-tester/src/test/java/com/passus/st/source/NcEventSourceTest.java	Thu Apr 16 14:14:53 2020 +0200
@@ -26,10 +26,6 @@
  */
 public class NcEventSourceTest {
 
-    static {
-        Log4jConfigurationFactory.enableFactory("trace");
-    }
-
     private FileEvents writeEvents(String pcapFile) throws IOException {
         PortRangeSet portRanges = new PortRangeSet();
         portRanges.add(4214).add(8080).add(53).add(2055).add(5432);