foreman_statistics 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +619 -0
- data/README.md +40 -0
- data/Rakefile +47 -0
- data/app/controllers/concerns/foreman_statistics/parameters/trend.rb +20 -0
- data/app/controllers/foreman_statistics/api/v2/statistics_controller.rb +33 -0
- data/app/controllers/foreman_statistics/api/v2/trends_controller.rb +58 -0
- data/app/controllers/foreman_statistics/react_controller.rb +19 -0
- data/app/controllers/foreman_statistics/statistics_controller.rb +24 -0
- data/app/controllers/foreman_statistics/trends_controller.rb +58 -0
- data/app/helpers/foreman_statistics/trends_helper.rb +53 -0
- data/app/models/concerns/foreman_statistics/compute_resource_decorations.rb +9 -0
- data/app/models/concerns/foreman_statistics/environment_decorations.rb +9 -0
- data/app/models/concerns/foreman_statistics/general_setting_decorations.rb +17 -0
- data/app/models/concerns/foreman_statistics/hostgroup_decorations.rb +9 -0
- data/app/models/concerns/foreman_statistics/model_decorations.rb +9 -0
- data/app/models/concerns/foreman_statistics/operatingsystem_decorations.rb +9 -0
- data/app/models/concerns/foreman_statistics/setting_decorations.rb +9 -0
- data/app/models/foreman_statistics/fact_trend.rb +57 -0
- data/app/models/foreman_statistics/foreman_trend.rb +41 -0
- data/app/models/foreman_statistics/trend.rb +38 -0
- data/app/models/foreman_statistics/trend_counter.rb +11 -0
- data/app/services/foreman_statistics/statistics.rb +21 -0
- data/app/services/foreman_statistics/statistics/base.rb +39 -0
- data/app/services/foreman_statistics/statistics/count_facts.rb +17 -0
- data/app/services/foreman_statistics/statistics/count_hosts.rb +9 -0
- data/app/services/foreman_statistics/statistics/count_numerical_fact_pair.rb +43 -0
- data/app/services/foreman_statistics/statistics/count_puppet_classes.rb +23 -0
- data/app/services/foreman_statistics/trend_importer.rb +63 -0
- data/app/views/foreman_statistics/api/v2/trends/base.json.rabl +4 -0
- data/app/views/foreman_statistics/api/v2/trends/create.json.rabl +3 -0
- data/app/views/foreman_statistics/api/v2/trends/index.json.rabl +3 -0
- data/app/views/foreman_statistics/api/v2/trends/main.json.rabl +5 -0
- data/app/views/foreman_statistics/api/v2/trends/show.json.rabl +3 -0
- data/app/views/foreman_statistics/api/v2/trends/update.json.rabl +3 -0
- data/app/views/foreman_statistics/layouts/application_react.html.erb +16 -0
- data/app/views/foreman_statistics/trends/_empty_data.html.erb +7 -0
- data/app/views/foreman_statistics/trends/_fields.html.erb +7 -0
- data/app/views/foreman_statistics/trends/_form.html.erb +8 -0
- data/app/views/foreman_statistics/trends/_hosts.html.erb +13 -0
- data/app/views/foreman_statistics/trends/edit.html.erb +46 -0
- data/app/views/foreman_statistics/trends/index.html.erb +39 -0
- data/app/views/foreman_statistics/trends/new.html.erb +4 -0
- data/app/views/foreman_statistics/trends/show.html.erb +25 -0
- data/app/views/foreman_statistics/trends/welcome.html.erb +12 -0
- data/config/routes.rb +22 -0
- data/db/migrate/20200605153005_migrate_core_types.rb +15 -0
- data/db/migrate_foreman/20121012170851_create_trends.rb +25 -0
- data/db/migrate_foreman/20121012170936_create_trend_counters.rb +14 -0
- data/db/migrate_foreman/20150202094307_add_range_to_trend_counters.rb +6 -0
- data/db/migrate_foreman/20181031155025_add_trend_counter_created_at_unique_constraint.rb +9 -0
- data/lib/foreman_statistics.rb +4 -0
- data/lib/foreman_statistics/engine.rb +104 -0
- data/lib/foreman_statistics/version.rb +3 -0
- data/lib/tasks/foreman_statistics_tasks.rake +78 -0
- data/locale/Makefile +60 -0
- data/locale/en/foreman_statistics.po +19 -0
- data/locale/foreman_statistics.pot +19 -0
- data/locale/gemspec.rb +2 -0
- data/test/factories/foreman_statistics_factories.rb +68 -0
- data/test/fixtures/permissions.yml +26 -0
- data/test/fixtures/settings.yml +6 -0
- data/test/functional/foreman_statistics/api/v2/statistics_controller_test.rb +19 -0
- data/test/functional/foreman_statistics/api/v2/trends_controller_test.rb +74 -0
- data/test/functional/foreman_statistics/statistics_controller_test.rb +23 -0
- data/test/functional/foreman_statistics/trends_controller_test.rb +115 -0
- data/test/models/foreman_statistics/trend_counter_test.rb +10 -0
- data/test/models/foreman_statistics/trend_test.rb +22 -0
- data/test/test_plugin_helper.rb +6 -0
- data/test/unit/foreman_statistics/access_permissions_test.rb +16 -0
- data/test/unit/foreman_statistics/statistics_test.rb +82 -0
- data/test/unit/foreman_statistics_test.rb +11 -0
- data/test/unit/tasks/foreman_statistics_tasks_test.rb +205 -0
- metadata +199 -0
@@ -0,0 +1,22 @@
|
|
1
|
+
require_relative '../../test_plugin_helper'
|
2
|
+
|
3
|
+
module ForemanStatistics
|
4
|
+
class TrendTest < ActiveSupport::TestCase
|
5
|
+
test 'should delete trend and associated trend counters' do
|
6
|
+
trend = FactoryBot.create(:foreman_statistics_trend, :value, :with_counters)
|
7
|
+
trend_id = trend.id
|
8
|
+
assert_equal 2, TrendCounter.where(:trend_id => trend_id).length
|
9
|
+
assert_difference('Trend.count', -1) do
|
10
|
+
as_admin do
|
11
|
+
trend.destroy
|
12
|
+
end
|
13
|
+
end
|
14
|
+
assert_equal 0, TrendCounter.where(:trend_id => trend_id).length
|
15
|
+
end
|
16
|
+
|
17
|
+
test '#find hosts returns empty result if associated record does not exist' do
|
18
|
+
trend = FactoryBot.build(:foreman_statistics_foreman_trend)
|
19
|
+
assert_empty trend.find_hosts
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'test_plugin_helper'
|
2
|
+
require 'unit/shared/access_permissions_test_base'
|
3
|
+
|
4
|
+
# Permissions are added in AccessPermissions with lists of controllers and
|
5
|
+
# actions that they enable access to. For non-admin users, we need to test
|
6
|
+
# that there are permissions available that cover every controller action, else
|
7
|
+
# it can't be delegated and this will lead to parts of the application that
|
8
|
+
# aren't functional for non-admin users.
|
9
|
+
#
|
10
|
+
# In particular, it's important that actions for AJAX requests are added to
|
11
|
+
# an appropriate permission so views using those requests function.
|
12
|
+
class AccessPermissionsTest < ActiveSupport::TestCase
|
13
|
+
include AccessPermissionsTestBase
|
14
|
+
|
15
|
+
check_routes(ForemanStatistics::Engine.routes, [])
|
16
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require_relative '../../test_plugin_helper'
|
2
|
+
|
3
|
+
module ForemanStatistics
|
4
|
+
class StatisticsTest < ActiveSupport::TestCase
|
5
|
+
def setup
|
6
|
+
User.current = users :admin
|
7
|
+
end
|
8
|
+
|
9
|
+
test 'it should return list of statistics objects' do
|
10
|
+
assert_not_empty Statistics.charts(nil, nil)
|
11
|
+
end
|
12
|
+
|
13
|
+
test 'it should include an Operating System stat' do
|
14
|
+
os = Statistics.charts(nil, nil).detect { |s| s.id == 'operatingsystem' }
|
15
|
+
assert_equal 'operatingsystem', os.id
|
16
|
+
data = { :id => 'operatingsystem', :title => 'OS Distribution', :url => '/foreman_statistics/statistics/operatingsystem', :search => '/hosts?search=os_title%3D~VAL~' }
|
17
|
+
assert_equal data, os.metadata
|
18
|
+
end
|
19
|
+
|
20
|
+
test 'it should set taxonomies as API paramaters according to current context' do
|
21
|
+
os = Statistics.charts(taxonomies(:empty_organization).id, nil).detect { |s| s.id == 'operatingsystem' }
|
22
|
+
data = { :id => 'operatingsystem', :title => 'OS Distribution', :url => "/foreman_statistics/statistics/operatingsystem?organization_id=#{taxonomies(:empty_organization).id}", :search => '/hosts?search=os_title%3D~VAL~' }
|
23
|
+
assert_equal data, os.metadata
|
24
|
+
|
25
|
+
os = Statistics.charts(nil, taxonomies(:location1).id).detect { |s| s.id == 'operatingsystem' }
|
26
|
+
data = { :id => 'operatingsystem', :title => 'OS Distribution', :url => "/foreman_statistics/statistics/operatingsystem?location_id=#{taxonomies(:location1).id}", :search => '/hosts?search=os_title%3D~VAL~' }
|
27
|
+
assert_equal data, os.metadata
|
28
|
+
|
29
|
+
os = Statistics.charts(taxonomies(:empty_organization).id, taxonomies(:location1).id).detect { |s| s.id == 'operatingsystem' }
|
30
|
+
data = { :id => 'operatingsystem', :title => 'OS Distribution', :url => "/foreman_statistics/statistics/operatingsystem?location_id=#{taxonomies(:location1).id}&organization_id=#{taxonomies(:empty_organization).id}", :search => '/hosts?search=os_title%3D~VAL~' }
|
31
|
+
assert_equal data, os.metadata
|
32
|
+
end
|
33
|
+
|
34
|
+
test 'it should initialize a base statistics object' do
|
35
|
+
stat = Statistics::Base.new(:count_by => :hostgroup)
|
36
|
+
assert_equal :hostgroup, stat.count_by
|
37
|
+
assert_equal 'hostgroup', stat.id
|
38
|
+
assert_equal '/foreman_statistics/statistics/hostgroup', stat.url
|
39
|
+
assert_raise(NotImplementedError) { stat.calculate }
|
40
|
+
end
|
41
|
+
|
42
|
+
test 'it should initialize a fact counter statistics object' do
|
43
|
+
stat = Statistics::CountFacts.new(:count_by => 'uptime')
|
44
|
+
assert_kind_of Array, stat.calculate
|
45
|
+
end
|
46
|
+
|
47
|
+
test 'it should initialize a fact counter statistics object with units' do
|
48
|
+
stat = Statistics::CountFacts.new(:count_by => 'uptime', :unit => ['%s core', '%s cores'])
|
49
|
+
assert_equal ['%s core', '%s cores'], stat.unit
|
50
|
+
assert_kind_of Array, stat.calculate
|
51
|
+
end
|
52
|
+
|
53
|
+
test 'it should initialize a host counter statistics object' do
|
54
|
+
stat = Statistics::CountHosts.new(:count_by => :compute_resource)
|
55
|
+
assert_kind_of Array, stat.calculate
|
56
|
+
end
|
57
|
+
|
58
|
+
test 'it should fail to calculate a puppet class counter statistics object without an id' do
|
59
|
+
assert_raise(ArgumentError) { Statistics::CountPuppetClasses.new }
|
60
|
+
end
|
61
|
+
|
62
|
+
test 'it should initialize a puppet class counter statistics object' do
|
63
|
+
stat = Statistics::CountPuppetClasses.new(:id => :classes)
|
64
|
+
assert_equal '/foreman_statistics/statistics/classes', stat.url
|
65
|
+
assert_kind_of Array, stat.calculate
|
66
|
+
end
|
67
|
+
|
68
|
+
test 'it should fail to calculate a Fact class counter statistics object without count_by' do
|
69
|
+
assert_raise(ArgumentError) { Statistics::CountNumericalFactPair.new }
|
70
|
+
end
|
71
|
+
|
72
|
+
test 'it should initialize a fact pair counter statistics object' do
|
73
|
+
stat = Statistics::CountNumericalFactPair.new(:count_by => :memory)
|
74
|
+
assert_equal 'memorysize', stat.send(:total_name)
|
75
|
+
assert_equal 'memoryfree', stat.send(:used_name)
|
76
|
+
calc = stat.calculate
|
77
|
+
assert_kind_of Array, calc
|
78
|
+
assert_equal 'free memory', calc[0][:label]
|
79
|
+
assert_equal 'used memory', calc[1][:label]
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,205 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
class ForemanStatisticsTasksTest < ActiveSupport::TestCase
|
5
|
+
setup do
|
6
|
+
Rake.application.rake_require 'tasks/foreman_statistics_tasks'
|
7
|
+
Rake::Task.define_task(:environment)
|
8
|
+
Rake::Task['foreman_statistics:trends:reduce'].reenable
|
9
|
+
|
10
|
+
ForemanStatistics::TrendCounter.unscoped.delete_all
|
11
|
+
ForemanStatistics::Trend.unscoped.delete_all
|
12
|
+
end
|
13
|
+
|
14
|
+
test 'foreman_statistics:trends:reduce reduces single trend' do
|
15
|
+
trend = FactoryBot.build(:foreman_statistics_trend_os)
|
16
|
+
point_dates = create_trend_line(trend, [1, 1, 1, 1, 1, 1])
|
17
|
+
|
18
|
+
Rake.application.invoke_task 'foreman_statistics:trends:reduce'
|
19
|
+
|
20
|
+
trend_counter = ForemanStatistics::TrendCounter.where(trend_id: trend.id)
|
21
|
+
|
22
|
+
assert_equal 1, trend_counter.count
|
23
|
+
|
24
|
+
trend_counter = trend_counter.first
|
25
|
+
|
26
|
+
assert_equal point_dates.min.to_i, trend_counter.interval_start.to_i
|
27
|
+
assert_nil trend_counter.interval_end
|
28
|
+
end
|
29
|
+
|
30
|
+
test 'foreman_statistics:trends:reduce does not iterfere between two trend ids' do
|
31
|
+
trend_1 = FactoryBot.build(:foreman_statistics_trend_os)
|
32
|
+
trend_2 = FactoryBot.build(:foreman_statistics_trend_os)
|
33
|
+
create_trend_line(trend_1, [1, 1, 1, 1, 1, 1])
|
34
|
+
create_trend_line(trend_2, [2, 2, 2, 2, 2, 2])
|
35
|
+
|
36
|
+
Rake.application.invoke_task 'foreman_statistics:trends:reduce'
|
37
|
+
|
38
|
+
trend_10 = ForemanStatistics::TrendCounter.where(trend_id: trend_1.id)
|
39
|
+
trend_20 = ForemanStatistics::TrendCounter.where(trend_id: trend_2.id)
|
40
|
+
|
41
|
+
assert_equal 1, trend_10.count
|
42
|
+
assert_equal 1, trend_20.count
|
43
|
+
|
44
|
+
trend_10 = trend_10.first
|
45
|
+
trend_20 = trend_20.first
|
46
|
+
|
47
|
+
assert_equal trend_10.interval_start, trend_20.interval_start
|
48
|
+
assert_nil trend_10.interval_end
|
49
|
+
assert_nil trend_20.interval_end
|
50
|
+
end
|
51
|
+
|
52
|
+
test 'foreman_statistics:trends:reduce crossing graphs' do
|
53
|
+
new_os_trend = FactoryBot.build(:foreman_statistics_trend_os)
|
54
|
+
old_os_trend = FactoryBot.build(:foreman_statistics_trend_os)
|
55
|
+
new_os_point_dates = create_trend_line(new_os_trend, [1, 1, 1, 2, 2, 2, 3, 3, 3])
|
56
|
+
create_trend_line(old_os_trend, [3, 3, 3, 2, 2, 2, 1, 1, 1])
|
57
|
+
interval_starts = [new_os_point_dates[0], new_os_point_dates[3], new_os_point_dates[6]]
|
58
|
+
|
59
|
+
Rake.application.invoke_task 'foreman_statistics:trends:reduce'
|
60
|
+
|
61
|
+
new_os_intervals = ForemanStatistics::TrendCounter.where(trend_id: new_os_trend.id).order(:interval_start).to_a
|
62
|
+
old_os_intervals = ForemanStatistics::TrendCounter.where(trend_id: old_os_trend.id).order(:interval_start).to_a
|
63
|
+
|
64
|
+
assert_equal 3, new_os_intervals.length
|
65
|
+
assert_equal 3, old_os_intervals.length
|
66
|
+
|
67
|
+
interval_starts.each_with_index do |start, idx|
|
68
|
+
assert_equal start, old_os_intervals[idx].interval_start
|
69
|
+
assert_equal start, new_os_intervals[idx].interval_start
|
70
|
+
|
71
|
+
if idx < 2
|
72
|
+
next_start = interval_starts[idx + 1]
|
73
|
+
assert_not_nil next_start
|
74
|
+
assert_equal next_start, old_os_intervals[idx].interval_end
|
75
|
+
assert_equal next_start, new_os_intervals[idx].interval_end
|
76
|
+
else
|
77
|
+
assert_nil old_os_intervals[idx].interval_end
|
78
|
+
assert_nil new_os_intervals[idx].interval_end
|
79
|
+
end
|
80
|
+
|
81
|
+
assert_equal 4, old_os_intervals[idx].count + new_os_intervals[idx].count
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
test 'foreman_statistics:trends:reduce mirrored saw graphs' do
|
86
|
+
new_os_trend = FactoryBot.build(:foreman_statistics_trend_os)
|
87
|
+
old_os_trend = FactoryBot.build(:foreman_statistics_trend_os)
|
88
|
+
new_os_point_dates = create_trend_line(new_os_trend, [1, 1, 1, 2, 2, 2, 1, 1, 1, 2, 2, 2])
|
89
|
+
create_trend_line(old_os_trend, [3, 3, 3, 2, 2, 2, 3, 3, 3, 2, 2, 2])
|
90
|
+
interval_starts = [new_os_point_dates[0], new_os_point_dates[3], new_os_point_dates[6], new_os_point_dates[9]]
|
91
|
+
new_os_counts = [1, 2, 1, 2]
|
92
|
+
|
93
|
+
Rake.application.invoke_task 'foreman_statistics:trends:reduce'
|
94
|
+
|
95
|
+
new_os_intervals = ForemanStatistics::TrendCounter.where(trend_id: new_os_trend.id).order(:interval_start).to_a
|
96
|
+
old_os_intervals = ForemanStatistics::TrendCounter.where(trend_id: old_os_trend.id).order(:interval_start).to_a
|
97
|
+
|
98
|
+
assert_equal 4, new_os_intervals.length
|
99
|
+
assert_equal 4, old_os_intervals.length
|
100
|
+
|
101
|
+
interval_starts.each_with_index do |start, idx|
|
102
|
+
assert_equal start, old_os_intervals[idx].interval_start
|
103
|
+
assert_equal start, new_os_intervals[idx].interval_start
|
104
|
+
|
105
|
+
if idx < 3
|
106
|
+
next_start = interval_starts[idx + 1]
|
107
|
+
assert_not_nil next_start
|
108
|
+
assert_equal next_start, old_os_intervals[idx].interval_end
|
109
|
+
assert_equal next_start, new_os_intervals[idx].interval_end
|
110
|
+
else
|
111
|
+
assert_nil old_os_intervals[idx].interval_end
|
112
|
+
assert_nil new_os_intervals[idx].interval_end
|
113
|
+
end
|
114
|
+
|
115
|
+
assert_equal 4, old_os_intervals[idx].count + new_os_intervals[idx].count
|
116
|
+
assert_equal new_os_counts[idx], new_os_intervals[idx].count
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
test 'foreman_statistics:trends:reduce can rerun with additional datapoint with the same value' do
|
121
|
+
os_trend = FactoryBot.build(:foreman_statistics_trend_os)
|
122
|
+
os_point_dates = create_trend_line(os_trend, [1, 1, 1, 1, 1, 1])
|
123
|
+
Rake.application.invoke_task 'foreman_statistics:trends:reduce'
|
124
|
+
|
125
|
+
interval = ForemanStatistics::TrendCounter.where(trend_id: os_trend.id).order(:interval_start).to_a
|
126
|
+
assert_equal 1, interval.length
|
127
|
+
interval = interval.first
|
128
|
+
|
129
|
+
FactoryBot.build(:foreman_statistics_trend_counter, :trend => os_trend, :created_at => os_point_dates[3], :updated_at => os_point_dates[3], :count => 1)
|
130
|
+
|
131
|
+
Rake::Task['foreman_statistics:trends:reduce'].reenable
|
132
|
+
Rake.application.invoke_task 'foreman_statistics:trends:reduce'
|
133
|
+
|
134
|
+
new_interval = ForemanStatistics::TrendCounter.where(trend_id: os_trend.id).order(:interval_start).to_a
|
135
|
+
assert_equal 1, new_interval.length
|
136
|
+
new_interval = new_interval.first
|
137
|
+
|
138
|
+
assert_equal new_interval, interval
|
139
|
+
end
|
140
|
+
|
141
|
+
test 'trends:reduce can rerun with additional datapoint with different value in open interval' do
|
142
|
+
os_trend = FactoryBot.build(:foreman_statistics_trend_os)
|
143
|
+
os_point_dates = create_trend_line(os_trend, [1, 1, 1, 1, 1, 1])
|
144
|
+
Rake.application.invoke_task 'foreman_statistics:trends:reduce'
|
145
|
+
|
146
|
+
interval = ForemanStatistics::TrendCounter.where(trend_id: os_trend.id).order(:interval_start).to_a
|
147
|
+
assert_equal 1, interval.length
|
148
|
+
|
149
|
+
FactoryBot.create(:foreman_statistics_trend_counter, :trend => os_trend, :created_at => os_point_dates[3], :updated_at => os_point_dates[3], :count => 2)
|
150
|
+
|
151
|
+
Rake::Task['foreman_statistics:trends:reduce'].reenable
|
152
|
+
Rake.application.invoke_task 'foreman_statistics:trends:reduce'
|
153
|
+
|
154
|
+
new_intervals = ForemanStatistics::TrendCounter.where(trend_id: os_trend.id).order(:interval_start).to_a
|
155
|
+
assert_equal 2, new_intervals.length
|
156
|
+
|
157
|
+
assert_equal 1, new_intervals[0].count
|
158
|
+
assert_equal 2, new_intervals[1].count
|
159
|
+
|
160
|
+
assert_equal os_point_dates[0], new_intervals[0].interval_start
|
161
|
+
assert_equal os_point_dates[3], new_intervals[0].interval_end
|
162
|
+
assert_equal os_point_dates[3], new_intervals[1].interval_start
|
163
|
+
end
|
164
|
+
|
165
|
+
test 'foreman_statistics:trends:reduce can rerun with additional datapoint with different value in closed interval' do
|
166
|
+
os_trend = FactoryBot.build(:foreman_statistics_trend_os)
|
167
|
+
os_point_dates = create_trend_line(os_trend, [1, 1, 1, 1, 1, 2])
|
168
|
+
Rake.application.invoke_task 'foreman_statistics:trends:reduce'
|
169
|
+
|
170
|
+
interval = ForemanStatistics::TrendCounter.where(trend_id: os_trend.id).order(:interval_start).to_a
|
171
|
+
assert_equal 2, interval.length
|
172
|
+
|
173
|
+
FactoryBot.create(:foreman_statistics_trend_counter, :trend => os_trend, :created_at => os_point_dates[3], :updated_at => os_point_dates[3], :count => 3)
|
174
|
+
|
175
|
+
Rake::Task['foreman_statistics:trends:reduce'].reenable
|
176
|
+
Rake.application.invoke_task 'foreman_statistics:trends:reduce'
|
177
|
+
|
178
|
+
new_intervals = ForemanStatistics::TrendCounter.where(trend_id: os_trend.id).order(:interval_start).to_a
|
179
|
+
assert_equal 3, new_intervals.length
|
180
|
+
|
181
|
+
assert_equal 1, new_intervals[0].count
|
182
|
+
assert_equal 3, new_intervals[1].count
|
183
|
+
assert_equal 2, new_intervals[2].count
|
184
|
+
|
185
|
+
assert_equal os_point_dates[0], new_intervals[0].interval_start
|
186
|
+
assert_equal os_point_dates[3], new_intervals[0].interval_end
|
187
|
+
assert_equal os_point_dates[3], new_intervals[1].interval_start
|
188
|
+
assert_equal os_point_dates[5], new_intervals[1].interval_end
|
189
|
+
assert_equal os_point_dates[5], new_intervals[2].interval_start
|
190
|
+
end
|
191
|
+
|
192
|
+
private
|
193
|
+
|
194
|
+
def create_trend_line(trend, values_line)
|
195
|
+
point_dates = []
|
196
|
+
point_date = Time.now.utc.beginning_of_day
|
197
|
+
values_line.each do |value|
|
198
|
+
point_dates << point_date
|
199
|
+
FactoryBot.create(:foreman_statistics_trend_counter, :trend => trend, :created_at => point_date, :updated_at => point_date, :count => value)
|
200
|
+
point_date += 10.minutes
|
201
|
+
end
|
202
|
+
|
203
|
+
point_dates
|
204
|
+
end
|
205
|
+
end
|
metadata
ADDED
@@ -0,0 +1,199 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: foreman_statistics
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ondrej Ezr
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-06-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rdoc
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rubocop
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rubocop-minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.9.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.9.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop-performance
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.5.2
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.5.2
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop-rails
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 2.5.2
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 2.5.2
|
83
|
+
description: Statistics and Trends for Foreman gives users overview of their infrastructure.
|
84
|
+
email:
|
85
|
+
- oezr@redhat.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- LICENSE
|
91
|
+
- README.md
|
92
|
+
- Rakefile
|
93
|
+
- app/controllers/concerns/foreman_statistics/parameters/trend.rb
|
94
|
+
- app/controllers/foreman_statistics/api/v2/statistics_controller.rb
|
95
|
+
- app/controllers/foreman_statistics/api/v2/trends_controller.rb
|
96
|
+
- app/controllers/foreman_statistics/react_controller.rb
|
97
|
+
- app/controllers/foreman_statistics/statistics_controller.rb
|
98
|
+
- app/controllers/foreman_statistics/trends_controller.rb
|
99
|
+
- app/helpers/foreman_statistics/trends_helper.rb
|
100
|
+
- app/models/concerns/foreman_statistics/compute_resource_decorations.rb
|
101
|
+
- app/models/concerns/foreman_statistics/environment_decorations.rb
|
102
|
+
- app/models/concerns/foreman_statistics/general_setting_decorations.rb
|
103
|
+
- app/models/concerns/foreman_statistics/hostgroup_decorations.rb
|
104
|
+
- app/models/concerns/foreman_statistics/model_decorations.rb
|
105
|
+
- app/models/concerns/foreman_statistics/operatingsystem_decorations.rb
|
106
|
+
- app/models/concerns/foreman_statistics/setting_decorations.rb
|
107
|
+
- app/models/foreman_statistics/fact_trend.rb
|
108
|
+
- app/models/foreman_statistics/foreman_trend.rb
|
109
|
+
- app/models/foreman_statistics/trend.rb
|
110
|
+
- app/models/foreman_statistics/trend_counter.rb
|
111
|
+
- app/services/foreman_statistics/statistics.rb
|
112
|
+
- app/services/foreman_statistics/statistics/base.rb
|
113
|
+
- app/services/foreman_statistics/statistics/count_facts.rb
|
114
|
+
- app/services/foreman_statistics/statistics/count_hosts.rb
|
115
|
+
- app/services/foreman_statistics/statistics/count_numerical_fact_pair.rb
|
116
|
+
- app/services/foreman_statistics/statistics/count_puppet_classes.rb
|
117
|
+
- app/services/foreman_statistics/trend_importer.rb
|
118
|
+
- app/views/foreman_statistics/api/v2/trends/base.json.rabl
|
119
|
+
- app/views/foreman_statistics/api/v2/trends/create.json.rabl
|
120
|
+
- app/views/foreman_statistics/api/v2/trends/index.json.rabl
|
121
|
+
- app/views/foreman_statistics/api/v2/trends/main.json.rabl
|
122
|
+
- app/views/foreman_statistics/api/v2/trends/show.json.rabl
|
123
|
+
- app/views/foreman_statistics/api/v2/trends/update.json.rabl
|
124
|
+
- app/views/foreman_statistics/layouts/application_react.html.erb
|
125
|
+
- app/views/foreman_statistics/trends/_empty_data.html.erb
|
126
|
+
- app/views/foreman_statistics/trends/_fields.html.erb
|
127
|
+
- app/views/foreman_statistics/trends/_form.html.erb
|
128
|
+
- app/views/foreman_statistics/trends/_hosts.html.erb
|
129
|
+
- app/views/foreman_statistics/trends/edit.html.erb
|
130
|
+
- app/views/foreman_statistics/trends/index.html.erb
|
131
|
+
- app/views/foreman_statistics/trends/new.html.erb
|
132
|
+
- app/views/foreman_statistics/trends/show.html.erb
|
133
|
+
- app/views/foreman_statistics/trends/welcome.html.erb
|
134
|
+
- config/routes.rb
|
135
|
+
- db/migrate/20200605153005_migrate_core_types.rb
|
136
|
+
- db/migrate_foreman/20121012170851_create_trends.rb
|
137
|
+
- db/migrate_foreman/20121012170936_create_trend_counters.rb
|
138
|
+
- db/migrate_foreman/20150202094307_add_range_to_trend_counters.rb
|
139
|
+
- db/migrate_foreman/20181031155025_add_trend_counter_created_at_unique_constraint.rb
|
140
|
+
- lib/foreman_statistics.rb
|
141
|
+
- lib/foreman_statistics/engine.rb
|
142
|
+
- lib/foreman_statistics/version.rb
|
143
|
+
- lib/tasks/foreman_statistics_tasks.rake
|
144
|
+
- locale/Makefile
|
145
|
+
- locale/en/foreman_statistics.po
|
146
|
+
- locale/foreman_statistics.pot
|
147
|
+
- locale/gemspec.rb
|
148
|
+
- test/factories/foreman_statistics_factories.rb
|
149
|
+
- test/fixtures/permissions.yml
|
150
|
+
- test/fixtures/settings.yml
|
151
|
+
- test/functional/foreman_statistics/api/v2/statistics_controller_test.rb
|
152
|
+
- test/functional/foreman_statistics/api/v2/trends_controller_test.rb
|
153
|
+
- test/functional/foreman_statistics/statistics_controller_test.rb
|
154
|
+
- test/functional/foreman_statistics/trends_controller_test.rb
|
155
|
+
- test/models/foreman_statistics/trend_counter_test.rb
|
156
|
+
- test/models/foreman_statistics/trend_test.rb
|
157
|
+
- test/test_plugin_helper.rb
|
158
|
+
- test/unit/foreman_statistics/access_permissions_test.rb
|
159
|
+
- test/unit/foreman_statistics/statistics_test.rb
|
160
|
+
- test/unit/foreman_statistics_test.rb
|
161
|
+
- test/unit/tasks/foreman_statistics_tasks_test.rb
|
162
|
+
homepage: https://theforeman.org
|
163
|
+
licenses:
|
164
|
+
- GPL-3.0
|
165
|
+
metadata: {}
|
166
|
+
post_install_message:
|
167
|
+
rdoc_options: []
|
168
|
+
require_paths:
|
169
|
+
- lib
|
170
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
171
|
+
requirements:
|
172
|
+
- - ">="
|
173
|
+
- !ruby/object:Gem::Version
|
174
|
+
version: '0'
|
175
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
176
|
+
requirements:
|
177
|
+
- - ">="
|
178
|
+
- !ruby/object:Gem::Version
|
179
|
+
version: '0'
|
180
|
+
requirements: []
|
181
|
+
rubygems_version: 3.0.3
|
182
|
+
signing_key:
|
183
|
+
specification_version: 4
|
184
|
+
summary: Add Statistics and Trends.
|
185
|
+
test_files:
|
186
|
+
- test/functional/foreman_statistics/trends_controller_test.rb
|
187
|
+
- test/functional/foreman_statistics/statistics_controller_test.rb
|
188
|
+
- test/functional/foreman_statistics/api/v2/trends_controller_test.rb
|
189
|
+
- test/functional/foreman_statistics/api/v2/statistics_controller_test.rb
|
190
|
+
- test/models/foreman_statistics/trend_test.rb
|
191
|
+
- test/models/foreman_statistics/trend_counter_test.rb
|
192
|
+
- test/unit/foreman_statistics/statistics_test.rb
|
193
|
+
- test/unit/foreman_statistics/access_permissions_test.rb
|
194
|
+
- test/unit/tasks/foreman_statistics_tasks_test.rb
|
195
|
+
- test/unit/foreman_statistics_test.rb
|
196
|
+
- test/factories/foreman_statistics_factories.rb
|
197
|
+
- test/fixtures/settings.yml
|
198
|
+
- test/fixtures/permissions.yml
|
199
|
+
- test/test_plugin_helper.rb
|