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

Add a User-Agent header to metadata API requests; allow overriding via config; add --version argument. #84

Merged
merged 4 commits into from
Mar 20, 2018

Conversation

igorpeshansky
Copy link
Member

@Georgehe4 FYI.

Copy link
Contributor

@supriyagarg supriyagarg left a comment

Choose a reason for hiding this comment

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

minor comments / questions.

@@ -77,11 +83,8 @@ install: metadatad

export DISTRO
PKG_NAME=stackdriver-metadata
PKG_VERSION=0.0.17
PKG_RELEASE=1
PKG_MAINTAINER=Stackdriver Agents <[email protected]>
Copy link
Contributor

Choose a reason for hiding this comment

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

How about moving all variables starting with PKG_ and DOCKER_ to the top so that they are defined in the same place?

Copy link
Member Author

Choose a reason for hiding this comment

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

I was debating whether to do this. At this point, only versions (that will be changed with each subsequent release) live at the top. Adding more stuff there may be confusing to readers.

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, that makes sense.

#endif

#define STRINGIFY_H(x) #x
#define STRINGIFY(x) STRINGIFY_H(x)
Copy link
Contributor

Choose a reason for hiding this comment

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

why are two macro definitions required? Isn't the first one sufficient?

Copy link
Member Author

Choose a reason for hiding this comment

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

Macros are substituted outside-in. If we simply called STRINGIFY_H(AGENT_VERSION), the result would have been the string "AGENT_VERSION" (because #x would be evaluated with x set to AGENT_VERSION). Adding another macro layer will expand both macros in the first pass, so STRINGIFY(AGENT_VERSION) expands to STRINGIFY_H(0.0.17-1) (assuming AGENT_VERSION is set to 0.0.17-1), which then expands on the next pass to #x with x set to 0.0.17-1, resulting in the string "0.0.17-1". The C preprocessor is weird.

Copy link
Contributor

Choose a reason for hiding this comment

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

thanks for the explanation. Please add a unit test for it to make this more explicit.

Copy link
Member Author

Choose a reason for hiding this comment

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

I actually tried. Doing this right would require rebuilding configuration.cc with a different AGENT_VERSION value (changing the way we build files under test), which is more upheaval than this PR warrants.
I suppose I could pull the STRINGIFY macro out into one of the headers (format.h?) and test it separately... Let me know if you want me to do that.

Copy link
Member Author

Choose a reason for hiding this comment

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

As discussed offline, referenced the GCC docs instead.

Copy link
Member 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.

PTAL.

@@ -77,11 +83,8 @@ install: metadatad

export DISTRO
PKG_NAME=stackdriver-metadata
PKG_VERSION=0.0.17
PKG_RELEASE=1
PKG_MAINTAINER=Stackdriver Agents <[email protected]>
Copy link
Member Author

Choose a reason for hiding this comment

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

I was debating whether to do this. At this point, only versions (that will be changed with each subsequent release) live at the top. Adding more stuff there may be confusing to readers.

#endif

#define STRINGIFY_H(x) #x
#define STRINGIFY(x) STRINGIFY_H(x)
Copy link
Member Author

Choose a reason for hiding this comment

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

Macros are substituted outside-in. If we simply called STRINGIFY_H(AGENT_VERSION), the result would have been the string "AGENT_VERSION" (because #x would be evaluated with x set to AGENT_VERSION). Adding another macro layer will expand both macros in the first pass, so STRINGIFY(AGENT_VERSION) expands to STRINGIFY_H(0.0.17-1) (assuming AGENT_VERSION is set to 0.0.17-1), which then expands on the next pass to #x with x set to 0.0.17-1, resulting in the string "0.0.17-1". The C preprocessor is weird.

Copy link
Contributor

@supriyagarg supriyagarg left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -124,6 +138,10 @@ int MetadataAgentConfiguration::ParseArguments(int ac, char** av) {
boost::program_options::notify(flags);

if (flags.count("help")) {
std::cout << flags_desc << std::endl;
return 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Previously help returned 1, was this change intended?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, yes, it was. It's a bug fix. There's nothing wrong with asking the program to print a help message, so it shouldn't return a failure exit code.

Copy link
Member Author

Choose a reason for hiding this comment

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

Turns out this bug fix introduced another bug -- we were using the nonzero return value of ParseArguments to cause the program to exit. Just fixed in another commit, which also added handling of argument parse errors and printing the version correctly.

Copy link
Member 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.

PTAL.

@@ -124,6 +138,10 @@ int MetadataAgentConfiguration::ParseArguments(int ac, char** av) {
boost::program_options::notify(flags);

if (flags.count("help")) {
std::cout << flags_desc << std::endl;
return 0;
Copy link
Member Author

Choose a reason for hiding this comment

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

Turns out this bug fix introduced another bug -- we were using the nonzero return value of ParseArguments to cause the program to exit. Just fixed in another commit, which also added handling of argument parse errors and printing the version correctly.

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

@igorpeshansky igorpeshansky changed the title Add a User-Agent header to metadata API requests; allow overriding via config. Add a User-Agent header to metadata API requests; allow overriding via config; add --version argument. Mar 20, 2018
Copy link
Contributor

@ACEmilG ACEmilG 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 f58374b into master Mar 20, 2018
@igorpeshansky igorpeshansky deleted the igorp-version-in-user-agent branch March 20, 2018 16:18
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.

4 participants