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

DefaultContextResolver should respect the defaultRealm configuration #309

Merged
merged 10 commits into from
Oct 19, 2024

Conversation

eric-maynard
Copy link
Contributor

Description

Previously DefaultContextResolver would always use default-realm as the default realm regardless of the configuration for defaultRealm. This PR fixes this behavior.

Fixes #281

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • Documentation update
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

Please delete options that are not relevant.

  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings

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.

Thanks @eric-maynard for working on it! Left some comments. Let me know if they make sense. Also this changes the behavior a bit, I believe it's worthwhile to add a test.

Comment on lines +94 to 95
realmContextResolver.setDefaultRealm(this.defaultRealm);
return realmContextResolver;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we combine these two fields(defaultRealm, realmContextResolver) to one? I don't see a reason to keep both of them. I'd prefer to keep the resolver, which may have different implementations.

What we can do is to mimic the rate limiter. The default realm name can be picked up by the implementation itself, instead of setting a string field then pass it to the resolver.

  @JsonProperty("rateLimiter")
  public RateLimiter getRateLimiter() {
    return rateLimiter;
  }

  @JsonProperty("rateLimiter")
  public void setRateLimiter(@Nullable RateLimiter rateLimiter) {
    this.rateLimiter = rateLimiter;
  }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm confused by this suggestion; the linked issue is about users not being able to pass an explicit string default via the config. Are you suggesting that we remove the config?

Copy link
Contributor

Choose a reason for hiding this comment

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

ah, I wasn't clear in the first place. I think we can combine these two configs to one.

realmContextResolver:
  type: default

defaultRealms:
  - default-realm

To

realmContextResolver:
  type: default
  defaultRealms: default-realm

With that, we don't have to keep two fields in the config class, and I think it is a nice way to manage the lifecycle of realmContextResolver. It could be immutable object without any setting methods.

Copy link
Contributor

@flyrain flyrain Oct 9, 2024

Choose a reason for hiding this comment

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

If we made the above change, I think we don't have to make the interface changes in RealmContextResolver. We just need to add a constructor in the class DefaultContextResolver like this

public DefaultContextResolver( @JsonProperty("defaultRealms") final String defaultRealm) {
    this.defaultRealm = defaultRealm;
}

Not setter and getter are needed in this way. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removing the default constructor is still a breaking change, so is this materially better?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, to be clear, we are not just changing how this works for DefaultContextResolver but for all RealmContextResolver implementations

Copy link
Contributor

Choose a reason for hiding this comment

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

It is cleaner solution unless the config defaultRealm would be used by other places than RealmContextResolver. Do we?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The defaultRealm is just the default realm used by RealmContextResolver when the realm cannot be parsed from the request

Copy link
Contributor

Choose a reason for hiding this comment

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

Synced with @eric-maynard offline, we agreed on pushing this break change to another PR.

@flyrain flyrain merged commit f1d46c5 into apache:main Oct 19, 2024
5 checks passed
@flyrain
Copy link
Contributor

flyrain commented Oct 19, 2024

Thanks @eric-maynard for the fix!

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.

[BUG] DefaultContextResolver is not using defaultRealm value from the PolarisApplicationConfig
3 participants