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

15873 - Make Cluster resource counters more readable #15900

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from

Conversation

Julio-Oliveira-Encora
Copy link
Contributor

Fixes: #15873

One method was created to normalize the VM's disk and memory sizes according to their units. That method is applied when the "Allocated Resources" is generated.

…e according to unit informed.

Changed "get_extra_context" method from "ClusterView" to use the method above and convert all the disks and memories from VMs to normalize the units.
Copy link
Member

@jeremystretch jeremystretch left a comment

Choose a reason for hiding this comment

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

I really think we just need to make some small adjustments to the existing humanize_megabytes() function to address the goals of #15873.

@@ -172,7 +173,17 @@ class ClusterView(generic.ObjectView):
queryset = Cluster.objects.all()

def get_extra_context(self, request, instance):
return instance.virtual_machines.aggregate(vcpus_sum=Sum('vcpus'), memory_sum=Sum('memory'), disk_sum=Sum('disk'))
Copy link
Member

Choose a reason for hiding this comment

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

We need to keep the aggregation logic at the database layer in the interest of performance.

@@ -172,7 +173,17 @@ class ClusterView(generic.ObjectView):
queryset = Cluster.objects.all()

def get_extra_context(self, request, instance):
return instance.virtual_machines.aggregate(vcpus_sum=Sum('vcpus'), memory_sum=Sum('memory'), disk_sum=Sum('disk'))
vm_memory = [convert_byte_size(item.memory, 'mega') for item in instance.virtual_machines.all() if item.memory]
Copy link
Member

Choose a reason for hiding this comment

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

It's sufficient to capture and then round the raw aggregate value. Also, we generally want to handle this sort of massaging of numbers in the template (via a template tag) rather than in the view to afford maximum flexibility.

@Julio-Oliveira-Encora
Copy link
Contributor Author

Julio-Oliveira-Encora commented May 9, 2024

I was analyzing it, and there is no point in trying to convert and predict any incorrect input from the customer.
The "memory" field in the VM is already informed that the value must be in MB, so if the client enters, for example, the value "68000" for one VM and "64" for another, the result of the sum will be "68064 ", but this is not Netbox's "fault", but rather the incorrect input.

I think we should talk about it.

I changed "humanize_megabytes" to convert non-divisible values to 1024 in this commit and reverted all previous changes.

Screenshot from 2024-05-09 16-16-17

DO-AMS3

@jeremystretch jeremystretch changed the base branch from feature to develop May 13, 2024 20:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants