use of org.openkilda.model.FlowStats in project open-kilda by telstra.
the class ActionServiceTest method shouldFailTier1AndDoNotSendRerouteRequestWhenToggleIsFalse.
@Test
public void shouldFailTier1AndDoNotSendRerouteRequestWhenToggleIsFalse() {
transactionManager.doInTransaction(() -> {
KildaFeatureToggles featureToggles = featureTogglesRepository.find().orElseThrow(() -> new IllegalStateException("Feature toggle not found"));
featureToggles.setFlowLatencyMonitoringReactions(false);
});
service.processFlowLatencyMeasurement(flow.getFlowId(), FlowDirection.FORWARD, NANOSECOND);
service.processFlowLatencyMeasurement(flow.getFlowId(), FlowDirection.REVERSE, NANOSECOND);
Duration latency = Duration.ofNanos((long) (flow.getMaxLatency() * (1 + THRESHOLD)) + 5);
for (int i = 0; i < 10; i++) {
clock.adjust(Duration.ofSeconds(10));
service.processFlowLatencyMeasurement(flow.getFlowId(), FlowDirection.FORWARD, latency);
service.processFlowLatencyMeasurement(flow.getFlowId(), FlowDirection.REVERSE, latency.minus(NANOSECOND));
service.processTick();
if (i == 0) {
assertTrue(service.fsms.values().stream().allMatch(fsm -> UNSTABLE.equals(fsm.getCurrentState())));
}
}
assertEquals(2, service.fsms.values().size());
assertTrue(service.fsms.values().stream().allMatch(fsm -> TIER_1_FAILED.equals(fsm.getCurrentState())));
FlowStats actual = flowStatsRepository.findByFlowId(flow.getFlowId()).orElseThrow(() -> new IllegalStateException("Flow not found"));
assertEquals(latency.getNano(), actual.getForwardLatency().intValue());
assertEquals(latency.minus(NANOSECOND).getNano(), actual.getReverseLatency().intValue());
verifyNoMoreInteractions(carrier);
}
use of org.openkilda.model.FlowStats in project open-kilda by telstra.
the class ActionServiceTest method shouldFailTier1AndDoNotSendRerouteRequestForCostStrategy.
@Test
public void shouldFailTier1AndDoNotSendRerouteRequestForCostStrategy() {
transactionManager.doInTransaction(() -> {
Flow flowSetup = flowRepository.findById(flow.getFlowId()).orElseThrow(() -> new IllegalStateException("Flow not found"));
flowSetup.setPathComputationStrategy(PathComputationStrategy.COST);
});
service.processFlowLatencyMeasurement(flow.getFlowId(), FlowDirection.FORWARD, NANOSECOND);
service.processFlowLatencyMeasurement(flow.getFlowId(), FlowDirection.REVERSE, NANOSECOND);
Duration latency = Duration.ofNanos((long) (flow.getMaxLatency() * (1 + THRESHOLD)) + 5);
for (int i = 0; i < 10; i++) {
clock.adjust(Duration.ofSeconds(10));
service.processFlowLatencyMeasurement(flow.getFlowId(), FlowDirection.FORWARD, latency);
service.processFlowLatencyMeasurement(flow.getFlowId(), FlowDirection.REVERSE, latency.minus(NANOSECOND));
service.processTick();
if (i == 0) {
assertTrue(service.fsms.values().stream().allMatch(fsm -> UNSTABLE.equals(fsm.getCurrentState())));
}
}
assertEquals(2, service.fsms.values().size());
assertTrue(service.fsms.values().stream().allMatch(fsm -> TIER_1_FAILED.equals(fsm.getCurrentState())));
FlowStats actual = flowStatsRepository.findByFlowId(flow.getFlowId()).orElseThrow(() -> new IllegalStateException("Flow not found"));
assertEquals(latency.getNano(), actual.getForwardLatency().intValue());
assertEquals(latency.minus(NANOSECOND).getNano(), actual.getReverseLatency().intValue());
verifyNoMoreInteractions(carrier);
}
use of org.openkilda.model.FlowStats in project open-kilda by telstra.
the class ActionServiceTest method shouldFailTier2AndSendRerouteRequest.
@Test
public void shouldFailTier2AndSendRerouteRequest() {
transactionManager.doInTransaction(() -> {
Flow flowSetup = flowRepository.findById(flow.getFlowId()).orElseThrow(() -> new IllegalStateException("Flow not found"));
flowSetup.setPathComputationStrategy(PathComputationStrategy.MAX_LATENCY);
});
service.processFlowLatencyMeasurement(flow.getFlowId(), FlowDirection.FORWARD, NANOSECOND);
service.processFlowLatencyMeasurement(flow.getFlowId(), FlowDirection.REVERSE, NANOSECOND);
Duration latency = Duration.ofNanos((long) (flow.getMaxLatencyTier2() * (1 + THRESHOLD)) + 5);
for (int i = 0; i < 10; i++) {
clock.adjust(Duration.ofSeconds(10));
service.processFlowLatencyMeasurement(flow.getFlowId(), FlowDirection.FORWARD, latency);
service.processFlowLatencyMeasurement(flow.getFlowId(), FlowDirection.REVERSE, latency.minus(NANOSECOND));
service.processTick();
if (i == 0) {
assertTrue(service.fsms.values().stream().allMatch(fsm -> UNSTABLE.equals(fsm.getCurrentState())));
}
}
assertEquals(2, service.fsms.values().size());
assertTrue(service.fsms.values().stream().allMatch(fsm -> TIER_2_FAILED.equals(fsm.getCurrentState())));
FlowStats actual = flowStatsRepository.findByFlowId(flow.getFlowId()).orElseThrow(() -> new IllegalStateException("Flow not found"));
assertEquals(latency.getNano(), actual.getForwardLatency().intValue());
assertEquals(latency.minus(NANOSECOND).getNano(), actual.getReverseLatency().intValue());
verify(carrier, times(2)).sendFlowRerouteRequest(flow.getFlowId());
verifyNoMoreInteractions(carrier);
}
use of org.openkilda.model.FlowStats in project open-kilda by telstra.
the class ActionServiceTest method shouldFailTier2AndDoNotSendRerouteRequestForCostStrategy.
@Test
public void shouldFailTier2AndDoNotSendRerouteRequestForCostStrategy() {
transactionManager.doInTransaction(() -> {
Flow flowSetup = flowRepository.findById(flow.getFlowId()).orElseThrow(() -> new IllegalStateException("Flow not found"));
flowSetup.setPathComputationStrategy(PathComputationStrategy.COST);
});
service.processFlowLatencyMeasurement(flow.getFlowId(), FlowDirection.FORWARD, NANOSECOND);
service.processFlowLatencyMeasurement(flow.getFlowId(), FlowDirection.REVERSE, NANOSECOND);
Duration latency = Duration.ofNanos((long) (flow.getMaxLatencyTier2() * (1 + THRESHOLD)) + 5);
for (int i = 0; i < 10; i++) {
clock.adjust(Duration.ofSeconds(10));
service.processFlowLatencyMeasurement(flow.getFlowId(), FlowDirection.FORWARD, latency);
service.processFlowLatencyMeasurement(flow.getFlowId(), FlowDirection.REVERSE, latency.minus(NANOSECOND));
service.processTick();
if (i == 0) {
assertTrue(service.fsms.values().stream().allMatch(fsm -> UNSTABLE.equals(fsm.getCurrentState())));
}
}
assertEquals(2, service.fsms.values().size());
assertTrue(service.fsms.values().stream().allMatch(fsm -> TIER_2_FAILED.equals(fsm.getCurrentState())));
FlowStats actual = flowStatsRepository.findByFlowId(flow.getFlowId()).orElseThrow(() -> new IllegalStateException("Flow not found"));
assertEquals(latency.getNano(), actual.getForwardLatency().intValue());
assertEquals(latency.minus(NANOSECOND).getNano(), actual.getReverseLatency().intValue());
verifyNoMoreInteractions(carrier);
}
use of org.openkilda.model.FlowStats in project open-kilda by telstra.
the class ActionService method saveFlowLatency.
@Override
public void saveFlowLatency(String flowId, String direction, long latency) {
try {
transactionManager.doInTransaction(() -> {
FlowStats flowStats = flowStatsRepository.findByFlowId(flowId).orElse(null);
if (flowStats == null) {
Optional<Flow> flow = flowRepository.findById(flowId);
if (flow.isPresent()) {
FlowStats toCreate = new FlowStats(flow.get(), null, null);
flowStatsRepository.add(toCreate);
flowStats = toCreate;
} else {
log.warn("Can't save latency for flow '{}'. Flow not found.", flowId);
return;
}
}
if (FORWARD.name().toLowerCase().equals(direction)) {
flowStats.setForwardLatency(latency);
} else {
flowStats.setReverseLatency(latency);
}
});
} catch (PersistenceException e) {
log.error("Can't save latency for flow '{}'.", flowId, e);
}
}
Aggregations