Skip to content

android: move common yaml configuration down to java layer#385

Merged
buildbreaker merged 17 commits intomasterfrom
ac/move-configuration
Sep 4, 2019
Merged

android: move common yaml configuration down to java layer#385
buildbreaker merged 17 commits intomasterfrom
ac/move-configuration

Conversation

@buildbreaker
Copy link
Copy Markdown

@buildbreaker buildbreaker commented Aug 26, 2019

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 Engine layer 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:]

public final int dnsRefreshSeconds;
public final int statsFlushSeconds;

public EnvoyConfiguration(String configYAML, int connectTimeoutSeconds, int dnsRefreshSeconds,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 resolve is called). Can we inline some documentation for this here @buildbreaker?

Copy link
Copy Markdown
Contributor

@rebello95 rebello95 left a comment

Choose a reason for hiding this comment

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

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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we abstract the EnvoyConfiguration into a private/internal function so we can test that it's properly initialized?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Discussed further offline and we will:

  • Have EnvoyConfiguration only 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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

^ SGTM

public final int dnsRefreshSeconds;
public final int statsFlushSeconds;

public EnvoyConfiguration(String configYAML, int connectTimeoutSeconds, int dnsRefreshSeconds,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 resolve is called). Can we inline some documentation for this here @buildbreaker?

@buildbreaker buildbreaker marked this pull request as ready for review September 3, 2019 20:07
Alan Chiu added 12 commits September 3, 2019 13:13
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>
fix
Signed-off-by: Alan Chiu <achiu@lyft.com>
Signed-off-by: Alan Chiu <achiu@lyft.com>
Signed-off-by: Alan Chiu <achiu@lyft.com>
fix
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>
Signed-off-by: Alan Chiu <achiu@lyft.com>
@buildbreaker buildbreaker changed the title android: move yaml configuration down to java layer android: move common yaml configuration down to java layer Sep 4, 2019
Signed-off-by: Alan Chiu <achiu@lyft.com>
Copy link
Copy Markdown
Contributor

@rebello95 rebello95 left a comment

Choose a reason for hiding this comment

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

LGTM overall, some final comments

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")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe also assert that the template doesn't contain any {{?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not sure this really provides any benefit 🤷‍♂

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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>
rebello95
rebello95 previously approved these changes Sep 4, 2019
Signed-off-by: Alan Chiu <achiu@lyft.com>
rebello95
rebello95 previously approved these changes Sep 4, 2019
fix
Signed-off-by: Alan Chiu <achiu@lyft.com>
fix
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) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sure, I'm good with that

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Actually, let's revisit at a later date on this 😬

Copy link
Copy Markdown
Contributor

@goaway goaway left a comment

Choose a reason for hiding this comment

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

Overall this looks great. One suggestion above.

@buildbreaker buildbreaker merged commit b9b1370 into master Sep 4, 2019
@buildbreaker buildbreaker deleted the ac/move-configuration branch September 4, 2019 22:39
rebello95 added a commit that referenced this pull request Sep 6, 2019
This is a mirror of the Android change made in #385.

Signed-off-by: Michael Rebello <me@michaelrebello.com>
rebello95 added a commit that referenced this pull request Sep 6, 2019
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>
jpsim pushed a commit to envoyproxy/envoy that referenced this pull request Nov 28, 2022
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>
jpsim pushed a commit to envoyproxy/envoy that referenced this pull request Nov 29, 2022
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>
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.

3 participants