io.keyko.monitoring.preprocessing.Transformations Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of web3-event-streamer Show documentation
Show all versions of web3-event-streamer Show documentation
Kafka stream processors that enrich data generated with web3-monitoring agent
package io.keyko.monitoring.preprocessing;
import io.keyko.monitoring.exceptions.EventFromLogException;
import io.keyko.monitoring.exceptions.TypeConversionException;
import io.keyko.monitoring.schemas.*;
import io.keyko.monitoring.serde.Web3MonitoringSerdes;
import io.keyko.monitoring.services.EventLogService;
import io.keyko.monitoring.services.KafkaProducerService;
import org.apache.kafka.common.serialization.Serdes;
import org.apache.kafka.streams.kstream.Joined;
import org.apache.kafka.streams.kstream.KStream;
import org.apache.kafka.streams.kstream.KTable;
import org.apache.log4j.Logger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Transformations {
private static Logger log = Logger.getLogger(Transformations.class);
/**
* Join the events with the corresponding block to track the timestamp of mining.
*
* @param eventStream Stream with the confirmed events
* @param blockStream Table with the blocks
* @return KStream
*/
public static KStream joinEventWithBlock(KStream eventStream, KTable blockStream) {
return eventStream
.selectKey((key, event) -> event.getBlockHash())
.join(blockStream,
(event, block) -> {
EventBlockRecord eventblock = new EventBlockRecord();
eventblock.setEvent(event);
eventblock.setBlock(block);
eventblock.setId(event.getId());
eventblock.setRetries(event.getRetries());
return eventblock;
},
Joined.with(Serdes.String(), Web3MonitoringSerdes.getEventSerde(), Web3MonitoringSerdes.getBlockSerde())
)
.selectKey((key, event) -> event.getId());
}
/**
* Join the views with the corresponding block to track the timestamp of mining.
*
* @param viewStream Stream with the confirmed views
* @param blockStream Table with the blocks
* @return KStream
*/
public static KStream joinViewWithBlock(KStream viewStream, KTable blockStream) {
return viewStream
.selectKey((key, view) -> view.getBlockHash())
.join(blockStream,
(view, block) -> {
ViewBlockRecord viewBlock = new ViewBlockRecord();
viewBlock.setId(view.getId());
viewBlock.setRetries(view.getRetries());
viewBlock.setBlock(block);
viewBlock.setView(view);
return viewBlock;
},
Joined.with(Serdes.String(), Web3MonitoringSerdes.getViewSerde(), Web3MonitoringSerdes.getBlockSerde())
)
.selectKey((key, view) -> view.getId())
;
}
/**
* Transform the ViewBlock records into a TimeSeriesRecord
*
* @param stream
* @return
*/
public static KStream transformToTimeSeries(KStream stream) {
return stream.mapValues(viewBlock -> {
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy