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

Change metric accuracy in container projects dashboard #2762

Merged
merged 5 commits into from
Dec 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
data.ems_utilization.xy_data.cpu.xData = data.ems_utilization.xy_data.cpu.xData.map(function(date) {
return dashboardUtilsFactory.parseDate(date);
});
data.ems_utilization.xy_data.mem.xData = data.ems_utilization.xy_data.mem.xData.map(function(date) {
data.ems_utilization.xy_data.memory.xData = data.ems_utilization.xy_data.memory.xData.map(function(date) {
return dashboardUtilsFactory.parseDate(date);
});
}
Expand All @@ -125,7 +125,7 @@
'dates',
$scope.cpuUsageConfig.units);

$scope.memoryUsageData = chartsMixin.processUtilizationData(data.ems_utilization.xy_data.mem,
$scope.memoryUsageData = chartsMixin.processUtilizationData(data.ems_utilization.xy_data.memory,
'dates',
$scope.memoryUsageConfig.units);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ ManageIQ.angular.app.controller('containerProjectDashboardController', ['$scope'
data.project_utilization.xy_data.cpu.xData = data.project_utilization.xy_data.cpu.xData.map(function(date) {
return dashboardUtilsFactory.parseDate(date);
});
data.project_utilization.xy_data.mem.xData = data.project_utilization.xy_data.mem.xData.map(function(date) {
data.project_utilization.xy_data.memory.xData = data.project_utilization.xy_data.memory.xData.map(function(date) {
return dashboardUtilsFactory.parseDate(date);
});
}
Expand All @@ -52,7 +52,7 @@ ManageIQ.angular.app.controller('containerProjectDashboardController', ['$scope'
'dates',
$scope.cpuUsageConfig.units);

$scope.memoryUsageData = chartsMixin.processUtilizationData(data.project_utilization.xy_data.mem,
$scope.memoryUsageData = chartsMixin.processUtilizationData(data.project_utilization.xy_data.memory,
'dates',
$scope.memoryUsageConfig.units);

Expand Down
4 changes: 2 additions & 2 deletions app/services/container_dashboard_service.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class ContainerDashboardService
class ContainerDashboardService < DashboardService
include UiServiceMixin
include ContainerServiceMixin

CPU_USAGE_PRECISION = 2 # 2 decimal points

def initialize(provider_id, controller)
@provider_id = provider_id
Expand Down
7 changes: 5 additions & 2 deletions app/services/container_project_dashboard_service.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
class ContainerProjectDashboardService
class ContainerProjectDashboardService < DashboardService
include UiServiceMixin
include ContainerServiceMixin
CPU_USAGE_PRECISION = 2 # 2 decimal points

def initialize(project_id, controller)
@project_id = project_id
Expand All @@ -10,6 +9,10 @@ def initialize(project_id, controller)
@controller = controller
end

def display_precision
2
end

def all_data
{
:status => status,
Expand Down
24 changes: 6 additions & 18 deletions app/services/container_service_mixin.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
module ContainerServiceMixin
CPU_USAGE_PRECISION = 2 # 2 decimal points
def graph_precision
2
end

REALTIME_TIME_RANGE = 10 # 10 minutes

def daily_pod_metrics
Expand Down Expand Up @@ -60,22 +63,7 @@ def fill_utilization(m, time, used_cpu, used_mem, total_cpu, total_mem)
end

def utilization_data(used_cpu, total_cpu, used_mem, total_mem)
if used_cpu.any?
{
:cpu => {
:used => used_cpu.values.last.round,
:total => total_cpu.values.last.round,
:xData => used_cpu.keys,
:yData => used_cpu.values.map(&:round)
},
:mem => {
:used => (used_mem.values.last / 1024.0).round,
:total => (total_mem.values.last / 1024.0).round,
:xData => used_mem.keys,
:yData => used_mem.values.map { |m| (m / 1024.0).round }
}
}
end
format_utilization_data(used_cpu, used_mem, total_cpu, total_mem)
end

def trend_data(trend)
Expand Down Expand Up @@ -120,7 +108,7 @@ def hourly_network_metrics
def empty_utilization_trend_data
{
:interval_name => "",
:xy_data => {:cpu => nil, :mem => nil}
:xy_data => {:cpu => nil, :memory => nil}
}
end

Expand Down
42 changes: 42 additions & 0 deletions app/services/dashboard_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
class DashboardService
def display_precision
0
end

def graph_precision
0
end

def format_utilization_data(used_cpu, used_mem, total_cpu, total_mem)
{
:cpu => used_cpu.any? ? format_cpu(used_cpu, total_cpu) : nil,
:memory => used_mem.any? ? format_memory(used_mem, total_mem) : nil,
}
end

def format_cpu(used, total)
{
:used => cpu_num(used.values.last).round(display_precision),
:total => cpu_num(total.values.last).round(0),
:xData => used.keys,
:yData => used.values.map { |v| cpu_num(v).round(graph_precision) },
}
end

def cpu_num(val)
(val || 0)
end

def format_memory(used, total)
{
:used => mem_num(used.values.last).round(display_precision),
:total => mem_num(total.values.last).round(0),
:xData => used.keys,
:yData => used.values.map { |v| mem_num(v).round(graph_precision) },
}
end

def mem_num(val)
((val || 0) / 1024.0)
end
end
24 changes: 2 additions & 22 deletions app/services/ems_infra_dashboard_service.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class EmsInfraDashboardService
class EmsInfraDashboardService < DashboardService
include UiServiceMixin
CPU_USAGE_PRECISION = 2 # 2 decimal points

Expand Down Expand Up @@ -129,27 +129,7 @@ def ems_utilization
total_mem[date] += metric.derived_memory_available if metric.derived_memory_available.present?
end

if used_cpu.any?
{
:cpu => {
:used => used_cpu.values.last.round,
:total => total_cpu.values.last.round,
:xData => used_cpu.keys,
:yData => used_cpu.values.map(&:round)
},
:memory => {
:used => (used_mem.values.last / 1024.0).round,
:total => (total_mem.values.last / 1024.0).round,
:xData => used_mem.keys,
:yData => used_mem.values.map { |m| (m / 1024.0).round }
}
}
else
{
:cpu => nil,
:memory => nil
}
end
format_utilization_data(used_cpu, used_mem, total_cpu, total_mem)
end

def daily_provider_metrics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"interval_name": "realtime",
"xy_data": {
"cpu": null,
"mem": null
"memory": null
}
},
"network_metrics" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
3
]
},
"mem": {
"memory": {
"total": 21,
"used": 12,
"xData": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
4
]
},
"mem":{
"memory":{
"used":4,
"total":30,
"xData":[
Expand Down
12 changes: 6 additions & 6 deletions spec/services/container_dashboard_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
:xData => [current_date.strftime("%Y-%m-%d")],
:yData => [2]
},
:mem => {
:memory => {
:used => 1,
:total => 2,
:xData => [current_date.strftime("%Y-%m-%d")],
Expand All @@ -91,13 +91,13 @@
:used => 3,
:total => 3,
:xData => [current_date.strftime("%Y-%m-%d")],
:yData => [3]
:yData => [3.0]
},
:mem => {
:memory => {
:used => 2,
:total => 3,
:xData => [current_date.strftime("%Y-%m-%d")],
:yData => [2]
:yData => [1.5]
}
)
end
Expand All @@ -106,8 +106,8 @@
ems_openshift = FactoryGirl.create(:ems_openshift, :zone => @zone)
node_utilization_all_providers = described_class.new(nil, controller).ems_utilization[:xy_data]
node_utilization_single_provider = described_class.new(ems_openshift.id, controller).ems_utilization[:xy_data]
expect(node_utilization_all_providers).to eq(:cpu => nil, :mem => nil)
expect(node_utilization_single_provider).to eq(:cpu => nil, :mem => nil)
expect(node_utilization_all_providers).to eq(:cpu => nil, :memory => nil)
expect(node_utilization_single_provider).to eq(:cpu => nil, :memory => nil)
end
end

Expand Down