Skip to content

Commit 09eeb86

Browse files
author
Dominik Rosiek
committed
[receiver/journald]: add support for grep
Signed-off-by: Dominik Rosiek <[email protected]>
1 parent fbd9a99 commit 09eeb86

File tree

5 files changed

+43
-5
lines changed

5 files changed

+43
-5
lines changed

.chloggen/drosiek-grep-support.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Use this changelog template to create an entry for release notes.
2+
# If your change doesn't affect end users, such as a test fix or a tooling change,
3+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
4+
5+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
6+
change_type: enhancement
7+
8+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
9+
component: journaldreceiver
10+
11+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
12+
note: add support for grep
13+
14+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
15+
issues: [20295]
16+
17+
# (Optional) One or more lines of additional information to render under the primary note.
18+
# These lines will be padded with 2 spaces and then inserted directly into the document.
19+
# Use pipe (|) for multiline entries.
20+
subtext:

pkg/stanza/docs/operators/journald_input.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ The `journald_input` operator will use the `__REALTIME_TIMESTAMP` field of the j
1414
| `output` | Next in pipeline | The connected operator(s) that will receive all outbound entries. |
1515
| `directory` | | A directory containing journal files to read entries from. |
1616
| `files` | | A list of journal files to read entries from. |
17-
| `units` | | A list of units to read entries from. See [Multiple filtering options](#multiple-filtering-options) examples, if you want to use it together with `matches` and/or `priority`. |
17+
| `units` | | A list of units to read entries from. See [Multiple filtering options](#multiple-filtering-options) examples. |
1818
| `matches` | | A list of matches to read entries from. See [Matches](#matches) and [Multiple filtering options](#multiple-filtering-options) examples. |
19-
| `priority` | `info` | Filter output by message priorities or priority ranges. See [Multiple filtering options](#multiple-filtering-options) examples, if you want to use it together with `units` and/or `matches`. |
19+
| `priority` | `info` | Filter output by message priorities or priority ranges. See [Multiple filtering options](#multiple-filtering-options) examples. |
20+
| `grep` | | Filter output to entries where the MESSAGE= field matches the specified regular expression. See [Multiple filtering options](#multiple-filtering-options) examples. |
2021
| `start_at` | `end` | At startup, where to start reading logs from the file. Options are `beginning` or `end`. |
2122
| `attributes` | {} | A map of `key: value` pairs to add to the entry's attributes. |
2223
| `resource` | {} | A map of `key: value` pairs to add to the entry's resource. |
@@ -64,6 +65,8 @@ AND
6465
( units[0] OR units[1] OR units[2] OR ... units[U] )
6566
AND
6667
( matches[0] OR matches[1] OR matches[2] OR ... matches[M] )
68+
AND
69+
( grep )
6770
```
6871

6972
Consider the following example:

pkg/stanza/operator/input/journald/journald.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ type Config struct {
5757
Units []string `mapstructure:"units,omitempty"`
5858
Priority string `mapstructure:"priority,omitempty"`
5959
Matches []MatchConfig `mapstructure:"matches,omitempty"`
60+
Grep string `mapstructure:"grep,omitempty"`
6061
}
6162

6263
type MatchConfig map[string]string
@@ -112,6 +113,10 @@ func (c Config) buildArgs() ([]string, error) {
112113

113114
args = append(args, "--priority", c.Priority)
114115

116+
if len(c.Grep) > 0 {
117+
args = append(args, "--grep", c.Grep)
118+
}
119+
115120
switch {
116121
case c.Directory != nil:
117122
args = append(args, "--directory", *c.Directory)

pkg/stanza/operator/input/journald/journald_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,13 @@ func TestBuildConfig(t *testing.T) {
166166
},
167167
Expected: []string{"--utc", "--output=json", "--follow", "--unit", "ssh", "--priority", "info", "_SYSTEMD_UNIT=dbus.service"},
168168
},
169+
{
170+
Name: "grep",
171+
Config: func(cfg *Config) {
172+
cfg.Grep = "test_grep"
173+
},
174+
Expected: []string{"--utc", "--output=json", "--follow", "--priority", "info", "--grep", "test_grep"},
175+
},
169176
}
170177

171178
for _, tt := range testCases {

receiver/journaldreceiver/README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,16 @@ Journald receiver requires that:
2626
| `directory` | `/run/log/journal` or `/run/journal` | A directory containing journal files to read entries from |
2727
| `files` | | A list of journal files to read entries from |
2828
| `start_at` | `end` | At startup, where to start reading logs from the file. Options are beginning or end |
29-
| `units` | | A list of units to read entries from. See [Multiple filtering options](#multiple-filtering-options) examples, if you want to use it together with `matches` and/or `priority`. |
29+
| `units` | | A list of units to read entries from. See [Multiple filtering options](#multiple-filtering-options) examples. |
3030
| `matches` | | A list of matches to read entries from. See [Matches](#matches) and [Multiple filtering options](#multiple-filtering-options) examples. |
31-
| `priority` | `info` | Filter output by message priorities or priority ranges. See [Multiple filtering options](#multiple-filtering-options) examples, if you want to use it together with `units` and/or `matches`. |
31+
| `priority` | `info` | Filter output by message priorities or priority ranges. See [Multiple filtering options](#multiple-filtering-options) examples. |
32+
| `grep` | | Filter output to entries where the MESSAGE= field matches the specified regular expression. See [Multiple filtering options](#multiple-filtering-options) examples. |
3233
| `storage` | none | The ID of a storage extension to be used to store cursors. Cursors allow the receiver to pick up where it left off in the case of a collector restart. If no storage extension is used, the receiver will manage cursors in memory only. |
3334
| `retry_on_failure.enabled` | `false` | If `true`, the receiver will pause reading a file and attempt to resend the current batch of logs if it encounters an error from downstream components. |
3435
| `retry_on_failure.initial_interval` | `1 second` | Time to wait after the first failure before retrying. |
3536
| `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. |
3637
| `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`. |
37-
| `operators` | [] | An array of [operators](../../pkg/stanza/docs/operators/README.md#what-operators-are-available). See below for more details |
38+
| `operators` | [] | An array of [operators](../../pkg/stanza/docs/operators/README.md#what-operators-are-available). See below for more details |
3839

3940
### Operators
4041

@@ -87,6 +88,8 @@ AND
8788
( units[0] OR units[1] OR units[2] OR ... units[U] )
8889
AND
8990
( matches[0] OR matches[1] OR matches[2] OR ... matches[M] )
91+
AND
92+
( grep )
9093
```
9194

9295
Consider the following example:

0 commit comments

Comments
 (0)