Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement IntoJson filter #768

Merged
merged 1 commit into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/into_json/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
output
24 changes: 24 additions & 0 deletions examples/into_json/daemon.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[source]
type = "N2N"
peers = ["relays-new.cardano-mainnet.iohk.io:3001"]

[intersect]
type = "Point"
value = [4493860, "ce7f821d2140419fea1a7900cf71b0c0a0e94afbb1f814a6717cff071c3b6afc"]

[[filters]]
type = "SplitBlock"

[[filters]]
type = "ParseCbor"

[[filters]]
type = "IntoJson"

[sink]
type = "FileRotate"
max_total_files = 5
output_format = "JSONL"
output_path = "./output/logs.jsonl"
max_bytes_per_file = 5_000_000
compress_files = true
5 changes: 3 additions & 2 deletions src/filters/json.rs → src/filters/into_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

use gasket::framework::*;
use serde::Deserialize;
use serde_json::Value as JsonValue;

use crate::framework::*;

#[derive(Default, Stage)]
#[stage(name = "filter-json", unit = "ChainEvent", worker = "Worker")]
#[stage(name = "into-json", unit = "ChainEvent", worker = "Worker")]
pub struct Stage {
pub input: FilterInputPort,
pub output: FilterOutputPort,
Expand All @@ -25,7 +26,7 @@ impl From<&Stage> for Worker {
}

gasket::impl_mapper!(|_worker: Worker, stage: Stage, unit: ChainEvent| => {
let out = unit.clone();
let out = unit.clone().map_record(|r| Record::GenericJson(JsonValue::from(r)));
stage.ops_count.inc(1);
out
});
Expand Down
14 changes: 7 additions & 7 deletions src/filters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use serde::Deserialize;

use crate::framework::*;

pub mod json;
pub mod into_json;
pub mod legacy_v1;
pub mod noop;
pub mod parse_cbor;
Expand All @@ -19,7 +19,7 @@ pub mod deno;
pub enum Bootstrapper {
Noop(noop::Stage),
SplitBlock(split_block::Stage),
Json(json::Stage),
IntoJson(into_json::Stage),
LegacyV1(legacy_v1::Stage),
ParseCbor(parse_cbor::Stage),
Select(select::Stage),
Expand All @@ -36,7 +36,7 @@ impl Bootstrapper {
match self {
Bootstrapper::Noop(p) => &mut p.input,
Bootstrapper::SplitBlock(p) => &mut p.input,
Bootstrapper::Json(p) => &mut p.input,
Bootstrapper::IntoJson(p) => &mut p.input,
Bootstrapper::LegacyV1(p) => &mut p.input,
Bootstrapper::ParseCbor(p) => &mut p.input,
Bootstrapper::Select(p) => &mut p.input,
Expand All @@ -53,7 +53,7 @@ impl Bootstrapper {
match self {
Bootstrapper::Noop(p) => &mut p.output,
Bootstrapper::SplitBlock(p) => &mut p.output,
Bootstrapper::Json(p) => &mut p.output,
Bootstrapper::IntoJson(p) => &mut p.output,
Bootstrapper::LegacyV1(p) => &mut p.output,
Bootstrapper::ParseCbor(p) => &mut p.output,
Bootstrapper::Select(p) => &mut p.output,
Expand All @@ -70,7 +70,7 @@ impl Bootstrapper {
match self {
Bootstrapper::Noop(x) => gasket::runtime::spawn_stage(x, policy),
Bootstrapper::SplitBlock(x) => gasket::runtime::spawn_stage(x, policy),
Bootstrapper::Json(x) => gasket::runtime::spawn_stage(x, policy),
Bootstrapper::IntoJson(x) => gasket::runtime::spawn_stage(x, policy),
Bootstrapper::LegacyV1(x) => gasket::runtime::spawn_stage(x, policy),
Bootstrapper::ParseCbor(x) => gasket::runtime::spawn_stage(x, policy),
Bootstrapper::Select(x) => gasket::runtime::spawn_stage(x, policy),
Expand All @@ -89,7 +89,7 @@ impl Bootstrapper {
pub enum Config {
Noop(noop::Config),
SplitBlock(split_block::Config),
Json(json::Config),
IntoJson(into_json::Config),
LegacyV1(legacy_v1::Config),
ParseCbor(parse_cbor::Config),
Select(select::Config),
Expand All @@ -106,7 +106,7 @@ impl Config {
match self {
Config::Noop(c) => Ok(Bootstrapper::Noop(c.bootstrapper(ctx)?)),
Config::SplitBlock(c) => Ok(Bootstrapper::SplitBlock(c.bootstrapper(ctx)?)),
Config::Json(c) => Ok(Bootstrapper::Json(c.bootstrapper(ctx)?)),
Config::IntoJson(c) => Ok(Bootstrapper::IntoJson(c.bootstrapper(ctx)?)),
Config::LegacyV1(c) => Ok(Bootstrapper::LegacyV1(c.bootstrapper(ctx)?)),
Config::ParseCbor(c) => Ok(Bootstrapper::ParseCbor(c.bootstrapper(ctx)?)),
Config::Select(c) => Ok(Bootstrapper::Select(c.bootstrapper(ctx)?)),
Expand Down
Loading