Skip to content

Commit

Permalink
Resolve review notes and rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitryAstafyev committed Jan 2, 2025
1 parent 25f3a19 commit 6fc4a2a
Show file tree
Hide file tree
Showing 9 changed files with 165 additions and 148 deletions.
24 changes: 22 additions & 2 deletions application/apps/indexer/processor/src/search/extractor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,27 @@ use std::{
path::{Path, PathBuf},
str::FromStr,
};

fn get_extracted_value(index: u64, input: &str, filters: &[Regex]) -> stypes::ExtractedMatchValue {
let mut values: Vec<(usize, Vec<String>)> = vec![];
for (filter_index, filter) in filters.iter().enumerate() {
for caps in filter.captures_iter(input) {
// Element on 0 always is the whole match. Here we don't need it
let matches: Vec<String> = caps
.iter()
.flatten()
.map(|m| m.as_str().to_owned())
.skip(1)
.collect();
if matches.is_empty() {
warn!("Filter doesn't give matches on matches extracting")
} else {
values.push((filter_index, matches));
}
}
}
stypes::ExtractedMatchValue { index, values }
}
pub struct MatchesExtractor {
pub file_path: PathBuf,
filters: Vec<SearchFilter>,
Expand All @@ -27,7 +48,6 @@ impl MatchesExtractor {
}
}

