Skip to content

Commit eab1701

Browse files
authored
Merge branch 'main' into main
2 parents 5680e22 + 96e7cd8 commit eab1701

16 files changed

+850
-93
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: netflowreceiver
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Adds the implementation of the netflow receiver
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [32732]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext: The receiver now supports receiving NetFlow v5, NetFow v9, IPFIX, and sFlow v5 logs.
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: [user]

receiver/netflowreceiver/README.md

Lines changed: 48 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ receivers:
3232
port: 2055
3333
sockets: 16
3434
workers: 32
35+
netflow/sflow:
36+
- scheme: sflow
37+
port: 6343
38+
sockets: 16
39+
workers: 32
3540

3641
processors:
3742
batch:
@@ -45,7 +50,7 @@ exporters:
4550
service:
4651
pipelines:
4752
logs:
48-
receivers: [netflow]
53+
receivers: [netflow, netflow/sflow]
4954
processors: [batch]
5055
exporters: [debug]
5156
telemetry:
@@ -61,42 +66,52 @@ You would then configure your network devices to send netflow, sflow, or ipfix d
6166
6267
| Field | Description | Examples | Default |
6368
|-------|-------------|--------| ------- |
64-
| scheme | The type of flow data that to receive | `sflow`, `netflow`, `flow` | `netflow` |
69+
| scheme | The type of flow data that to receive | `sflow`, `netflow` | `netflow` |
6570
| hostname | The hostname or IP address to bind to | `localhost` | `0.0.0.0` |
6671
| port | The port to bind to | `2055` or `6343` | `2055` |
6772
| sockets | The number of sockets to use | 1 | 1 |
6873
| workers | The number of workers used to decode incoming flow messages | 2 | 2 |
69-
| queue_size | The size of the incoming netflow packets queue | 1000 | 1000000 |
74+
| queue_size | The size of the incoming netflow packets queue, it will always be at least 1000. | 5000 | 1000 |
7075

7176
## Data format
7277

