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

Conversation

@igorpeshansky
Copy link
Contributor

Note: this is a large refactoring, but I tried to keep each commit incremental. Please review one commit at a time.

Copy link

@rbuskens rbuskens left a comment

Choose a reason for hiding this comment

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

Thanks for breaking up your changes into bite-sized chunks. A few minor comments.

src/api_server.h Outdated
// Runs the metadata tasks.
class MetadataAgent {
public:
using Metadata = MetadataStore::Metadata;

Choose a reason for hiding this comment

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

This doesn't seem to be used anywhere in the MetadataAgent class. Can we remove?

Choose a reason for hiding this comment

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

NM. I see you remove this in a later commit.

src/api_server.h Outdated
#include <memory>

#include "configuration.h"
#include "reporter.h"

Choose a reason for hiding this comment

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

I don't think we need to include this header file here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No longer relevant.

src/reporter.h Outdated

namespace google {

// Storage for the metadata mapping.

Choose a reason for hiding this comment

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

This comment isn't correct. Please fix.

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. This does bring up an interesting question of whether we should reference the config/storage objects directly instead of lugging the agent pointer around. Let me try that instead.

src/agent.h Outdated
#include <memory>

#include "configuration.h"
#include "reporter.h"

Choose a reason for hiding this comment

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

Would "class MetadataReporter" be enough?

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 would. Done.

Replace includes by forward declarations in headers whenever possible.
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 for the review. PTAL.

src/api_server.h Outdated
#include <memory>

#include "configuration.h"
#include "reporter.h"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

No longer relevant.

src/agent.h Outdated
#include <memory>

#include "configuration.h"
#include "reporter.h"
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 would. Done.

src/reporter.h Outdated

namespace google {

// Storage for the metadata mapping.
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. This does bring up an interesting question of whether we should reference the config/storage objects directly instead of lugging the agent pointer around. Let me try that instead.

#ifndef AGENT_H_
#define AGENT_H_

//#include "config.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's remove unnecessary imports, same throughout.

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 specific one was a "reminder" to set up autotools to make this more portable. It appears all over the place. Probably no sense in keeping it, but I'd rather do it as a separate cleanup to keep this PR focused.

std::lock_guard<std::mutex> lock(agent_.resource_mu_);
const auto result = agent_.resource_map_.find(id);
if (result == agent_.resource_map_.end()) {
std::lock_guard<std::mutex> lock(store_.resource_mu_);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't love the fact that the resource_mu_ is being handled outside of the store, can we setup getters to protect direct access of resource_mu_?

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 don't love this either, and was thinking along the same lines, except in a different PR. Let's keep this one focused on the refactoring.

<< " headers: " << request.headers
<< " body: " << request.body;
}
if (request.method == "GET" && request.destination.find(kPrefix) == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It'd be awesome to call something like MonitoredResourceHandler here, so that we can easily start adding other handlers based on method / path such as HealthcheckHandler, then, each handler would be easily testable as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea, bad timing. This is supposed to be a refactoring with a specific purpose — I'll do this in a follow-up PR if you don't mind.

#include <boost/network/protocol/http/client.hpp>
#include <chrono>

#include "configuration.h"
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 line necessary? I only ask because it didn't exist before, and it doesn't seem like any lines added call out this as a requirement any more than the lines before this PR. Same question throughout.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It got moved from the header file.

}
std::this_thread::sleep_for(period_);
}
//LOG(INFO) << "Metadata reporter exiting";
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd vote for uncommenting this, so I can create a log metric, but please remove if you disagree.

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'd like to keep this PR focused on the refactoring. Happy to do it in a follow-up PR — there are a few other places where extra logging would 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.

FWIW, I think this specific bit follows an infinite loop, so will never be printed. It's commented out pending the TODO above the loop.

});
// TODO: This is probably all kinds of inefficient...
const int size = metadata_entry->ToString().size();
if (empty_size + size > limit_bytes) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious, do we expect this to happen often? Do you know what likely scenarios would exist where this would be exceeded frequently? I'll setup log metrics for this line, and try to reproduce the event, so that we can get a handle on frequency once I hear from you.

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 is just defensive programming to catch individual metadata entries that would take the whole request over the size limit. We haven't seen any so far, but given that we include the raw output of an unrelated API, this isn't too outrageous of a scenario in my mind.

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 for the review. PTAL.

#ifndef AGENT_H_
#define AGENT_H_

//#include "config.h"
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 specific one was a "reminder" to set up autotools to make this more portable. It appears all over the place. Probably no sense in keeping it, but I'd rather do it as a separate cleanup to keep this PR focused.

<< " headers: " << request.headers
<< " body: " << request.body;
}
if (request.method == "GET" && request.destination.find(kPrefix) == 0) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea, bad timing. This is supposed to be a refactoring with a specific purpose — I'll do this in a follow-up PR if you don't mind.

std::lock_guard<std::mutex> lock(agent_.resource_mu_);
const auto result = agent_.resource_map_.find(id);
if (result == agent_.resource_map_.end()) {
std::lock_guard<std::mutex> lock(store_.resource_mu_);
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 don't love this either, and was thinking along the same lines, except in a different PR. Let's keep this one focused on the refactoring.

#include <boost/network/protocol/http/client.hpp>
#include <chrono>

#include "configuration.h"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It got moved from the header file.

}
std::this_thread::sleep_for(period_);
}
//LOG(INFO) << "Metadata reporter exiting";
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'd like to keep this PR focused on the refactoring. Happy to do it in a follow-up PR — there are a few other places where extra logging would help.

});
// TODO: This is probably all kinds of inefficient...
const int size = metadata_entry->ToString().size();
if (empty_size + size > limit_bytes) {
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 is just defensive programming to catch individual metadata entries that would take the whole request over the size limit. We haven't seen any so far, but given that we include the raw output of an unrelated API, this isn't too outrageous of a scenario in my mind.

@rbuskens
Copy link

LGTM.

auth_(environment_),
period_(period_s),
reporter_thread_(&MetadataReporter::ReportMetadata, this) {}
reporter_thread_([=]() { ReportMetadata(); }) {}
Copy link
Contributor

@ACEmilG ACEmilG Mar 22, 2018

Choose a reason for hiding this comment

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

Nit: Can't this be [this] rather than [=]? That would seem to be tighter/more explicit to me. I know that this change basically belongs to another commit and thus my questioning it here is maybe not very useful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It can, and probably should in the future. However, #74 used [=] consistently throughout, so I'm just following that style. If we decide to tighten these captures, we could do it in a separate cleanup (and at this point I'm not sure it's worth it).


#include "configuration.h"
#include "reporter.h"
#include "store.h"
Copy link
Contributor

@ACEmilG ACEmilG Mar 23, 2018

Choose a reason for hiding this comment

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

I believe that this could also be replaced with a forward declaration of MetadataStore here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not really -- we need the full definition of MetadataStore to declare a field of this type, otherwise we'll get a "field has incomplete type" compiler error.
We could, however, forward-declare MetadataAgentConfiguration, which I did.

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

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.

Responded to comments, PTAL.


#include "configuration.h"
#include "reporter.h"
#include "store.h"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not really -- we need the full definition of MetadataStore to declare a field of this type, otherwise we'll get a "field has incomplete type" compiler error.
We could, however, forward-declare MetadataAgentConfiguration, which I did.

auth_(environment_),
period_(period_s),
reporter_thread_(&MetadataReporter::ReportMetadata, this) {}
reporter_thread_([=]() { ReportMetadata(); }) {}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It can, and probably should in the future. However, #74 used [=] consistently throughout, so I'm just following that style. If we decide to tighten these captures, we could do it in a separate cleanup (and at this point I'm not sure it's worth it).

@ACEmilG
Copy link
Contributor

ACEmilG commented Mar 23, 2018

LGTM

@igorpeshansky igorpeshansky merged commit 114e2b4 into master Mar 23, 2018
@igorpeshansky igorpeshansky deleted the igorp-api_server-refactor branch March 23, 2018 19:45
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.

5 participants