Search in sources :

Example 1 with CapacityGroupUndefinedEvent

use of com.netflix.titus.master.service.management.ResourceConsumptionEvents.CapacityGroupUndefinedEvent in project titus-control-plane by Netflix.

the class ResourceConsumptionLog method doLog.

/* Visible for testing */
static String doLog(ResourceConsumptionEvents.ResourceConsumptionEvent event) {
    if (event instanceof CapacityGroupAllocationEvent) {
        CapacityGroupAllocationEvent changeEvent = (CapacityGroupAllocationEvent) event;
        CompositeResourceConsumption consumption = changeEvent.getCapacityGroupConsumption();
        StringBuilder sb = new StringBuilder("Resource consumption change: group=");
        sb.append(consumption.getConsumerName());
        if (consumption.isAboveLimit()) {
            sb.append(" [above limit] ");
        } else {
            sb.append(" [below limit] ");
        }
        sb.append("actual=");
        ResourceDimensions.format(consumption.getCurrentConsumption(), sb);
        sb.append(", max=");
        ResourceDimensions.format(consumption.getMaxConsumption(), sb);
        sb.append(", limit=");
        ResourceDimensions.format(consumption.getAllowedConsumption(), sb);
        if (consumption.getAttributes().isEmpty()) {
            sb.append(", attrs={}");
        } else {
            sb.append(", attrs={");
            consumption.getAttributes().forEach((k, v) -> sb.append(k).append('=').append(v).append(','));
            sb.setCharAt(sb.length() - 1, '}');
        }
        String message = sb.toString();
        if (consumption.isAboveLimit()) {
            logger.warn(message);
        } else {
            logger.info(message);
        }
        return message;
    }
    if (event instanceof CapacityGroupUndefinedEvent) {
        String message = "Capacity group not defined: group=" + event.getCapacityGroup();
        logger.warn(message);
        return message;
    }
    if (event instanceof CapacityGroupRemovedEvent) {
        String message = "Capacity group no longer defined: group=" + event.getCapacityGroup();
        logger.info(message);
        return message;
    }
    String message = "Unrecognized resource consumption event type " + event.getClass();
    logger.error(message);
    return message;
}
Also used : CompositeResourceConsumption(com.netflix.titus.master.service.management.CompositeResourceConsumption) CapacityGroupUndefinedEvent(com.netflix.titus.master.service.management.ResourceConsumptionEvents.CapacityGroupUndefinedEvent) CapacityGroupRemovedEvent(com.netflix.titus.master.service.management.ResourceConsumptionEvents.CapacityGroupRemovedEvent) CapacityGroupAllocationEvent(com.netflix.titus.master.service.management.ResourceConsumptionEvents.CapacityGroupAllocationEvent)

Example 2 with CapacityGroupUndefinedEvent

use of com.netflix.titus.master.service.management.ResourceConsumptionEvents.CapacityGroupUndefinedEvent in project titus-control-plane by Netflix.

the class ResourceConsumptionLogTest method testGroupUndefinedEvent.

@Test
public void testGroupUndefinedEvent() throws Exception {
    CapacityGroupUndefinedEvent event = new CapacityGroupUndefinedEvent("myCapacityGroup", System.currentTimeMillis());
    String result = ResourceConsumptionLog.doLog(event);
    String expected = "Capacity group not defined: group=myCapacityGroup";
    assertThat(result).isEqualTo(expected);
}
Also used : CapacityGroupUndefinedEvent(com.netflix.titus.master.service.management.ResourceConsumptionEvents.CapacityGroupUndefinedEvent) Test(org.junit.Test)

Aggregations

CapacityGroupUndefinedEvent (com.netflix.titus.master.service.management.ResourceConsumptionEvents.CapacityGroupUndefinedEvent)2 CompositeResourceConsumption (com.netflix.titus.master.service.management.CompositeResourceConsumption)1 CapacityGroupAllocationEvent (com.netflix.titus.master.service.management.ResourceConsumptionEvents.CapacityGroupAllocationEvent)1 CapacityGroupRemovedEvent (com.netflix.titus.master.service.management.ResourceConsumptionEvents.CapacityGroupRemovedEvent)1 Test (org.junit.Test)1