/// TODO: add description
pub fn extract_matches(&self) -> Result<Vec<stypes::ExtractedMatchValue>, SearchError> {
if self.filters.is_empty() {
return Err(SearchError::Input(
Expand Down Expand Up @@ -56,7 +76,7 @@ impl MatchesExtractor {
&regex_matcher,
&self.file_path,
UTF8(|lnum, line| {
values.push(stypes::ExtractedMatchValue::new(lnum - 1, line, &regexs));
values.push(get_extracted_value(lnum - 1, line, &regexs));
Ok(true)
}),
)
Expand Down
10 changes: 5 additions & 5 deletions application/apps/indexer/stypes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ edition = "2021"
[features]
test_and_gen = []
rustcore = [
"tokio",
"walkdir",
"regex",
"envvars",
"dep:tokio",
"dep:walkdir",
"dep:regex",
"dep:envvars",
"dlt-core/statistics",
"dlt-core/serde-support",
]
nodejs = [
"node-bindgen"
"dep:node-bindgen"
]

[dependencies]
Expand Down
6 changes: 6 additions & 0 deletions application/apps/indexer/stypes/bindings/dlt.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* ATTENTION:
* THIS FILE IS MANUALLY CREATED BECAUSE `ts_rs` CANNOT BE APPLIED
* TO FOREIGN TYPES (`DltFilterConfig` comes from the `dlt-core` crate).
* DO NOT REMOVE THIS FILE.
*/
export interface DltFilterConfig {
/// only select log entries with level MIN_LEVEL and more severe
///
Expand Down
5 changes: 5 additions & 0 deletions application/apps/indexer/stypes/bindings/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* ATTENTION:
* THIS FILE IS MANUALLY CREATED TO MANAGE TYPE EXPORTS.
* DO NOT DELETE. ADD EXPORT STATEMENTS FOR ANY NEW TYPES.
*/
export * from './attachment';
export * from './callback';
export * from './command';
Expand Down
225 changes: 124 additions & 101 deletions application/apps/indexer/stypes/bindings/observe.ts
Original file line number Diff line number Diff line change
@@ -1,159 +1,182 @@
/**
* ATTENTION:
* REFERENCE TO `DltFilterConfig` HAS BEEN ADDED MANUALLY
* BECAUSE THIS TYPE IS NOT GENERATED BY `ts_rs`.
*/
import { DltFilterConfig } from './dlt';

// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

/**
* Settings for the DLT parser.
*/
export type DltParserSettings = {
/**
* Configuration for filtering DLT messages.
*/
filter_config: DltFilterConfig,
/**
* Paths to FIBEX files for additional interpretation of `payload` content.
*/
fibex_file_paths: Array<string> | null,
/**
* Indicates whether the source contains a `StorageHeader`. Set to `true` if applicable.
*/
with_storage_header: boolean,
/**
* Timezone for timestamp adjustment. If specified, timestamps are converted to this timezone.
*/
tz: string | null, };
export type DltParserSettings = {
/**
* Configuration for filtering DLT messages.
*/
filter_config: DltFilterConfig;
/**
* Paths to FIBEX files for additional interpretation of `payload` content.
*/
fibex_file_paths: Array<string> | null;
/**
* Indicates whether the source contains a `StorageHeader`. Set to `true` if applicable.
*/
with_storage_header: boolean;
/**
* Timezone for timestamp adjustment. If specified, timestamps are converted to this timezone.
*/
tz: string | null;
};

/**
* Supported file formats for observation.
*/
export type FileFormat = "PcapNG" | "PcapLegacy" | "Text" | "Binary";
export type FileFormat = 'PcapNG' | 'PcapLegacy' | 'Text' | 'Binary';

/**
* Multicast configuration information.
* - `multiaddr`: A valid multicast address.
* - `interface`: The address of the local interface used to join the multicast group.
* If set to `INADDR_ANY`, the system selects an appropriate interface.
*/
export type MulticastInfo = { multiaddr: string, interface: string | null, };
export type MulticastInfo = { multiaddr: string; interface: string | null };

/**
* Options for observing data within a session.
*/
export type ObserveOptions = {
/**
* The description of the data source.
*/
origin: ObserveOrigin,
/**
* The parser configuration to be applied.
*/
parser: ParserType, };
export type ObserveOptions = {
/**
* The description of the data source.
*/
origin: ObserveOrigin;
/**
* The parser configuration to be applied.
*/
parser: ParserType;
};

/**
* Describes the source of data for observation.
*/
export type ObserveOrigin = { "File": [string, FileFormat, string] } | { "Concat": Array<[string, FileFormat, string]> } | { "Stream": [string, Transport] };
export type ObserveOrigin =
| { File: [string, FileFormat, string] }
| { Concat: Array<[string, FileFormat, string]> }
| { Stream: [string, Transport] };

/**
* Specifies the parser to be used for processing session data.
*/
export type ParserType = { "Dlt": DltParserSettings } | { "SomeIp": SomeIpParserSettings } | { "Text": null };
export type ParserType =
| { Dlt: DltParserSettings }
| { SomeIp: SomeIpParserSettings }
| { Text: null };

/**
* Configuration for executing terminal commands.
*/
export type ProcessTransportConfig = {
/**
* The working directory for the command.
*/
cwd: string,
/**
* The command to execute.
*/
command: string,
/**
* Environment variables. If empty, the default environment variables are used.
*/
envs: Map<string, string>, };
export type ProcessTransportConfig = {
/**
* The working directory for the command.
*/
cwd: string;
/**
* The command to execute.
*/
command: string;
/**
* Environment variables. If empty, the default environment variables are used.
*/
envs: Map<string, string>;
};

/**
* Configuration for serial port connections.
*/
export type SerialTransportConfig = {
/**
* The path to the serial port.
*/
path: string,
/**
* The baud rate for the connection.
*/
baud_rate: number,
/**
* The number of data bits per frame.
*/
data_bits: number,
/**
* The flow control setting.
*/
flow_control: number,
/**
* The parity setting.
*/
parity: number,
/**
* The number of stop bits.
*/
stop_bits: number,
/**
* The delay in sending data, in milliseconds.
*/
send_data_delay: number,
/**
* Whether the connection is exclusive.
*/
exclusive: boolean, };
export type SerialTransportConfig = {
/**
* The path to the serial port.
*/
path: string;
/**
* The baud rate for the connection.
*/
baud_rate: number;
/**
* The number of data bits per frame.
*/
data_bits: number;
/**
* The flow control setting.
*/
flow_control: number;
/**
* The parity setting.
*/
parity: number;
/**
* The number of stop bits.
*/
stop_bits: number;
/**
* The delay in sending data, in milliseconds.
*/
send_data_delay: number;
/**
* Whether the connection is exclusive.
*/
exclusive: boolean;
};

/**
* Settings for the SomeIp parser.
*/
export type SomeIpParserSettings = {
/**
* Paths to FIBEX files for additional interpretation of `payload` content.
*/
fibex_file_paths: Array<string> | null, };
export type SomeIpParserSettings = {
/**
* Paths to FIBEX files for additional interpretation of `payload` content.
*/
fibex_file_paths: Array<string> | null;
};

/**
* Configuration for TCP connections.
*/
export type TCPTransportConfig = {
/**
* The address to bind the TCP connection to.
*/
bind_addr: string, };
export type TCPTransportConfig = {
/**
* The address to bind the TCP connection to.
*/
bind_addr: string;
};

/**
* Describes the transport source for a session.
*/
export type Transport = { "Process": ProcessTransportConfig } | { "TCP": TCPTransportConfig } | { "UDP": UDPTransportConfig } | { "Serial": SerialTransportConfig };
export type Transport =
| { Process: ProcessTransportConfig }
| { TCP: TCPTransportConfig }
| { UDP: UDPTransportConfig }
| { Serial: SerialTransportConfig };

/**
* Configuration for UDP connections.
*/
export type UDPTransportConfig = {
/**
* The address to bind the UDP connection to.
*/
bind_addr: string,
/**
* A list of multicast configurations.
*/
multicast: Array<MulticastInfo>, };
export type UDPTransportConfig = {
/**
* The address to bind the UDP connection to.
*/
bind_addr: string;
/**
* A list of multicast configurations.
*/
multicast: Array<MulticastInfo>;
};

/**
* Configuration for UDP connections.
*/
export type UdpConnectionInfo = {
/**
* A list of multicast addresses to listen on.
*/
multicast_addr: Array<MulticastInfo>, };
export type UdpConnectionInfo = {
/**
* A list of multicast addresses to listen on.
*/
multicast_addr: Array<MulticastInfo>;
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::*;
use std::{ffi::OsStr, fs::Metadata};
use std::fs::Metadata;
use walkdir::DirEntry;

impl FolderEntityDetails {
Expand All @@ -20,7 +20,7 @@ impl FolderEntityDetails {
ext: entity
.path()
.extension()
.unwrap_or(OsStr::new(""))
.unwrap_or_default()
.to_string_lossy()
.to_string(),
})
Expand Down
Loading

0 comments on commit 6fc4a2a

Please sign in to comment.