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
1 change: 1 addition & 0 deletions docs/root/intro/version_history.rst
Expand Up @@ -9,6 +9,7 @@ Version history
minimum.
* aws_request_signing: a few fixes so that it works with S3.
* admin: added support for displaying ip address subject alternate names in :ref:`certs<operations_admin_interface_certs>` end point.
* admin: added :http:post:`/reopen_logs` endpoint to control log rotation.
* buffer: force copy when appending small slices to OwnedImpl buffer to avoid fragmentation.
* config: use type URL to select an extension whenever the config type URL (or its previous versions) uniquely identify a typed extension, see :ref:`extension configuration <config_overview_extension_configuration>`.
* config: added stat :ref:`update_time <config_cluster_manager_cds>`.
Expand Down
4 changes: 4 additions & 0 deletions docs/root/operations/admin.rst
Expand Up @@ -558,3 +558,7 @@ modify different aspects of the server:
been configured to accept admin configuration. See:

* :ref:`HTTP tap filter configuration <config_http_filters_tap_admin_handler>`

.. http:post:: /reopen_logs

Triggers reopen of all access logs. Behavior is similar to SIGUSR1 handling.
9 changes: 9 additions & 0 deletions source/server/http/admin.cc
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,
true},
},
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
Expand Up @@ -357,6 +357,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
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, postCallback("/reopen_logs", header_map, response));
}

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