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

Add instance association to Docker containers.#59

Merged
igorpeshansky merged 2 commits intomasterfrom
igorp-docker-instance-id
Feb 26, 2018
Merged

Add instance association to Docker containers.#59
igorpeshansky merged 2 commits intomasterfrom
igorp-docker-instance-id

Conversation

@igorpeshansky
Copy link
Copy Markdown
Contributor

Refactor the Docker code to look more uniform with Kubernetes.

Refactor the Docker code to look more uniform with Kubernetes.
Comment thread src/docker.cc
#endif
constexpr const char docker_endpoint_path[] = "/containers";
constexpr const char kDockerEndpointPath[] = "/containers";
constexpr const char kDockerContainerResourcePrefix[] = "container";
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Comment thread src/docker.cc
#endif
constexpr const char docker_endpoint_path[] = "/containers";
constexpr const char kDockerEndpointPath[] = "/containers";
constexpr const char kDockerContainerResourcePrefix[] = "container";
Copy link
Copy Markdown
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.

Comment thread src/docker.cc Outdated
const std::string id = container->Get<json::String>("Id");
// Inspect the container.
try {
json::value raw_docker = QueryDocker(
Copy link
Copy Markdown
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
Copy Markdown
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).

Comment thread src/docker.cc
MetadataAgent::Metadata::IGNORED()
#endif
);
} catch (const QueryException& e) {
Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread src/docker.cc
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
Copy Markdown
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
Copy Markdown
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.

Comment thread src/docker.cc
#ifdef VERBOSE
LOG(DEBUG) << "QueryDocker: Response: " << body(response);
#endif
return json::Parser::FromString(body(response));
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Comment thread src/docker.cc Outdated
const std::string id = container->Get<json::String>("Id");
// Inspect the container.
try {
json::value raw_docker = QueryDocker(
Copy link
Copy Markdown
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).

Comment thread src/docker.cc
MetadataAgent::Metadata::IGNORED()
#endif
);
} catch (const QueryException& e) {
Copy link
Copy Markdown
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.

Comment thread src/docker.cc
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
Copy Markdown
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.

Comment thread src/docker.cc
#ifdef VERBOSE
LOG(DEBUG) << "QueryDocker: Response: " << body(response);
#endif
return json::Parser::FromString(body(response));
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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