1.support section for INFO command

2.fix authority bug
3.fix test base
This commit is contained in:
fortrue 2017-11-23 15:08:05 +08:00
parent 6da3706900
commit dc1de3935c
4 changed files with 99 additions and 81 deletions

View File

@ -10,8 +10,8 @@
#include "Request.h"
Auth::Auth():
mMode(Command::Read|Command::Write|Command::Admin),
Auth::Auth(int mode):
mMode(mode),
mReadKeyPrefix(nullptr),
mWriteKeyPrefix(nullptr)
{
@ -75,10 +75,11 @@ bool Auth::permission(Request* req, const String& key) const
return true;
}
Auth Authority::DefaultAuth;
Auth Authority::AuthAllowAll;
Auth Authority::AuthDenyAll(0);
Authority::Authority():
mDefault(&DefaultAuth)
mDefault(&AuthAllowAll)
{
}
@ -102,5 +103,7 @@ void Authority::add(const AuthConf& ac)
mAuthMap[a->password()] = a;
if (a->password().empty()) {
mDefault = a;
} else if (mDefault == &AuthAllowAll) {
mDefault = &AuthDenyAll;
}
}

View File

@ -15,7 +15,7 @@
class Auth
{
public:
Auth();
Auth(int mode = Command::Read|Command::Write|Command::Admin);
Auth(const AuthConf& conf);
~Auth();
const String& password() const
@ -53,7 +53,8 @@ public:
private:
std::map<String, Auth*> mAuthMap;
Auth* mDefault;
static Auth DefaultAuth;
static Auth AuthAllowAll;
static Auth AuthDenyAll;
};
#endif

View File

@ -889,10 +889,17 @@ void Handler::infoRequest(Request* req, const String& key)
infoServerLatencyRequest(req);
return;
}
bool all = key.equal("All", true);
bool empty = key.empty();
ResponsePtr res = ResponseAlloc::create();
res->setType(Reply::String);
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("Name:%s\n", mProxy->conf()->name());
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");
#endif
buf = buf->fappend("WorkerThreads:%d\n", mProxy->conf()->workerThreads());
buf = buf->fappend("Uptime:%ld\n", (long)mProxy->startTime());
SString<32> timeStr;
timeStr.strftime("%Y-%m-%d %H:%M:%S", mProxy->startTime());
buf = buf->fappend("UptimeSince:%s\n", timeStr.data());
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("MaxMemory:%ld\n", AllocBase::getMaxMemory());
struct rusage ru;
@ -921,8 +930,9 @@ void Handler::infoRequest(Request* req, const String& key)
logError("h %d getrusage fail %s", id(), StrError());
}
buf = buf->fappend("\n");
}
buf = buf->fappend("# Stats\n");
if (Scope(all, empty, "Stats")) {
HandlerStats st(mStats);
for (auto h : mProxy->handlers()) {
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("TotalSendClientBytes:%ld\n", st.sendClientBytes);
buf = buf->fappend("\n");
}
buf = buf->fappend("# Servers\n");
if (Scope(all, empty, "Servers")) {
int servCursor = 0;
auto sp = mProxy->serverPool();
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("# LatencyMonitor\n");
if (Scope(all, empty, "LatencyMonitor")) {
LatencyMonitor lm;
for (size_t i = 0; i < mLatencyMonitors.size(); ++i) {
lm = mLatencyMonitors[i];
@ -980,6 +992,7 @@ void Handler::infoRequest(Request* req, const String& key)
buf = lm.output(buf);
buf = buf->fappend("\n");
}
}
buf = buf->fappend("\r\n");
body.end().buf = buf;

View File

@ -133,6 +133,7 @@ Cases = [
[('del', 'list', 'u1', 'u2', 'u3', 'u4', 'u5', 'u6'), 7],
]),
('touch', [
[('del', 'k1', 'k2', 'k3', 'k4'), ],
[('mset', 'k1', 'v1', 'k2', 'v2', 'k3', 'v3'), 'OK'],
[('touch', 'k1'), 1],
[('touch', 'k1', 'k2', 'k3', 'k4'), 3],