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

HPC-9713: Add service modality models #197

Merged
merged 4 commits into from
Dec 13, 2024
Merged

HPC-9713: Add service modality models #197

merged 4 commits into from
Dec 13, 2024

Conversation

Pl217
Copy link
Contributor

@Pl217 Pl217 commented Dec 2, 2024

No description provided.

@Pl217 Pl217 added the ready for review All comments have been addressed, and the Pull Request is ready for review label Dec 2, 2024
@Pl217 Pl217 requested a review from a team as a code owner December 2, 2024 16:21
Copy link
Contributor

@enxtur enxtur left a comment

Choose a reason for hiding this comment

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

It would be better to mention adding breakdownByServiceModality in the commit 3507bbe message instead of just distinguishing, wouldn't it?

Comment on lines 20 to 32
breakdownByGlobalCluster: t.array(
t.exact(
t.type({
objectId: t.number,
cost: t.number,
})
)
),
/**
* Unlike global cluster breakdown, service modality breakdown
* doesn't need to add up to the total cost
*/
breakdownByServiceModality: t.array(
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe it would be better to split this change into two separate commits. One commit should add the breakdownByServiceModality, while the other should change the breakdown to breakdownByGlobalCluster.
Also what about creating common codec for breakdown, and use it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, I should have split the changes across two commits. Thanks for pointing that out, I'll make that change.

Now, for the other point, about using common codec for both breakdowns. They are already part of the same codec, but I think you meant keeping breakdown as a key and have it as object, that would be like this:

breakdown: t.partial({
  byGlobalCluster: t.array(
    ...
  ),
  byServiceModality: t.array(
    ...
  ),
})

This is really similar to having separate breakdownByGlobalCluster and breakdownByServiceModality at the top level. We're essentially just increasing the indentation. But, a comparison can be made:

  • When reading this value, we need to pass it through the codec to verify it in both cases, so nothing changes there. But since type of breakdown changed from array to object, we'd need one more accessor now to pick the desired breakdown
  • Also, this type change from array to object means we'd need to change all existing values in the database to be objects with one key - byGlobalCluster. The code changes would also be needed, and it would need to be a little more complex than renaming a key. I viewed key rename as simple enough and thus went with that approach. The downside of the approach I took is that key names are now really long, maybe approaching "too long" territory
  • If we have a single breakdown object with two subkeys, we would have all breakdown-related data semantically and logically grouped, but we'd also need to handle the entire breakdown object in updates

There is another possibility and that is to keep breakdown as-is and add one more property to each array element, called type which would make a distinction between "globalCluster" and "serviceModality". So, values would be like this:

{
  "cost": 100,
  "breakdown": [
    { "type": "globalCluster", "objectId": 7, "cost": 50 },
    { "type": "serviceModality", "objectId": 1, "cost": 50 }
    { "type": "globalCluster", "objectId": 11, "cost": 50 },
    { "type": "serviceModality", "objectId": 2, "cost": 50 }
  ]
}

This looks like simplest approach as it should be trivial to migrate the data. But, it has a few down sides:

  • It makes it hard to distinguish between breakdowns by different types, it is less human-readable. This is exacerbated by the fact that sum of global cluster breakdowns needs to add up to the total cost, but breakdown by service modality doesn't
  • When we need to update only one of the breakdowns, we'd need more complex filtering and trying not to override the other
  • Migrating the data is easy, but finding all the places which need code changes would be really hard. If we fail to update code in some place, all would be treated as breakdown by global cluster, which could lead to some ugly bugs. Since service modality is a new DB table, first two entries (from the ticket) will be assigned IDs 1 & 2 and if we don't update all the code properly, these would be treated as breakdowns by global clusters with those IDs, because they definitely exist
  • Breakdowns cannot evolve differently. If we need to store something extra for one of these two kinds of breakdowns, but not for other, it will be complicating the codec to a point that we lose initial simplicity. We'd likely not need this, but it is still a downside
  • Let's end with a positive, as adding new breakdown types in the future seems easier with this approach

Having said all of this, I think this is valid discussion and thanks for bringing it up. But, unless you see a clear benefit of storing data differently, I'd keep what I did, for the most practical reason: I don't need to make any changes and waste time for marginal benefits, if any.

@enxtur enxtur assigned Pl217 and unassigned enxtur Dec 4, 2024
@enxtur enxtur added needs minor changes There are review or issue comments to address and removed ready for review All comments have been addressed, and the Pull Request is ready for review labels Dec 4, 2024
@Pl217 Pl217 assigned enxtur and unassigned Pl217 Dec 6, 2024
@Pl217 Pl217 added ready for review All comments have been addressed, and the Pull Request is ready for review and removed needs minor changes There are review or issue comments to address labels Dec 6, 2024
Copy link
Contributor

@enxtur enxtur left a comment

Choose a reason for hiding this comment

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

I hadn't considered that far. I mean, just using a common codec between these globalCluster and serviceModality breakdowns.

@enxtur enxtur assigned Pl217 and unassigned enxtur Dec 11, 2024
@enxtur enxtur added ready for merge Review and testing is complete. It is ready for merging as soon as CI has finished. and removed ready for review All comments have been addressed, and the Pull Request is ready for review labels Dec 11, 2024
This property will store breakdown by service modality,
opposed to other breakdown property that stores
breakdown by global cluster
This is done to distinguish between breakdowns
by global cluster and by service modality
@Pl217
Copy link
Contributor Author

Pl217 commented Dec 13, 2024

I hadn't considered that far. I mean, just using a common codec between these globalCluster and serviceModality breakdowns.

Right, I planned to do that, but somehow forgot. Extracted the codec into a common variable now.

@Pl217 Pl217 merged commit 2c61ebb into develop Dec 13, 2024
2 checks passed
@Pl217 Pl217 deleted the HPC-9713 branch December 13, 2024 08:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready for merge Review and testing is complete. It is ready for merging as soon as CI has finished.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants