Skip to content

Commit

Permalink
[AMLII-2036] Add check for readonly file systems (#29320)
Browse files Browse the repository at this point in the history
Co-authored-by: Jen Gilbert <[email protected]>
  • Loading branch information
soberpeach and jhgilbert authored Sep 17, 2024
1 parent b0ba63c commit cce2d6d
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pkg/logs/launchers/integration/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ type Launcher struct {
func NewLauncher(sources *sources.LogSources, integrationsLogsComp integrations.Component) *Launcher {
runPath := filepath.Join(pkgConfig.Datadog().GetString("logs_config.run_path"), "integrations")
err := os.MkdirAll(runPath, 0755)

if err != nil {
ddLog.Warn("Unable to make integrations logs directory: ", err)
return nil
ddLog.Warn("Unable to create integrations logs directory:", err)
}

return &Launcher{
Expand Down Expand Up @@ -76,6 +76,7 @@ func (s *Launcher) run() {
for {
select {
case cfg := <-s.addedConfigs:

sources, err := ad.CreateSources(cfg.Config)
if err != nil {
ddLog.Warn("Failed to create source ", err)
Expand Down
28 changes: 28 additions & 0 deletions pkg/logs/launchers/integration/launcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,31 @@ func (suite *LauncherTestSuite) TestIntegrationLogFilePath() {
func TestLauncherTestSuite(t *testing.T) {
suite.Run(t, new(LauncherTestSuite))
}

// TestReadyOnlyFileSystem ensures the launcher doesn't panic in a read-only
// file system. There will be errors but it should handle them gracefully.
func TestReadyOnlyFileSystem(t *testing.T) {
readOnlyDir := filepath.Join(t.TempDir(), "readonly")
err := os.Mkdir(readOnlyDir, 0444)
assert.Nil(t, err, "Unable to make tempdir readonly")

pkgConfig.Datadog().SetWithoutSource("logs_config.run_path", readOnlyDir)

integrationsComp := integrationsmock.Mock()
s := NewLauncher(sources.NewLogSources(), integrationsComp)

// Check the launcher doesn't block on receiving channels
mockConf := &integration.Config{}
mockConf.Provider = "container"
mockConf.LogsConfig = integration.Data(`[{"type": "integration", "source": "foo", "service": "bar"}]`)
id := "123456789"

s.Start(nil, nil, nil, nil)
integrationsComp.RegisterIntegration(id, *mockConf)

logSample := "hello world"
integrationsComp.SendLog(logSample, id)

// send a second log to make sure the launcher isn't blocking
integrationsComp.SendLog(logSample, id)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Each section from every release note are combined when the
# CHANGELOG.rst is rendered. So the text needs to be worded so that
# it does not depend on any information only available in another
# section. This may mean repeating some details, but each section
# must be readable independently of the other.
#
# Each section note must be formatted as reStructuredText.
---
fixes:
- |
Fixes a panic caused by running the Agent on readonly filesystems. The
Agent will now return integration launchers and handle memory gracefully.

0 comments on commit cce2d6d

Please sign in to comment.