Skip to content

Commit 64f122b

Browse files
authored
feat(interactive): Add readiness probe for graph_db_service (#4586)
For the queries service, add an HTTP API to detect whether it is OK.
1 parent c332f70 commit 64f122b

File tree

5 files changed

+58
-11
lines changed

5 files changed

+58
-11
lines changed

flex/engines/http_server/handler/graph_db_http_handler.cc

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,35 @@ class adhoc_query_handler : public StoppableHandler {
881881
#endif
882882
};
883883

884+
class service_status_handler : public seastar::httpd::handler_base {
885+
public:
886+
service_status_handler() {}
887+
~service_status_handler() override = default;
888+
889+
seastar::future<std::unique_ptr<seastar::httpd::reply>> handle(
890+
const seastar::sstring& path,
891+
std::unique_ptr<seastar::httpd::request> req,
892+
std::unique_ptr<seastar::httpd::reply> rep) override {
893+
if (req->_method == "GET") {
894+
if (path.find("ready") != seastar::sstring::npos) {
895+
auto& graph_db_service = GraphDBService::get();
896+
rep->set_content_type("application/json");
897+
if (graph_db_service.is_actors_running()) {
898+
return new_reply(std::move(rep),
899+
seastar::httpd::reply::status_type::ok,
900+
"Service Is Ready");
901+
} else {
902+
return new_reply(
903+
std::move(rep),
904+
seastar::httpd::reply::status_type::service_unavailable,
905+
"Service Is Not Ready");
906+
}
907+
}
908+
}
909+
return new_bad_request_reply(std::move(rep), "Unsupported action");
910+
}
911+
};
912+
884913
///////////////////////////graph_db_http_handler/////////////////////////////
885914

886915
graph_db_http_handler::graph_db_http_handler(uint16_t http_port,
@@ -1081,6 +1110,10 @@ seastar::future<> graph_db_http_handler::set_routes() {
10811110
r.add(match_rule, OPERATIONS[i]);
10821111
}
10831112

1113+
r.add(seastar::httpd::operation_type::GET,
1114+
seastar::httpd::url("/v1/service/ready"),
1115+
new service_status_handler());
1116+
10841117
return seastar::make_ready_future<>();
10851118
});
10861119
}

flex/engines/http_server/handler/http_utils.cc

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,23 @@
1717

1818
namespace server {
1919

20-
seastar::future<std::unique_ptr<seastar::httpd::reply>> new_bad_request_reply(
21-
std::unique_ptr<seastar::httpd::reply> rep, const std::string& msg) {
22-
rep->set_status(seastar::httpd::reply::status_type::bad_request);
20+
seastar::future<std::unique_ptr<seastar::httpd::reply>> new_reply(
21+
std::unique_ptr<seastar::httpd::reply> rep,
22+
seastar::httpd::reply::status_type status, const std::string& msg) {
23+
rep->set_status(status);
2324
rep->set_content_type("application/json");
24-
gs::Status status = gs::Status(gs::StatusCode::BAD_REQUEST, msg);
2525
rep->write_body("json", seastar::sstring(msg));
2626
rep->done();
2727
return seastar::make_ready_future<std::unique_ptr<seastar::httpd::reply>>(
2828
std::move(rep));
2929
}
3030

31+
seastar::future<std::unique_ptr<seastar::httpd::reply>> new_bad_request_reply(
32+
std::unique_ptr<seastar::httpd::reply> rep, const std::string& msg) {
33+
return new_reply(std::move(rep),
34+
seastar::httpd::reply::status_type::bad_request, msg);
35+
}
36+
3137
seastar::future<std::unique_ptr<seastar::httpd::reply>>
3238
new_internal_error_reply(std::unique_ptr<seastar::httpd::reply> rep,
3339
const std::string& msg) {

flex/engines/http_server/handler/http_utils.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* See the License for the specific language governing permissions and
1313
* limitations under the License.
1414
*/
15+
#include <seastar/http/httpd.hh>
1516
#include "flex/engines/http_server/types.h"
1617
#include "flex/utils/result.h"
1718
#include "seastar/http/common.hh"
@@ -22,6 +23,10 @@
2223

2324
namespace server {
2425

26+
seastar::future<std::unique_ptr<seastar::httpd::reply>> new_reply(
27+
std::unique_ptr<seastar::httpd::reply> rep,
28+
seastar::httpd::reply::status_type status, const std::string& msg);
29+
2530
seastar::future<std::unique_ptr<seastar::httpd::reply>> new_bad_request_reply(
2631
std::unique_ptr<seastar::httpd::reply> rep, const std::string& msg);
2732

flex/utils/remote/oss_storage.cc

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ void OSSConf::load_conf_from_env() {
5050
bucket_name_ = bucket_name;
5151
}
5252
}
53+
if (std::getenv(kOSSConcurrency)) {
54+
concurrency_ = std::stoi(std::getenv(kOSSConcurrency));
55+
}
56+
LOG(INFO) << "OSS concurrency: " << concurrency_;
5357
}
5458

5559
class UserRetryStrategy : public AlibabaCloud::OSS::RetryStrategy {
@@ -155,9 +159,8 @@ gs::Status OSSRemoteStorageUploader::Put(const std::string& local_path,
155159
remote_path, local_path);
156160
request.MetaData().addHeader("x-oss-forbid-overwrite", "true");
157161
request.setPartSize(conf_.partition_size_);
158-
request.setThreadNum(
159-
conf_.uploading_concurrency_); // Increase the thread number to improve
160-
// the upload speed
162+
request.setThreadNum(conf_.concurrency_); // Increase the thread number to
163+
// improve the upload speed
161164
auto outcome = client_->ResumableUploadObject(request);
162165
if (!outcome.isSuccess()) {
163166
std::string error_string = "OSS ResumableUploadObject from local " +
@@ -231,9 +234,8 @@ gs::Status OSSRemoteStorageDownloader::Get(const std::string& remote_path,
231234
AlibabaCloud::OSS::DownloadObjectRequest request(conf_.bucket_name_,
232235
remote_path, local_path);
233236
request.setPartSize(conf_.partition_size_);
234-
request.setThreadNum(
235-
conf_.uploading_concurrency_); // Increase the thread number to improve
236-
// the download speed
237+
request.setThreadNum(conf_.concurrency_); // Increase the thread number to
238+
// improve the download speed
237239
auto outcome = client_->ResumableDownloadObject(request);
238240
if (!outcome.isSuccess()) {
239241
std::string error_string = oss_outcome_to_string(

flex/utils/remote/oss_storage.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,13 @@ struct OSSConf {
3232
static constexpr const char* kOSSAccessKeySecret = "OSS_ACCESS_KEY_SECRET";
3333
static constexpr const char* kOSSEndpoint = "OSS_ENDPOINT";
3434
static constexpr const char* kOSSBucketName = "OSS_BUCKET_NAME";
35+
static constexpr const char* kOSSConcurrency = "OSS_CONCURRENCY";
3536
// Avoid storing or printing the accesskey_id and accesskey_secret
3637
std::string accesskey_id_;
3738
std::string accesskey_secret_;
3839
std::string endpoint_;
3940
std::string bucket_name_;
40-
int32_t uploading_concurrency_ = 4;
41+
int32_t concurrency_ = 4;
4142
uint64_t partition_size_ = 1024 * 1024 * 128;
4243
AlibabaCloud::OSS::ClientConfiguration client_conf_;
4344

0 commit comments

Comments
 (0)