Skip to content

Don't stop the agent when journald is stopped or crashes#2416

Merged
remicalixte merged 5 commits into
masterfrom
remicalixte/fix-journald
Oct 11, 2018
Merged

Don't stop the agent when journald is stopped or crashes#2416
remicalixte merged 5 commits into
masterfrom
remicalixte/fix-journald

Conversation

@remicalixte

@remicalixte remicalixte commented Oct 4, 2018

Copy link
Copy Markdown
Contributor

What does this PR do?

By default systemd redirect the stdout to journald. When journald is stopped or crashes we receive a SIGPIPE signal. Go ignore SIGPIPE signals unless it is when stdout or stdout is closed, in this case the agent is stopped. We don't want that so we intercept the SIGPIPE signals and just discard them using the new --ignore-sigpipe flag

Other small fix, don't display the absolute path of the source files when using syslog:
before:

Oct 04 20:41:03 ubuntu-xenial agent[22041]: INFO | (/go/src/github.com/DataDog/datadog-agent/.omnibus/src/datadog-agent/src/github.com/DataDog/datadog-agent/pkg/collector/runner/runner.go:258) | Running check memory

after:

Oct 04 20:42:06 ubuntu-xenial agent[22501]: INFO | (runner.go:258) | Running check memory

Motivation

Fix #1555

@remicalixte
remicalixte requested a review from a team as a code owner October 4, 2018 20:37
@remicalixte remicalixte added the [deprecated] team/agent-core Deprecated. Use metrics-logs / shared-components labels instead.. label Oct 4, 2018
@remicalixte remicalixte added this to the 6.6.0 milestone Oct 4, 2018
@remicalixte remicalixte changed the title Don't stop the agent when journald is stopped or crash Don't stop the agent when journald is stopped or crashes Oct 4, 2018
@remicalixte

remicalixte commented Oct 5, 2018

Copy link
Copy Markdown
Contributor Author

This issue also affects the trace agent, we should fix it for this one too. The process agent is not affected since it doesn't output anything to stdout but it might be safer to do the same thing for it too

@nmuesch

nmuesch commented Oct 9, 2018

Copy link
Copy Markdown
Contributor

Hey! Thanks for this @remicalixte It seems I'm currently hitting this issue in one of my environments. In my case it seems like its the Trace Agent thats experiencing the issue. Would it be possible to extend this to Trace and Process as well?

@palazzem

Copy link
Copy Markdown
Contributor

On APM side, we're waiting for your review before merging DataDog/datadog-trace-agent#486

@remicalixte
remicalixte force-pushed the remicalixte/fix-journald branch from d6fbcf0 to 3fa214a Compare October 10, 2018 14:05
arbll
arbll previously approved these changes Oct 11, 2018

@arbll arbll left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Just a question by curiosity: why don't just ignore SIGPIPE by default ?

@gbbr

gbbr commented Oct 11, 2018

Copy link
Copy Markdown
Contributor

Good question. Do we need the flag?

@remicalixte

remicalixte commented Oct 11, 2018

Copy link
Copy Markdown
Contributor Author

I wanted to change the default behavior in the fewest cases possible. With the flag we don't ignore SIGPIPE when we run the datadog-agent status command for example, and stopping when we receive a SIGPIPE is the behavior of many unix command line programs. There is a bit of info there: https://golang.org/pkg/os/signal/#pkg-overview.

@olivielpeau olivielpeau left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a question, disregard if it's not relevant

Comment thread cmd/agent/app/run.go Outdated
@arbll

arbll commented Oct 11, 2018

Copy link
Copy Markdown
Member

The current implementation is scoped to run & start so it would not interfere with the other commands. I think the question is if there is a case where we want to exit a running agent when we get a SIGPIPE for stdout or stderr. I would answer no but I might be missing something.

Regardless both options are fine for me

@remicalixte

Copy link
Copy Markdown
Contributor Author

Oh yes you're right. I guess the flag is not really necessary then...

@remicalixte

Copy link
Copy Markdown
Contributor Author

The process agent is already ignoring all signals for example. I think it's fine to always ignore SIGPIPEs

@remicalixte
remicalixte force-pushed the remicalixte/fix-journald branch from e769708 to 0be6e0b Compare October 11, 2018 17:52
olivielpeau
olivielpeau previously approved these changes Oct 11, 2018

@olivielpeau olivielpeau left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just a few nits :)

Comment thread cmd/agent/app/run.go Outdated
}
}()

// By default systemd redirect the stdout to journald. When journald is stopped or crashes we receive a SIGPIPE signal.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: redirects

Comment thread cmd/agent/app/run.go Outdated
}()

// By default systemd redirect the stdout to journald. When journald is stopped or crashes we receive a SIGPIPE signal.
// Go ignore SIGPIPE signals unless it is when stdout or stdout is closed, in this case the agent is stopped. We don't want that

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: ignores. Also, it's not very clear what we don't want that refers to, maybe this would be clearer: We never want the agent to stop upon receiving SIGPIPE, so [...]

Comment thread pkg/config/log.go Outdated
<format id="common" format="%%Date(%s) | %%LEVEL | (%%File:%%Line in %%FuncShort) | %%Msg%%n"/>
<format id="syslog-json" format="%%CustomSyslogHeader(20,`+strconv.FormatBool(rfc)+`){&quot;level&quot;:&quot;%%LEVEL&quot;,&quot;relfile&quot;:&quot;%%RelFile&quot;,&quot;line&quot;:&quot;%%Line&quot;,&quot;msg&quot;:&quot;%%Msg&quot;}%%n"/>
<format id="syslog-common" format="%%CustomSyslogHeader(20,`+strconv.FormatBool(rfc)+`) %%LEVEL | (%%RelFile:%%Line) | %%Msg%%n" />
<format id="syslog-common" format="%%CustomSyslogHeader(20,`+strconv.FormatBool(rfc)+`) %%LEVEL | (%%File:%%Line) | %%Msg%%n" />

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to give slightly more context, we use (%%File:%%Line in %%FuncShort) for agent.log (for ex: somefile.go:23 in myFunction), I think we should normalize to the latter unless there's a good reason not to

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I agree

@olivielpeau olivielpeau left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌👌

@remicalixte
remicalixte merged commit d3e291a into master Oct 11, 2018
@remicalixte
remicalixte deleted the remicalixte/fix-journald branch October 11, 2018 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[deprecated] team/agent-core Deprecated. Use metrics-logs / shared-components labels instead.. kind/bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Agent doesn't restart on journald failure

6 participants