fluentd-ui 0.3.11 → 0.3.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of fluentd-ui might be problematic. Click here for more details.

Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/ChangeLog +11 -0
  3. data/Gemfile.lock +1 -1
  4. data/app/assets/stylesheets/common.css.scss +4 -0
  5. data/app/controllers/application_controller.rb +25 -15
  6. data/app/controllers/concerns/setting_history_concern.rb +28 -0
  7. data/app/controllers/fluentd/agents_controller.rb +13 -15
  8. data/app/controllers/fluentd/settings/histories_controller.rb +3 -13
  9. data/app/controllers/fluentd/settings/notes_controller.rb +16 -0
  10. data/app/controllers/fluentd/settings/running_backup_controller.rb +2 -12
  11. data/app/controllers/fluentd/settings_controller.rb +2 -2
  12. data/app/controllers/misc_controller.rb +27 -18
  13. data/app/controllers/polling_controller.rb +10 -13
  14. data/app/helpers/settings_helper.rb +67 -29
  15. data/app/models/{fluentd/setting/backup_file.rb → concerns/fluentd/setting_archive/archivable.rb} +11 -11
  16. data/app/models/fluent_gem.rb +1 -1
  17. data/app/models/fluentd/agent/fluentd_gem.rb +7 -3
  18. data/app/models/fluentd/agent/local_common.rb +44 -9
  19. data/app/models/fluentd/agent/td_agent/macosx.rb +5 -2
  20. data/app/models/fluentd/agent/td_agent/unix.rb +4 -0
  21. data/app/models/fluentd/setting/out_s3.rb +3 -3
  22. data/app/models/fluentd/setting_archive/backup_file.rb +20 -0
  23. data/app/models/fluentd/setting_archive/note.rb +28 -0
  24. data/app/models/plugin.rb +12 -6
  25. data/app/views/fluentd/settings/histories/_list.html.haml +17 -6
  26. data/app/views/fluentd/settings/histories/show.html.haml +12 -2
  27. data/app/views/fluentd/settings/running_backup/show.html.haml +8 -3
  28. data/app/views/layouts/application.html.erb +1 -1
  29. data/app/views/plugins/updated.html.haml +21 -19
  30. data/app/views/shared/_flash.html.haml +3 -0
  31. data/config/locales/translation_en.yml +5 -0
  32. data/config/locales/translation_ja.yml +5 -0
  33. data/config/routes.rb +4 -0
  34. data/lib/file_reverse_reader.rb +38 -13
  35. data/lib/fluentd-ui/version.rb +1 -1
  36. data/spec/controllers/application_controller_spec.rb +88 -0
  37. data/spec/controllers/fluentd/agents_controller_spec.rb +45 -0
  38. data/spec/controllers/misc_controller_spec.rb +68 -0
  39. data/spec/controllers/polling_controller_spec.rb +34 -0
  40. data/spec/features/fluentd/setting/histories_spec.rb +87 -0
  41. data/spec/features/fluentd/setting/notes_spec.rb +27 -0
  42. data/spec/features/fluentd/setting/out_forward_spec.rb +40 -0
  43. data/spec/features/fluentd/setting/{ranning_backup_spec.rb → running_backup_spec.rb} +36 -0
  44. data/spec/features/setting_spec.rb +2 -2
  45. data/spec/models/fluentd/agent_spec.rb +49 -0
  46. data/spec/support/fixtures/error3.log +7 -0
  47. data/spec/support/fluentd_agent_common_behavior.rb +14 -0
  48. metadata +23 -13
  49. data/app/helpers/miscs_helper.rb +0 -2
  50. data/db/seeds.rb +0 -7
  51. data/spec/controllers/plugins_controller_spec.rb +0 -5
  52. data/spec/controllers/tutorials_controller_spec.rb +0 -5
  53. data/spec/features/fluentd/setting/hisotries_spec.rb +0 -48
@@ -12,6 +12,8 @@ ja:
12
12
  fluentd_status_running: 稼働中
13
13
  fluentd_status_stopped: 停止中
14
14
  config_successfully_copied: "設定をコピーしました。反映させるには、 %{brand}を再起動してください。"
15
+ note_updating_success: "メモを更新しました。"
16
+ dryrun_is_passed: この設定でのdry-runが成功しました
15
17
 
16
18
  terms: &terms
17
19
  name: アカウント名
@@ -59,8 +61,11 @@ ja:
59
61
  notice_restart_for_config_edit: "※更新すると稼働中の%{brand}が再起動されます"
60
62
  lines: 行
61
63
  languages: 言語
64
+ backup_file: バックアップファイル
62
65
  backup_time: バックアップ日時
66
+ note: メモ
63
67
  reuse: 再利用
68
+ configtest: この設定を検証する(dry-run)
64
69
 
65
70
  plugins:
66
71
  view_on_rubygems_org: rubygems.orgで見る
@@ -66,10 +66,14 @@ Rails.application.routes.draw do
66
66
 
67
67
  resources :histories, only: [:index, :show], module: :settings, controller: :histories do
68
68
  post "reuse", action: 'reuse', on: :member, as: 'reuse'
69
+ post "configtest" , action: "configtest", on: :member, as: "configtest"
69
70
  end
70
71
 
72
+ resources :notes, only: [:update], module: :settings, controller: :notes
73
+
71
74
  resource :running_backup, only: [:show], module: :settings, controller: :running_backup do
72
75
  post "reuse", action: 'reuse', on: :member, as: 'reuse'
76
+ post "configtest" , action: "configtest", on: :member, as: "configtest"
73
77
  end
74
78
  end
75
79
  end
@@ -7,26 +7,24 @@ class FileReverseReader
7
7
  end
8
8
 
9
9
  def each_line(&block)
10
+ #read from the end of file
10
11
  io.seek(0, IO::SEEK_END)
11
12
  buf = ""
12
13
  loop do
13
14
  if reach_start_of_file?
14
- last_pos = io.pos
15
- io.seek(0, IO::SEEK_SET)
16
- buf.insert(0, io.read(last_pos))
17
- split_each_line(buf, &block)
15
+ read_rest(buf, &block)
18
16
  break
19
17
  end
20
18
 
21
- io.seek(-1 * step, IO::SEEK_CUR)
22
- buf.insert(0, io.read(step))
23
- io.seek(-1 * step, IO::SEEK_CUR)
24
- next if buf[$/].nil?
25
- gap = buf.index($/)
26
- buf.gsub!(/\A.*?\n/, "")
27
- split_each_line(buf, &block)
28
- buf = ""
29
- io.seek(gap, IO::SEEK_CUR)
19
+ read_to_buf_by_step(buf)
20
+
21
+ #if buffer dose not include multi lines, seek more.
22
+ if buf[$/].nil?
23
+ next
24
+ else
25
+ split_only_whole_lines(buf, &block)
26
+ buf = ""
27
+ end
30
28
  end
31
29
  end
32
30
 
@@ -43,6 +41,33 @@ class FileReverseReader
43
41
 
44
42
  private
45
43
 
44
+ def read_rest(buf, &block)
45
+ last_pos = io.pos
46
+ io.seek(0, IO::SEEK_SET)
47
+ buf.insert(0, io.read(last_pos))
48
+ split_each_line(buf, &block)
49
+ end
50
+
51
+ def read_to_buf_by_step(buf)
52
+ #move up file pointer by one step
53
+ io.seek(-1 * step, IO::SEEK_CUR) #point[A]
54
+ #read strings by one step from the pointer, and insert to buffer
55
+ #(on io.read, file pointer returns down to the point before [A])
56
+ buf.insert(0, io.read(step))
57
+ #forword file pointer to [A]
58
+ io.seek(-1 * step, IO::SEEK_CUR)
59
+ end
60
+
61
+ def split_only_whole_lines(buf, &block)
62
+ #if budder includes multi lines,
63
+ gap = buf.index($/)
64
+ #cut off first line (*first* line because it's seeking from end of file, and first line may be broken-line)
65
+ buf.gsub!(/\A.*?\n/, "")
66
+ split_each_line(buf, &block)
67
+ #move file pointer to the gap(= the end of *first* line)
68
+ io.seek(gap, IO::SEEK_CUR)
69
+ end
70
+
46
71
  def split_each_line(buf, &block)
