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

Add new "--log-to-stdout" CLI flag #460

Closed
wants to merge 6 commits into from
Closed

Conversation

Kami
Copy link
Contributor

@Kami Kami commented Mar 16, 2020

This pull request adds new --log-to-stdout flag to the agent which can be used in combination with the existing --no-fork flag.

When this flag is used, the agent will log all the messages to stdout.

This comes handy in various scenarios such as when troubleshooting things and for local development.

In builds on top of my comments from #415.

TODO

  • Tests

When this flag is used, agent will output all the log files to stdout,
in addition to the log files.

This comes handy in local development environment and while
troubleshooting various issues.
@Kami Kami changed the title Add new "--log-to-stdout" CLI flag [WIP] Add new "--log-to-stdout" CLI flag Mar 16, 2020
@codecov
Copy link

codecov bot commented Mar 16, 2020

Codecov Report

Merging #460 into master will increase coverage by 0.04%.
The diff coverage is 91.67%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #460      +/-   ##
==========================================
+ Coverage   67.88%   67.92%   +0.04%     
==========================================
  Files         107      107              
  Lines       26981    27012      +31     
  Branches     3284     3283       -1     
==========================================
+ Hits        18314    18347      +33     
  Misses       7797     7797              
+ Partials      870      868       -2
Impacted Files Coverage Δ
scalyr_agent/scalyr_logging.py 80.58% <ø> (+0.58%) ⬆️
scalyr_agent/tests/agent_main_test.py 100% <100%> (ø) ⬆️
scalyr_agent/agent_main.py 49.08% <57.14%> (+0.08%) ⬆️
.../builtin_monitors/tests/kubernetes_monitor_test.py 96.7% <0%> (ø) ⬆️
scalyr_agent/util.py 85.54% <0%> (+0.14%) ⬆️

@Kami
Copy link
Contributor Author

Kami commented Mar 16, 2020

@czerwingithub What's your take on this?

I think it's reasonable and something I missed from the agent.

Most of the Unix daemons which have foreground / no-fork mode usually also have an option to log things to stdout instead of log files.

Usually that's also the default behavior when "foreground" mode is used, but I know this really won't work for us because our agent relies on logs being written to disk so we can ship them to Scalyr API.

@Kami Kami changed the title [WIP] Add new "--log-to-stdout" CLI flag Add new "--log-to-stdout" CLI flag Mar 16, 2020
@Kami Kami requested a review from czerwingithub March 16, 2020 17:51
@czerwingithub
Copy link
Contributor

I hear what you are saying about the expected behavior of non-forked processes. Maybe we should strive to respect that. So, I have a little different take on this. Let me know what you think.

  1. When non-forked, log (by default) to both stdout and the agent log. You are right that we do still want that to go up to Scalyr.

  2. We then need to preserve the current behavior that K8s and Docker does not have the agent log go to stdout (even though they are not forked.) So, we can have a special --full-log-to-stdout flag that K8s and Docker can specify as false in their run commands. That will be documented as, if true, then send the full agent.log to stdout if the process is not forked.

I know #2 is a little odd, but only we'd have to really use it when defining the container images we publish.

Thoughts?

@yanscalyr
Copy link
Contributor

One idea I had is to avoid any new flags at all we could use the "log only things above some severity to stdout" functionality in place of it. By default we could have no-fork processes log INFO and above, then in the k8s config file define it as ERROR or something else that would only output things that would be useful to see in k8s logs. The documentations for the config file would also advertise this new feature that some customers wanted.

A concern I have with this idea is that people upgrading their k8s agents wouldn't update their config and would get everything logged to stdout.

@czerwingithub
Copy link
Contributor

I think you might be onto something there Yan. I like that idea and I'll add one new twist to it.. but I don't know if it will work.

It is possible in Dockerfiles to define values for environment variables. If we define an ENV variable for our K8s container images, will that be used if the user has not explicitly set a value for that variable in the configmap? If so, then we don't need to set it in the K8s config but instead in the actual container images.. so we won't have that config divergence problem you alluded to.

@yanscalyr
Copy link
Contributor

That actually sounds perfect! I will let @Kami comment on it as well but I think thats the way to go.

@czerwingithub
Copy link
Contributor

@yanscalyr You might want to make sure it works... an ENV variable defined in your container is available in K8s... and that you can override it by defining variables in the K8s config. You could do a small experiment and see.

@Kami
Copy link
Contributor Author

Kami commented Mar 18, 2020

@yanscalyr That approach sounds good to me 👍

And ideally, for development / testing purposes you could also control this level / severity setting.

@Kami
Copy link
Contributor Author

Kami commented Mar 18, 2020

@yanscalyr How do you want me to proceed with this PR?

Should I close it? Should we merge it? Will you incorporate it into your changes?

@yanscalyr
Copy link
Contributor

@Kami probably just close this PR, the work is pretty duplicate with mine and mine is also almost ready.
@czerwingithub Did some testing and it does seem to work, so we would default the severity limit to DEBUG (I need to test that the debug level config option will stop actual debug messages unless we set it, shouldn't be hard to add if it doesn't just work) and in the k8s docker file set the environment variable to WARN I guess, unless you think ERROR would be better.

@Kami Kami closed this Mar 19, 2020
@Kami Kami deleted the use_use_stdout_option branch March 19, 2020 13:52
@Kami Kami restored the use_use_stdout_option branch March 23, 2020 22:32
@Kami Kami deleted the use_use_stdout_option branch March 23, 2020 22:34
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.

None yet

3 participants