Search in sources :

Example 1 with V1ObjectReference

use of io.kubernetes.client.openapi.models.V1ObjectReference in project java by kubernetes-client.

the class EventCorrelatorTest method data.

// creates the test data
@Parameters
public static Collection<Object[]> data() {
    V1ObjectReference podRef = new V1ObjectReferenceBuilder().withApiVersion("v1").withName("my-pod").withNamespace("default").build();
    V1EventSource source = new V1EventSourceBuilder().withComponent("foo").withHost("bar").build();
    CoreV1Event firstEvent = new CoreV1EventBuilder().withMetadata(new V1ObjectMetaBuilder().withName("").withNamespace("").build()).withSource(source).withInvolvedObject(podRef).withReason("first").withCount(1).withMessage("am a first").build();
    CoreV1Event duplicatedEvent = new CoreV1EventBuilder().withMetadata(new V1ObjectMetaBuilder().withName("").withNamespace("").build()).withSource(source).withInvolvedObject(podRef).withReason("duplicated").withCount(1).withMessage("am a dup").build();
    CoreV1Event similarEvent = new CoreV1EventBuilder().withMetadata(new V1ObjectMetaBuilder().withName("").withNamespace("").build()).withSource(source).withInvolvedObject(podRef).withReason("similar").withCount(1).withMessage("am a similar").build();
    CoreV1Event aggregateEvent = new CoreV1EventBuilder().withMetadata(new V1ObjectMetaBuilder().withName("").withNamespace("").build()).withSource(source).withInvolvedObject(podRef).withReason("similar").withCount(1).withMessage(EventUtils.getAggregatedMessageByReason(similarEvent)).build();
    Object[][] data = new Object[][] { { // create a single event should work
    new CoreV1Event[] {}, deepCopy(firstEvent), deepCopy(firstEvent).count(1), false }, { // the same event should just count
    new CoreV1Event[] { deepCopy(duplicatedEvent) }, deepCopy(duplicatedEvent), deepCopy(duplicatedEvent).count(2), false }, { // the same event should just count even if more than aggregate
    deepCopyFor(duplicatedEvent, EventAggregator.DEFAULT_MAX_EVENT_LOCAL_KEYS), deepCopy(duplicatedEvent), deepCopy(duplicatedEvent).count(EventAggregator.DEFAULT_MAX_EVENT_LOCAL_KEYS + 1), false }, { // the same event is spam if too frequent
    deepCopyFor(duplicatedEvent, EventSpamFilter.DEFAULT_TOKEN_BUCKET_CAPACITY + 1), deepCopy(duplicatedEvent), null, true }, { // similar events should be aggregated
    deepCopyWithSimilarMessageFor(similarEvent, similarEvent.getMessage(), EventAggregator.DEFAULT_MAX_EVENT_LOCAL_KEYS - 1), deepCopy(similarEvent), deepCopy(aggregateEvent), false }, { // similar events many times should count the aggregate
    deepCopyWithSimilarMessageFor(similarEvent, similarEvent.getMessage(), EventAggregator.DEFAULT_MAX_EVENT_LOCAL_KEYS), deepCopy(similarEvent), deepCopy(aggregateEvent).count(2), false } };
    return Arrays.asList(data);
}
Also used : V1EventSourceBuilder(io.kubernetes.client.openapi.models.V1EventSourceBuilder) V1ObjectReference(io.kubernetes.client.openapi.models.V1ObjectReference) V1ObjectReferenceBuilder(io.kubernetes.client.openapi.models.V1ObjectReferenceBuilder) V1EventSource(io.kubernetes.client.openapi.models.V1EventSource) CoreV1EventBuilder(io.kubernetes.client.openapi.models.CoreV1EventBuilder) V1ObjectMetaBuilder(io.kubernetes.client.openapi.models.V1ObjectMetaBuilder) CoreV1Event(io.kubernetes.client.openapi.models.CoreV1Event) Parameters(org.junit.runners.Parameterized.Parameters)

Example 2 with V1ObjectReference

use of io.kubernetes.client.openapi.models.V1ObjectReference 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 3 with V1ObjectReference

use of io.kubernetes.client.openapi.models.V1ObjectReference 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

CoreV1Event (io.kubernetes.client.openapi.models.CoreV1Event)3 CoreV1EventBuilder (io.kubernetes.client.openapi.models.CoreV1EventBuilder)3 V1ObjectReference (io.kubernetes.client.openapi.models.V1ObjectReference)3 EventUtils (io.kubernetes.client.extended.event.legacy.EventUtils)2 V1EventSource (io.kubernetes.client.openapi.models.V1EventSource)2 V1EventSourceBuilder (io.kubernetes.client.openapi.models.V1EventSourceBuilder)2 Test (org.junit.Test)2 EventAggregator (io.kubernetes.client.extended.event.legacy.EventAggregator)1 EventSpamFilter (io.kubernetes.client.extended.event.legacy.EventSpamFilter)1 V1ObjectMetaBuilder (io.kubernetes.client.openapi.models.V1ObjectMetaBuilder)1 V1ObjectReferenceBuilder (io.kubernetes.client.openapi.models.V1ObjectReferenceBuilder)1 Parameters (org.junit.runners.Parameterized.Parameters)1