New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mon/LogMonitor: separate out summary by channel #21395
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -428,29 +428,57 @@ bool LogMonitor::preprocess_command(MonOpRequestRef op) | |
|
||
// We'll apply this twice, once while counting out lines | ||
// and once while outputting them. | ||
auto match = [level, channel](const LogEntry &entry) { | ||
return entry.prio >= level && (entry.channel == channel || channel == "*"); | ||
auto match = [level](const LogEntry &entry) { | ||
return entry.prio >= level; | ||
}; | ||
|
||
auto rp = summary.tail.rbegin(); | ||
for (; num > 0 && rp != summary.tail.rend(); ++rp) { | ||
if (match(*rp)) { | ||
num--; | ||
} | ||
} | ||
if (rp == summary.tail.rend()) { | ||
--rp; | ||
} | ||
ostringstream ss; | ||
for (; rp != summary.tail.rbegin(); --rp) { | ||
if (!match(*rp)) { | ||
continue; | ||
if (channel == "*") { | ||
list<LogEntry> full_tail; | ||
summary.build_ordered_tail(&full_tail); | ||
derr << "full " << full_tail << dendl; | ||
auto rp = full_tail.rbegin(); | ||
for (; num > 0 && rp != full_tail.rend(); ++rp) { | ||
if (match(*rp)) { | ||
num--; | ||
} | ||
} | ||
|
||
if (f) { | ||
f->dump_object("entry", *rp); | ||
} else { | ||
ss << *rp << "\n"; | ||
if (rp == full_tail.rend()) { | ||
--rp; | ||
} | ||
for (; rp != full_tail.rbegin(); --rp) { | ||
if (!match(*rp)) { | ||
continue; | ||
} | ||
if (f) { | ||
f->dump_object("entry", *rp); | ||
} else { | ||
ss << *rp << "\n"; | ||
} | ||
} | ||
} else { | ||
derr << "bar" << dendl; | ||
auto p = summary.tail_by_channel.find(channel); | ||
if (p != summary.tail_by_channel.end()) { | ||
auto rp = p->second.rbegin(); | ||
for (; num > 0 && rp != p->second.rend(); ++rp) { | ||
if (match(rp->second)) { | ||
num--; | ||
} | ||
} | ||
if (rp == p->second.rend()) { | ||
--rp; | ||
} | ||
for (; rp != p->second.rbegin(); --rp) { | ||
if (!match(rp->second)) { | ||
continue; | ||
} | ||
if (f) { | ||
f->dump_object("entry", rp->second); | ||
} else { | ||
ss << rp->second << "\n"; | ||
} | ||
} | ||
} | ||
} | ||
if (f) { | ||
|
@@ -563,12 +591,7 @@ void LogMonitor::check_sub(Subscription *s) | |
|
||
if (s->next == 0) { | ||
/* First timer, heh? */ | ||
bool ret = _create_sub_summary(mlog, sub_level); | ||
if (!ret) { | ||
dout(1) << __func__ << " ret = " << ret << dendl; | ||
mlog->put(); | ||
return; | ||
} | ||
_create_sub_incremental(mlog, sub_level, get_last_committed()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this going to work if the latest message at There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Never mind, the old _create_sub_summary was only looking at the current summary anyway |
||
} else { | ||
/* let us send you an incremental log... */ | ||
_create_sub_incremental(mlog, sub_level, s->next); | ||
|
@@ -589,37 +612,6 @@ void LogMonitor::check_sub(Subscription *s) | |
s->next = summary_version+1; | ||
} | ||
|
||
/** | ||
* Create a log message containing only the last message in the summary. | ||
* | ||
* @param mlog Log message we'll send to the client. | ||
* @param level Maximum log level the client is interested in. | ||
* @return 'true' if we consider we successfully populated @mlog; | ||
* 'false' otherwise. | ||
*/ | ||
bool LogMonitor::_create_sub_summary(MLog *mlog, int level) | ||
{ | ||
dout(10) << __func__ << dendl; | ||
|
||
assert(mlog != NULL); | ||
|
||
if (!summary.tail.size()) | ||
return false; | ||
|
||
list<LogEntry>::reverse_iterator it = summary.tail.rbegin(); | ||
for (; it != summary.tail.rend(); ++it) { | ||
LogEntry e = *it; | ||
if (e.prio < level) | ||
continue; | ||
|
||
mlog->entries.push_back(e); | ||
mlog->version = summary.version; | ||
break; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* Create an incremental log message from version \p sv to \p summary.version | ||
* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we avoid writing out this loop twice? Maybe pull it up into a lambda at the start of the function and then apply it to
full_tail
ortail_by_channel.find(channel)
conditionallyThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's awkward because one is a list of entries and the other is a list of pairs.. not sure how to generalize that?