Search in sources :

Example 1 with Event

use of com.marcnuri.yakc.model.io.k8s.api.events.v1.Event in project yakc by manusa.

the class EventsV1ApiIT method patchNamespacedEvent.

@Test
@DisplayName("patchNamespacedEvent, should patch reason of Event")
void patchNamespacedEvent() throws IOException {
    // Given
    final Event patch = new Event();
    patch.setMetadata(ObjectMeta.builder().generateName("patched").build());
    // When
    final Event result = KC.create(EventsV1Api.class).patchNamespacedEvent(eventName, NAMESPACE, patch).get();
    // Then
    assertThat(result).isNotNull().hasFieldOrPropertyWithValue("metadata.generateName", "patched").extracting("metadata.resourceVersion").asString().isNotEmpty().isNotEqualTo(event.getMetadata().getResourceVersion());
}
Also used : Event(com.marcnuri.yakc.model.io.k8s.api.events.v1.Event) ListNamespacedEvent(com.marcnuri.yakc.api.events.v1.EventsV1Api.ListNamespacedEvent) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 2 with Event

use of com.marcnuri.yakc.model.io.k8s.api.events.v1.Event in project yakc by manusa.

the class EventsV1ApiIT method listNamespacedEventStream.

@Test
@DisplayName("listNamespacedEvent.stream, cluster contains events")
void listNamespacedEventStream() throws IOException {
    // TODO: Use specific event because events from cluster may come with eventTime null :O -->
    // this throws a NPE
    // When
    final Stream<Event> result = KC.create(EventsV1Api.class).listNamespacedEvent(NAMESPACE, new ListNamespacedEvent().fieldSelector(String.format("metadata.name=%s", eventName))).stream();
    // Then
    assertThat(result).hasSize(1).allSatisfy(e -> assertThat(e).hasFieldOrPropertyWithValue("metadata.name", eventName).hasFieldOrPropertyWithValue("action", "mock-action"));
}
Also used : ListNamespacedEvent(com.marcnuri.yakc.api.events.v1.EventsV1Api.ListNamespacedEvent) Event(com.marcnuri.yakc.model.io.k8s.api.events.v1.Event) ListNamespacedEvent(com.marcnuri.yakc.api.events.v1.EventsV1Api.ListNamespacedEvent) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 3 with Event

use of com.marcnuri.yakc.model.io.k8s.api.events.v1.Event in project Signal-Server by signalapp.

the class RecaptchaClient method verify.

public boolean verify(final String input, final String ip) {
    final String[] parts = parseInputToken(input);
    final String sitekey = parts[0];
    final String expectedAction = parts[1];
    final String token = parts[2];
    Event.Builder eventBuilder = Event.newBuilder().setSiteKey(sitekey).setToken(token).setUserIpAddress(ip);
    if (expectedAction != null) {
        eventBuilder.setExpectedAction(expectedAction);
    }
    final Event event = eventBuilder.build();
    final Assessment assessment = client.createAssessment(projectPath, Assessment.newBuilder().setEvent(event).build());
    Metrics.counter(ASSESSMENTS_COUNTER_NAME, "action", String.valueOf(expectedAction), "valid", String.valueOf(assessment.getTokenProperties().getValid())).increment();
    if (assessment.getTokenProperties().getValid()) {
        final float score = assessment.getRiskAnalysis().getScore();
        final DistributionSummary.Builder distributionSummaryBuilder = DistributionSummary.builder(SCORE_DISTRIBUTION_NAME).scale(100).maximumExpectedValue(100.0d).tags("action", String.valueOf(expectedAction));
        distributionSummaryBuilder.register(Metrics.globalRegistry).record(score);
        return score >= dynamicConfigurationManager.getConfiguration().getCaptchaConfiguration().getScoreFloor().floatValue();
    } else {
        return false;
    }
}
Also used : DistributionSummary(io.micrometer.core.instrument.DistributionSummary) Assessment(com.google.recaptchaenterprise.v1.Assessment) Event(com.google.recaptchaenterprise.v1.Event)

Example 4 with Event

use of com.marcnuri.yakc.model.io.k8s.api.events.v1.Event in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class EventCollector method storeNamespaceEvents.

/**
 * Store events in provided namespace
 *
 * @param client
 * @param logFolderName Name of a folder used to store logs
 * @param namespace
 * @throws IOException In case event log cannot be stored on filesystem for any reason
 */
public static void storeNamespaceEvents(OpenShiftClient client, String logFolderName, String namespace) throws IOException {
    Path logParentDirectory = LogConfig.getLogParentDirectory(logFolderName);
    Files.createDirectories(logParentDirectory);
    List<Event> events = client.events().v1().events().inNamespace(namespace).list().getItems();
    List<Map<EventEntry, String>> eventContent = new ArrayList<>();
    Map<EventEntry, String> eventHeader = new HashMap<>();
    eventHeader.put(EventEntry.LAST_SEEN, EventEntry.LAST_SEEN.toString());
    eventHeader.put(EventEntry.FIRST_SEEN, EventEntry.FIRST_SEEN.toString());
    eventHeader.put(EventEntry.COUNT, EventEntry.COUNT.toString());
    eventHeader.put(EventEntry.NAME, EventEntry.NAME.toString());
    eventHeader.put(EventEntry.KIND, EventEntry.KIND.toString());
    eventHeader.put(EventEntry.SUBOBJECT, EventEntry.SUBOBJECT.toString());
    eventHeader.put(EventEntry.TYPE, EventEntry.TYPE.toString());
    eventHeader.put(EventEntry.REASON, EventEntry.REASON.toString());
    eventHeader.put(EventEntry.ACTION, EventEntry.ACTION.toString());
    eventHeader.put(EventEntry.MESSAGE, EventEntry.MESSAGE.toString());
    eventContent.add(eventHeader);
    for (Event event : events) {
        Map<EventEntry, String> eventEntry = new HashMap<>();
        eventEntry.put(EventEntry.LAST_SEEN, getLastSeen(event));
        eventEntry.put(EventEntry.FIRST_SEEN, getFirstSeen(event));
        eventEntry.put(EventEntry.COUNT, event.getSeries() != null ? event.getSeries().getCount().toString() : "1");
        eventEntry.put(EventEntry.NAME, event.getRegarding().getName());
        eventEntry.put(EventEntry.KIND, event.getRegarding().getKind());
        eventEntry.put(EventEntry.SUBOBJECT, event.getRegarding().getFieldPath());
        eventEntry.put(EventEntry.TYPE, event.getType());
        eventEntry.put(EventEntry.REASON, event.getReason());
        eventEntry.put(EventEntry.ACTION, event.getAction());
        eventEntry.put(EventEntry.MESSAGE, event.getNote());
        eventContent.add(eventEntry);
    }
    for (Map<EventEntry, String> eventEntry : eventContent) {
        Files.write(logParentDirectory.resolve(Paths.get("events.log")), getEventLogLine(eventEntry).getBytes(), StandardOpenOption.CREATE, StandardOpenOption.APPEND, StandardOpenOption.WRITE);
    }
}
Also used : Path(java.nio.file.Path) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Event(io.fabric8.kubernetes.api.model.events.v1.Event) Map(java.util.Map) HashMap(java.util.HashMap)

Example 5 with Event

use of com.marcnuri.yakc.model.io.k8s.api.events.v1.Event in project skywalking by apache.

the class EventRestServiceHandler method doPost.

@Override
protected void doPost(final HttpServletRequest req, final HttpServletResponse resp) {
    try (HistogramMetrics.Timer ignored = histogram.createTimer()) {
        List<Event> events = Lists.newArrayList();
        JsonArray array = gson.fromJson(req.getReader(), JsonArray.class);
        for (JsonElement element : array) {
            Event.Builder builder = Event.newBuilder();
            ProtoBufJsonUtils.fromJSON(element.toString(), builder);
            events.add(builder.build());
        }
        events.forEach(eventAnalyzerService::analyze);
    } catch (Exception e) {
        errorCounter.inc();
        log.error(e.getMessage(), e);
    }
}
Also used : JsonArray(com.google.gson.JsonArray) JsonElement(com.google.gson.JsonElement) Event(org.apache.skywalking.apm.network.event.v3.Event) HistogramMetrics(org.apache.skywalking.oap.server.telemetry.api.HistogramMetrics)

Aggregations

Test (org.junit.Test)18 Event (io.requery.test.model3.Event)9 UUID (java.util.UUID)9 Event (org.apache.skywalking.apm.network.event.v3.Event)9 Test (org.junit.jupiter.api.Test)9 Event (org.eclipse.bpmn2.Event)5 Event (com.google.cloud.video.livestream.v1.Event)4 LivestreamServiceClient (com.google.cloud.video.livestream.v1.LivestreamServiceClient)4 Place (io.requery.test.model3.Place)4 Tag (io.requery.test.model3.Tag)4 AlarmMessage (org.apache.skywalking.oap.server.core.alarm.AlarmMessage)4 ListNamespacedEvent (com.marcnuri.yakc.api.events.v1.EventsV1Api.ListNamespacedEvent)3 Event (com.marcnuri.yakc.model.io.k8s.api.events.v1.Event)3 Event (io.fabric8.kubernetes.api.model.events.v1.Event)3 Event (io.requery.test.model2.Event)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Event (uk.gov.justice.hmpps.prison.api.model.v1.Event)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 JsonArray (com.google.gson.JsonArray)2