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

Protocol based on serde #2161

Merged
merged 61 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
0a23067
Introduce stypes crate and related
DmitryAstafyev Nov 28, 2024
84dd041
Rearrange protocol wasm module
DmitryAstafyev Nov 28, 2024
1003a08
Update indexer code (switch to stypes)
DmitryAstafyev Nov 28, 2024
6de96d9
Cleaun up clippy warnings
DmitryAstafyev Nov 28, 2024
a62c10e
Resolve clippy issues
DmitryAstafyev Nov 28, 2024
5eb8f91
Rearrange modules in the session
DmitryAstafyev Nov 28, 2024
baf1de7
Add feature "nodejs" to stypes crate
DmitryAstafyev Nov 28, 2024
172affb
Update rs-bindings with feature "nodejs" of protocol
DmitryAstafyev Nov 29, 2024
e107c9c
Get rid of JSON in the scope of SearchMapUpdate event
DmitryAstafyev Nov 29, 2024
61def86
Remove factory and config from base
DmitryAstafyev Nov 29, 2024
e4063f5
Add generic CommandOutput into protocol
DmitryAstafyev Nov 29, 2024
3c00fac
Update protocol wasm module
DmitryAstafyev Nov 29, 2024
07dbc8a
Update wasm module
DmitryAstafyev Nov 29, 2024
0fc6dae
Add proptest strategies
DmitryAstafyev Nov 29, 2024
9cb0d4d
Writing random message examples for testing
DmitryAstafyev Dec 2, 2024
65d0f78
Reading generated tests for protocol
DmitryAstafyev Dec 2, 2024
7d72842
Test protocol on both sides
DmitryAstafyev Dec 5, 2024
f2edc33
Update lock files after rebasing
DmitryAstafyev Dec 5, 2024
ba11fb8
Add protocol test runner
DmitryAstafyev Dec 5, 2024
2b60366
Finalize crate stypes
DmitryAstafyev Dec 6, 2024
a2e2351
Change types on nodejs/client levels
DmitryAstafyev Dec 6, 2024
a1705cc
Avoid BigInt usage on JS level
DmitryAstafyev Dec 6, 2024
bec3a78
Update tests for search and observe
DmitryAstafyev Dec 6, 2024
e8238de
Add tests methods
DmitryAstafyev Dec 6, 2024
bffa9b4
Upgrade ComputationError handeling
DmitryAstafyev Dec 9, 2024
179a32e
Turn Jasmine tests into "green"
DmitryAstafyev Dec 9, 2024
f86c8c5
Bind listContent to type & remove debug output
DmitryAstafyev Dec 9, 2024
c1a0099
Add basic generator of TS types
DmitryAstafyev Dec 11, 2024
b044cb1
Update generated types
DmitryAstafyev Dec 12, 2024
cce3b66
Switch TS types genereating to ts-rs crate usage
DmitryAstafyev Dec 12, 2024
592664c
Using bytes in OperationResults instead JSON (rustcore)
DmitryAstafyev Dec 12, 2024
17dd208
Update stypes with new types
DmitryAstafyev Dec 12, 2024
cd5f941
Pull OperationDone group types to TS level
DmitryAstafyev Dec 12, 2024
f5daa2c
Replace CandlePoint with Point on stypes
DmitryAstafyev Dec 13, 2024
29ad567
Extract operations related types into mod
DmitryAstafyev Dec 15, 2024
8acb461
Update releated parts to fit updated types
DmitryAstafyev Dec 15, 2024
f2240e6
Avoid bigint usage on ts level
DmitryAstafyev Dec 15, 2024
e97dda0
Include bindings types into platform
DmitryAstafyev Dec 15, 2024
8ae7315
Resolve types conflicts (ts-binding to client/holder)
DmitryAstafyev Dec 16, 2024
435bdd5
Fix tests and avoid observe proxy obj
DmitryAstafyev Dec 17, 2024
53225b7
Update protocol module docs
DmitryAstafyev Dec 17, 2024
cf7669c
Update docs for tools/extend
DmitryAstafyev Dec 17, 2024
4764e17
Replace some types on platform level with bindings
DmitryAstafyev Dec 18, 2024
e5799f7
Update tests and types
DmitryAstafyev Dec 18, 2024
8bcf6dc
Update stype (added envvars related types)
DmitryAstafyev Dec 19, 2024
eb4e5e2
Update TS types
DmitryAstafyev Dec 19, 2024
9aab989
Update types (Dlt stat info)
DmitryAstafyev Dec 19, 2024
f470257
Update types on holder/client scope
DmitryAstafyev Dec 19, 2024
7d98827
Update build scripts (rake + cli)
DmitryAstafyev Dec 20, 2024
66c63c3
Add missed tests for recently added types
DmitryAstafyev Dec 22, 2024
70fc492
Update documentation
DmitryAstafyev Dec 22, 2024
420588e
Fix chart's issue (invalid map data)
DmitryAstafyev Dec 23, 2024
0d40177
Prevent running stypes tests in regular way
DmitryAstafyev Dec 23, 2024
bdbc729
Update CLI sys tests
DmitryAstafyev Dec 23, 2024
25f3a19
Build before run test in CI (temporary solution)
DmitryAstafyev Dec 23, 2024
6fc4a2a
Resolve review notes and rebase
DmitryAstafyev Jan 2, 2025
96d1c30
Build CLI: Include Protocol in test dependencies
AmmarAbouZor Jan 3, 2025
4d9775f
CI: Remove temp fix
AmmarAbouZor Jan 3, 2025
6f05b22
BinCode: Exclude Generating files on normal tests
AmmarAbouZor Jan 3, 2025
69f75b4
BinCode: Ignore prop tests by default.
AmmarAbouZor Jan 3, 2025
b7c86d0
Fix protocol test runner script
DmitryAstafyev Jan 6, 2025
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
816 changes: 806 additions & 10 deletions application/apps/indexer/Cargo.lock

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion application/apps/indexer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ members = [
"processor",
"session",
"sources",
"stypes"
]

[workspace.dependencies]
Expand All @@ -23,7 +24,7 @@ thiserror = "2.0"
lazy_static = "1.5"
tokio = { version = "1", features = ["full"] }
tokio-stream = "0.1"
dlt-core = "0.17"
dlt-core = "0.18.0"
crossbeam-channel = "0.5"
futures = "0.3"
tokio-util = "0.7"
Expand All @@ -36,6 +37,8 @@ uuid = "1.3"
grep-searcher = "0.1"
tempfile = "3.14"
env_logger = "0.11"
walkdir = "2.5"
envvars = "0.1"

## Development Dependencies ##
# Support for `html_reports` needs running the benchmarks via `cargo-criterion` tool.
Expand Down
4 changes: 2 additions & 2 deletions application/apps/indexer/addons/dlt-tools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ mod tests {
match scan_dlt_ft(input, None, true, cancel).await {
Ok(files) => {
assert_eq!(files.len(), 3);
assert_eq!("test1.txt", files.get(0).unwrap().name);
assert_eq!("test1.txt", files.first().unwrap().name);
assert_eq!("test2.txt", files.get(1).unwrap().name);
assert_eq!("test3.txt", files.get(2).unwrap().name);
}
Expand Down Expand Up @@ -179,7 +179,7 @@ mod tests {
match scan_dlt_ft(input, Some(filter), true, cancel).await {
Ok(files) => {
assert_eq!(files.len(), 1);
assert_eq!("test2.txt", files.get(0).unwrap().name);
assert_eq!("test2.txt", files.first().unwrap().name);
}
Err(error) => {
panic!("{}", format!("{error}"));
Expand Down
7 changes: 1 addition & 6 deletions application/apps/indexer/addons/file-tools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@ use std::{
const BYTES_TO_READ: u64 = 10240;

pub fn is_binary(file_path: String) -> Result<bool> {
let chunks = fetch_starting_chunk(Path::new(&file_path));
let buffer = match chunks {
Ok(buffer) => buffer,
Err(err) => return Err(err),
};

let buffer = fetch_starting_chunk(Path::new(&file_path))?;
Ok(from_utf8(&buffer).map_or(true, |_file_content| false))
}

Expand Down
6 changes: 3 additions & 3 deletions application/apps/indexer/addons/someip-tools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ use nom::{
combinator::map,
number::streaming::{be_u16, be_u32, be_u8},
sequence::tuple,
IResult,
Finish,
Finish, IResult,
};

use thiserror::Error;
Expand Down Expand Up @@ -60,7 +59,8 @@ pub fn parse_prefix(input: &[u8]) -> Result<(&[u8], std::string::String), Error>
.map_or_else(String::default, |s| format!(" {}", s))
)
},
)(input).finish()
)(input)
.finish()
}

fn parse_instance(input: &[u8]) -> IResult<&[u8], usize, Error> {
Expand Down
80 changes: 1 addition & 79 deletions application/apps/indexer/indexer_base/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,7 @@
// is strictly forbidden unless prior written permission is obtained
// from E.S.R.Labs.
use serde::{Deserialize, Serialize};
use std::{
net::{IpAddr, SocketAddr},
ops::RangeInclusive,
};
use thiserror::Error;

#[derive(Error, Debug)]
pub enum Error {
#[error("Problem with configuration found: {0}")]
Configuration(String),
#[error("IO error: {0:?}")]
Io(#[from] std::io::Error),
}
use std::ops::RangeInclusive;

/// A IndexSection describes a section of a file by indicies
/// to identify lines 10-12 (inclusively) => first_line = 10, last_line = 12
Expand All @@ -33,11 +21,6 @@ pub struct IndexSection {
pub last_line: usize,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct SectionConfig {
pub sections: Vec<IndexSection>,
}

impl IndexSection {
pub fn len(&self) -> usize {
self.last_line - self.first_line + 1
Expand Down Expand Up @@ -67,64 +50,3 @@ impl IndexSection {
}
}
}

#[derive(Serialize, Deserialize, Debug)]
pub struct UdpConnectionInfo {
pub multicast_addr: Vec<MulticastInfo>,
}

/// network socket config
/// if udp packets are sent via multicast, then the `multicast_addr` has to
/// be specified
#[derive(Serialize, Deserialize, Debug)]
pub struct SocketConfig {
pub udp_connection_info: Option<UdpConnectionInfo>,
pub bind_addr: String,
pub port: String,
}

impl SocketConfig {
pub fn socket_addr(&self) -> Result<SocketAddr, Error> {
// Touch IPv4
let addr: Option<SocketAddr> = match format!("{}:{}", self.bind_addr, self.port).parse() {
Ok(addr) => Some(addr),
Err(_) => None,
};
if let Some(addr) = addr {
Ok(addr)
} else {
// Touch IPv6
format!("[{}]:{}", self.bind_addr, self.port)
.parse()
.map_err(|_| {
Error::Configuration(format!(
"Could not parse socket address from {}, port {}",
self.bind_addr, self.port
))
})
}
}
}

/// Multicast config information.
/// `multiaddr` address must be a valid multicast address
/// `interface` is the address of the local interface with which the
/// system should join the
/// multicast group. If it's equal to `INADDR_ANY` then an appropriate
/// interface is chosen by the system.
#[derive(Clone, Serialize, Deserialize, Debug)]
pub struct MulticastInfo {
pub multiaddr: String,
pub interface: Option<String>,
}

impl MulticastInfo {
pub fn multicast_addr(&self) -> Result<IpAddr, Error> {
self.multiaddr.to_string().parse().map_err(|e| {
Error::Configuration(format!(
"Could not parse multicast address \"{}\": {e}",
self.multiaddr
))
})
}
}
1 change: 1 addition & 0 deletions application/apps/indexer/indexer_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ serde_json.workspace = true
tokio = { workspace = true , features = ["full"] }
tokio-util = { workspace = true, features = ["codec", "net"] }
uuid.workspace = true
stypes = { path = "../stypes", features=["rustcore"] }
16 changes: 6 additions & 10 deletions application/apps/indexer/indexer_cli/src/interactive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ use parsers::{dlt::DltParser, MessageStreamItem, ParseYield};
use processor::grabber::LineRange;
use rustyline::{error::ReadlineError, DefaultEditor};
use session::session::Session;
use sources::{
factory::{DltParserSettings, FileFormat, ObserveOptions, ParserType},
producer::MessageProducer,
socket::udp::UdpSource,
};
use sources::{producer::MessageProducer, socket::udp::UdpSource};
use std::path::PathBuf;
use tokio_util::sync::CancellationToken;

Expand Down Expand Up @@ -88,25 +84,25 @@ pub(crate) async fn handle_interactive_session(input: Option<PathBuf>) {
start = Instant::now();
let uuid = Uuid::new_v4();
let file_path = input.clone().expect("input must be present");
session.observe(uuid, ObserveOptions::file(file_path.clone(),FileFormat::Text, ParserType::Text)).expect("observe failed");
session.observe(uuid, stypes::ObserveOptions::file(file_path.clone(),stypes::FileFormat::Text, stypes::ParserType::Text(()))).expect("observe failed");
}
Some(Command::Dlt) => {
println!("dlt command received");
start = Instant::now();
let uuid = Uuid::new_v4();
let file_path = input.clone().expect("input must be present");
let dlt_parser_settings = DltParserSettings { filter_config: None, fibex_file_paths: None, with_storage_header: true, tz: None, fibex_metadata: None };
session.observe(uuid, ObserveOptions::file(file_path.clone(), FileFormat::Binary, ParserType::Dlt(dlt_parser_settings))).expect("observe failed");
let dlt_parser_settings = stypes::DltParserSettings { filter_config: None, fibex_file_paths: None, with_storage_header: true, tz: None, fibex_metadata: None };
session.observe(uuid, stypes::ObserveOptions::file(file_path.clone(), stypes::FileFormat::Binary, stypes::ParserType::Dlt(dlt_parser_settings))).expect("observe failed");
println!("dlt session was destroyed");
}
Some(Command::Grab) => {
println!("grab command received");
start = Instant::now();
let start_op = Instant::now();
let content = session.grab(LineRange::from(0u64..=1000)).await.expect("grab failed");
let len = content.len();
let len = content.0.len();
println!("content has {len} elemenst");
for elem in content {
for elem in content.0 {
println!("{elem:?}");
}
duration_report(start_op, format!("grabbing {len} lines"));
Expand Down
72 changes: 36 additions & 36 deletions application/apps/indexer/parsers/src/dlt/attachment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,42 @@ impl FileExtractor {
}
}

pub struct TempDir {
pub dir: PathBuf,
}

impl TempDir {
pub fn new() -> Self {
use rand::Rng;
use std::{env, fs};
let mut rand = rand::thread_rng();
let dir = env::current_dir()
.unwrap()
.join(format!("temp_{}", rand.gen::<u64>()));
fs::create_dir(dir.clone()).unwrap();
TempDir { dir }
}

pub fn assert_file(&self, name: &str, content: &str) {
let path = self.dir.join(name);
let string =
std::fs::read_to_string(&path).unwrap_or_else(|_| panic!("{:?} should exist", &path));
assert_eq!(string, content);
}
}

impl Drop for TempDir {
fn drop(&mut self) {
std::fs::remove_dir_all(self.dir.clone()).unwrap();
}
}

impl Default for TempDir {
fn default() -> Self {
Self::new()
}
}

#[allow(clippy::get_first)]
#[cfg(test)]
pub mod tests {
Expand Down Expand Up @@ -751,39 +787,3 @@ pub mod tests {
assert_eq!(files[2].1, "00000002_test3.txt");
}
}

pub struct TempDir {
pub dir: PathBuf,
}

impl TempDir {
pub fn new() -> Self {
use rand::Rng;
use std::{env, fs};
let mut rand = rand::thread_rng();
let dir = env::current_dir()
.unwrap()
.join(format!("temp_{}", rand.gen::<u64>()));
fs::create_dir(dir.clone()).unwrap();
TempDir { dir }
}

pub fn assert_file(&self, name: &str, content: &str) {
let path = self.dir.join(name);
let string =
std::fs::read_to_string(&path).unwrap_or_else(|_| panic!("{:?} should exist", &path));
assert_eq!(string, content);
}
}

impl Drop for TempDir {
fn drop(&mut self) {
std::fs::remove_dir_all(self.dir.clone()).unwrap();
}
}

impl Default for TempDir {
fn default() -> Self {
Self::new()
}
}
1 change: 1 addition & 0 deletions application/apps/indexer/processor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ serde_json.workspace = true
thiserror.workspace = true
tokio-util.workspace = true
uuid = { workspace = true , features = ["serde", "v4"] }
stypes = { path = "../stypes", features=["rustcore"] }

[dev-dependencies]
criterion.workspace = true
Expand Down
6 changes: 3 additions & 3 deletions application/apps/indexer/processor/benches/map_benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ extern crate criterion;
extern crate processor;

use criterion::{Criterion, *};
use processor::map::{FilterMatch, SearchMap};
use processor::map::SearchMap;

fn scaled_benchmark(c: &mut Criterion) {
let mut example_map: SearchMap = SearchMap::new();
let mut v = vec![];
for i in (1..1_000_000).step_by(50) {
v.push(FilterMatch::new(i, vec![0]));
v.push(FilterMatch::new(i + 22, vec![0, 1]));
v.push(stypes::FilterMatch::new(i, vec![0]));
v.push(stypes::FilterMatch::new(i + 22, vec![0, 1]));
}
example_map.set(Some(v), None);

Expand Down
42 changes: 42 additions & 0 deletions application/apps/indexer/processor/src/grabber/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,48 @@ pub enum GrabError {
Unsupported(String),
}

impl From<GrabError> for stypes::NativeError {
fn from(val: GrabError) -> Self {
match val {
GrabError::IoOperation(e) => stypes::NativeError {
severity: stypes::Severity::ERROR,
kind: stypes::NativeErrorKind::ComputationFailed,
message: Some(e),
},
GrabError::Config(msg) => stypes::NativeError {
severity: stypes::Severity::ERROR,
kind: stypes::NativeErrorKind::Configuration,
message: Some(msg),
},
GrabError::Interrupted => stypes::NativeError {
severity: stypes::Severity::ERROR,
kind: stypes::NativeErrorKind::Interrupted,
message: None,
},
GrabError::InvalidRange { .. } => stypes::NativeError {
severity: stypes::Severity::ERROR,
kind: stypes::NativeErrorKind::ComputationFailed,
message: Some("Invalid Range".to_string()),
},
GrabError::Communication(s) => stypes::NativeError {
severity: stypes::Severity::ERROR,
kind: stypes::NativeErrorKind::ComputationFailed,
message: Some(s),
},
GrabError::NotInitialize => stypes::NativeError {
severity: stypes::Severity::ERROR,
kind: stypes::NativeErrorKind::ComputationFailed,
message: Some("Grabbing failed, not initialized".to_owned()),
},
GrabError::Unsupported(s) => stypes::NativeError {
severity: stypes::Severity::ERROR,
kind: stypes::NativeErrorKind::ComputationFailed,
message: Some(format!("File type is not supported: {s}")),
},
}
}
}

#[derive(Debug)]
pub enum ComputationResult<T> {
Item(T),
Expand Down
Loading
Loading