-
Notifications
You must be signed in to change notification settings - Fork 11
Add a User-Agent header to metadata API requests; allow overriding via config; add --version argument. #84
Conversation
There was a problem hiding this 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]> |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, that makes sense.
src/configuration.cc
Outdated
#endif | ||
|
||
#define STRINGIFY_H(x) #x | ||
#define STRINGIFY(x) STRINGIFY_H(x) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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]> |
There was a problem hiding this comment.
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.
src/configuration.cc
Outdated
#endif | ||
|
||
#define STRINGIFY_H(x) #x | ||
#define STRINGIFY(x) STRINGIFY_H(x) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
src/configuration.cc
Outdated
@@ -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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
…ents return value bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PTAL.
src/configuration.cc
Outdated
@@ -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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
@Georgehe4 FYI.