-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Logs]: Added a support for journald (#1618)
- Loading branch information
1 parent
188e0d0
commit 519c226
Showing
25 changed files
with
807 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
logs: | ||
- type: journald |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed | ||
// under the Apache License Version 2.0. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
// Copyright 2018 Datadog, Inc. | ||
|
||
package journald | ||
|
||
import ( | ||
log "github.com/cihub/seelog" | ||
|
||
"github.com/DataDog/datadog-agent/pkg/logs/auditor" | ||
"github.com/DataDog/datadog-agent/pkg/logs/config" | ||
"github.com/DataDog/datadog-agent/pkg/logs/pipeline" | ||
"github.com/DataDog/datadog-agent/pkg/logs/restart" | ||
) | ||
|
||
// Launcher is in charge of starting and stopping new journald tailers | ||
type Launcher struct { | ||
sources []*config.LogSource | ||
pipelineProvider pipeline.Provider | ||
auditor *auditor.Auditor | ||
tailers map[string]*Tailer | ||
} | ||
|
||
// New returns a new Launcher. | ||
func New(sources []*config.LogSource, pipelineProvider pipeline.Provider, auditor *auditor.Auditor) *Launcher { | ||
journaldSources := []*config.LogSource{} | ||
for _, source := range sources { | ||
if source.Config.Type == config.JournaldType { | ||
journaldSources = append(journaldSources, source) | ||
} | ||
} | ||
return &Launcher{ | ||
sources: journaldSources, | ||
pipelineProvider: pipelineProvider, | ||
auditor: auditor, | ||
tailers: make(map[string]*Tailer), | ||
} | ||
} | ||
|
||
// Start starts new tailers. | ||
func (l *Launcher) Start() { | ||
for _, source := range l.sources { | ||
identifier := source.Config.Path | ||
if _, exists := l.tailers[identifier]; exists { | ||
// set up only one tailer per journal | ||
continue | ||
} | ||
tailer, err := l.setupTailer(source) | ||
if err != nil { | ||
log.Warn("Could not set up journald tailer: ", err) | ||
} else { | ||
l.tailers[identifier] = tailer | ||
} | ||
} | ||
} | ||
|
||
// Stop stops all active tailers | ||
func (l *Launcher) Stop() { | ||
stopper := restart.NewParallelStopper() | ||
for identifier, tailer := range l.tailers { | ||
stopper.Add(tailer) | ||
delete(l.tailers, identifier) | ||
} | ||
stopper.Stop() | ||
} | ||
|
||
// setupTailer configures and starts a new tailer, | ||
// returns the tailer or an error. | ||
func (l *Launcher) setupTailer(source *config.LogSource) (*Tailer, error) { | ||
tailer := NewTailer(source, l.pipelineProvider.NextPipelineChan()) | ||
err := tailer.Start(l.auditor.GetLastCommittedOffset(tailer.Identifier())) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return tailer, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed | ||
// under the Apache License Version 2.0. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
// Copyright 2018 Datadog, Inc. | ||
|
||
// +build systemd | ||
|
||
package journald | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/DataDog/datadog-agent/pkg/logs/auditor" | ||
"github.com/DataDog/datadog-agent/pkg/logs/config" | ||
pipeline "github.com/DataDog/datadog-agent/pkg/logs/pipeline/mock" | ||
) | ||
|
||
func TestShouldStartOnlyOneTailerPerJournal(t *testing.T) { | ||
sources := []*config.LogSource{ | ||
config.NewLogSource("", &config.LogsConfig{Type: config.JournaldType}), | ||
config.NewLogSource("", &config.LogsConfig{Type: config.JournaldType}), | ||
} | ||
launcher := New(sources, pipeline.NewMockProvider(), auditor.New(nil, "")) | ||
|
||
// expect two new tailers | ||
launcher.Start() | ||
assert.Equal(t, 1, len(launcher.tailers)) | ||
|
||
// expect all tailers to be released | ||
launcher.Stop() | ||
assert.Equal(t, 0, len(launcher.tailers)) | ||
} |
Oops, something went wrong.