47
72
  return unless buf.force_encoding('utf-8').valid_encoding?
48
73
  buf.split($/).reverse.each do |line|
@@ -1,3 +1,3 @@
1
1
  module FluentdUI
2
- VERSION = "0.3.11"
2
+ VERSION = "0.3.12"
3
3
  end
@@ -0,0 +1,88 @@
1
+ require 'spec_helper'
2
+
3
+ class DummyController < ApplicationController; end
4
+
5
+ describe DummyController do
6
+ controller DummyController do
7
+ skip_before_action :login_required
8
+ def index
9
+ render :text => "Hello World"
10
+ end
11
+ end
12
+
13
+ describe '#set_locale' do
14
+ let!(:default_locale) { :en }
15
+ let!(:available_locales) { [:en, :ja] }
16
+
17
+ before do
18
+ I18n.stub(:default_locale).and_return(default_locale)
19
+ I18n.stub(:available_locales).and_return(available_locales)
20
+
21
+ I18n.locale = I18n.default_locale #initialize
22
+ end
23
+
24
+ context 'with params[:lang]' do
25
+ before do
26
+ get 'index', lang: param_lang
27
+ end
28
+
29
+ context 'and in available_locales' do
30
+ let(:param_lang) { :ja }
31
+
32
+ it 'params[:lang] will be set as locale' do
33
+ expect(I18n.locale).to eq :ja
34
+ end
35
+ end
36
+
37
+ context 'and out of available_locales' do
38
+ let(:param_lang) { :ka }
39
+
40
+ it 'defalut locale will be set as locale' do
41
+ expect(I18n.locale).to eq default_locale
42
+ end
43
+ end
44
+ end
45
+
46
+ context 'with session[:prefer_lang]' do
47
+ before do
48
+ controller.session[:prefer_lang] = :ja
49
+ end
50
+
51
+ it 'session[:prefer_lang] will be set as locale' do
52
+ get 'index'
53
+ expect(I18n.locale).to eq :ja
54
+ end
55
+ end
56
+
57
+ context 'with request.env["HTTP_ACCEPT_LANGUAGE"]' do
58
+ before do
59
+ request.stub(:env).and_return({ "HTTP_ACCEPT_LANGUAGE" => accept_language })
60
+ get 'index'
61
+ end
62
+
63
+ context 'accept_language is available' do
64
+ let(:accept_language) { 'ja' }
65
+
66
+ it 'session[:prefer_lang] will be set as locale' do
67
+ expect(I18n.locale).to eq :ja
68
+ end
69
+ end
70
+
71
+ context 'accept_language is not available but start with en' do
72
+ let(:accept_language) { 'en-us' }
73
+
74
+ it ':en will be set as locale' do
75
+ expect(I18n.locale).to eq :en
76
+ end
77
+ end
78
+
79
+ context 'accept_language is not available' do
80
+ let(:accept_language) { 'ka' }
81
+
82
+ it 'default_locale will be set as locale' do
83
+ expect(I18n.locale).to eq default_locale
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe Fluentd::AgentsController do
4
+ before do
5
+ allow(controller).to receive(:current_user).and_return true
6
+ allow(controller).to receive(:find_fluentd).and_return(nil)
7
+ controller.instance_variable_set(:@fluentd, double(agent: @agent = double(:agent)))
8
+ end
9
+
10
+ describe "when the action succeeds" do
11
+ it "stops" do
12
+ expect(@agent).to receive(:stop).and_return true
13
+ put :stop
14
+ end
15
+
16
+ it "starts" do
17
+ expect(@agent).to receive(:start).and_return true
18
+ put :start
19
+ end
20
+
21
+ it "restarts" do
22
+ expect(@agent).to receive(:restart).and_return true
23
+ put :restart
24
+ end
25
+ end
26
+
27
+ describe "when the action does not succeed" do
28
+ it "stops" do
29
+ expect(@agent).to receive(:stop).and_return false
30
+ put :stop
31
+ end
32
+
33
+ it "starts" do
34
+ expect(@agent).to receive(:start).and_return false
35
+ expect(@agent).to receive(:log_tail).with(1).and_return ["some message"]
36
+ put :start
37
+ end
38
+
39
+ it "restarts" do
40
+ expect(@agent).to receive(:restart).and_return false
41
+ expect(@agent).to receive(:log_tail).with(1).and_return ["some message"]
42
+ put :restart
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,68 @@
1
+ require 'spec_helper'
2
+
3
+ describe MiscController do
4
+ let(:instance) { Fluentd.new(id: nil, variant: "fluentd_gem", log_file: "dummy.log", pid_file: "dummy.pid", config_file: "dummy.conf") }
5
+
6
+ class DummyAagent
7
+ def log
8
+ "dummy_log_content"
9
+ end
10
+
11
+ def version
12
+ "dummy version"
13
+ end
14
+ end
15
+
16
+ let!(:dummy_agent) { DummyAagent.new }
17
+ let!(:fluentd_log_content) { dummy_agent.log }
18
+ let!(:fluentd_version) { dummy_agent.version }
19
+ let(:fluentd_ui_log_content) { <<-LOG.strip_heredoc }
20
+ log1
21
+ log2
22
+ log3
23
+ LOG
24
+
25
+ let!(:dummy_log_path) { "tmp/dummy.log" }
26
+ let!(:expand_dir) { Rails.root.join("tmp/system_info") }
27
+
28
+ before do
29
+ allow(controller).to receive(:current_user).and_return true
30
+
31
+ #dummy log for fluentd-ui.log
32
+ File.open(dummy_log_path, 'w') { |file| file.write(fluentd_ui_log_content) }
33
+ controller.stub(:log_path) { dummy_log_path }
34
+
35
+ instance.stub(:agent).and_return(dummy_agent)
36
+ Fluentd.stub(:instance).and_return(instance)
37
+ end
38
+
39
+ describe 'download_info' do
40
+ before do
41
+ get 'download_info'
42
+
43
+ #expand files in zip
44
+ Zip::File.open(Rails.root.join("tmp/system_info.zip")) do |zip_file|
45
+ FileUtils.mkdir_p(expand_dir)
46
+
47
+ zip_file.each do |f|
48
+ f_path = File.join(expand_dir, f.name)
49
+ zip_file.extract(f, f_path) unless File.exist?(f_path)
50
+ end
51
+ end
52
+ end
53
+
54
+ #remove all temp files for this spec
55
+ after do
56
+ FileUtils.rm Rails.root.join("tmp/system_info.zip")
57
+ FileUtils.rm_r expand_dir
58
+ FileUtils.rm dummy_log_path
59
+ end
60
+
61
+ it 'write files' do
62
+ expect(File.read(File.join(expand_dir, "fluentd.log"))).to eq "#{fluentd_log_content}\n"
63
+ expect(File.read(File.join(expand_dir, "fluentd-ui.log"))).to eq "#{fluentd_ui_log_content}"
64
+ expect(File.read(File.join(expand_dir, "env.txt"))).to match "RAILS_ENV=test"
65
+ expect(File.read(File.join(expand_dir, "versions.txt"))).to match "fluentd: #{fluentd_version}"
66
+ end
67
+ end
68
+ end
@@ -1,5 +1,39 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe PollingController do
4
+ describe 'polling for alerts' do
5
+ before do
6
+ allow(controller).to receive(:current_user).and_return true
7
+ end
4
8
 
