Support reloading Fluentd/td-agent

Signed-off-by: Kenji Okimoto <okimoto@clear-code.com>
This commit is contained in:
Kenji Okimoto 2018-04-25 14:36:53 +09:00
parent e3c6d9032f
commit ecd40a81f4
5 changed files with 20 additions and 1 deletions

View File

@ -16,6 +16,11 @@ class Fluentd::AgentsController < ApplicationController
redirect_to daemon_path(@fluentd), status: 303 # 303 is change HTTP Verb GET
end
def reload
run_action(__method__) { @fluentd.agent.log.tail(1).first }
redirect_to daemon_path(@fluentd), status: 303 # 303 is change HTTP Verb GET
end
def log_tail
@logs = @fluentd.agent.log.tail(params[:limit]).reverse if @fluentd
render json: @logs

View File

@ -36,7 +36,7 @@ class Fluentd
end
end
def reload # NOTE: does not used currently
def reload
return false unless running?
actual_reload
end

View File

@ -17,6 +17,7 @@
= link_to icon("fa-play") << t("fluentd.common.start"), start_daemon_agent_path(@fluentd), method: :put, class: "btn #{@fluentd.agent.running? ? "disabled btn-outline-dark" : "btn-primary"}"
= link_to icon("fa-pause") << t("fluentd.common.stop"), stop_daemon_agent_path(@fluentd), method: :put, class: "btn #{@fluentd.agent.running? ? "btn-danger" : "disabled btn-outline-dark"}"
= link_to icon("fa-refresh") << t("fluentd.common.restart"), restart_daemon_agent_path(@fluentd), method: :put, class: "btn #{@fluentd.agent.running? ? "btn-warning" : "disabled btn-outline-dark"}"
= link_to icon("fa-refresh") << t("fluentd.common.reload"), reload_daemon_agent_path(@fluentd), method: :put, class: "btn #{@fluentd.agent.running? ? "btn-info" : "disabled btn-default"}"
.col-xl-6.col-sm-6
.card.card-default
.card-header

View File

@ -11,6 +11,7 @@ Rails.application.routes.draw do
put "start"
put "stop"
put "restart"
put "reload"
get "log_tail"
end

View File

@ -24,6 +24,11 @@ describe Fluentd::AgentsController do
expect(@agent).to receive(:restart).and_return true
put :restart
end
it "reaload" do
expect(@agent).to receive(:reload).and_return true
put :reload
end
end
describe "when the action does not succeed" do
@ -45,5 +50,12 @@ describe Fluentd::AgentsController do
expect(log).to receive(:tail).with(1)
put :restart
end
it "reload" do
expect(@agent).to receive(:reload).and_return false
expect(@agent).to receive(:log).and_return(log)
expect(log).to receive(:tail).with(1)
put :reload
end
end
end