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

Preserve workload resources structure on serialization #133

Merged
merged 1 commit into from
Nov 1, 2023

Conversation

teroyks
Copy link
Contributor

@teroyks teroyks commented Nov 1, 2023

Related to https://github.com/valohai/meta/issues/275

Workload resource keys (cpu, memory, etc.) need to be preserved so that the UI can correctly parse the resource values.

Serialized resources in step before:

{'resources': [{'max': 20, 'min': 10}, {'max': 1.0, 'min': 0.5}, {'big machine': 2}]}

After:

{'resources': {'cpu': {'max': 20, 'min': 10}, 'devices': {'big machine': 2}, 'memory': {'max': 1.0, 'min': 0.5}}}

The default for most keys (all of them so far) is to flatten them, which is why the test is a bit backwards (not in [do_not_flatten] instead of key in [do_flatten]).

@teroyks teroyks self-assigned this Nov 1, 2023
@teroyks teroyks added the Fix label Nov 1, 2023
@teroyks teroyks marked this pull request as ready for review November 1, 2023 12:02
@teroyks teroyks requested review from ruksi and akx November 1, 2023 12:03
Copy link
Member

@akx akx left a comment

Choose a reason for hiding this comment

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

Can you base the test on the (apparently unused!) step_with_resources fixture (i.e. step-with-resources.yaml) that was added in #121? When using our examples fixtures, we automagically do both direct and round-tripped variants of the test. As I see it, that should surface the bug.

Workload resource keys ("cpu", "memory", etc.) need to be preserved so
that the UI can correctly parse the resource values.
@teroyks teroyks force-pushed the tero/fix/resources-serialization branch from 724207c to be3cbc4 Compare November 1, 2023 12:54
Comment on lines +6 to +7
assert isinstance(resources, dict), "Resources should be defined."
assert "cpu" in resources, "Resources should contain data."
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These lines serve more to demonstrate the serialized result than to actually test the process – without the fix, the serialization crashes before reaching here.

@teroyks teroyks requested a review from akx November 1, 2023 12:56
@teroyks
Copy link
Contributor Author

teroyks commented Nov 1, 2023

Can you base the test on the (apparently unused!) step_with_resources fixture (i.e. step-with-resources.yaml) that was added in #121?

Right. Done, pushed a rebased commit (without the unneeded new test data).

Copy link
Member

@akx akx left a comment

Choose a reason for hiding this comment

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

Good stuff!

@akx akx merged commit 7e1c6aa into master Nov 1, 2023
6 checks passed
@akx akx deleted the tero/fix/resources-serialization branch November 1, 2023 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants