Skip to content

Commit

Permalink
[receiver/syslog] Support setting on_error mode for syslog receiver (o…
Browse files Browse the repository at this point in the history
…pen-telemetry#37847)

<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description
As per the discussion in
open-telemetry#36906,
this PR supports setting the `on_error` mode in syslog receiver that
controls the behaviour of the underlying `syslog_parser` when it
encounters an error.

<!-- Issue number (e.g. #1234) or full URL to issue, if applicable. -->
#### Link to tracking issue
Closes
open-telemetry#36906.

<!--Describe what testing was performed and which tests were added.-->
#### Testing
Tested setting `on_error` in the syslog receiver config.

<!--Describe the documentation added.-->
#### Documentation
Documented the `on_error` entry in both the syslog input and receiver
config.
<!--Please delete paragraphs that you did not use before submitting.-->

Signed-off-by: Mengnan Gong <[email protected]>
  • Loading branch information
namco1992 authored Feb 13, 2025
1 parent 5879a03 commit 9d7bf1b
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 9 deletions.
27 changes: 27 additions & 0 deletions .chloggen/syslog-receiver-add-error-mode.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: syslogreceiver

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Support setting `on_error` config for syslog receiver.

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [36906]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
18 changes: 9 additions & 9 deletions pkg/stanza/docs/operators/syslog_input.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ The `syslog_input` operator listens for syslog format logs from UDP/TCP packages

### Configuration Fields

| Field | Default | Description |
| --- | --- | --- |
| `id` | `syslog_input` | A unique identifier for the operator. |
| `output` | Next in pipeline | The connected operator(s) that will receive all outbound entries. |
| `tcp` | {} | A [tcp_input config](./tcp_input.md#configuration-fields) to defined syslog_parser operator. |
| `udp` | {} | A [udp_input config](./udp_input.md#configuration-fields) to defined syslog_parser operator. |
| Field | Default | Description |
|--------------|------------------|-------------------------------------------------------------------------------------------------------|
| `id` | `syslog_input` | A unique identifier for the operator. |
| `output` | Next in pipeline | The connected operator(s) that will receive all outbound entries. |
| `tcp` | {} | A [tcp_input config](./tcp_input.md#configuration-fields) to defined syslog_parser operator. |
| `udp` | {} | A [udp_input config](./udp_input.md#configuration-fields) to defined syslog_parser operator. |
| `syslog` | required | A [syslog parser config](./syslog_parser.md#configuration-fields) to defined syslog_parser operator. |
| `attributes` | {} | A map of `key: value` pairs to add to the entry's attributes. |
| `resource` | {} | A map of `key: value` pairs to add to the entry's resource. |

| `attributes` | {} | A map of `key: value` pairs to add to the entry's attributes. |
| `resource` | {} | A map of `key: value` pairs to add to the entry's resource. |
| `on_error` | `send` | The behavior of the syslog parser if it encounters an error. See [on_error](../types/on_error.md). |



Expand Down
4 changes: 4 additions & 0 deletions pkg/stanza/operator/input/syslog/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type Config struct {
syslog.BaseConfig `mapstructure:",squash"`
TCP *tcp.BaseConfig `mapstructure:"tcp"`
UDP *udp.BaseConfig `mapstructure:"udp"`
OnError string `mapstructure:"on_error"`
}

func (c Config) Build(set component.TelemetrySettings) (operator.Operator, error) {
Expand All @@ -52,6 +53,9 @@ func (c Config) Build(set component.TelemetrySettings) (operator.Operator, error
syslogParserCfg.SetID(inputBase.ID() + "_internal_parser")
syslogParserCfg.OutputIDs = c.OutputIDs
syslogParserCfg.MaxOctets = c.MaxOctets
if c.OnError != "" {
syslogParserCfg.OnError = c.OnError
}
syslogParser, err := syslogParserCfg.Build(set)
if err != nil {
return nil, fmt.Errorf("failed to resolve syslog config: %w", err)
Expand Down
1 change: 1 addition & 0 deletions pkg/stanza/operator/input/syslog/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func TestUnmarshal(t *testing.T) {
cfg := NewConfig()
cfg.Protocol = "rfc5424"
cfg.Location = "foo"
cfg.OnError = "send_quiet"
cfg.UDP = &udp.NewConfig().BaseConfig
cfg.UDP.ListenAddress = "10.0.0.1:9000"
cfg.UDP.AddAttributes = true
Expand Down
1 change: 1 addition & 0 deletions pkg/stanza/operator/input/syslog/testdata/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ udp:
type: syslog_input
protocol: rfc5424
location: foo
on_error: send_quiet
udp:
listen_address: 10.0.0.1:9000
add_attributes: true
Expand Down
1 change: 1 addition & 0 deletions receiver/syslogreceiver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Parses Syslogs received over TCP or UDP.
| `retry_on_failure.initial_interval` | `1 second` | Time to wait after the first failure before retrying. |
| `retry_on_failure.max_interval` | `30 seconds` | Upper bound on retry backoff interval. Once this value is reached the delay between consecutive retries will remain constant at the specified value. |
| `retry_on_failure.max_elapsed_time` | `5 minutes` | Maximum amount of time (including retries) spent trying to send a logs batch to a downstream consumer. Once this value is reached, the data is discarded. Retrying never stops if set to `0`. |
| `on_error` | `send` | The behavior of the [syslog parser](../../pkg/stanza/docs/operators/syslog_parser.md) if it encounters an error. See [on_error](../../pkg/stanza/docs/types/on_error.md). |

### Operators

Expand Down

0 comments on commit 9d7bf1b

Please sign in to comment.