Skip to content
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

admin: Add /reopen_logs admin handler #10286

Merged
merged 15 commits into from
Mar 18, 2020
4 changes: 2 additions & 2 deletions source/extensions/filters/network/common/redis/codec_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@ RespValue::CompositeArray::CompositeArrayConstIterator::operator++() {
return *this;
}

bool RespValue::CompositeArray::CompositeArrayConstIterator::operator!=(
const CompositeArrayConstIterator& rhs) const {
bool RespValue::CompositeArray::CompositeArrayConstIterator::
operator!=(const CompositeArrayConstIterator& rhs) const {
veshij marked this conversation as resolved.
Show resolved Hide resolved
return command_ != (rhs.command_) || &array_ != &(rhs.array_) || index_ != rhs.index_ ||
first_ != rhs.first_;
}
Expand Down
9 changes: 9 additions & 0 deletions source/server/http/admin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1344,6 +1344,13 @@ Http::Code AdminImpl::handlerRuntimeModify(absl::string_view url, Http::Response
return Http::Code::OK;
}

Http::Code AdminImpl::handlerReopenLogs(absl::string_view, Http::ResponseHeaderMap&,
Buffer::Instance& response, AdminStream&) {
server_.accessLogManager().reopen();
response.add("OK\n");
return Http::Code::OK;
}

ConfigTracker& AdminImpl::getConfigTracker() { return config_tracker_; }

void AdminFilter::onComplete() {
Expand Down Expand Up @@ -1449,6 +1456,8 @@ AdminImpl::AdminImpl(const std::string& profile_path, Server::Instance& server)
{"/runtime", "print runtime values", MAKE_ADMIN_HANDLER(handlerRuntime), false, false},
{"/runtime_modify", "modify runtime values", MAKE_ADMIN_HANDLER(handlerRuntimeModify),
false, true},
{"/reopen_logs", "reopen access logs", MAKE_ADMIN_HANDLER(handlerReopenLogs), false,
false},
veshij marked this conversation as resolved.
Show resolved Hide resolved
},
date_provider_(server.dispatcher().timeSource()),
admin_filter_chain_(std::make_shared<AdminFilterChain>()) {}
Expand Down
3 changes: 3 additions & 0 deletions source/server/http/admin.h
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,9 @@ class AdminImpl : public Admin,
Http::Code handlerRuntimeModify(absl::string_view path_and_query,
Http::ResponseHeaderMap& response_headers,
Buffer::Instance& response, AdminStream&);
Http::Code handlerReopenLogs(absl::string_view path_and_query,
Http::ResponseHeaderMap& response_headers,
Buffer::Instance& response, AdminStream&);
bool isFormUrlEncoded(const Http::HeaderEntry* content_type) const;

class AdminListenSocketFactory : public Network::ListenSocketFactory {
Expand Down
10 changes: 10 additions & 0 deletions test/server/http/admin_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1249,6 +1249,16 @@ TEST_P(AdminInstanceTest, RuntimeModifyNoArguments) {
EXPECT_TRUE(absl::StartsWith(response.toString(), "usage:"));
}

TEST_P(AdminInstanceTest, ReopenLogs) {
Http::ResponseHeaderMapImpl header_map;
Buffer::OwnedImpl response;
testing::NiceMock<AccessLog::MockAccessLogManager> access_log_manager_;

EXPECT_CALL(server_, accessLogManager()).WillRepeatedly(ReturnRef(access_log_manager_));
EXPECT_CALL(access_log_manager_, reopen());
EXPECT_EQ(Http::Code::OK, getCallback("/reopen_logs", header_map, response));
veshij marked this conversation as resolved.
Show resolved Hide resolved
}

TEST_P(AdminInstanceTest, TracingStatsDisabled) {
const std::string& name = admin_.tracingStats().service_forced_.name();
for (const Stats::CounterSharedPtr& counter : server_.stats().counters()) {
Expand Down