Skip to content

Commit 263f2ed

Browse files
rseltmannatoulmeandrzej-stencel
authored
[exporter/syslogexporter] Add support for Unix sockets (open-telemetry#40740)
#### Description If the collector is running on the same system as the syslog endpoint, being able to export the logs to a socket means not having to open an extra port. The `network` configuration now accepts `"unix"` as a valid option in addition to `"tcp"` and `"udp"`. When `network` is set to `"unix"`, the `endpoint` must be a valid Unix socket file path, and `port` is ignored. #### Testing Manual testing by building the collector, configuring a Unix socket as endpoint, sending logs to the collector endpoint and verifying the logs are received via the socket. Also adjusted existing tests. #### Documentation Adjusted README. --------- Co-authored-by: Antoine Toulme <[email protected]> Co-authored-by: Andrzej Stencel <[email protected]>
1 parent 22815ac commit 263f2ed

File tree

7 files changed

+299
-47
lines changed

7 files changed

+299
-47
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: syslogexporter
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Add support for Unix sockets
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: [40740]
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 `network` configuration now accepts `"unix"` as a valid option in addition to `"tcp"` and `"udp"`. When `network` is set to `"unix"`, the `endpoint` must be a valid Unix socket file path, and `port` is ignored.
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]

exporter/syslogexporter/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<!-- end autogenerated section -->
1515

1616
The Syslog exporter sends logs in [syslog][syslog_wikipedia] format to a remote syslog server.
17-
It supports syslog protocols [RFC5424][RFC5424] and [RFC3164][RFC3164] and can send data over `TCP` or `UDP`.
17+
It supports syslog protocols [RFC5424][RFC5424] and [RFC3164][RFC3164] and can send data over `TCP`, `UDP` or Unix sockets.
1818
The exporter aims to be compatible with the [Syslog receiver][syslog_receiver].
1919
This means that syslog messages received via the Syslog receiver and exported via the Syslog exporter should be unchanged.
2020

@@ -23,8 +23,8 @@ This means that syslog messages received via the Syslog receiver and exported vi
2323
**The following configuration options are available**:
2424

2525
- `endpoint` - (required) syslog endpoint
26-
- `network` - (default = `tcp`) tcp/udp
27-
- `port` - (default = `514`) A syslog port
26+
- `network` - (default = `tcp`) tcp/udp/unix
27+
- `port` - (default = `514`) A syslog port, ignored when `network` is set to `unix`
2828
- `protocol` - (default = `rfc5424`) rfc5424/rfc3164
2929
- `rfc5424` - Expects the syslog messages to be rfc5424 compliant
3030
- `rfc3164` - Expects the syslog messages to be rfc3164 compliant

