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

Fixed correct setting of record to get counts of relationships #5995

Merged
merged 2 commits into from
Aug 16, 2019

Conversation

h-kataria
Copy link
Contributor

  • Fixed to use CloudTenant record to get counts of relationships for Cloud Tenant dashboard, prior to changes in this PR, code was using a Provider record to get counts and was also passing in an incorrect controller to the CloudTenantDashboardService module.

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1731735
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1487178

before
Screenshot from 2019-08-12 13-45-00

after
Screenshot from 2019-08-12 13-54-53

@himdel
Copy link
Contributor

himdel commented Aug 13, 2019

@h-kataria We should not be calling the CloudTenant @ems, right?

But also, looks like in EmsDashboardService, recent_records is using @ems.id to search for Vm|Template by ems_id. Which will now fail because @ems.id is actually a tenant id (as opposed to @ems_id).

(Also, format_data is using @ems.send, that probably works, but the @ems name is still misleading.)


Maybe the real problem is that CloudTenantDashboardService should not inherit from EmsDashboardService but only share a DashboardService or a mixin that doesn't assume the record is an ems?

Or can we just get rid of the @ems name and use @record, and move anything that needs to know the class of the record to the service that actually knows it?

@h-kataria
Copy link
Contributor Author

@h-kataria We should not be calling the CloudTenant @ems, right?

But also, looks like in EmsDashboardService, recent_records is using @ems.id to search for Vm|Template by ems_id. Which will now fail because @ems.id is actually a tenant id (as opposed to @ems_id).

(Also, format_data is using @ems.send, that probably works, but the @ems name is still misleading.)

Maybe the real problem is that CloudTenantDashboardService should not inherit from EmsDashboardService but only share a DashboardService or a mixin that doesn't assume the record is an ems?

Or can we just get rid of the @ems name and use @record, and move anything that needs to know the class of the record to the service that actually knows it?

@himdel i agree with you, CloudTenant Dashboard should not be using the shared code with EmsDashboardService. Let me try to fix that, since these BZs need to be backported i was trying to keep changes to minimum.

@himdel
Copy link
Contributor

himdel commented Aug 13, 2019

Aah,
thanks :) Yeah, I think we should fix that, but if you want to backport a minimal change,
I think just changing @ems.id to @ems_id in recent_records may do the trick.

@h-kataria h-kataria force-pushed the fixed_cloud_tenant_dashboard_view branch from 5653565 to 92adb18 Compare August 13, 2019 15:33
- Fixed to CloudTenantService to not inherit from EmsDashboardService, instead inherit from DashboardService and have it's own methods so correct data can be fetched using CloudTenant record.

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1731735
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1487178
@h-kataria h-kataria force-pushed the fixed_cloud_tenant_dashboard_view branch from 92adb18 to 6440497 Compare August 13, 2019 15:55
@h-kataria
Copy link
Contributor Author

@himdel please re-review

to_char_args = [db_table[:created_on], Arel::Nodes::SqlLiteral.new("'YYYY-MM-DD'")]
group_by_sql = Arel::Nodes::NamedFunction.new("to_char", to_char_args)

model.where(:ems_id => @record.ext_management_system.id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this is right after all.

I mean, we're showing a list of vms or images whcih have the same ems as the cloud tenant.
This is definitely better than before, where we would show vms and images of a random EMS (that happened to have the same db id as the cloud tenant).

But.. don't we have a ..more directl link between cloud tenant and instances/images?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... we do, @record.vms and @record.miq_templates.

So, what about adding a relation argument to recent_records and recent_resources and doing..

def recent_records(model, relation)
    db_table     = model.arel_table
    to_char_args = [db_table[:created_on], Arel::Nodes::SqlLiteral.new("'YYYY-MM-DD'")]
    group_by_sql = Arel::Nodes::NamedFunction.new("to_char", to_char_args)

   relation.where(db_table[:created_on].gt(30.days.ago.utc))
         .group(group_by_sql.to_sql)
         .count
end

def recent_images_data
  recent_resources(MiqTemplate, _('Recent Images'), _('Images'), @record.miq_templates)
end

def recent_instances_data
  recent_resources(ManageIQ::Providers::CloudManager::Vm, _('Recent Instances'), _('Instances'), @record.vms)
end

@himdel
Copy link
Contributor

himdel commented Aug 14, 2019

LGTM, thanks for splitting this! :)

Just that cloud_tenant.vms vs all vms under cloud_tenant.ext_management_system difference :)

@h-kataria
Copy link
Contributor Author

LGTM, thanks for splitting this! :)

Just that cloud_tenant.vms vs all vms under cloud_tenant.ext_management_system difference :)

@himdel thx for the suggestion on passing the relation, implemented that, it works better now.

@h-kataria h-kataria force-pushed the fixed_cloud_tenant_dashboard_view branch from 79454b5 to 28427c4 Compare August 14, 2019 15:46
Passing in a relation to `recent_records` to get recent vms/templates for the selected CloudTenant record

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1731735
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1487178
@h-kataria h-kataria force-pushed the fixed_cloud_tenant_dashboard_view branch from 28427c4 to 1371c00 Compare August 14, 2019 15:46
@miq-bot
Copy link
Member

miq-bot commented Aug 14, 2019

Checked commits h-kataria/manageiq-ui-classic@6440497~...1371c00 with ruby 2.4.6, rubocop 0.69.0, haml-lint 0.20.0, and yamllint 1.10.0
3 files checked, 0 offenses detected
Everything looks fine. 👍

@himdel himdel self-assigned this Aug 16, 2019
@himdel himdel added this to the Sprint 118 Ending Aug 19, 2019 milestone Aug 16, 2019
@himdel
Copy link
Contributor

himdel commented Aug 16, 2019

LGTM, seeing consistent counts in the dashboard and the list screen :)

@himdel himdel merged commit 1492f6a into ManageIQ:master Aug 16, 2019
simaishi pushed a commit that referenced this pull request Aug 16, 2019
@simaishi
Copy link
Contributor

Ivanchuk backport details:

$ git log -1
commit 482aa40349860fac6d8d903f8c0132beece02494
Author: Martin Hradil <[email protected]>
Date:   Fri Aug 16 15:27:01 2019 +0200

    Merge pull request #5995 from h-kataria/fixed_cloud_tenant_dashboard_view
    
    Fixed correct setting of record to get counts of relationships
    
    (cherry picked from commit 1492f6a42e723d5afce9bcd23a61ff02542a2b6e)
    
    Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1731735
    Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1487178

@h-kataria h-kataria deleted the fixed_cloud_tenant_dashboard_view branch August 22, 2019 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants