aboutsummaryrefslogtreecommitdiffstats
path: root/jrt/src/com/yahoo/jrt/TransportMetrics.java
diff options
context:
space:
mode:
authorBjørn Christian Seime <bjorncs@verizonmedia.com>2019-01-21 13:58:19 +0100
committerBjørn Christian Seime <bjorncs@verizonmedia.com>2019-01-22 12:26:50 +0100
commite7a2b1be18fa1b9238ec863f8b99cb73183c3afd (patch)
treedf53e3fa450442e4ea677453ae20bce10ee83a8a /jrt/src/com/yahoo/jrt/TransportMetrics.java
parent485f81f1eb9200511b22c7f984363592567b1508 (diff)
Add calculation of metrics changes since previous snapshot
- Move metric diff calculation to TransportMetrics.Snapshot. - Remove TransportMetrics.reset() and use changesSince() instead in EchoTest. - Remove unnecessary volatile modifier on JrtMetrics.previousSnapshot. - Initialize JrtMetrics.previousSnapshot in constructor. - Use separate field declarations for fields in TransportMetrics.Snapshot.
Diffstat (limited to 'jrt/src/com/yahoo/jrt/TransportMetrics.java')
-rw-r--r--jrt/src/com/yahoo/jrt/TransportMetrics.java58
1 files changed, 41 insertions, 17 deletions
diff --git a/jrt/src/com/yahoo/jrt/TransportMetrics.java b/jrt/src/com/yahoo/jrt/TransportMetrics.java
index e4524b138e7..507a925572f 100644
--- a/jrt/src/com/yahoo/jrt/TransportMetrics.java
+++ b/jrt/src/com/yahoo/jrt/TransportMetrics.java
@@ -2,6 +2,7 @@
package com.yahoo.jrt;
import java.util.concurrent.atomic.AtomicLong;
+import java.util.function.ToLongFunction;
/**
* Metric values produced by {@link Transport}.
@@ -73,15 +74,6 @@ public class TransportMetrics {
clientUnencryptedConnectionsEstablished.incrementAndGet();
}
- void reset() {
- tlsCertificateVerificationFailures.set(0);
- peerAuthorizationFailures.set(0);
- serverTlsConnectionsEstablished.set(0);
- clientTlsConnectionsEstablished.set(0);
- serverUnencryptedConnectionsEstablished.set(0);
- clientUnencryptedConnectionsEstablished.set(0);
- }
-
@Override
public String toString() {
return "TransportMetrics{" +
@@ -95,16 +87,34 @@ public class TransportMetrics {
}
public static class Snapshot {
- private final long tlsCertificateVerificationFailures, peerAuthorizationFailures, serverTlsConnectionsEstablished,
- clientTlsConnectionsEstablished, serverUnencryptedConnectionsEstablished, clientUnencryptedConnectionsEstablished;
+ private final long tlsCertificateVerificationFailures;
+ private final long peerAuthorizationFailures;
+ private final long serverTlsConnectionsEstablished;
+ private final long clientTlsConnectionsEstablished;
+ private final long serverUnencryptedConnectionsEstablished;
+ private final long clientUnencryptedConnectionsEstablished;
private Snapshot(TransportMetrics metrics) {
- tlsCertificateVerificationFailures = metrics.tlsCertificateVerificationFailures.get();
- peerAuthorizationFailures = metrics.peerAuthorizationFailures.get();
- serverTlsConnectionsEstablished = metrics.serverTlsConnectionsEstablished.get();
- clientTlsConnectionsEstablished = metrics.clientTlsConnectionsEstablished.get();
- serverUnencryptedConnectionsEstablished = metrics.serverUnencryptedConnectionsEstablished.get();
- clientUnencryptedConnectionsEstablished = metrics.clientUnencryptedConnectionsEstablished.get();
+ this(metrics.tlsCertificateVerificationFailures.get(),
+ metrics.peerAuthorizationFailures.get(),
+ metrics.serverTlsConnectionsEstablished.get(),
+ metrics.clientTlsConnectionsEstablished.get(),
+ metrics.serverUnencryptedConnectionsEstablished.get(),
+ metrics.clientUnencryptedConnectionsEstablished.get());
+ }
+
+ private Snapshot(long tlsCertificateVerificationFailures,
+ long peerAuthorizationFailures,
+ long serverTlsConnectionsEstablished,
+ long clientTlsConnectionsEstablished,
+ long serverUnencryptedConnectionsEstablished,
+ long clientUnencryptedConnectionsEstablished) {
+ this.tlsCertificateVerificationFailures = tlsCertificateVerificationFailures;
+ this.peerAuthorizationFailures = peerAuthorizationFailures;
+ this.serverTlsConnectionsEstablished = serverTlsConnectionsEstablished;
+ this.clientTlsConnectionsEstablished = clientTlsConnectionsEstablished;
+ this.serverUnencryptedConnectionsEstablished = serverUnencryptedConnectionsEstablished;
+ this.clientUnencryptedConnectionsEstablished = clientUnencryptedConnectionsEstablished;
}
public long tlsCertificateVerificationFailures() { return tlsCertificateVerificationFailures; }
@@ -114,6 +124,20 @@ public class TransportMetrics {
public long serverUnencryptedConnectionsEstablished() { return serverUnencryptedConnectionsEstablished; }
public long clientUnencryptedConnectionsEstablished() { return clientUnencryptedConnectionsEstablished; }
+ public Snapshot changesSince(Snapshot base) {
+ return new Snapshot(
+ changesSince(base, Snapshot::tlsCertificateVerificationFailures),
+ changesSince(base, Snapshot::peerAuthorizationFailures),
+ changesSince(base, Snapshot::serverTlsConnectionsEstablished),
+ changesSince(base, Snapshot::clientTlsConnectionsEstablished),
+ changesSince(base, Snapshot::serverUnencryptedConnectionsEstablished),
+ changesSince(base, Snapshot::clientUnencryptedConnectionsEstablished));
+ }
+
+ private long changesSince(Snapshot base, ToLongFunction<Snapshot> metricProperty) {
+ return metricProperty.applyAsLong(this) - metricProperty.applyAsLong(base);
+ }
+
@Override
public String toString() {
return "Snapshot{" +