Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd: log built-in-config.yaml and merged-config.yaml #202

Merged
merged 2 commits into from
Apr 28, 2022

Conversation

ridwanmsharif
Copy link
Contributor

@ridwanmsharif ridwanmsharif commented Sep 13, 2021

This change logs the config files on both windows and linux. It does so
by logging to STDOUT on linux and to the event log on windows.

This is what it looks like in cloud logging:
image

@ridwanmsharif ridwanmsharif force-pushed the ridwanmsharif/log-config branch from 77c2588 to 36952e5 Compare September 13, 2021 19:55
@ridwanmsharif ridwanmsharif force-pushed the ridwanmsharif/log-config branch 3 times, most recently from fa677e5 to 34a6cb8 Compare September 27, 2021 20:14
@ridwanmsharif ridwanmsharif force-pushed the ridwanmsharif/log-config branch from 44513bf to c476b08 Compare January 28, 2022 19:31
@ridwanmsharif ridwanmsharif marked this pull request as ready for review January 28, 2022 20:25
@ridwanmsharif
Copy link
Contributor Author

ridwanmsharif commented Jan 28, 2022

Alternatively, we could add separate fluent bit tail input plugin to read from the config files directly. And for those receivers have a multi line processor that tries to combine everything into one LogEntry. Its a bit tricker.

The rule definition would be something like:
start_state: "# Generated by Google Cloud Ops Agent" -> A string we would write as the first line of the config files
cont: Negative lookahead of the start_state

With this alternative approach, we would get a single LogEntry with the entire config file (though I don't know what it would do if the input ends up in separate chunks, if the files are too large for example).

I went with the simpler approach for the PR -> just logging to std out.

cc'ing @davidbtucker and @quentinmit to get some thoughts around how we should self-log something like this.

@davidbtucker
Copy link
Contributor

davidbtucker commented Feb 1, 2022 via email


// logConfigFiles logs the built-in and merged config files to STDOUT. These are then written by journald to var/log/syslog and so to
// Cloud Logging once the ops-agent is running.
func logConfigFiles(builtInConfigFile, mergedConfigFile string) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if it would make more sense to do this within mergeConfFiles. Maybe see what @quentinmit thinks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought about that but since this is logged differently for Linux (stdout -> journald -> logging agent) and Windows (event log -> logging agent), I thought it probably should live outside the common code

Copy link
Member

Choose a reason for hiding this comment

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

My main comment here is that we shouldn't be reading the files to log them; we should be serializing the in-memory config directly out to the log. I believe we have plans to get rid of the on-disk merged config file at some point.

I don't particularly care about formatting; we can clean that up as part of the improved/structured logging work that @davidbtucker is embarking on.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Restructured some of the changes so we don't rely on reading from files and instead use the in memory structures. Additionally, I moved some code around so we don't rely on reading from these files unnecessarily.

These files are now written to just for debugging purposes.

@ridwanmsharif ridwanmsharif force-pushed the ridwanmsharif/log-config branch 2 times, most recently from b387dd0 to e3af30d Compare February 10, 2022 20:57
@ridwanmsharif
Copy link
Contributor Author

Could we get the indentation to show up?

The indentation is actually preserved, I see the indentation in jsonPayload but looks like Cloud Logging's UI removes leading whitespace in the quickview

@ridwanmsharif ridwanmsharif force-pushed the ridwanmsharif/log-config branch from 7be51b4 to 1368471 Compare February 16, 2022 21:20
@ridwanmsharif ridwanmsharif force-pushed the ridwanmsharif/log-config branch 2 times, most recently from a85ad08 to 02ca99a Compare April 1, 2022 15:07
@ridwanmsharif
Copy link
Contributor Author

ridwanmsharif commented Apr 1, 2022

Had some free cycles so fixed up this PR. The PR now makes it so we no longer write the debug files to disk as we talked about.

@ridwanmsharif ridwanmsharif force-pushed the ridwanmsharif/log-config branch 5 times, most recently from d0e15ac to 859aa23 Compare April 6, 2022 16:12
@ridwanmsharif ridwanmsharif force-pushed the ridwanmsharif/log-config branch from 859aa23 to 5e19bd6 Compare April 26, 2022 15:37
Copy link
Member

@quentinmit quentinmit left a comment

Choose a reason for hiding this comment

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

+100, thanks for the cleanup. Still more work to do but this is already a nice improvement.

@ridwanmsharif ridwanmsharif force-pushed the ridwanmsharif/log-config branch from 5e19bd6 to bf319a2 Compare April 28, 2022 17:00
This change logs the config files on both windows and linux. It does so
by logging to STDOUT on linux and to the event log on windows.

Additionally, it stop writing debug configs to disk.

Signed-off-by: Ridwan Sharif <[email protected]>
@ridwanmsharif ridwanmsharif force-pushed the ridwanmsharif/log-config branch from bf319a2 to 70d7a2c Compare April 28, 2022 18:40
@ridwanmsharif ridwanmsharif merged commit 47d43ec into master Apr 28, 2022
@ridwanmsharif ridwanmsharif deleted the ridwanmsharif/log-config branch April 28, 2022 18:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants