Search in sources :

Example 1 with EventUtils

use of io.kubernetes.client.extended.event.legacy.EventUtils in project java by kubernetes-client.

the class EventAggregatorTest method testSpammingEventsShouldBeAggregated.

@Test
public void testSpammingEventsShouldBeAggregated() {
    String aggregatedMessage = "noxu";
    EventAggregator aggregator = new EventAggregator(100, EventUtils::getAggregatedAndLocalKeyByReason, event -> aggregatedMessage);
    for (int i = 0; i < aggregator.getMaxEvents() - 1; i++) {
        String message = aggregator.aggregate(new CoreV1EventBuilder().withSource(new V1EventSource()).withInvolvedObject(new V1ObjectReference()).withMessage("foo: " + i).build()).getLeft().getMessage();
        assertNotEquals(aggregatedMessage, message);
    }
    CoreV1Event aggregatedEvent = aggregator.aggregate(new CoreV1EventBuilder().withSource(new V1EventSource()).withInvolvedObject(new V1ObjectReference()).withMessage("not_noxu").build()).getLeft();
    assertEquals(aggregatedMessage, aggregatedEvent.getMessage());
}
Also used : V1ObjectReference(io.kubernetes.client.openapi.models.V1ObjectReference) EventAggregator(io.kubernetes.client.extended.event.legacy.EventAggregator) EventUtils(io.kubernetes.client.extended.event.legacy.EventUtils) V1EventSource(io.kubernetes.client.openapi.models.V1EventSource) CoreV1EventBuilder(io.kubernetes.client.openapi.models.CoreV1EventBuilder) CoreV1Event(io.kubernetes.client.openapi.models.CoreV1Event) Test(org.junit.Test)

Example 2 with EventUtils

use of io.kubernetes.client.extended.event.legacy.EventUtils in project java by kubernetes-client.

the class EventLoggerTest method testPatchComputing.

@Test
public void testPatchComputing() {
    CoreV1Event event1 = new CoreV1EventBuilder().withSource(new V1EventSourceBuilder().build()).withMetadata(new V1ObjectMeta()).withInvolvedObject(new V1ObjectReferenceBuilder().build()).withCount(1).withMessage("foo1").build();
    CoreV1Event event2 = new CoreV1EventBuilder().withSource(new V1EventSourceBuilder().build()).withMetadata(new V1ObjectMeta()).withInvolvedObject(new V1ObjectReferenceBuilder().build()).withCount(2).withMessage("foo2").build();
    String aggregatedKey = EventUtils.getAggregatedAndLocalKeyByReason(event1).getRight();
    EventLogger eventLogger = new EventLogger(100, EventUtils::getEventKey);
    MutablePair<CoreV1Event, V1Patch> result1 = eventLogger.observe(event1, aggregatedKey);
    assertEquals(event1, result1.getLeft());
    assertNull(result1.getRight());
    MutablePair<CoreV1Event, V1Patch> result2 = eventLogger.observe(event2, aggregatedKey);
    assertEquals(event2, result2.getLeft());
    assertNotNull(result2.getRight());
}
Also used : V1EventSourceBuilder(io.kubernetes.client.openapi.models.V1EventSourceBuilder) V1ObjectReferenceBuilder(io.kubernetes.client.openapi.models.V1ObjectReferenceBuilder) EventLogger(io.kubernetes.client.extended.event.legacy.EventLogger) V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) EventUtils(io.kubernetes.client.extended.event.legacy.EventUtils) V1Patch(io.kubernetes.client.custom.V1Patch) CoreV1EventBuilder(io.kubernetes.client.openapi.models.CoreV1EventBuilder) CoreV1Event(io.kubernetes.client.openapi.models.CoreV1Event) Test(org.junit.Test)

Example 3 with EventUtils

use of io.kubernetes.client.extended.event.legacy.EventUtils in project java by kubernetes-client.

the class EventSpamFilterTest method testSpammingEventFiltering.

@Test
public void testSpammingEventFiltering() {
    int burst = 10;
    EventSpamFilter filter = new EventSpamFilter(100, EventUtils::getSpamKey, burst, Duration.ofDays(1), // never refill
    1);
    CoreV1Event spammingEvent1 = new CoreV1EventBuilder().withMessage("1").withSource(new V1EventSourceBuilder().withComponent("c1").build()).withInvolvedObject(new V1ObjectReference()).build();
    CoreV1Event spammingEvent2 = new CoreV1EventBuilder().withMessage("2").withSource(new V1EventSourceBuilder().withComponent("c1").build()).withInvolvedObject(new V1ObjectReference()).build();
    CoreV1Event spammingEvent3 = new CoreV1EventBuilder().withMessage("3").withSource(new V1EventSourceBuilder().withComponent("c2").build()).withInvolvedObject(new V1ObjectReference()).build();
    for (int i = 0; i < burst; i++) {
        assertEquals(true, filter.filter(spammingEvent1));
    }
    assertEquals(false, filter.filter(spammingEvent1));
    assertEquals(false, filter.filter(spammingEvent2));
    assertEquals(true, filter.filter(spammingEvent3));
}
Also used : V1EventSourceBuilder(io.kubernetes.client.openapi.models.V1EventSourceBuilder) V1ObjectReference(io.kubernetes.client.openapi.models.V1ObjectReference) EventSpamFilter(io.kubernetes.client.extended.event.legacy.EventSpamFilter) EventUtils(io.kubernetes.client.extended.event.legacy.EventUtils) CoreV1EventBuilder(io.kubernetes.client.openapi.models.CoreV1EventBuilder) CoreV1Event(io.kubernetes.client.openapi.models.CoreV1Event) Test(org.junit.Test)

Aggregations

EventUtils (io.kubernetes.client.extended.event.legacy.EventUtils)3 CoreV1Event (io.kubernetes.client.openapi.models.CoreV1Event)3 CoreV1EventBuilder (io.kubernetes.client.openapi.models.CoreV1EventBuilder)3 Test (org.junit.Test)3 V1EventSourceBuilder (io.kubernetes.client.openapi.models.V1EventSourceBuilder)2 V1ObjectReference (io.kubernetes.client.openapi.models.V1ObjectReference)2 V1Patch (io.kubernetes.client.custom.V1Patch)1 EventAggregator (io.kubernetes.client.extended.event.legacy.EventAggregator)1 EventLogger (io.kubernetes.client.extended.event.legacy.EventLogger)1 EventSpamFilter (io.kubernetes.client.extended.event.legacy.EventSpamFilter)1 V1EventSource (io.kubernetes.client.openapi.models.V1EventSource)1 V1ObjectMeta (io.kubernetes.client.openapi.models.V1ObjectMeta)1 V1ObjectReferenceBuilder (io.kubernetes.client.openapi.models.V1ObjectReferenceBuilder)1