8000
Skip to content

Entity type refactor (simplified)#13846

Merged
tomponline merged 3 commits intocanonical:mainfrom
markylaing:entity-type-refactor-simplified
Aug 2, 2024
Merged

Entity type refactor (simplified)#13846
tomponline merged 3 commits intocanonical:mainfrom
markylaing:entity-type-refactor-simplified

Conversation

@markylaing
Copy link
Copy Markdown
Contributor
@markylaing markylaing commented Jul 31, 2024

@tomponline @hamistao this is a much more concise entity type refactor that I think works much better. (Thanks Tom for the idea of keeping the types as they are, but storing them in a map the returns a struct/interface with relevant fields/methods).

With this change, I think it should be easy to add the URL prefix classification by:

  1. Adding a PrefixMatch() []string method to typeImpl that returns a slice of URL prefixes to match the entity type against.
  2. Adding a function MatchURLPrefix which iterates over the entityType map, and iterates over the PrefixMatch() array for each typeImpl, then returns the entity type if strings.HasPrefix(u.Path, prefix).

Closes #13262
Closes #12928

@markylaing markylaing changed the title WIP Entity type refactor (simplified) Jul 31, 2024
@markylaing markylaing force-pushed the entity-type-refactor-simplified branch 2 times, most recently from a232935 to fa6bfa2 Compare August 1, 2024 14:56
@markylaing markylaing self-assigned this Aug 1, 2024
@markylaing markylaing marked this pull request as ready for review August 2, 2024 06:52
@tomponline
Copy link
Copy Markdown
Member
tomponline commented Aug 2, 2024

@markylaing can we mark this one as "closes #13262"? and "closes #12928"?

Comment thread shared/entity/type.go Outdated
@markylaing markylaing force-pushed the entity-type-refactor-simplified branch from fa6bfa2 to 6946912 Compare August 2, 2024 10:26
@markylaing markylaing requested a review from tomponline August 2, 2024 10:27
@hamistao
Copy link
Copy Markdown
hamistao commented Aug 2, 2024

@tomponline @markylaing Entities will need to be grouped to classify endpoints for the API metrics, grouping them on the metrics package makes sense but I think it would fall out of date eventually because one would have to update the metrics package as weel when adding an entity type that did not fall within the previous categories. Do you think it would be appropriate to extend this implementation in the futute with a field on typeInfo (could maybe be called EntityDomain or ResourceClass, not sure yet) specifying the group on which that entity type belongs?

The groups themselves would also be created within the entity package entity

Edit: This comment can just be disregarded as we agreed upon just using the approach outlined in the PR description.

Comment thread shared/entity/type.go Outdated
Comment thread lxd/db/cluster/stmt.go Outdated
Comment thread lxd/db/cluster/entity_type_instance_snapshot.go Outdated
Comment thread lxd/db/cluster/entities.go
Copy link
Copy Markdown
Member
@tomponline tomponline left a comment

Choose a reason for hiding this comment

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

This looks good, a couple of nits then ready to go!

hamistao
hamistao previously approved these changes Aug 2, 2024
Copy link
Copy Markdown
@hamistao hamistao left a comment

Choose a reason for hiding this comment

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

As far as the metrics go, this look good. Thanks for this, will help a lot!

Comment thread lxd/db/cluster/identities.go
Signed-off-by: Mark Laing <mark.laing@canonical.com>
Signed-off-by: Mark Laing <mark.laing@canonical.com>
Signed-off-by: Mark Laing <mark.laing@canonical.com>
@markylaing markylaing force-pushed the entity-type-refactor-simplified branch from e1298b9 to fa09b2e Compare August 2, 2024 14:59
Copy link
Copy Markdown
Member
@tomponline tomponline left a comment

Choose a reason for hiding this comment

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

Thanks!

@tomponline tomponline merged commit 156ce71 into canonical:main Aug 2, 2024
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.

Refactor entity types for maintainability

3 participants

0