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

*: switch to glog #853

Open
andyxning opened this issue Feb 12, 2017 · 25 comments
Open

*: switch to glog #853

andyxning opened this issue Feb 12, 2017 · 25 comments

Comments

@andyxning
Copy link
Member

andyxning commented Feb 12, 2017

Currently, iiuc, nsq does not support log rotation. This is not user friendly for some users.

How about we move log package to glog which is used by Kubernetes organization and supports log rotation when log file size exceed 1.8GB by default.

/cc @mreiferson @jehiah

@mreiferson mreiferson changed the title Move log package to glog *: switch to glog Feb 15, 2017
@andyxning
Copy link
Member Author

@mreiferson Any thoughts about this?

@ploxiln
Copy link
Member

ploxiln commented Feb 17, 2017

glog isn't strictly required in order for logs to be rotated.

There are a few different systems that collect stdout/stderr from processes/services and manage the writing of log files. This could be considered a better separation of concerns than if every service had its own logic for log files/rotation/relaying.

Docker, which Kubernetes typically uses, can (now) rotate its own "json-file" logs for each container. It can also forward logs to other logging systems like logstash or fluentd which can rotate logs. I currently have it forwarding to rsyslog, which actually can't rotate logs on its own, it depends on the old standard "logrotate" to help it do that (and so does syslog-ng by the way). I don't know anything about Kubernetes though.

A more feature-full logging package could be nice... but most core users seem content with the current logging, and a replacement will need some work and consensus.

@andyxning
Copy link
Member Author

andyxning commented Feb 17, 2017

@ploxiln

There are a few different systems that collect stdout/stderr from processes/services and manage the writing of log files. This could be considered a better separation of concerns than if every service had its own logic for log files/rotation/relaying.

Agree. Just like what is recommended in 12factor#log. glog can meets this, too. By default, glog will send all logs to stderr which is consistent with log usage in nsq. At the same time, glog supports to log to a file with file size rotation. glog even supports logging to stderr and file at the same time. By enabling glog, we add more option for users and do not import any inconsistence. WDYT.

@ploxiln
Copy link
Member

ploxiln commented Feb 17, 2017

I do not object to a few more logging features, or to glog in particular.

@judwhite
Copy link
Contributor

judwhite commented Feb 19, 2017

Coming from the wonderful world of Windows, when executables are started by Service Control Manager (running as a Windows Service, which any semi-serious production app does) you don't get access to stdin, stdout, or stderr. For real. Of all the things that annoy me about platform differences this is probably the top. Handling the streams is the right way to do it IMO, but when you're under SCM you're cut off and your only option is to wrap it or write log files yourself.

That said, Windows users are used to this and are happy if they can even specify where the logs and written. Rolling, max size, and max age would be downright magical. I use a combination of Logrus for structured, leveled logs and Lumberjack for rolling logs. This combo is common enough in my own work I rolled them into one, Logrjack (don't judge, naming is hard :D).

As a client library, go-nsq is a different story and already does the right thing by letting the user specify their log implementation. If you wanted to support writing structured logs from go-nsq a few tweaks wouldn't be so hard and could be done by expanding the API without breaking backwards compat.

It would be nice to add structure to the log output of nsqd/nsqlookupd for easier parsing. For example, maybe logfmt (my preference, easy for both machines and people to read) or JSON for nsqd/nsqlookupd, and go-nsq could provide the ability to write structured logs, but still be agnostic about how that happens.

I'd be happy to contribute to this if we come up with goals and non-goals and which packages to use (based solely on prior experience, Logrus and Lumberjack have worked well for me). If Linux users want to use direct-to-file logging I don't see why not, but I'd much rather be in their position and use stdout/stderr. Thoughts on next steps? Maybe a WIP PR to move the conversation toward an implementation?

EDIT: Related, if we do this we can close #817.

@ploxiln
Copy link
Member

ploxiln commented Feb 19, 2017

For windows support, I'd personally suggest ripping out the windows service hooks that are in nsqd/nsqlookupd, and tell people to use winsw to wrap them for windows. It looks like it runs any normal long-lived process, and also handles stdout/stderr logging to files: https://github.com/kohsuke/winsw/blob/master/doc/loggingAndErrorReporting.md

@judwhite
Copy link
Contributor

@ploxiln NSSM is the de facto standard, but I'm not in favor of this approach. It would add another thing that can go wrong, can have compatibility issues, and has to be deployed. It's more work for the user and a barrier to entry. It would also change how people are deploying NSQ on Windows today. I added this support in a fork of 0.3.2 before it was merged in, we've been running like this for 2 years and it's been working great as-is.

I know it's related, but "ripping out windows service hooks" seems outside the scope of this discussion. Can we move this conversation back toward logging? If you want to discuss Windows Services can we please do that in another issue or on IRC/Slack?

@ploxiln
Copy link
Member

ploxiln commented Feb 19, 2017

Not arguing, just bringing up the datapoint to be considered. To be clear, it seems that #817 is in fact caused by the windows service hooks in nsqd and nsqlookupd, so users can't run processes as services with their preferred manager (nssm or winsw), and thus can't log to file and rotate logs.

@ploxiln
Copy link
Member

ploxiln commented Feb 19, 2017

Also, honest question, how do you manage nsqd / nsqlookupd logs on windows?

@judwhite
Copy link
Contributor

@ploxiln Honest answer, we don't log nsqd/nsqlookupd. We monitor the clients. If people prefer to use NSSM there are ways to support that without removing native support.

@andyxning
Copy link
Member Author

andyxning commented Feb 19, 2017

@judwhite @ploxiln @judwhite

I previously mean that whether we should replace log package with glog. IMO, this has nothing to do with the nsq deployment platform. We should make a decision about this movement in a general way instead of adjusting for any particular OS. :)