73-
The netflow data is standardized for the different schemas and is converted to OpenTelemetry logs following the [semantic conventions](https://opentelemetry.io/docs/specs/semconv/general/attributes/#server-client-and-shared-network-attributes)
74-
75-
The output will adhere the format:
76-
77-
```json
78-
{
79-
"destination": {
80-
"address": "192.168.0.1",
81-
"port": 22
82-
},
83-
"flow": {
84-
"end": 1731073104662487000,
85-
"sampler_address": "192.168.0.2",
86-
"sequence_num": 49,
87-
"start": 1731073077662487000,
88-
"time_received": 1731073138662487000,
89-
"type": "NETFLOW_V5"
90-
},
91-
"io": {
92-
"bytes": 529,
93-
"packets": 378
94-
},
95-
"source": {
96-
"address": "192.168.0.3",
97-
"port": 40
98-
},
99-
"transport": "TCP",
100-
"type": "IPv4"
101-
}
102-
```
78+
The netflow data is standardized for the different schemas and is converted to OpenTelemetry log records following the [semantic conventions](https://opentelemetry.io/docs/specs/semconv/general/attributes/#server-client-and-shared-network-attributes)
79+
80+
The log record will have the following attributes (with examples):
81+
82+
* **source.address**: Str(132.189.238.100)
83+
* **source.port**: Int(1255)
84+
* **destination.address**: Str(241.171.33.110)
85+
* **destination.port**: Int(64744)
86+
* **network.transport**: Str(tcp)
87+
* **network.type**: Str(ipv4)
88+
* **flow.io.bytes**: Int(853)
89+
* **flow.io.packets**: Int(83)
90+
* **flow.type**: Str(netflow_v5)
91+
* **flow.sequence_num**: Int(191)
92+
* **flow.time_received**: Int(1736309689918929427)
93+
* **flow.start**: Int(1736309689830846400)
94+
* **flow.end**: Int(1736309689871846400)
95+
* **flow.sampling_rate**: Int(0)
96+
* **flow.sampler_address**: Str(172.28.176.1)
97+
98+
The log record timestamps will be:
99+
100+
* **Observed timestamp**: The time the flow was received.
101+
* **Timestamp**: The flow `start` field.
102+
103+
### Schema support
104+
105+
#### netflow
106+
107+
* Process [Template Records](https://www.cisco.com/en/US/technologies/tk648/tk362/technologies_white_paper09186a00800a3db9.html) if present
108+
* Process Netflow V5, V9, and IPFIX messages
109+
* Extract the attributes documented above
110+
* Mapping of custom fields is not yet supported
111+
112+
#### sflow
113+
114+
* Process [sFlow version 5](https://sflow.org/sflow_version_5.txt) datagrams
115+
* `flow_sample` and `flow_sample_expanded` are supported.
116+
* `counter_sample` and `counter_sample_expanded` are NOT yet supported.
117+
* Mapping of custom fields is not yet supported

receiver/netflowreceiver/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type Config struct {
3232

3333
// Validate checks if the receiver configuration is valid
3434
func (cfg *Config) Validate() error {
35-
validSchemes := [3]string{"sflow", "netflow", "flow"}
35+
validSchemes := [2]string{"sflow", "netflow"}
3636

3737
validScheme := false
3838
for _, scheme := range validSchemes {
@@ -42,7 +42,7 @@ func (cfg *Config) Validate() error {
4242
}
4343
}
4444
if !validScheme {
45-
return fmt.Errorf("scheme must be one of sflow, netflow, or flow")
45+
return fmt.Errorf("scheme must be netflow or sflow")
4646
}
4747

4848
if cfg.Sockets <= 0 {

receiver/netflowreceiver/config_test.go

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,27 @@ func TestLoadConfig(t *testing.T) {
3636
Port: 2055,
3737
Sockets: 1,
3838
Workers: 1,
39-
QueueSize: 1000000,
39+
QueueSize: 1000,
40+
},
41+
},
42+
{
43+
id: component.NewIDWithName(metadata.Type, "zero_queue"),
44+
expected: &Config{
45+
Scheme: "netflow",
46+
Port: 2055,
47+
Sockets: 1,
48+
Workers: 1,
49+
QueueSize: 1000,
50+
},
51+
},
52+
{
53+
id: component.NewIDWithName(metadata.Type, "sflow"),
54+
expected: &Config{
55+
Scheme: "sflow",
56+
Port: 6343,
57+
Sockets: 1,
58+
Workers: 1,
59+
QueueSize: 1000,
4060
},
4161
},
4262
}
@@ -68,12 +88,20 @@ func TestInvalidConfig(t *testing.T) {
6888
}{
6989
{
7090
id: component.NewIDWithName(metadata.Type, "invalid_schema"),
71-
err: "scheme must be one of sflow, netflow, or flow",
91+
err: "scheme must be netflow or sflow",
7292
},
7393
{
7494
id: component.NewIDWithName(metadata.Type, "invalid_port"),
7595
err: "port must be greater than 0",
7696
},
97+
{
98+
id: component.NewIDWithName(metadata.Type, "zero_sockets"),
99+
err: "sockets must be greater than 0",
100+
},
101+
{
102+
id: component.NewIDWithName(metadata.Type, "zero_workers"),
103+
err: "workers must be greater than 0",
104+
},
77105
}
78106

79107
for _, tt := range tests {

receiver/netflowreceiver/factory.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@ import (
1414
)
1515

1616
const (
17-
defaultSockets = 1
18-
defaultWorkers = 2
19-
defaultQueueSize = 1_000_000
17+
defaultSockets = 1
18+
defaultWorkers = 2
19+
// The default UDP packet buffer size in GoFlow2 is 9000 bytes, which means
20+
// that for a full queue of 1000 messages, the size in memory will be 9MB.
21+
// Source: https://github.com/netsampler/goflow2/blob/v2.2.1/README.md#security-notes-and-assumptions
22+
defaultQueueSize = 1_000
2023
)
2124

2225
// NewFactory creates a factory for netflow receiver.
@@ -27,6 +30,8 @@ func NewFactory() receiver.Factory {
2730
receiver.WithLogs(createLogsReceiver, metadata.LogsStability))
2831
}
2932

33+
// Config defines configuration for netflow receiver.
34+
// By default we listen for netflow traffic on port 2055
3035
func createDefaultConfig() component.Config {
3136
return &Config{
3237
Scheme: "netflow",
@@ -37,14 +42,15 @@ func createDefaultConfig() component.Config {
3742
}
3843
}
3944

45+
// createLogsReceiver creates a netflow receiver.
46+
// We also create the UDP receiver, which is the piece of software that actually listens
47+
// for incoming netflow traffic on an UDP port.
4048
func createLogsReceiver(_ context.Context, params receiver.Settings, cfg component.Config, consumer consumer.Logs) (receiver.Logs, error) {
41-
logger := params.Logger
42-
conf := cfg.(*Config)
49+
conf := *(cfg.(*Config))
4350

44-
nr := &netflowReceiver{
45-
logger: logger,
46-
logConsumer: consumer,
47-
config: conf,
51+
nr, err := newNetflowLogsReceiver(params, conf, consumer)
52+
if err != nil {
53+
return nil, err
4854
}
4955

5056
return nr, nil

receiver/netflowreceiver/go.mod

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@ module github.com/open-telemetry/opentelemetry-collector-contrib/receiver/netflo
33
go 1.22.0
44

55
require (
6+
github.com/netsampler/goflow2/v2 v2.2.1
67
github.com/stretchr/testify v1.10.0
78
go.opentelemetry.io/collector/component v0.118.1-0.20250121185328-fbefb22cc2b3
89
go.opentelemetry.io/collector/component/componenttest v0.118.1-0.20250121185328-fbefb22cc2b3
910
go.opentelemetry.io/collector/confmap v1.24.1-0.20250121185328-fbefb22cc2b3
1011
go.opentelemetry.io/collector/consumer v1.24.1-0.20250121185328-fbefb22cc2b3
1112
go.opentelemetry.io/collector/consumer/consumertest v0.118.1-0.20250121185328-fbefb22cc2b3
13+
go.opentelemetry.io/collector/pdata v1.24.1-0.20250121185328-fbefb22cc2b3
1214
go.opentelemetry.io/collector/receiver v0.118.1-0.20250121185328-fbefb22cc2b3
1315
go.opentelemetry.io/collector/receiver/receivertest v0.118.1-0.20250121185328-fbefb22cc2b3
16+
go.opentelemetry.io/collector/semconv v0.118.1-0.20250121185328-fbefb22cc2b3
1417
go.uber.org/goleak v1.3.0
1518
go.uber.org/zap v1.27.0
1619
)
@@ -26,6 +29,7 @@ require (
2629
github.com/knadh/koanf/maps v0.1.1 // indirect
2730
github.com/knadh/koanf/providers/confmap v0.1.0 // indirect
2831
github.com/knadh/koanf/v2 v2.1.2 // indirect
32+
github.com/libp2p/go-reuseport v0.4.0 // indirect
2933
github.com/mitchellh/copystructure v1.2.0 // indirect
3034
github.com/mitchellh/reflectwalk v1.0.2 // indirect
3135
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
@@ -35,7 +39,6 @@ require (
3539
go.opentelemetry.io/collector/config/configtelemetry v0.118.1-0.20250121185328-fbefb22cc2b3 // indirect
3640
go.opentelemetry.io/collector/consumer/consumererror v0.118.1-0.20250121185328-fbefb22cc2b3 // indirect
3741
go.opentelemetry.io/collector/consumer/xconsumer v0.118.1-0.20250121185328-fbefb22cc2b3 // indirect
38-
go.opentelemetry.io/collector/pdata v1.24.1-0.20250121185328-fbefb22cc2b3 // indirect
3942
go.opentelemetry.io/collector/pdata/pprofile v0.118.1-0.20250121185328-fbefb22cc2b3 // indirect
4043
go.opentelemetry.io/collector/pipeline v0.118.1-0.20250121185328-fbefb22cc2b3 // indirect
4144
go.opentelemetry.io/collector/receiver/xreceiver v0.118.1-0.20250121185328-fbefb22cc2b3 // indirect

receiver/netflowreceiver/go.sum

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

receiver/netflowreceiver/listener.go

Lines changed: 0 additions & 11 deletions
This file was deleted.

receiver/netflowreceiver/listener_test.go

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)