This repository was archived by the owner on Dec 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathConnection.h
61 lines (52 loc) · 1.53 KB
/
Connection.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
* Copyright (c) 2014, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
#pragma once
#include <folly/Memory.h>
#include "common/thrift/thrift/gen-cpp2/MonitorAsyncClient.h"
DECLARE_string(counter_name);
DECLARE_int32(counter_threshold);
namespace facebook {
namespace windtunnel {
namespace treadmill {
/**
* Specializations of this template should implement:
*
* bool isReady();
*
* folly::Future<Service::Reply>
* sendRequest(std::unique_ptr<typename Service::Request>&& request);
*
* */
template <class Service>
class Connection {
public:
/**
* Sample implementation below shows how to wait for a specific counter
* value to cross a threshold
* e.g. usage: --wait_for_target_ready --counter_threshold 10
* --counter_name thrift.accepted_connections.count
* */
bool isReady() const {
if (!FLAGS_counter_name.empty()) {
int64_t value = client_->sync_getCounter(FLAGS_counter_name);
if (value < FLAGS_counter_threshold) {
LOG(INFO) << "Threshold: " << FLAGS_counter_threshold
<< " Counter: " << FLAGS_counter_name << " Value: " << value;
return false;
}
}
return true;
}
private:
std::unique_ptr<facebook::thrift::MonitorAsyncClient> client_;
};
} // namespace treadmill
} // namespace windtunnel
} // namespace facebook