If you want to discuss this further, please move to #817.

For the discussion about this topic please take a look at #853 comment.

@judwhite
Copy link
Contributor

judwhite commented Feb 19, 2017

@andyxning Sorry we got on a tangent 😃 If you have previous experience with glog and it meets the needs then great, let's try that if the core team is open to it. It does overlap a bit if we're seriously considering Logrus (overall one of the most popular golang packages, used in Prometheus and other high profile projects) which also handles the "leveling" aspect, but not the rotating part.

@andyxning
Copy link
Member Author

@judwhite
glog also supports log leveles. :) For more info about it, please consult https://github.com/golang/glog @mreiferson .

glog has been used in almost all kubernetes projects. It has been tested already. :)

One of the biggest benefit is that log destination can be customized through command line.

@andyxning
Copy link
Member Author

andyxning commented Feb 20, 2017

Finally, i googled that cronolog is a awesome tool for redirect and rotate stderr/stdout. 👏

@mreiferson
Copy link
Member

I agree with @ploxiln — the handling of logs is the responsibility of the environment, not the process.

@judwhite I'm interested in the answer to #853 (comment)

@judwhite
Copy link
Contributor

@mreiferson We don't log nsqd/nsqlookupd.

I also agree that handling logs is the responsibility of the environment. In practice, on Windows, it doesn't work that way. I wish it did.

@andyxning
Copy link
Member Author

andyxning commented Feb 21, 2017

@mreiferson IIUC, you mean that we will not consider replacing log with glog, right?

@ploxiln
Copy link
Member

ploxiln commented Feb 21, 2017

If nsqd/nsqlookupd/... were to use a more sophisticated logging library, like glog or logrus, it would need to be made to integrate nicely with nsqd/nsqlookupd/... command-line flags and config files, and it would need to default to logging to stderr. If a pull request were opened that accomplished those goals in an elegant way, I don't know if it would be accepted, but it would have the best chance, IMHO.

@mreiferson
Copy link
Member

If someone did all that work I think there's a 99% chance we would accept that PR. There's a 0% chance that I'm going to do that work.

@andyxning
Copy link
Member Author

andyxning commented Feb 22, 2017 via email

@judwhite
Copy link
Contributor

@andyxning Would you like to pair on this? You can find me on the Gopher Slack.

@andyxning
Copy link
Member Author

andyxning commented Feb 22, 2017 via email

@lihan
Copy link

lihan commented Apr 5, 2017

Is there an update for this? Having the same issue here, would like to check to avoid double up work. @andyxning @judwhite

@andyxning
Copy link
Member Author

@lihan No work has been done. Hard work :(.
If you have time for adding this feature, I may review it. :)

@mreiferson
Copy link
Member

ping #892 for an initial set of changes that relate to this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants