Added glue code to expose various http handlers from dragonfly

This commit is contained in:
Roman Gershman 2022-05-30 11:53:39 +03:00
parent 5af2fe0145
commit e239fc68b4
7 changed files with 25 additions and 4 deletions

View File

@ -37,8 +37,8 @@ jobs:
${{github.workspace}}/build-opt/
!${{github.workspace}}/build-opt/CMakeCache.txt
key: ${{ runner.os }}-release-deps-${{ github.sha }}
restore-keys: |
${{ runner.os }}-release-deps-
#restore-keys: |
# ${{ runner.os }}-release-deps-
- uses: uraimo/run-on-arch-action@v2
name: Run commands

View File

@ -9,6 +9,7 @@
#include "base/flags.h"
#include "base/logging.h"
#include "facade/dragonfly_connection.h"
#include "facade/service_interface.h"
#include "util/proactor_pool.h"
using namespace std;
@ -119,7 +120,7 @@ bool ConfigureKeepAlive(int fd, unsigned interval_sec) {
} // namespace
Listener::Listener(Protocol protocol, ServiceInterface* e) : service_(e), protocol_(protocol) {
Listener::Listener(Protocol protocol, ServiceInterface* si) : service_(si), protocol_(protocol) {
if (GetFlag(FLAGS_tls)) {
OPENSSL_init_ssl(OPENSSL_INIT_SSL_DEFAULT, NULL);
ctx_ = CreateSslCntx();
@ -127,6 +128,7 @@ Listener::Listener(Protocol protocol, ServiceInterface* e) : service_(e), protoc
http_base_.reset(new HttpListener<>);
http_base_->set_resource_prefix("https://romange.s3.eu-west-1.amazonaws.com/static");
http_base_->enable_metrics();
si->ConfigureHttpHandlers(http_base_.get());
}
Listener::~Listener() {

View File

@ -6,9 +6,12 @@
#include "facade/facade_types.h"
#include "facade/memcache_parser.h"
#include "util/fiber_socket_base.h"
namespace util {
class HttpListenerBase;
} // namespace util
namespace facade {
class ConnectionContext;
@ -26,6 +29,9 @@ class ServiceInterface {
virtual ConnectionContext* CreateContext(util::FiberSocketBase* peer, Connection* owner) = 0;
virtual ConnectionStats* GetThreadLocalConnectionStats() = 0;
virtual void ConfigureHttpHandlers(util::HttpListenerBase* base) {
}
};
} // namespace facade

View File

@ -1000,6 +1000,10 @@ GlobalState Service::SwitchState(GlobalState from, GlobalState to) {
return to;
}
void Service::ConfigureHttpHandlers(util::HttpListenerBase* base) {
server_family_.ConfigureMetrics(base);
}
using ServiceFunc = void (Service::*)(CmdArgList, ConnectionContext* cntx);
#define HFUNC(x) SetHandler(&Service::x)

View File

@ -81,6 +81,8 @@ class Service : public facade::ServiceInterface {
// Upon switch, updates cached global state in threadlocal ServerState struct.
GlobalState SwitchState(GlobalState from , GlobalState to);
void ConfigureHttpHandlers(util::HttpListenerBase* base) final;
private:
static void Quit(CmdArgList args, ConnectionContext* cntx);
static void Multi(CmdArgList args, ConnectionContext* cntx);

View File

@ -266,6 +266,10 @@ error_code ServerFamily::LoadRdb(const std::string& rdb_file) {
return ec;
}
void ServerFamily::ConfigureMetrics(util::HttpListenerBase* http_base) {
}
void ServerFamily::StatsMC(std::string_view section, facade::ConnectionContext* cntx) {
if (!section.empty()) {
return cntx->reply_builder()->SendError("");

View File

@ -12,6 +12,7 @@
namespace util {
class AcceptServer;
class ListenerInterface;
class HttpListenerBase;
} // namespace util
namespace dfly {
@ -77,6 +78,8 @@ class ServerFamily {
return is_saving_.load(std::memory_order_relaxed);
}
void ConfigureMetrics(util::HttpListenerBase* listener);
private:
uint32_t shard_count() const {
return shard_set->size();