Skip to content
This repository was archived by the owner on Aug 19, 2019. It is now read-only.

Conversation

@igorpeshansky
Copy link
Contributor

Adds command-line flag support as well.

Copy link
Contributor

@bmoyles0117 bmoyles0117 left a comment

Choose a reason for hiding this comment

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

I would generally vote for log levels instead of having conditionals based on the flag everywhere. I think this is a good interim solution for reducing log spam, but the complexity could be greatly reduced with log levels.

// frequent, and could be promoted to ERROR.
LOG(WARNING) << "No matching resource for " << id;
if (agent_.config_.VerboseLogging()) {
LOG(WARNING) << "No matching resource for " << id;
Copy link
Contributor

Choose a reason for hiding this comment

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

I would consider logging this at least once per resource instead of guarding by verbose logging, as I would agree repetitively spamming an undiscovered resource would be spammy, even though this would happen within the 60 second poll interval for newly created docker containers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Logging this once isn't something that's easy to do with the current logging framework.
Besides, this is a handler for the incoming requests, so it would log every time an agent wants to translate a resource, which is a lot more frequent than once a minute.

boost::program_options::options_description flags_desc;
flags_desc.add_options()
("help", "Print help message")
("verbose", boost::program_options::value<bool>(&verbose_logging_),
Copy link
Contributor

@bmoyles0117 bmoyles0117 Oct 13, 2017

Choose a reason for hiding this comment

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

Will this support shorthand for the first letter as well? It would be nice to have -v as well as --verbose.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

};

json::value ReadCredentials(const std::string& credentials_file)
json::value ReadCredentials(const std::string& credentials_file, bool verbose)
Copy link
Contributor

@bmoyles0117 bmoyles0117 Oct 13, 2017

Choose a reason for hiding this comment

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

s/verbose/verbose_logging/g for consistency.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor Author

@igorpeshansky igorpeshansky left a comment

Choose a reason for hiding this comment

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

Thanks. PTAL.

boost::program_options::options_description flags_desc;
flags_desc.add_options()
("help", "Print help message")
("verbose", boost::program_options::value<bool>(&verbose_logging_),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

};

json::value ReadCredentials(const std::string& credentials_file)
json::value ReadCredentials(const std::string& credentials_file, bool verbose)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

// frequent, and could be promoted to ERROR.
LOG(WARNING) << "No matching resource for " << id;
if (agent_.config_.VerboseLogging()) {
LOG(WARNING) << "No matching resource for " << id;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Logging this once isn't something that's easy to do with the current logging framework.
Besides, this is a handler for the incoming requests, so it would log every time an agent wants to translate a resource, which is a lot more frequent than once a minute.

.options(all_desc).positional(positional_desc).run(), flags);
boost::program_options::notify(flags);

if (flags.count("help")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this work if -h is passed in instead of --help?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it will.

Copy link
Contributor

@bmoyles0117 bmoyles0117 left a comment

Choose a reason for hiding this comment

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

LGTM

("verbose", boost::program_options::value<bool>(&verbose_logging_),
"Enable verbose logging")
;
boost::program_options::options_description hidden_desc;
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you explain why this is hidden as opposed to just setup to have a default value?

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 didn't want it to show up in the --help output. Maybe that was overkill. I went back and forth on that (and also tried an approach where the config file could only be specified as a positional parameter, but quickly reverted that). But it's harmless to leave it as-is for now.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good to me just wanted the rationale behind it. Thanks.

// As we add more resource mappings, these will become less and less
// frequent, and could be promoted to ERROR.
LOG(WARNING) << "No matching resource for " << id;
if (agent_.config_.VerboseLogging()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this the only way to do it? Seems like if conditionals to guard logging defeats the purpose of using log levels like INFO and DEBUG. Also elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, the two are orthogonal. With verbose logging, we can get messages at all 4 levels (ERROR, WARNING, INFO, DEBUG). You're right that ideally this would be built into the logging framework itself, but that's a much larger undertaking.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we all agree here, I had spoken with @igorpeshansky offline and we came to the conclusion that the goal for now is to reduce log spam with a simple flag and implement full support for log levels later on down the road.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. Alright. Deferring for now.

Copy link
Contributor

@dhrupadb dhrupadb left a comment

Choose a reason for hiding this comment

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

LGTM 👌

("verbose", boost::program_options::value<bool>(&verbose_logging_),
"Enable verbose logging")
;
boost::program_options::options_description hidden_desc;
Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good to me just wanted the rationale behind it. Thanks.

Copy link
Contributor

@dhrupadb dhrupadb left a comment

Choose a reason for hiding this comment

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

LGTM 👌

@igorpeshansky igorpeshansky merged commit c9d1816 into master Nov 7, 2017
@igorpeshansky igorpeshansky deleted the igorp-verbose-logging branch November 7, 2017 18:00
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants