-
Notifications
You must be signed in to change notification settings - Fork 233
Remove defaults
/ overrides
from feature configurations
#1572
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
Changes from all commits
21df5a5
5a3b827
81d842e
c03b04d
63213b9
363250d
7959c72
44db4f5
6cd9bc4
a20984c
8a07197
439ab04
7761cc0
a1d2d45
ef79de5
9819f3d
fe38c22
ef31c93
61383a8
ba263af
d90a4f8
5e0c8b8
f2f3e63
c04b2d4
b7462ad
1713f38
a0adc9e
04fea8f
5b3a11b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,15 +19,23 @@ | |
package org.apache.polaris.service.quarkus.config; | ||
|
||
import io.smallrye.config.ConfigMapping; | ||
import io.smallrye.config.WithParentName; | ||
import java.util.Map; | ||
import org.apache.polaris.service.config.FeaturesConfiguration; | ||
|
||
@ConfigMapping(prefix = "polaris.features") | ||
public interface QuarkusFeaturesConfiguration extends FeaturesConfiguration { | ||
|
||
@WithParentName | ||
@Override | ||
Map<String, String> defaults(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI this is creating an unwanted behavior: I injected
You will notice the strange The contents of
At this point, I wonder if a better solution wouldn't be to simply define one single map here to hold all the configs: public interface QuarkusFeaturesConfiguration extends FeaturesConfiguration {
@WithParentName
@Override
Map<String, String> allConfigs();
} And parse that map manually (we are already doing it half-manually anyway): public interface FeaturesConfiguration {
Map<String, String> allConfigs();
default Map<String, Object> parseDefaults(ObjectMapper objectMapper) {
Map<String, Object> defaults = new HashMap<>();
for (String key : allConfigs().keySet()) {
if (!key.contains(".")) {
defaults.put(key, convertProperty(objectMapper, key, allConfigs().get(key)));
}
}
return defaults;
}
default Map<String, Map<String, Object>> parseRealmOverrides(ObjectMapper objectMapper) {
Map<String, Map<String, Object>> realmOverrides = new HashMap<>();
for (String key : allConfigs().keySet()) {
if (key.contains(".")) {
String[] parts = key.split("\\.");
String realm = parts[0];
String configName = parts[1];
Map<String, Object> realmValues = realmOverrides.computeIfAbsent(realm, k -> new HashMap<>());
realmValues.put(configName, convertProperty(objectMapper, key, allConfigs().get(key)));
}
}
return realmOverrides;
}
private static Object convertProperty(ObjectMapper objectMapper, String key, String value) {
try {
JsonNode node = objectMapper.readTree(value);
return configValue(node);
} catch (JsonProcessingException e) {
throw new RuntimeException(
"Invalid JSON value for feature configuration: " + key, e);
}
}
private static Object configValue(JsonNode node) {
// same as before
}
} WDYT? (this obviously assumes that a feature configuration name cannot contain a dot.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see the same thing, thanks for highlighting this. One doubt I have is this: if we assume config names can't contain a dot, is the current behavior okay? Since Also, either way I can add some code enforcing that config keys don't contain a dot. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel uncomfortable if we don't fix this, I confess. We know that (Side note: my suggestion above goes a bit further than that, actually: it also removes the need to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, let's fix it then! I was able to pull in your change and I see it working, but I have some reservations:
If it's alright with you, I will try to implement your suggestion in a way that preserves the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also thought of one other concern -- we may need a more sophisticated approach to parsing.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds like a plan! 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For now, I added another wrapper around the FeaturesConfiguration to clean out the properties. It may be a bit hacky but it does address the bad entries in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Indeed. My example did not cover these corner cases, but you are right that we need to deal with dots in realm ids and also quoted identifiers. |
||
|
||
@Override | ||
Map<String, FeaturesConfiguration.RealmOverrides> realmOverrides(); | ||
Map<String, QuarkusRealmOverrides> realmOverrides(); | ||
|
||
interface QuarkusRealmOverrides extends RealmOverrides { | ||
@WithParentName | ||
@Override | ||
Map<String, String> overrides(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.polaris.service.quarkus.config; | ||
|
||
import jakarta.annotation.Priority; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.enterprise.inject.Alternative; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* Wraps around {@link QuarkusBehaviorChangesConfiguration} but removes properties from `defaults` | ||
* that shouldn't be there | ||
*/ | ||
@ApplicationScoped | ||
@Alternative | ||
@Priority(1) | ||
public class QuarkusResolvedBehaviorChangesConfiguration | ||
implements QuarkusBehaviorChangesConfiguration { | ||
|
||
private final Map<String, String> cleanedDefaults; | ||
private final Map<String, ? extends QuarkusBehaviorChangesConfiguration.QuarkusRealmOverrides> | ||
realmOverrides; | ||
|
||
public QuarkusResolvedBehaviorChangesConfiguration(QuarkusBehaviorChangesConfiguration raw) { | ||
this.realmOverrides = raw.realmOverrides(); | ||
|
||
// Filter out any keys that look like realm overrides | ||
this.cleanedDefaults = | ||
raw.defaults().entrySet().stream() | ||
.filter(e -> e.getKey().split("\\.").length == 1) | ||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); | ||
} | ||
|
||
@Override | ||
public Map<String, String> defaults() { | ||
return cleanedDefaults; | ||
} | ||
|
||
@Override | ||
public Map<String, ? extends QuarkusBehaviorChangesConfiguration.QuarkusRealmOverrides> | ||
realmOverrides() { | ||
return realmOverrides; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.polaris.service.quarkus.config; | ||
|
||
import jakarta.annotation.Priority; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.enterprise.inject.Alternative; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
import org.apache.polaris.service.config.FeaturesConfiguration; | ||
|
||
/** | ||
* Wraps around {@link QuarkusFeaturesConfiguration} but removes properties from `defaults` that | ||
* shouldn't be there | ||
*/ | ||
@ApplicationScoped | ||
@Alternative | ||
@Priority(1) | ||
public class QuarkusResolvedFeaturesConfiguration implements FeaturesConfiguration { | ||
|
||
private final Map<String, String> cleanedDefaults; | ||
private final Map<String, ? extends RealmOverrides> realmOverrides; | ||
|
||
public QuarkusResolvedFeaturesConfiguration(QuarkusFeaturesConfiguration raw) { | ||
this.realmOverrides = raw.realmOverrides(); | ||
|
||
// Filter out any keys that look like realm overrides | ||
this.cleanedDefaults = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you could just introduce a default method in @Override
public Map<String, String> cleanedDefaults() {
return defaults().entrySet().stream()
.filter(e -> e.getKey().split("\\.").length == 1)
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
} But I'm OK with this alternative bean. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That will work, but it seems like we risk a caller using the |
||
raw.defaults().entrySet().stream() | ||
.filter(e -> e.getKey().split("\\.").length == 1) | ||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); | ||
} | ||
|
||
@Override | ||
public Map<String, String> defaults() { | ||
return cleanedDefaults; | ||
} | ||
|
||
@Override | ||
public Map<String, ? extends RealmOverrides> realmOverrides() { | ||
return realmOverrides; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eric-maynard and @adutra so are we changing how default parameters are configured ? i though we intended to stay as the same behavior before to avoid uncessary regression to existing users?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was changed in between 0.9 and 0.10, so changing it between 0.10 and 1.0 might not be so bad. We certainly should try to hammer this out before 1.0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that should be fine, just want to double confirm since that wasn't the original plan. Can i ask what is the reason for this behavior change ?