summaryrefslogtreecommitdiffstats
path: root/controller-server
diff options
context:
space:
mode:
authorMartin Polden <mpolden@mpolden.no>2017-11-24 09:12:38 +0100
committerMartin Polden <mpolden@mpolden.no>2017-11-24 09:12:38 +0100
commit35908c5dbaa2234f8a3c390c63cbe1ae1e712ada (patch)
treeffbeb2123399cd5e8d4dccd2b4e6b2f5e6083b7e /controller-server
parentb46c7c42a0aca18b8c7c54e2fa07bc08bcfecd12 (diff)
Fix rotations metric
Diffstat (limited to 'controller-server')
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/rotation/ControllerRotationRepository.java26
-rw-r--r--controller-server/src/test/java/com/yahoo/vespa/hosted/rotation/ControllerRotationRepositoryTest.java15
2 files changed, 23 insertions, 18 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/rotation/ControllerRotationRepository.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/rotation/ControllerRotationRepository.java
index 9eef1dac70b..363a2ea19cd 100644
--- a/controller-server/src/main/java/com/yahoo/vespa/hosted/rotation/ControllerRotationRepository.java
+++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/rotation/ControllerRotationRepository.java
@@ -4,13 +4,12 @@ package com.yahoo.vespa.hosted.rotation;
import com.yahoo.config.application.api.DeploymentSpec;
import com.yahoo.config.provision.ApplicationId;
import com.yahoo.config.provision.Environment;
+import com.yahoo.jdisc.Metric;
import com.yahoo.log.LogLevel;
-import com.yahoo.metrics.simple.Gauge;
-import com.yahoo.metrics.simple.MetricReceiver;
-import com.yahoo.vespa.hosted.controller.api.identifiers.RotationId;
import com.yahoo.vespa.hosted.controller.api.ApplicationAlias;
-import com.yahoo.vespa.hosted.controller.persistence.ControllerDb;
+import com.yahoo.vespa.hosted.controller.api.identifiers.RotationId;
import com.yahoo.vespa.hosted.controller.api.rotation.Rotation;
+import com.yahoo.vespa.hosted.controller.persistence.ControllerDb;
import com.yahoo.vespa.hosted.rotation.config.RotationsConfig;
import org.jetbrains.annotations.NotNull;
@@ -31,17 +30,16 @@ import java.util.stream.Collectors;
public class ControllerRotationRepository implements RotationRepository {
private static final Logger log = Logger.getLogger(ControllerRotationRepository.class.getName());
-
- private static final String REMAINING_ROTATIONS_METRIC_NAME = "remaining_rotations";
- private final Gauge remainingRotations;
+ public static final String REMAINING_ROTATIONS_METRIC_NAME = "remaining_rotations";
private final ControllerDb controllerDb;
private final Map<RotationId, Rotation> rotationsMap;
+ private final Metric metric;
- public ControllerRotationRepository(RotationsConfig rotationConfig, ControllerDb controllerDb, MetricReceiver metricReceiver) {
+ public ControllerRotationRepository(RotationsConfig rotationConfig, ControllerDb controllerDb, Metric metric) {
this.controllerDb = controllerDb;
this.rotationsMap = buildRotationsMap(rotationConfig);
- this.remainingRotations = metricReceiver.declareGauge(REMAINING_ROTATIONS_METRIC_NAME);
+ this.metric = metric;
}
private static Map<RotationId, Rotation> buildRotationsMap(RotationsConfig rotationConfig) {
@@ -73,7 +71,7 @@ public class ControllerRotationRepository implements RotationRepository {
.collect(Collectors.toSet());
}
- if( ! deploymentSpec.globalServiceId().isPresent()) {
+ if (!deploymentSpec.globalServiceId().isPresent()) {
return Collections.emptySet();
}
@@ -84,13 +82,12 @@ public class ControllerRotationRepository implements RotationRepository {
if (productionZoneCount >= 2) {
return assignRotation(applicationId);
- }
- else {
+ } else {
throw new IllegalArgumentException("global-service-id is set but less than 2 prod zones are defined");
}
}
- private boolean isCorp(DeploymentSpec.DeclaredZone zone) {
+ private static boolean isCorp(DeploymentSpec.DeclaredZone zone) {
return zone.region().isPresent() && zone.region().get().value().contains("corp");
}
@@ -139,7 +136,8 @@ public class ControllerRotationRepository implements RotationRepository {
try {
int freeRotationsCount = availableRotations().size();
log.log(LogLevel.INFO, "Rotation: {0} global rotations remaining", freeRotationsCount);
- remainingRotations.sample(freeRotationsCount);
+ metric.set(REMAINING_ROTATIONS_METRIC_NAME, freeRotationsCount,
+ metric.createContext(Collections.emptyMap()));
} catch (Exception e) {
log.log(LogLevel.INFO, "Failed to report rotations metric", e);
}
diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/rotation/ControllerRotationRepositoryTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/rotation/ControllerRotationRepositoryTest.java
index 561799529f9..b4074fc1944 100644
--- a/controller-server/src/test/java/com/yahoo/vespa/hosted/rotation/ControllerRotationRepositoryTest.java
+++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/rotation/ControllerRotationRepositoryTest.java
@@ -3,7 +3,7 @@ package com.yahoo.vespa.hosted.rotation;
import com.yahoo.config.application.api.DeploymentSpec;
import com.yahoo.config.provision.ApplicationId;
-import com.yahoo.metrics.simple.MetricReceiver;
+import com.yahoo.jdisc.Metric;
import com.yahoo.vespa.hosted.controller.api.identifiers.RotationId;
import com.yahoo.vespa.hosted.controller.api.rotation.Rotation;
import com.yahoo.vespa.hosted.controller.persistence.ControllerDb;
@@ -22,6 +22,10 @@ import java.util.Set;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
/**
* @author Oyvind Gronnesby
@@ -100,12 +104,13 @@ public class ControllerRotationRepositoryTest {
private ControllerRotationRepository repository;
private ControllerRotationRepository repositoryWhitespaces;
-
+ private Metric metric;
@Before
public void setup_repository() {
- repository = new ControllerRotationRepository(rotationsConfig, controllerDb, MetricReceiver.nullImplementation);
- repositoryWhitespaces = new ControllerRotationRepository(rotationsConfigWhitespaces, controllerDb, MetricReceiver.nullImplementation);
+ metric = mock(Metric.class);
+ repository = new ControllerRotationRepository(rotationsConfig, controllerDb, metric);
+ repositoryWhitespaces = new ControllerRotationRepository(rotationsConfigWhitespaces, controllerDb, metric);
controllerDb.assignRotation(new RotationId("foo-1"), applicationId);
}
@@ -129,6 +134,7 @@ public class ControllerRotationRepositoryTest {
Set<Rotation> rotations = repository.getOrAssignRotation(other, deploymentSpec);
Rotation assignedRotation = new Rotation(new RotationId("foo-2"), "foo-2.com");
assertContainsOnly(assignedRotation, rotations);
+ verify(metric).set(eq(ControllerRotationRepository.REMAINING_ROTATIONS_METRIC_NAME), eq(1), any());
}
@Test
@@ -140,6 +146,7 @@ public class ControllerRotationRepositoryTest {
thrown.expectMessage("no rotations available");
repository.getOrAssignRotation(third, deploymentSpec);
+ verify(metric).set(eq(ControllerRotationRepository.REMAINING_ROTATIONS_METRIC_NAME), eq(0), any());
}
@Test