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

Refactor RealmContext to RealmId #741

Merged
merged 2 commits into from
Jan 15, 2025
Merged

Conversation

snazy
Copy link
Member

@snazy snazy commented Jan 14, 2025

RealmContext is not an actual context but just a container for the ID of the realm. This change makes this explicit.

helm/polaris/README.md Outdated Show resolved Hide resolved

@ApplicationScoped
public class QuarkusValueExpressionResolver implements ValueExpressionResolver {

@Override
public String resolve(@Nonnull String expression, @Nullable Object parameter) {
// TODO maybe replace with CEL of some expression engine and make this more generic
if (parameter instanceof RealmContext realmContext && expression.equals("realmIdentifier")) {
return realmContext.getRealmIdentifier();
if (parameter instanceof RealmId realmId && expression.equals("realmIdentifier")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This class exists only because the old RealmContext did not have a meaningful toString() representation.

When this class is passed as a method argument to a generated API method:

@Context @MeterTag(key="realm_id",expression="realmIdentifier") RealmContext realmContext

I had to use an expression + expression resolver in order to extract the id from RealmContext.

Question: is it possible for RealmId to have a custom toString() representation that simply returns the realm ID? In this case we can get rid of the expression + resolver.

Copy link
Member Author

Choose a reason for hiding this comment

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

Let me check...

Copy link
Member Author

Choose a reason for hiding this comment

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

works

Copy link
Member Author

Choose a reason for hiding this comment

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

meh - does not work :(

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, let's at least change the expression from "realmIdentifier" to "id" – I mean, for now it doesn't matter (it could be any string), but if we ever introduce CEL, then the expression must be valid.

Copy link
Member Author

Choose a reason for hiding this comment

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

shouldn't it be "realm.id" ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm yes, that's probably better 👍

@snazy snazy force-pushed the rename-realm-context branch 3 times, most recently from b8de206 to 166b8ed Compare January 14, 2025 13:17
@snazy snazy force-pushed the rename-realm-context branch 2 times, most recently from cdd336e to e273f1f Compare January 14, 2025 13:51
Copy link
Contributor

@dimas-b dimas-b left a comment

Choose a reason for hiding this comment

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

The new RealmId name does look more appropriate given its usage.

snazy added 2 commits January 14, 2025 22:47
`RealmContext` is not an actual context but just a container for the ID of the realm. This change makes this explicit.
@snazy snazy force-pushed the rename-realm-context branch from e273f1f to be51c21 Compare January 14, 2025 21:49
@PolarisImmutable
@JsonSerialize(as = ImmutableRealmId.class)
@JsonDeserialize(as = ImmutableRealmId.class)
public interface RealmId {
Copy link
Contributor

Choose a reason for hiding this comment

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

If we were making this change, why don't we call it Realm, instead of RealmId?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because it's the ID of a realm - not the realm itself.

Copy link
Contributor

Choose a reason for hiding this comment

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

The realmId used to be a simple string, but it has now been replaced by a RealmId type, which contains a field called id—essentially an id of an id. While this approach works, it feels cumbersome and lacks extensibility. For instance, if we want to add new fields like a description for a realm, we would have to either include it under this interface or create a separate interface, such as Realm or RealmContext.

Adding new fields directly under RealmId feels odd since these fields typically represent a concept that is part of a realm rather than the realmId. On the other hand, introducing a separate interface adds complexity by requiring an additional structure to be defined.

Additionally, I’m questioning whether the concepts of realm and realmId are truly distinct or interchangeable. If they are interchangeable, using the name realm instead of realmId might be a more concise and descriptive choice, simplifying the naming and making the code easier to understand.

Copy link
Contributor

@flyrain flyrain left a comment

Choose a reason for hiding this comment

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

This is a breaking change and is not compatible with the existing deployment. I'm fine with moving forward if others are comfortable with it, but I’d like to hear more input from the team first. cc @dennishuo @collado-mike @eric-maynard

Copy link
Contributor

@collado-mike collado-mike left a comment

Choose a reason for hiding this comment

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

This seems innocuous enough. My main concern would be if application users suddenly didn't see the keys they were looking for in the logs or the headers suddenly stopped working, bug AFAICT, there are no such changes

@snazy snazy merged commit 390f1fa into apache:main Jan 15, 2025
5 checks passed
@snazy snazy deleted the rename-realm-context branch January 15, 2025 06:16
@flyrain
Copy link
Contributor

flyrain commented Jan 16, 2025

Please don’t merge a PR if there are open comments. It’s important to work through all feedback, especially for something as impactful as a breaking change. Plus this isn’t an urgent fix, and just filed 2 days ago, we should take the time to think it through carefully before merging.
cc @RussellSpitzer @jbonofre @eric-maynard @collado-mike @dennishuo

@collado-mike
Copy link
Contributor

Please don’t merge a PR if there are open comments. It’s important to work through all feedback, especially for something as impactful as a breaking change. Plus this isn’t an urgent fix, and just filed 2 days ago, we should take the time to think it through carefully before merging.

+1 There are a lot of changes to interfaces and user-facing APIs being pushed and some of them are not really more than cosmetic. I'm all for refactoring and nailing down the right APIs, but these changes should have appropriate review and feedback. If there are open comments, people shouldn't be merging without closing the conversation first.

@jbonofre
Copy link
Member

Please don’t merge a PR if there are open comments. It’s important to work through all feedback, especially for something as impactful as a breaking change. Plus this isn’t an urgent fix, and just filed 2 days ago, we should take the time to think it through carefully before merging.

cc @RussellSpitzer @jbonofre @eric-maynard @collado-mike @dennishuo

Absolutely ! It's required in an Apache project to have collaboration. If it helps we can enabled blocking PR merge if all discussions are not resolved.

@snazy
Copy link
Member Author

snazy commented Jan 16, 2025

Please don’t merge a PR if there are open comments. It’s important to work through all feedback, especially for something as impactful as a breaking change. Plus this isn’t an urgent fix, and just filed 2 days ago, we should take the time to think it through carefully before merging.

@flyrain @jbonofre The PR got two approvals. The comment with the approval from @collado-mike answering your question: "This seems innocuous enough. My main concern would be if application users suddenly didn't see the keys they were looking for in the logs or the headers suddenly stopped working, bug AFAICT, there are no such changes" (emphasis mine)

BTW: This RealmId is still an interface - so I do not understand why this could not be extended. The documentation did and still clearly states that this type is used to identify the realm from a REST request - and from a REST request all you have is the ID.

@jbonofre
Copy link
Member

Please don’t merge a PR if there are open comments. It’s important to work through all feedback, especially for something as impactful as a breaking change. Plus this isn’t an urgent fix, and just filed 2 days ago, we should take the time to think it through carefully before merging.

@flyrain @jbonofre The PR got two approvals. The comment with the approval from @collado-mike answering your question: "This seems innocuous enough. My main concern would be if application users suddenly didn't see the keys they were looking for in the logs or the headers suddenly stopped working, bug AFAICT, there are no such changes" (emphasis mine)

BTW: This RealmId is still an interface - so I do not understand why this could not be extended. The documentation did and still clearly states that this type is used to identify the realm from a REST request - and from a REST request all you have is the ID.

My previous comment was a general one: if there are comments before merge it should be considered. For this PR in particular, we had approval from two committers and no non resolved discussions (before the merge) so we are probably fine. If it needs to be revisited later, a committer can open a revert PR or an update PR that's fine.

@collado-mike
Copy link
Contributor

The comment with the approval from @collado-mike answering your question

I explicitly did not mark the PR as approved, as I was expecting for other folks to chime in. The change does seem innocuous, but I think asking to wait for feedback and the expectation to wait for @flyrain to resolve the conversation before merging seems reasonable

@collado-mike
Copy link
Contributor

I explicitly did not mark the PR as approved, as I was expecting for other folks to chime in

Shoot. I didn't mean to click approve. Sorry about the confusion. I meant for others to be able to chime in

@sfc-gh-ygu
Copy link
Contributor

no non resolved discussions (before the merge)

@jbonofre This comment wasn't resolved before the merge, #741 (comment).

@snazy, we don’t really need an interface for an ID. An ID is just a string, which I see as an atomic concept—simple and self-contained, without properties. Adding sub-properties to an ID interface (e.g., RealmId) feels conceptually incorrect and somewhat counterintuitive. Given this, I believe names like RealmContext or Realm are much more fitting for the interface, as they better reflect the broader context or functionality it represents. This assumes we need an interface here. For any use case just requiring an id, we could use a string type instead of an interface.

@snazy
Copy link
Member Author

snazy commented Jan 17, 2025

A distinct type is needed to eventually inject it via CDI. Further, a distinct type makes it very clear that this string is the realm-id. I also noted above that the docs for this interface clearly state that this type represents the realm-ID extracted from a REST request - and there is only the ID that can be extracted from a REST request. That can then be used to get more information.

@flyrain
Copy link
Contributor

flyrain commented Jan 17, 2025

If the ID is the only element we need to extract, realm is a better choice than RealmId due to its simplicity and conciseness. For instance, we wouldn't use nameId for name, cityId for city, or ageId for age when they all inherently refer to the same concept.

@snazy
Copy link
Member Author

snazy commented Jan 17, 2025

If the ID is the only element we need to extract, realm is a better choice than RealmId due to its simplicity and conciseness. For instance, we wouldn't use nameId for name, cityId for city, or ageId for age when they all inherently refer to the same concept.

That's your personal preference, right?

@flyrain
Copy link
Contributor

flyrain commented Jan 17, 2025

If my name is Bob, I will be uncomfortable if others call me BobID.

@eric-maynard
Copy link
Contributor

Is the RealmId object itself the identifier, or does RealmId.id return the identifier? It can't be both.

@dimas-b
Copy link
Contributor

dimas-b commented Jan 17, 2025

I'll add my 2 cents, since I commented above saying that the renaming made sense :)

It's true that RealmId by itself is not used as the realm's identifier in code. However, the real identifier is a String, so to add type safety and simplify usage searches (in IDEs), I still think using a dedicated "holder" class for that ID makes sense.

As to Realm vs. RealmId, I think the former implies that the realm's data or content is held by the object, which is not the case. Only the ID is held inside that object.

Now, I see that RealmId.id may look awkward. I think it would also be ok for follow-up PRs to rename that. I'm personally ok with RealmId.id(), but RealmId.asString() would also work from my POV (but it's more verbose).

flyrain added a commit that referenced this pull request Feb 3, 2025
* Revert "Copy RealmId when passing it to TaskExecutorImpl (#879)"

This reverts commit febe4e8.

* Revert #741
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.

8 participants