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());
}
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"));
}
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;
}
}
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);
}
}
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);
}
}
Aggregations