exporter/syslogexporter/config.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
var (
1717
errUnsupportedPort = errors.New("unsupported port: port is required, must be in the range 1-65535")
1818
errInvalidEndpoint = errors.New("invalid endpoint: endpoint is required but it is not configured")
19-
errUnsupportedNetwork = errors.New("unsupported network: network is required, only tcp/udp supported")
19+
errUnsupportedNetwork = errors.New("unsupported network: network is required, only tcp/udp/unix supported")
2020
errUnsupportedProtocol = errors.New("unsupported protocol: Only rfc5424 and rfc3164 supported")
2121
errOctetCounting = errors.New("octet counting is only supported for rfc5424 protocol")
2222
)
@@ -25,10 +25,10 @@ var (
2525
type Config struct {
2626
// Syslog server address
2727
Endpoint string `mapstructure:"endpoint"`
28-
// Syslog server port
28+
// Syslog server port (ignored for Unix sockets)
2929
Port int `mapstructure:"port"`
3030
// Network for syslog communication
31-
// options: tcp, udp
31+
// options: tcp, udp, unix
3232
Network string `mapstructure:"network"`
3333
// Protocol of syslog messages
3434
// options: rfc5424, rfc3164
@@ -48,19 +48,22 @@ type Config struct {
4848
// Validate the configuration for errors. This is required by component.Config.
4949
func (cfg *Config) Validate() error {
5050
invalidFields := []error{}
51-
if cfg.Port < 1 || cfg.Port > 65535 {
52-
invalidFields = append(invalidFields, errUnsupportedPort)
51+
52+
cfg.Network = strings.ToLower(cfg.Network)
53+
switch cfg.Network {
54+
case string(confignet.TransportTypeTCP), string(confignet.TransportTypeUDP):
55+
if cfg.Port < 1 || cfg.Port > 65535 {
56+
invalidFields = append(invalidFields, errUnsupportedPort)
57+
}
58+
case string(confignet.TransportTypeUnix):
59+
default:
60+
invalidFields = append(invalidFields, errUnsupportedNetwork)
5361
}
5462

5563
if cfg.Endpoint == "" {
5664
invalidFields = append(invalidFields, errInvalidEndpoint)
5765
}
5866

59-
cfg.Network = strings.ToLower(cfg.Network)
60-
if cfg.Network != string(confignet.TransportTypeTCP) && cfg.Network != string(confignet.TransportTypeUDP) {
61-
invalidFields = append(invalidFields, errUnsupportedNetwork)
62-
}
63-
6467
switch cfg.Protocol {
6568
case protocolRFC3164Str:
6669
case protocolRFC5424Str:

exporter/syslogexporter/config_test.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func TestValidate(t *testing.T) {
4444
Protocol: "rfc5424",
4545
Network: "ftp",
4646
},
47-
err: "unsupported network: network is required, only tcp/udp supported",
47+
err: "unsupported network: network is required, only tcp/udp/unix supported",
4848
},
4949
{
5050
name: "Unsupported Protocol",
@@ -56,6 +56,15 @@ func TestValidate(t *testing.T) {
5656
},
5757
err: "unsupported protocol: Only rfc5424 and rfc3164 supported",
5858
},
59+
{
60+
name: "invalid Unix Socket",
61+
cfg: &Config{
62+
Endpoint: "",
63+
Network: "unix",
64+
Protocol: "rfc5424",
65+
},
66+
err: "invalid endpoint: endpoint is required but it is not configured",
67+
},
5968
}
6069
for _, testInstance := range tests {
6170
t.Run(testInstance.name, func(t *testing.T) {
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
extensions:
2+
file_storage/syslog:
3+
directory: /tmp/otc
4+
timeout: 10s
5+
6+
exporters:
7+
syslog:
8+
network: unix
9+
endpoint: /var/run/my-socket.sock
10+
protocol: rfc5424
11+
12+
# for below described queueing and retry related configuration please refer to:
13+
# https://github.com/open-telemetry/opentelemetry-collector/blob/main/exporter/exporterhelper/README.md#configuration
14+
retry_on_failure:
15+
# default = true
16+
enabled: true
17+
# time to wait after the first failure before retrying;
18+
# ignored if enabled is false, default = 5s
19+
initial_interval: 10s
20+
# is the upper bound on backoff; ignored if enabled is false, default = 30s
21+
max_interval: 40s
22+
# is the maximum amount of time spent trying to send a batch;
23+
# ignored if enabled is false, default = 120s
24+
max_elapsed_time: 150s
25+
26+
sending_queue:
27+
# default = false
28+
enabled: true
29+
# number of consumers that dequeue batches; ignored if enabled is false,
30+
# default = 10
31+
num_consumers: 20
32+
# when set, enables persistence and uses the component specified as a storage extension for the persistent queue
33+
# make sure to configure and add a `file_storage` extension in `service.extensions`.
34+
# default = None
35+
storage: file_storage/syslog
36+
# maximum number of batches kept in memory before data;
37+
# ignored if enabled is false, default = 5000
38+
#
39+
# user should calculate this as num_seconds * requests_per_second where:
40+
# num_seconds is the number of seconds to buffer in case of a backend outage,
41+
# requests_per_second is the average number of requests per seconds.
42+
queue_size: 10000
43+
# Time to wait per individual attempt to send data to a backend
44+
# default = 5s
45+
timeout: 1s
46+
receivers:
47+
syslog:
48+
tcp:
49+
listen_address: "0.0.0.0:6514"
50+
protocol: rfc5424
51+
52+
service:
53+
telemetry:
54+
logs:
55+
level: "debug"
56+
extensions:
57+
- file_storage/syslog
58+
pipelines:
59+
logs:
60+
receivers:
61+
- syslog
62+
exporters:
63+
- syslog

0 commit comments

Comments
 (0)