9
+ after do
10
+ response.should be_success
11
+ end
12
+
13
+ it 'may find nothing' do
14
+ expect(controller).to receive(:uninstalling_gems).and_return []
15
+ expect(controller).to receive(:installing_gems).and_return []
16
+ get :alerts
17
+ end
18
+
19
+ it 'may find gems being uninstalled' do
20
+ expect(controller).to receive(:uninstalling_gems).and_return [
21
+ double(gem_name: "foobar", version: "1.0.0")
22
+ ]
23
+
24
+ allow(controller).to receive(:installing_gems).and_return []
25
+
26
+ get :alerts
27
+ end
28
+
29
+ it 'may find gems being installed' do
30
+ expect(controller).to receive(:installing_gems).and_return [
31
+ double(gem_name: "bazbang", version: "0.0.1")
32
+ ]
33
+
34
+ allow(controller).to receive(:uninstalling_gems).and_return []
35
+
36
+ get :alerts
37
+ end
38
+ end
5
39
  end
@@ -0,0 +1,87 @@
1
+ require "spec_helper"
2
+
3
+ describe "histories", stub: :daemon do
4
+ let!(:exists_user) { build(:user) }
5
+ include_context 'daemon has some config histories'
6
+
7
+ before do
8
+ login_with exists_user
9
+ end
10
+
11
+ describe 'index' do
12
+ before do
13
+ visit '/daemon/setting/histories'
14
+ end
15
+
16
+ it 'show histories#index' do
17
+ page.should have_css('h1', text: I18n.t('fluentd.settings.histories.index.page_title'))
18
+ expect(all('.row tr').count).to eq 9 + 1 # links to hisotries#show + 1 table header
19
+ end
20
+
21
+ it 'will go to histories#show' do
22
+ all('.row tr td a').first.click
23
+
24
+ page.should have_css('h1', text: I18n.t('fluentd.settings.histories.show.page_title'))
25
+ end
26
+ end
27
+
28
+ describe 'show' do
29
+ let(:last_backup_file) { Fluentd::SettingArchive::BackupFile.new(daemon.agent.backup_files_in_new_order.first) }
30
+
31
+ before do
32
+ visit "/daemon/setting/histories/#{last_backup_file.file_id}"
33
+ end
34
+
35
+ it 'show histories#show' do
36
+ page.should have_css('h1', text: I18n.t('fluentd.settings.histories.show.page_title'))
37
+ page.should have_text(last_backup_file.content)
38
+ end
39
+
40
+ it 'update config and redirect to setting#show' do
41
+ click_link I18n.t("terms.reuse")
42
+
43
+ page.should have_css('h1', text: I18n.t('fluentd.settings.show.page_title'))
44
+ page.should have_text(I18n.t('messages.config_successfully_copied', brand: 'fluentd') )
45
+ page.should have_text(last_backup_file.content)
46
+ end
47
+
48
+ describe "configtest" do
49
+ let(:daemon) { build(:fluentd, variant: "fluentd_gem") } # To use fluentd_gem for real dry-run checking
50
+ before do
51
+ daemon.agent.config_write config
52
+ daemon.agent.config_write "# dummy"
53
+ backup = Fluentd::SettingArchive::BackupFile.new(daemon.agent.backup_files_in_new_order.first)
54
+ visit "/daemon/setting/histories/#{backup.file_id}"
55
+ click_link I18n.t("terms.configtest")
56
+ end
57
+
58
+ context "invalid configfile" do
59
+ let(:config) { <<-CONFIG }
60
+ <source>
61
+ type aaaaaaaaaaaa
62
+ </source>
63
+ CONFIG
64
+
65
+ it do
66
+ page.should_not have_css('.alert-success')
67
+ page.should have_css('.alert-danger')
68
+ page.should have_text(%Q|Unknown input plugin 'aaaaaaaaaaaa'|)
69
+ end
70
+ end
71
+
72
+ context "valid configfile" do
73
+ let(:config) { <<-CONFIG }
74
+ <source>
75
+ type syslog
76
+ tag syslog
77
+ </source>
78
+ CONFIG
79
+
80
+ it do
81
+ page.should have_css('.alert-success')
82
+ page.should_not have_css('.alert-danger')
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,27 @@
1
+ require "spec_helper"
2
+
3
+ describe "notes", stub: :daemon do
4
+ let!(:exists_user) { build(:user) }
5
+ include_context 'daemon has some config histories'
6
+
7
+ before { login_with exists_user }
8
+
9
+ describe 'update' do
10
+ let(:note_field) { ".note-content" }
11
+ let(:updating_content) { "This config file is for ..." }
12
+
13
+ before do
14
+ visit '/daemon/setting/histories'
15
+ within first("form") do
16
+ first(note_field).set updating_content
17
+ click_button(I18n.t('terms.save'))
18
+ end
19
+ end
20
+
21
+ it "update a content of a note" do
22
+ within first("form") do
23
+ first(note_field).value.should eq updating_content
24
+ end
25
+ end
26
+ end
27
+ end