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

Conversation

@igorpeshansky
Copy link
Contributor

Refactor the Docker code to look more uniform with Kubernetes.

Refactor the Docker code to look more uniform with Kubernetes.
#endif
constexpr const char docker_endpoint_path[] = "/containers";
constexpr const char kDockerEndpointPath[] = "/containers";
constexpr const char kDockerContainerResourcePrefix[] = "container";
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps use a more descriptive prefix like "docker_container" to differentiate from "k8s_container" and "gke_container"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately, this string is user-visible, and we're already stuck with it. I'm just moving it from a hard-coded string into a constant.

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.

#endif
constexpr const char docker_endpoint_path[] = "/containers";
constexpr const char kDockerEndpointPath[] = "/containers";
constexpr const char kDockerContainerResourcePrefix[] = "container";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately, this string is user-visible, and we're already stuck with it. I'm just moving it from a hard-coded string into a constant.

src/docker.cc Outdated
const std::string id = container->Get<json::String>("Id");
// Inspect the container.
try {
json::value raw_docker = QueryDocker(
Copy link
Contributor

Choose a reason for hiding this comment

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

Being that we're querying for metadata, raw_metadata, raw_container, or raw_container_metadata may be clearer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed to raw_container (raw_metadata was used for the object sent to the API).

MetadataAgent::Metadata::IGNORED()
#endif
);
} catch (const QueryException& e) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a thought, now that we know what we know with the cpp-netlib, and that non 200 responses aren't actually throwing exceptions, the reason for this is more likely to be an issue with the docker daemon or the server it's running, not that the container disappears.

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, I plan to fix status code handling in a subsequent PR, but it would be easier with this refactoring submitted.

json::value parsed_list = QueryDocker(
std::string(kDockerEndpointPath) + "/json?all=true" + container_filter);
Timestamp collected_at = std::chrono::system_clock::now();
if (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.

Why did you remove this verbose logging? Is it only helpful during development?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This verbose logging is now part of QueryDocker.

#ifdef VERBOSE
LOG(DEBUG) << "QueryDocker: Response: " << body(response);
#endif
return json::Parser::FromString(body(response));
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the area I'm referring to for non 200 responses. This is likely work for the future, but we should be checking for the response status code, instead of just assuming we're returning the right response based on ANY response at all.

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, I have a PR ready to go with a fix, just waiting to rebase on this refactoring.

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.

src/docker.cc Outdated
const std::string id = container->Get<json::String>("Id");
// Inspect the container.
try {
json::value raw_docker = QueryDocker(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed to raw_container (raw_metadata was used for the object sent to the API).

MetadataAgent::Metadata::IGNORED()
#endif
);
} catch (const QueryException& e) {
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, I plan to fix status code handling in a subsequent PR, but it would be easier with this refactoring submitted.

json::value parsed_list = QueryDocker(
std::string(kDockerEndpointPath) + "/json?all=true" + container_filter);
Timestamp collected_at = std::chrono::system_clock::now();
if (config_.VerboseLogging()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This verbose logging is now part of QueryDocker.

#ifdef VERBOSE
LOG(DEBUG) << "QueryDocker: Response: " << body(response);
#endif
return json::Parser::FromString(body(response));
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, I have a PR ready to go with a fix, just waiting to rebase on this refactoring.

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

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

@igorpeshansky igorpeshansky merged commit 381fa76 into master Feb 26, 2018
@igorpeshansky igorpeshansky deleted the igorp-docker-instance-id branch February 26, 2018 12:16
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