diff options
author | Jon Bratseth <bratseth@gmail.com> | 2020-10-20 17:09:01 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@gmail.com> | 2020-10-22 15:30:30 +0200 |
commit | 64918c40aaf2d0ec632a91b699d4cd92886e9884 (patch) | |
tree | 7b1f10412b0997bdef151977b563f5cc110668bf | |
parent | d4731bc1fbefc4efe1d26ca183e4510b5bd6861b (diff) |
Minor cleanup
3 files changed, 23 insertions, 34 deletions
diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/Metric.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/Metric.java index b98535f19c3..5185a6f9854 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/Metric.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/Metric.java @@ -2,7 +2,7 @@ package com.yahoo.vespa.hosted.provision.autoscale; /** - * A kind of measurement we are making for autoscaling purposes + * A metric for autoscaling purposes * * @author bratseth */ @@ -10,37 +10,25 @@ public enum Metric { cpu { // a node resource public String fullName() { return "cpu.util"; } - float valueFromMetric(double metricValue) { return (float)metricValue / 100; } // % to ratio + float measurementFromMetric(double metricValue) { return (float)metricValue / 100; } // % to ratio }, memory { // a node resource public String fullName() { return "mem_total.util"; } - float valueFromMetric(double metricValue) { return (float)metricValue / 100; } // % to ratio + float measurementFromMetric(double metricValue) { return (float)metricValue / 100; } // % to ratio }, disk { // a node resource public String fullName() { return "disk.util"; } - float valueFromMetric(double metricValue) { return (float)metricValue / 100; } // % to ratio + float measurementFromMetric(double metricValue) { return (float)metricValue / 100; } // % to ratio }, generation { // application config generation active on the node public String fullName() { return "application_generation"; } - float valueFromMetric(double metricValue) { return (float)metricValue; } // Really an integer, ok up to 16M gens + float measurementFromMetric(double metricValue) { return (float)metricValue; } // Really an integer, ok up to 16M gens }; /** The name of this metric as emitted from its source */ public abstract String fullName(); /** Convert from the emitted value of this metric to the value we want to use here */ - abstract float valueFromMetric(double metricValue); - - public static Metric fromFullName(String name) { - for (Metric metric : values()) - if (metric.fullName().equals(name)) return metric; - throw new IllegalArgumentException("Metric '" + name + "' has no mapping"); - } - - public static Metric from(Resource resource) { - for (Metric metric : values()) - if (metric.name().equals(resource.name())) return metric; - throw new IllegalArgumentException("Resource '" + resource + "' does not map to a metric"); - } + abstract float measurementFromMetric(double metricValue); } diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/MetricSnapshot.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/MetricSnapshot.java index e0a94c362cd..52a8a3bd2ed 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/MetricSnapshot.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/MetricSnapshot.java @@ -82,10 +82,10 @@ public class MetricSnapshot { return Optional.of(measurementSum / measurementCount); } - private double value(Resource resource, NodeMetricsDb.Measurement measurement) { + private double value(Resource resource, NodeMetricsDb.Measurements measurement) { switch (resource) { case cpu: return measurement.cpu(); - case memory: return measurement.memopry(); + case memory: return measurement.memory(); case disk: return measurement.disk(); default: throw new IllegalArgumentException("Got an unknown resource " + resource); } diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/NodeMetricsDb.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/NodeMetricsDb.java index fbd8c90837e..ef9ddceeb75 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/NodeMetricsDb.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/NodeMetricsDb.java @@ -41,12 +41,12 @@ public class NodeMetricsDb { public void add(Collection<MetricsFetcher.NodeMetrics> nodeMetrics) { synchronized (lock) { for (var value : nodeMetrics) { - add(value.hostname(), new Measurement(value)); + add(value.hostname(), new Measurements(value)); } } } - private void add(String hostname, Measurement measurement) { + private void add(String hostname, Measurements measurement) { NodeMeasurements measurements = db.get(hostname); if (measurements == null) { // new node Optional<Node> node = nodeRepository.getNode(hostname); @@ -92,14 +92,15 @@ public class NodeMetricsDb { } } + /** A list of measurements from a host */ public static class NodeMeasurements { private final String hostname; private final ClusterSpec.Type type; - private final List<Measurement> measurements; + private final List<Measurements> measurements; // Note: This transfers ownership of the measurement list to this - private NodeMeasurements(String hostname, ClusterSpec.Type type, List<Measurement> measurements) { + private NodeMeasurements(String hostname, ClusterSpec.Type type, List<Measurements> measurements) { this.hostname = hostname; this.type = type; this.measurements = measurements; @@ -111,9 +112,9 @@ public class NodeMetricsDb { public int size() { return measurements.size(); } - public Measurement get(int index) { return measurements.get(index); } + public Measurements get(int index) { return measurements.get(index); } - public List<Measurement> asList() { return Collections.unmodifiableList(measurements); } + public List<Measurements> asList() { return Collections.unmodifiableList(measurements); } public String hostname() { return hostname; } @@ -127,7 +128,7 @@ public class NodeMetricsDb { // Private mutation - private void add(Measurement measurement) { measurements.add(measurement); } + private void add(Measurements measurement) { measurements.add(measurement); } private void removeOlderThan(long oldestTimestamp) { while (!measurements.isEmpty() && measurements.get(0).timestamp < oldestTimestamp) @@ -137,7 +138,7 @@ public class NodeMetricsDb { } /** A single measurement of all values we measure, for one node */ - public static class Measurement { + public static class Measurements { // TODO: Order by timestamp /** The time of this measurement in epoch millis */ @@ -148,17 +149,17 @@ public class NodeMetricsDb { private final double disk; private final long generation; - public Measurement(MetricsFetcher.NodeMetrics metrics) { + public Measurements(MetricsFetcher.NodeMetrics metrics) { this.timestamp = metrics.timestampSecond() * 1000; - this.cpu = Metric.cpu.valueFromMetric(metrics.cpuUtil()); - this.memory = Metric.memory.valueFromMetric(metrics.totalMemUtil()); - this.disk = Metric.disk.valueFromMetric(metrics.diskUtil()); - this.generation = (long)Metric.generation.valueFromMetric(metrics.applicationGeneration()); + this.cpu = Metric.cpu.measurementFromMetric(metrics.cpuUtil()); + this.memory = Metric.memory.measurementFromMetric(metrics.totalMemUtil()); + this.disk = Metric.disk.measurementFromMetric(metrics.diskUtil()); + this.generation = (long)Metric.generation.measurementFromMetric(metrics.applicationGeneration()); } public double cpu() { return cpu; } - public double memopry() { return memory; } + public double memory() { return memory; } public double disk() { return disk; } public long generation() { return generation; } public Instant at() { return Instant.ofEpochMilli(timestamp); } |