Skip to content

Commit

Permalink
Journald config (open-telemetry#252)
Browse files Browse the repository at this point in the history
  • Loading branch information
rockb1017 authored Aug 28, 2021
1 parent eeab999 commit 1b149bb
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
19 changes: 16 additions & 3 deletions docs/operators/journald_input.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,26 @@ The `journald_input` operator will use the `__REALTIME_TIMESTAMP` field of the j
| `output` | Next in pipeline | The connected operator(s) that will receive all outbound entries |
| `directory` | | A directory containing journal files to read entries from |
| `files` | | A list of journal files to read entries from |
| `write_to` | `$body` | The body [field](/docs/types/field.md) written to when creating a new log entry |
| `units` | | A list of units to read entries from |
| `priority` | `info` | Filter output by message priorities or priority ranges |
| `write_to` | `$body` | The body [field](/docs/types/field.md) written to when creating a new log entry |
| `start_at` | `end` | At startup, where to start reading logs from the file. Options are `beginning` or `end` |
| `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 |

### Example Configurations
```yaml
- type: journald_input
units:
- ssh
- kubelet
priority: info
```
```yaml
- type: journald_input
priority: emerg..err
```
#### Simple journald input
Configuration:
Expand Down
9 changes: 9 additions & 0 deletions operator/builtin/input/journald/journald.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func NewJournaldInputConfig(operatorID string) *JournaldInputConfig {
return &JournaldInputConfig{
InputConfig: helper.NewInputConfig(operatorID, "journald_input"),
StartAt: "end",
Priority: "info",
}
}

Expand All @@ -54,6 +55,8 @@ type JournaldInputConfig struct {
Directory *string `mapstructure:"directory,omitempty" json:"directory,omitempty" yaml:"directory,omitempty"`
Files []string `mapstructure:"files,omitempty" json:"files,omitempty" yaml:"files,omitempty"`
StartAt string `mapstructure:"start_at,omitempty" json:"start_at,omitempty" yaml:"start_at,omitempty"`
Units []string `mapstructure:"units,omitempty" json:"units,omitempty" yaml:"units,omitempty"`
Priority string `mapstructure:"priority,omitempty" json:"priority,omitempty" yaml:"priority,omitempty"`
}

// Build will build a journald input operator from the supplied configuration
Expand Down Expand Up @@ -82,6 +85,12 @@ func (c JournaldInputConfig) Build(buildContext operator.BuildContext) ([]operat
return nil, fmt.Errorf("invalid value '%s' for parameter 'start_at'", c.StartAt)
}

for _, unit := range c.Units {
args = append(args, "--unit", unit)
}

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

switch {
case c.Directory != nil:
args = append(args, "--directory", *c.Directory)
Expand Down
1 change: 1 addition & 0 deletions operator/builtin/input/journald/journald_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ func TestJournaldInputConfig(t *testing.T) {
input := map[string]interface{}{
"id": "my_journald_input",
"type": "journald_input",
"priority": "info",
"start_at": "end",
"write_to": "$body.to",
"attributes": map[string]interface{}{},
Expand Down

0 comments on commit 1b149bb

Please sign in to comment.