diff options
author | bjormel <bjormel@verizonmedia.com> | 2021-08-16 14:43:05 +0200 |
---|---|---|
committer | bjormel <bjormel@verizonmedia.com> | 2021-08-16 14:43:05 +0200 |
commit | 26f817a8e5433f6c4d2083bc5703c7cdbd8cb656 (patch) | |
tree | 16bd2cf2d5409726af80a3b5afadcb05378e5cdf /node-admin | |
parent | 8dffb0ecdde3188a43a66110ebc5ffb0b3af2aad (diff) |
Simplify
Diffstat (limited to 'node-admin')
-rw-r--r-- | node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/acl/AclMaintainer.java | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/acl/AclMaintainer.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/acl/AclMaintainer.java index c4c01f74e26..e9efe69f874 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/acl/AclMaintainer.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/acl/AclMaintainer.java @@ -56,9 +56,9 @@ public class AclMaintainer { this.containerOperations = containerOperations; this.ipAddresses = ipAddresses; this.metrics = metrics; - var now = System.currentTimeMillis(); - this.lastSuccess = new HashMap<>(Map.of(IPVersion.IPv4.id(), now, - IPVersion.IPv6.id(), now)); + long timestamp = System.currentTimeMillis() / 1_000; + this.lastSuccess = new HashMap<>(Map.of(IPVersion.IPv4.id(), timestamp, + IPVersion.IPv6.id(), timestamp)); } // ip(6)tables operate while having the xtables lock, run with synchronized to prevent multiple NodeAgents @@ -69,8 +69,11 @@ public class AclMaintainer { // Apply acl to the filter table boolean updatedIPv4 = editFlushOnError(context, IPVersion.IPv4, "filter", FilterTableLineEditor.from(context.acl(), IPVersion.IPv4)); boolean updatedIPv6 = editFlushOnError(context, IPVersion.IPv6, "filter", FilterTableLineEditor.from(context.acl(), IPVersion.IPv6)); - updateMetric(context, updatedIPv4, IPVersion.IPv4.id()); - updateMetric(context, updatedIPv6, IPVersion.IPv6.id()); + + Dimensions dimensions = generateDimensions(context); + + updateMetric(dimensions, updatedIPv4, IPVersion.IPv4.id()); + updateMetric(dimensions, updatedIPv6, IPVersion.IPv6.id()); ipAddresses.getAddress(context.hostname().value(), IPVersion.IPv4).ifPresent(addr -> applyRedirect(context, addr)); ipAddresses.getAddress(context.hostname().value(), IPVersion.IPv6).ifPresent(addr -> applyRedirect(context, addr)); @@ -129,17 +132,18 @@ public class AclMaintainer { }; } - void updateMetric(NodeAgentContext context, boolean updated, String ipVersion) { - Dimensions dimensions = generateDimensions(context); - if (!updated) { - metrics.declareGauge(Metrics.APPLICATION_NODE, ipVersion + METRIC_NAME_POSTFIX, dimensions, Metrics.DimensionType.PRETAGGED) - .sample((System.currentTimeMillis() - lastSuccess.get(ipVersion)) / 1000); - return; + void updateMetric(Dimensions dimensions, boolean updated, String ipVersion) { + long updateAgeInSec; + long timestamp = System.currentTimeMillis() / 1_000; + if (updated) { + updateAgeInSec = 0; + lastSuccess.put(ipVersion, timestamp); + } else { + updateAgeInSec = timestamp - lastSuccess.get(ipVersion); } metrics.declareGauge(Metrics.APPLICATION_NODE, ipVersion + METRIC_NAME_POSTFIX, dimensions, Metrics.DimensionType.PRETAGGED) - .sample(0); - lastSuccess.put(ipVersion, System.currentTimeMillis()); + .sample(updateAgeInSec); } |