Skip to content

Commit 999b9c7

Browse files
authored
fix sampling rate (#7)
1 parent c881e2c commit 999b9c7

6 files changed

Lines changed: 59 additions & 35 deletions

File tree

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/rustflow/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rustflow"
3-
version = "0.3.1"
3+
version = "0.3.2"
44
edition = "2024"
55
description = "High-performance flow collector library for NetFlow, IPFIX, and sFlow"
66
license = "BSD-3-Clause"

crates/rustflow_collector/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rustflow_collector"
3-
version = "0.3.1"
3+
version = "0.3.2"
44
edition = "2024"
55

66
[dependencies]

crates/rustflow_collector/src/main.rs

Lines changed: 51 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -302,20 +302,33 @@ fn parse_netflow(
302302

303303
for flow_set in &parsed.flow_sets {
304304
for record in &flow_set.records {
305-
if let V9Record::Data(data_record) = record {
306-
if let Some(rate) = extract_v9_sampling_rate(data_record) {
307-
sampling_cache.set(cache_key, rate);
305+
match record {
306+
V9Record::OptionsData(data_record) => {
307+
if let Some(rate) =
308+
extract_v9_sampling_rate(data_record)
309+
{
310+
sampling_cache.set(cache_key, rate);
311+
}
308312
}
309-
310-
let ctx = NetFlowV9Context {
311-
header: &parsed.header,
312-
sampler_address: Some(src),
313-
sampling_rate: sampling_cache.get(&cache_key),
314-
};
315-
let mut common_flow = ctx.convert(data_record, flow_set.id);
316-
common_flow.time_received_ns = time_received_ns;
317-
let enriched = enrichment.enrich(&common_flow);
318-
output.write_enriched_flow(&common_flow, &enriched);
313+
V9Record::Data(data_record) => {
314+
if let Some(rate) =
315+
extract_v9_sampling_rate(data_record)
316+
{
317+
sampling_cache.set(cache_key, rate);
318+
}
319+
320+
let ctx = NetFlowV9Context {
321+
header: &parsed.header,
322+
sampler_address: Some(src),
323+
sampling_rate: sampling_cache.get(&cache_key),
324+
};
325+
let mut common_flow =
326+
ctx.convert(data_record, flow_set.id);
327+
common_flow.time_received_ns = time_received_ns;
328+
let enriched = enrichment.enrich(&common_flow);
329+
output.write_enriched_flow(&common_flow, &enriched);
330+
}
331+
_ => {}
319332
}
320333
}
321334
}
@@ -361,21 +374,32 @@ fn parse_netflow(
361374

362375
for set in &parsed.sets {
363376
for record in &set.records {
364-
if let IpfixRecord::Data(data_record) = record {
365-
if let Some(rate) = extract_ipfix_sampling_rate(data_record)
366-
{
367-
sampling_cache.set(cache_key, rate);
377+
match record {
378+
IpfixRecord::OptionsData(data_record) => {
379+
if let Some(rate) =
380+
extract_ipfix_sampling_rate(data_record)
381+
{
382+
sampling_cache.set(cache_key, rate);
383+
}
368384
}
369-
370-
let ctx = IpfixContext {
371-
header: &parsed.header,
372-
sampler_address: Some(src),
373-
sampling_rate: sampling_cache.get(&cache_key),
374-
};
375-
let mut common_flow = ctx.convert(data_record, set.id);
376-
common_flow.time_received_ns = time_received_ns;
377-
let enriched = enrichment.enrich(&common_flow);
378-
output.write_enriched_flow(&common_flow, &enriched);
385+
IpfixRecord::Data(data_record) => {
386+
if let Some(rate) =
387+
extract_ipfix_sampling_rate(data_record)
388+
{
389+
sampling_cache.set(cache_key, rate);
390+
}
391+
392+
let ctx = IpfixContext {
393+
header: &parsed.header,
394+
sampler_address: Some(src),
395+
sampling_rate: sampling_cache.get(&cache_key),
396+
};
397+
let mut common_flow = ctx.convert(data_record, set.id);
398+
common_flow.time_received_ns = time_received_ns;
399+
let enriched = enrichment.enrich(&common_flow);
400+
output.write_enriched_flow(&common_flow, &enriched);
401+
}
402+
_ => {}
379403
}
380404
}
381405
}

crates/rustflow_core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rustflow_core"
3-
version = "0.3.1"
3+
version = "0.3.2"
44
edition = "2024"
55

66
[dependencies]

crates/rustflow_exporter/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rustflow_exporter"
3-
version = "0.3.1"
3+
version = "0.3.2"
44
edition = "2024"
55

66
[dependencies]

0 commit comments

Comments
 (0)