Skip to content
This repository was archived by the owner on Aug 19, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/docker.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class DockerUpdater : public PollingMetadataUpdater {
: reader_(server->config()), PollingMetadataUpdater(
server, "DockerUpdater",
server->config().DockerUpdaterIntervalSeconds(),
std::bind(&google::DockerReader::MetadataQuery, &reader_)) { }
[=]() { return reader_.MetadataQuery(); }) { }

protected:
bool ValidateConfiguration() const;
Expand Down
2 changes: 1 addition & 1 deletion src/instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class InstanceUpdater : public PollingMetadataUpdater {
: reader_(server->config()), PollingMetadataUpdater(
server, "InstanceUpdater",
server->config().InstanceUpdaterIntervalSeconds(),
std::bind(&google::InstanceReader::MetadataQuery, &reader_)) { }
[=]() { return reader_.MetadataQuery(); }) { }
private:
InstanceReader reader_;
};
Expand Down
39 changes: 20 additions & 19 deletions src/kubernetes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -830,13 +830,16 @@ void KubernetesReader::WatchMaster(
// A notification for watch completion.
std::mutex completion_mutex;
std::unique_lock<std::mutex> watch_completion(completion_mutex);
// Pull this out, as nested std::bind expressions are nasty.
std::function<void(json::value)> event_callback =
std::bind(&WatchEventCallback, callback, std::placeholders::_1);
Watcher watcher(
endpoint,
std::bind(&BodyCallback, name, event_callback, std::placeholders::_1),
std::move(watch_completion), config_.VerboseLogging());
endpoint,
[=](const std::string& body) {
BodyCallback(name,
[=](json::value raw_watch) {
WatchEventCallback(callback, std::move(raw_watch));
},
body);
},
std::move(watch_completion), config_.VerboseLogging());
http::client::response response = client.get(request, std::ref(watcher));
if (config_.VerboseLogging()) {
LOG(INFO) << "Waiting for completion";
Expand Down Expand Up @@ -1095,9 +1098,9 @@ void KubernetesReader::WatchPods(MetadataUpdater::UpdateCallback callback)
"Pods",
std::string(kKubernetesEndpointPath) + "/pods" + node_selector
+ pod_label_selector,
std::bind(&KubernetesReader::PodCallback,
this, callback, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3));
[=](const json::Object* pod, Timestamp collected_at, bool is_deleted) {
PodCallback(callback, pod, collected_at, is_deleted);
});
} catch (const json::Exception& e) {
LOG(ERROR) << e.what();
LOG(ERROR) << "No more pod metadata will be collected";
Expand Down Expand Up @@ -1132,9 +1135,9 @@ void KubernetesReader::WatchNode(MetadataUpdater::UpdateCallback callback)
WatchMaster(
"Node",
std::string(kKubernetesEndpointPath) + "/watch/nodes/" + node_name,
std::bind(&KubernetesReader::NodeCallback,
this, callback, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3));
[=](const json::Object* node, Timestamp collected_at, bool is_deleted) {
NodeCallback(callback, node, collected_at, is_deleted);
});
} catch (const json::Exception& e) {
LOG(ERROR) << e.what();
LOG(ERROR) << "No more node metadata will be collected";
Expand All @@ -1154,13 +1157,11 @@ bool KubernetesUpdater::ValidateConfiguration() const {

void KubernetesUpdater::StartUpdater() {
if (config().KubernetesUseWatch()) {
// Wrap the bind expression into a function to use as a bind argument.
UpdateCallback cb = std::bind(&KubernetesUpdater::MetadataCallback, this,
std::placeholders::_1);
node_watch_thread_ =
std::thread(&KubernetesReader::WatchNode, &reader_, cb);
pod_watch_thread_ =
std::thread(&KubernetesReader::WatchPods, &reader_, cb);
auto cb = [=](std::vector<MetadataUpdater::ResourceMetadata>&& results) {
MetadataCallback(std::move(results));
};
node_watch_thread_ = std::thread([=]() { reader_.WatchNode(cb); });
pod_watch_thread_ = std::thread([=]() { reader_.WatchPods(cb); });
} else {
// Only try to poll if watch is disabled.
PollingMetadataUpdater::StartUpdater();
Expand Down
3 changes: 2 additions & 1 deletion src/kubernetes.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ class KubernetesUpdater : public PollingMetadataUpdater {
: reader_(server->config()), PollingMetadataUpdater(
server, "KubernetesUpdater",
server->config().KubernetesUpdaterIntervalSeconds(),
std::bind(&google::KubernetesReader::MetadataQuery, &reader_)) { }
[=]() { return reader_.MetadataQuery(); }) { }

~KubernetesUpdater() {
if (node_watch_thread_.joinable()) {
node_watch_thread_.join();
Expand Down
2 changes: 0 additions & 2 deletions src/metadatad.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

//#include "config.h"

#include <functional>

#include "api_server.h"
#include "configuration.h"
#include "docker.h"
Expand Down
3 changes: 1 addition & 2 deletions src/updater.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ void PollingMetadataUpdater::StartUpdater() {
LOG(INFO) << "Timer locked";
}
if (period_ > time::seconds::zero()) {
reporter_thread_ =
std::thread(&PollingMetadataUpdater::PollForMetadata, this);
reporter_thread_ = std::thread([=]() { PollForMetadata(); });
}
}

Expand Down