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

Entity type refactor (simplified) #13846

Merged

Conversation

markylaing
Copy link
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
Member

tomponline commented Aug 2, 2024

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

shared/entity/type.go Outdated Show resolved Hide resolved
@hamistao
Copy link
Contributor

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.

shared/entity/type.go Outdated Show resolved Hide resolved
lxd/db/cluster/stmt.go Outdated Show resolved Hide resolved
Copy link
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
Contributor

@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!

Copy link
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
28 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.

Refactor entity types for maintainability
3 participants