android: move common yaml configuration down to java layer#385
android: move common yaml configuration down to java layer#385buildbreaker merged 17 commits intomasterfrom
Conversation
| public final int dnsRefreshSeconds; | ||
| public final int statsFlushSeconds; | ||
|
|
||
| public EnvoyConfiguration(String configYAML, int connectTimeoutSeconds, int dnsRefreshSeconds, |
There was a problem hiding this comment.
I would make two constructors - one which takes just a yaml and another which takes the other parameters. The one which takes only yaml, should produce a configuration that is not interpolated, but rather is passed through directly. In other words, resolve should just pass-through a configYAML iff it's present.
There was a problem hiding this comment.
Talked offline with @buildbreaker about this and I agree with the 2-initializer approach. A couple other things to note though:
- The initializer that takes the
configYAML(pre-resolved) will not be used today, but will act as a convenience - The motivation for this PR/change is to defer calling into the JNI to get the template string until after the JNI is loaded (i.e., when
resolveis called). Can we inline some documentation for this here @buildbreaker?
library/java/src/io/envoyproxy/envoymobile/engine/EnvoyConfiguration.java
Outdated
Show resolved
Hide resolved
rebello95
left a comment
There was a problem hiding this comment.
I can make the equivalent change on iOS as well. Some comments.
| */ | ||
| fun build(): Envoy { | ||
| return Envoy(engineType(), resolvedYAML(), logLevel) | ||
| return Envoy(engineType(), EnvoyConfiguration(configYAML, connectTimeoutSeconds, dnsRefreshSeconds, statsFlushSeconds), logLevel) |
There was a problem hiding this comment.
Should we abstract the EnvoyConfiguration into a private/internal function so we can test that it's properly initialized?
There was a problem hiding this comment.
I don't quite understand what you have in mind here. Do you mean to have a way for us to create an EnvoyConfiguration with the appropriate values from the builder: initialize EnvoyConfiguration with a custom configuration versus with the connectTimeoutSeconds, dnsRefreshSeconds, statsFlushSeconds values?
There was a problem hiding this comment.
Discussed further offline and we will:
- Have
EnvoyConfigurationonly be used for template-based configurations and avoid conflating custom YAML configs with the template resolution - Add a constructor to Envoy Engine so we have one that takes an
EnvoyConfiguration(which resolves properties to the default template) or a custom string YAML file
library/java/src/io/envoyproxy/envoymobile/engine/EnvoyConfiguration.java
Outdated
Show resolved
Hide resolved
| public final int dnsRefreshSeconds; | ||
| public final int statsFlushSeconds; | ||
|
|
||
| public EnvoyConfiguration(String configYAML, int connectTimeoutSeconds, int dnsRefreshSeconds, |
There was a problem hiding this comment.
Talked offline with @buildbreaker about this and I agree with the 2-initializer approach. A couple other things to note though:
- The initializer that takes the
configYAML(pre-resolved) will not be used today, but will act as a convenience - The motivation for this PR/change is to defer calling into the JNI to get the template string until after the JNI is loaded (i.e., when
resolveis called). Can we inline some documentation for this here @buildbreaker?
Signed-off-by: Alan Chiu <achiu@lyft.com>
Signed-off-by: Alan Chiu <achiu@lyft.com>
Signed-off-by: Alan Chiu <achiu@lyft.com>
Signed-off-by: Alan Chiu <achiu@lyft.com>
b077bd1 to
af59361
Compare
library/java/src/io/envoyproxy/envoymobile/engine/EnvoyConfiguration.java
Outdated
Show resolved
Hide resolved
library/java/src/io/envoyproxy/envoymobile/engine/EnvoyConfiguration.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Alan Chiu <achiu@lyft.com>
rebello95
left a comment
There was a problem hiding this comment.
LGTM overall, some final comments
library/java/src/io/envoyproxy/envoymobile/engine/EnvoyConfiguration.java
Outdated
Show resolved
Hide resolved
library/java/src/io/envoyproxy/envoymobile/engine/EnvoyConfiguration.java
Outdated
Show resolved
Hide resolved
library/java/src/io/envoyproxy/envoymobile/engine/EnvoyEngine.java
Outdated
Show resolved
Hide resolved
library/java/src/io/envoyproxy/envoymobile/engine/EnvoyEngineImpl.java
Outdated
Show resolved
Hide resolved
| val resolvedTemplate = envoyConfiguration.resolveTemplate(TEST_CONFIG) | ||
| assertThat(resolvedTemplate).contains("connect_timeout: 123s") | ||
| assertThat(resolvedTemplate).contains("dns_refresh_rate: 234s") | ||
| assertThat(resolvedTemplate).contains("stats_flush_interval: 345s") |
There was a problem hiding this comment.
Maybe also assert that the template doesn't contain any {{?
There was a problem hiding this comment.
The behavior that is baked in the method is that if it contains any unresolved templates, we'll throw an exception so that test is: resolve templates with invalid templates will throw on build
| */ | ||
| fun build(): Envoy { | ||
| return Envoy(engineType(), resolvedYAML(), logLevel) | ||
| val configurationYAML = configYAML |
There was a problem hiding this comment.
Not sure this really provides any benefit 🤷♂
There was a problem hiding this comment.
It's a variable and the class isn't thread safe so the field could be changed between the lines of code. This way at the start of the method call we are guaranteed to have the correct configuration yaml...
Basically, I get it's silly but the IDE was complaining to me so I changed it :(
Signed-off-by: Alan Chiu <achiu@lyft.com>
| * @return String, the resolved template. | ||
| * @throws ConfigurationException, when the template provided is not fully resolved. | ||
| */ | ||
| String resolveTemplate(String templateYAML) { |
There was a problem hiding this comment.
Thoughts on moving the logic in this function into EnvoyConfigurationImpl (could be a helper method called out of runWithConfig)? That way the configuration really doesn't need to know or care about any implementation details of how its attributes are used.
There was a problem hiding this comment.
I can create another file which holds this method and just port the unit tests there -- it'll make this class a pure data class then. Wdyt?
cc: @rebello95
There was a problem hiding this comment.
Actually, let's revisit at a later date on this 😬
goaway
left a comment
There was a problem hiding this comment.
Overall this looks great. One suggestion above.
This is a mirror of the Android change made in #385. Signed-off-by: Michael Rebello <me@michaelrebello.com>
This is a mirror of the Android change made in #385. The change was originally motivated by the fact that Android was unable to obtain the configuration template within C++ before the JNI was loaded. Moving the template resolution logic to Java fixed this issue by allowing the JNI to be initialized before loading the template. Key changes in this PR: - Moved template resolution to Objective-C - Custom YAML files are no longer treated as templates, and are not resolved (but are passed through as-is). This matches Android - Updated initializers as necessary to match Android Signed-off-by: Michael Rebello <me@michaelrebello.com>
This is a mirror of the Android change made in envoyproxy/envoy-mobile#385. The change was originally motivated by the fact that Android was unable to obtain the configuration template within C++ before the JNI was loaded. Moving the template resolution logic to Java fixed this issue by allowing the JNI to be initialized before loading the template. Key changes in this PR: - Moved template resolution to Objective-C - Custom YAML files are no longer treated as templates, and are not resolved (but are passed through as-is). This matches Android - Updated initializers as necessary to match Android Signed-off-by: Michael Rebello <me@michaelrebello.com> Signed-off-by: JP Simard <jp@jpsim.com>
This is a mirror of the Android change made in envoyproxy/envoy-mobile#385. The change was originally motivated by the fact that Android was unable to obtain the configuration template within C++ before the JNI was loaded. Moving the template resolution logic to Java fixed this issue by allowing the JNI to be initialized before loading the template. Key changes in this PR: - Moved template resolution to Objective-C - Custom YAML files are no longer treated as templates, and are not resolved (but are passed through as-is). This matches Android - Updated initializers as necessary to match Android Signed-off-by: Michael Rebello <me@michaelrebello.com> Signed-off-by: JP Simard <jp@jpsim.com>
A small structural change to the configuration and builder relationship since we are unable to read the default configuration provided by the native layer without initializing the JNI library.
The change here is to move most of the configuration resolution down to the
Enginelayer since it is responsible for the JNI library interaction.Signed-off-by: Alan Chiu achiu@lyft.com
For an explanation of how to fill out the fields, please see the relevant section
in PULL_REQUESTS.md
Description: move common yaml configuration down to java layer
Risk Level: low
Testing: unit
Docs Changes: n/a
Release Notes: n/a
[Optional Fixes #Issue]
[Optional Deprecated:]