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

Add classes to model pod metrics and project invoices. #78

Merged
merged 1 commit into from
Oct 3, 2024

Conversation

naved001
Copy link
Collaborator

The class Pod represent a pod's metrics and exposes methods to get the service unit and runtime of a pod. The service unit information is returned as a namedtuple. The method to get runtime will allow us to ignore certain hours, though, that will be added in a later commit.

The class ProjectInvoice represents invoice data for a project. It has a method that takes in a pod and aggregates it's usage data. Another method generate_invoice_rows will return the csv data to be exported.

The caller write_metrics_by_namespace has been updated to use these new classes.

Tests have been updated to work with the new changes. There's some duplicate constants that I will sort in the next few commits.

The method write_metrics_by_pod isn't updated yet since it's not critical and I wanted to keep the size of this PR down.

gpu_request: Decimal,
memory_request: Decimal,
gpu_type: str,
gpu_resource: str,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think I should add namespace, the kubernetes node label, and the node model as part of a pod definition. Those would come in handy when I produce reports by pods.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

and most importantly the name of the pod itself

openshift_metrics/invoice.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@QuanMPhm QuanMPhm left a comment

Choose a reason for hiding this comment

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

Here are some comments I have so far. Mostly minor changes. Sorry if I missed anything!

elif gpu_type == GPU_A100_SXM4: # for MIG GPU of type A100_SXM4
su_type = A100_SXM4_MIG.get(gpu_resource, SU_UNKNOWN_MIG_GPU)
else:
return SU_UNKNOWN_GPU, 0, "GPU"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should these return statements use the ServiceUnit tuple like this?:

return ServiceUnit(SU_UNKNOWN_GPU, 0, "GPU")

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes they should! good catch.


# pods that requested a specific GPU but weren't scheduled may report 0 GPU
if gpu_resource is not None and gpu_count == 0:
return SU_UNKNOWN_GPU, 0, "GPU"
Copy link
Collaborator

Choose a reason for hiding this comment

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

^


return ServiceUnit(su_type, su_count, determining_resource)

def get_runtime(self, ignore_hours=None):
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's the point of the ignore_hours argument?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I should remove this, I plan to add a feature to ignore certain hours from calculating runtime. I'll add this in argument when I add that feature.

openshift_metrics/invoice.py Outdated Show resolved Hide resolved
The class `Pod` represent a pod's metrics and exposes methods to get the
service unit and runtime of a pod. The service unit information is returned as
a namedtuples. The method to get runtime will allow us to ignore certain
hours, though, that will be added in a later commit.

The class `ProjectInvoice` represents invoice data for a project. It has a
method that takes in a pod and aggregates it's usage data. Another method
`generate_invoice_rows` will return the csv data to be exported.

The caller write_metrics_by_namespace has been updated to use these new classes.

Tests have been updated to work with the new changes. There's some duplicate
constants that I will sort in the next few commits.
openshift_metrics/invoice.py Show resolved Hide resolved
@naved001 naved001 merged commit c9768a8 into CCI-MOC:main Oct 3, 2024
2 checks passed
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.

3 participants