mirror of
https://github.com/joyieldInc/predixy.git
synced 2025-12-24 22:46:41 +08:00
1.support section for INFO command
2.fix authority bug 3.fix test base
This commit is contained in:
parent
6da3706900
commit
dc1de3935c
11
src/Auth.cpp
11
src/Auth.cpp
@ -10,8 +10,8 @@
|
|||||||
#include "Request.h"
|
#include "Request.h"
|
||||||
|
|
||||||
|
|
||||||
Auth::Auth():
|
Auth::Auth(int mode):
|
||||||
mMode(Command::Read|Command::Write|Command::Admin),
|
mMode(mode),
|
||||||
mReadKeyPrefix(nullptr),
|
mReadKeyPrefix(nullptr),
|
||||||
mWriteKeyPrefix(nullptr)
|
mWriteKeyPrefix(nullptr)
|
||||||
{
|
{
|
||||||
@ -75,10 +75,11 @@ bool Auth::permission(Request* req, const String& key) const
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Auth Authority::DefaultAuth;
|
Auth Authority::AuthAllowAll;
|
||||||
|
Auth Authority::AuthDenyAll(0);
|
||||||
|
|
||||||
Authority::Authority():
|
Authority::Authority():
|
||||||
mDefault(&DefaultAuth)
|
mDefault(&AuthAllowAll)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,5 +103,7 @@ void Authority::add(const AuthConf& ac)
|
|||||||
mAuthMap[a->password()] = a;
|
mAuthMap[a->password()] = a;
|
||||||
if (a->password().empty()) {
|
if (a->password().empty()) {
|
||||||
mDefault = a;
|
mDefault = a;
|
||||||
|
} else if (mDefault == &AuthAllowAll) {
|
||||||
|
mDefault = &AuthDenyAll;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,7 +15,7 @@
|
|||||||
class Auth
|
class Auth
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Auth();
|
Auth(int mode = Command::Read|Command::Write|Command::Admin);
|
||||||
Auth(const AuthConf& conf);
|
Auth(const AuthConf& conf);
|
||||||
~Auth();
|
~Auth();
|
||||||
const String& password() const
|
const String& password() const
|
||||||
@ -53,7 +53,8 @@ public:
|
|||||||
private:
|
private:
|
||||||
std::map<String, Auth*> mAuthMap;
|
std::map<String, Auth*> mAuthMap;
|
||||||
Auth* mDefault;
|
Auth* mDefault;
|
||||||
static Auth DefaultAuth;
|
static Auth AuthAllowAll;
|
||||||
|
static Auth AuthDenyAll;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -889,10 +889,17 @@ void Handler::infoRequest(Request* req, const String& key)
|
|||||||
infoServerLatencyRequest(req);
|
infoServerLatencyRequest(req);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
bool all = key.equal("All", true);
|
||||||
|
bool empty = key.empty();
|
||||||
ResponsePtr res = ResponseAlloc::create();
|
ResponsePtr res = ResponseAlloc::create();
|
||||||
res->setType(Reply::String);
|
res->setType(Reply::String);
|
||||||
Segment& body = res->body();
|
Segment& body = res->body();
|
||||||
BufferPtr buf = body.fset(nullptr, "# Proxy\n");
|
Buffer* buf = body.fset(nullptr, "");
|
||||||
|
|
||||||
|
#define Scope(all, empty, header) ((all || empty || key.equal(header, true)) ? \
|
||||||
|
(buf = buf->fappend("# %s\n", header)) : nullptr)
|
||||||
|
|
||||||
|
if (Scope(all, empty, "Proxy")) {
|
||||||
buf = buf->fappend("Version:%s\n", _PREDIXY_VERSION_);
|
buf = buf->fappend("Version:%s\n", _PREDIXY_VERSION_);
|
||||||
buf = buf->fappend("Name:%s\n", mProxy->conf()->name());
|
buf = buf->fappend("Name:%s\n", mProxy->conf()->name());
|
||||||
buf = buf->fappend("Bind:%s\n", mProxy->conf()->bind());
|
buf = buf->fappend("Bind:%s\n", mProxy->conf()->bind());
|
||||||
@ -903,12 +910,14 @@ void Handler::infoRequest(Request* req, const String& key)
|
|||||||
buf = buf->fappend("SingleThread:false\n");
|
buf = buf->fappend("SingleThread:false\n");
|
||||||
#endif
|
#endif
|
||||||
buf = buf->fappend("WorkerThreads:%d\n", mProxy->conf()->workerThreads());
|
buf = buf->fappend("WorkerThreads:%d\n", mProxy->conf()->workerThreads());
|
||||||
|
buf = buf->fappend("Uptime:%ld\n", (long)mProxy->startTime());
|
||||||
SString<32> timeStr;
|
SString<32> timeStr;
|
||||||
timeStr.strftime("%Y-%m-%d %H:%M:%S", mProxy->startTime());
|
timeStr.strftime("%Y-%m-%d %H:%M:%S", mProxy->startTime());
|
||||||
buf = buf->fappend("UptimeSince:%s\n", timeStr.data());
|
buf = buf->fappend("UptimeSince:%s\n", timeStr.data());
|
||||||
buf = buf->fappend("\n");
|
buf = buf->fappend("\n");
|
||||||
|
}
|
||||||
|
|
||||||
buf = buf->fappend("# SystemResource\n");
|
if (Scope(all, empty, "SystemResource")) {
|
||||||
buf = buf->fappend("UsedMemory:%ld\n", AllocBase::getUsedMemory());
|
buf = buf->fappend("UsedMemory:%ld\n", AllocBase::getUsedMemory());
|
||||||
buf = buf->fappend("MaxMemory:%ld\n", AllocBase::getMaxMemory());
|
buf = buf->fappend("MaxMemory:%ld\n", AllocBase::getMaxMemory());
|
||||||
struct rusage ru;
|
struct rusage ru;
|
||||||
@ -921,8 +930,9 @@ void Handler::infoRequest(Request* req, const String& key)
|
|||||||
logError("h %d getrusage fail %s", id(), StrError());
|
logError("h %d getrusage fail %s", id(), StrError());
|
||||||
}
|
}
|
||||||
buf = buf->fappend("\n");
|
buf = buf->fappend("\n");
|
||||||
|
}
|
||||||
|
|
||||||
buf = buf->fappend("# Stats\n");
|
if (Scope(all, empty, "Stats")) {
|
||||||
HandlerStats st(mStats);
|
HandlerStats st(mStats);
|
||||||
for (auto h : mProxy->handlers()) {
|
for (auto h : mProxy->handlers()) {
|
||||||
if (h == this) {
|
if (h == this) {
|
||||||
@ -939,8 +949,9 @@ void Handler::infoRequest(Request* req, const String& key)
|
|||||||
buf = buf->fappend("TotalRecvServerBytes:%ld\n", st.recvServerBytes);
|
buf = buf->fappend("TotalRecvServerBytes:%ld\n", st.recvServerBytes);
|
||||||
buf = buf->fappend("TotalSendClientBytes:%ld\n", st.sendClientBytes);
|
buf = buf->fappend("TotalSendClientBytes:%ld\n", st.sendClientBytes);
|
||||||
buf = buf->fappend("\n");
|
buf = buf->fappend("\n");
|
||||||
|
}
|
||||||
|
|
||||||
buf = buf->fappend("# Servers\n");
|
if (Scope(all, empty, "Servers")) {
|
||||||
int servCursor = 0;
|
int servCursor = 0;
|
||||||
auto sp = mProxy->serverPool();
|
auto sp = mProxy->serverPool();
|
||||||
while (Server* serv = sp->iter(servCursor)) {
|
while (Server* serv = sp->iter(servCursor)) {
|
||||||
@ -965,8 +976,9 @@ void Handler::infoRequest(Request* req, const String& key)
|
|||||||
buf = buf->fappend("\n");
|
buf = buf->fappend("\n");
|
||||||
}
|
}
|
||||||
buf = buf->fappend("\n");
|
buf = buf->fappend("\n");
|
||||||
|
}
|
||||||
|
|
||||||
buf = buf->fappend("# LatencyMonitor\n");
|
if (Scope(all, empty, "LatencyMonitor")) {
|
||||||
LatencyMonitor lm;
|
LatencyMonitor lm;
|
||||||
for (size_t i = 0; i < mLatencyMonitors.size(); ++i) {
|
for (size_t i = 0; i < mLatencyMonitors.size(); ++i) {
|
||||||
lm = mLatencyMonitors[i];
|
lm = mLatencyMonitors[i];
|
||||||
@ -980,6 +992,7 @@ void Handler::infoRequest(Request* req, const String& key)
|
|||||||
buf = lm.output(buf);
|
buf = lm.output(buf);
|
||||||
buf = buf->fappend("\n");
|
buf = buf->fappend("\n");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
buf = buf->fappend("\r\n");
|
buf = buf->fappend("\r\n");
|
||||||
body.end().buf = buf;
|
body.end().buf = buf;
|
||||||
|
|||||||
@ -133,6 +133,7 @@ Cases = [
|
|||||||
[('del', 'list', 'u1', 'u2', 'u3', 'u4', 'u5', 'u6'), 7],
|
[('del', 'list', 'u1', 'u2', 'u3', 'u4', 'u5', 'u6'), 7],
|
||||||
]),
|
]),
|
||||||
('touch', [
|
('touch', [
|
||||||
|
[('del', 'k1', 'k2', 'k3', 'k4'), ],
|
||||||
[('mset', 'k1', 'v1', 'k2', 'v2', 'k3', 'v3'), 'OK'],
|
[('mset', 'k1', 'v1', 'k2', 'v2', 'k3', 'v3'), 'OK'],
|
||||||
[('touch', 'k1'), 1],
|
[('touch', 'k1'), 1],
|
||||||
[('touch', 'k1', 'k2', 'k3', 'k4'), 3],
|
[('touch', 'k1', 'k2', 'k3', 'k4'), 3],
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user