-
Notifications
You must be signed in to change notification settings - Fork 299
Add parameters to Remote Config template #479
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
Conversation
5e0dc25 to
b5878b3
Compare
b5878b3 to
fa23a4d
Compare
1480b24 to
83c69db
Compare
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.
Looks pretty good. I suggested a few renames and test additions.
src/main/java/com/google/firebase/remoteconfig/ExplicitParameterValue.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigClientImpl.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/firebase/remoteconfig/InAppDefaultValue.java
Outdated
Show resolved
Hide resolved
|
|
||
| public RemoteConfigParameter() { | ||
| conditionalValues = new HashMap<>(); | ||
| defaultValue = ExplicitParameterValue.of(""); |
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.
Why this default value?
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.
If no default value is set (if defaultValue is null), the REST API sets the default value to an empty string. We can allow null here and add a null check in the conversion or just set it to an empty value in the ctor.
src/main/java/com/google/firebase/remoteconfig/RemoteConfigParameter.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/firebase/remoteconfig/internal/TemplateResponse.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/firebase/remoteconfig/internal/TemplateResponse.java
Outdated
Show resolved
Hide resolved
src/test/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigClientImplTest.java
Outdated
Show resolved
Hide resolved
src/test/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigClientImplTest.java
Outdated
Show resolved
Hide resolved
src/test/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigClientImplTest.java
Show resolved
Hide resolved
b48cf0e to
0dcf08e
Compare
0dcf08e to
0f5d2c7
Compare
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.
Looks great. Just a couple of suggestions.
| public RemoteConfigParameter() { | ||
| conditionalValues = new HashMap<>(); | ||
| defaultValue = ExplicitParameterValue.of(""); | ||
| defaultValue = RemoteConfigParameterValue.of(""); |
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 feel like both these should remain null until explicitly set. It's ok to let the backend choose default values for these as necessary.
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 see your point. Updated the code and added null checks in conversions.
I have a few concerns with setting these to null though. Isn't it recommended not to return null collections in Java? If we don't set to conditionalValues to an empty map at init, the following will throw an exception on the client side.
RemoteConfigParameter p = new RemoteConfigParameter().getConditionalValues().put("ios_en", ParameterValue.of("text")
This can be prevented with a simple null check on the client side, though.
| assertTrue(parameters.containsKey("header_text")); | ||
| Map<String, RemoteConfigParameterValue> conditionalValues = parameters | ||
| .get("welcome_message_text").getConditionalValues(); | ||
| RemoteConfigParameter parameter = parameters.get("welcome_message_text"); |
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.
Also assert on header_text which has an in app default value param.
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.
A couple suggested edits and a few questions, thanks!
|
|
||
| /** | ||
| * Gets the conditional values of the parameter. | ||
| * The condition name of the highest priority (the one listed first in the |
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 is interesting . . . you mean this gets all the possible values, including the one actually assigned -- for a particular client instance? -- in the top position in the map?
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 gets all the conditional values assigned for that specific parameter. You can set a default value in a parameter to be used when all the conditional values are evaluated to false. Otherwise, the parameter will use the conditional value with the highest priority. The priority is determined by the order of the conditions are stored in the top-level conditions array of the RemoteConfigTemplate. The top-level conditions array is not part of this PR and will be added in a future PR.
https://firebase.google.com/docs/reference/remote-config/rest/v1/RemoteConfigParameter
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.
OK, thanks for the explanation. Parameter evaluation is pretty complex . . . when everything is done, I might try to start a review of our "parameters and conditions" concepts page, just to make sure it's all still accurate.
|
|
||
| /** | ||
| * Sets the default value of the parameter. | ||
| * This is the value to set the parameter to, when none of the named conditions |
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.
Does the developer actually set the value? Or does our backend logic?
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.
When getting an existing template the backend will set the values for existing Parameters. If the developer wants to create and add new parameters then they can set a default value to set the parameter to, when none of the named conditions evaluate to true.
| } | ||
|
|
||
| /** | ||
| * Sets the conditional values of the parameter. |
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.
Again this is maybe just my own confusion, but -- I can see how a developer might want to automate the setting of a list of conditional values. But isn't the actual value sort of set at runtime, after evaluating the conditions?
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.
When creating new parameters the developer needs to add conditional values manually. The condition names in conditionalValues map must match the names in the top-level conditions array in RemoteConfigTemplate. Otherwise, the API will throw a condition does not exist error.
| } | ||
|
|
||
| /** | ||
| * Represents an in-app-default parameter value. |
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.
Suggest removing the hyphen between app and default.
| } | ||
|
|
||
| /** | ||
| * The DTO for parsing Remote Config parameter value responses from the Remote Config service. |
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 wonder if we should spell out "Data Transfer Object" -- that's what this is, right? :)
I searched and couldn't immediately find a single other instance of "DTO" in docs/reference/
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 the classes in internal packages do not show up in the docs. I agree though Data Transfer Object makes more sense. I will update the comment here. Thanks!!
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.
Looks good Lahiru, thanks!
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.
The semantics aren't quite sitting well with me. But let's merge this and address any concerns later.
| return new RemoteConfigParameter() | ||
| .setDefaultValue(defaultValue.toRemoteConfigParameterValue()) | ||
| .setDefaultValue(remoteConfigParameterValue) | ||
| .setDescription(description).setConditionalValues(conditionalPublicValues); |
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.
Nit: One setter per line
| public ParameterResponse(@Nullable ParameterValueResponse defaultValue, | ||
| @Nullable String description, | ||
| @NonNull Map<String, ParameterValueResponse> conditionalValues) { | ||
| checkNotNull(conditionalValues, "conditional values must not be null."); |
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.
Probably redundant at this level.
Response TypesandPublic TypestoResponseType()andtoPublicType()parameterstoRemoteConfigTemplateRelated Issue: #446