-
Notifications
You must be signed in to change notification settings - Fork 108
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
Prevent config rendering on every process #3011
base: main
Are you sure you want to change the base?
Conversation
64265cd
to
16d7df1
Compare
…date_env() instead
1affb5f
to
2aa9588
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.
Just some small stuff.
So if we save the config to an env var, we don't get the templating breaking on get_env
secondary calls? Since we only do it once, is that what this PR is solving?
@@ -327,15 +331,50 @@ pub struct LayerConfig { | |||
} | |||
|
|||
impl LayerConfig { | |||
/// Given an encoded complete config from the [`MIRRORD_RESOLVED_CONFIG_ENV`] | |||
/// env var, attempt to decode it into [`LayerConfig`]. | |||
/// Intended to avoid re-resolving the config in every process mirrord in loaded into |
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.
/// Intended to avoid re-resolving the config in every process mirrord in loaded into | |
/// Intended to avoid re-resolving the config in every process mirrord is loaded into. |
Ok(BASE64_STANDARD.encode(serialized)) | ||
} | ||
|
||
pub fn update_env(&self) -> Result<(), ConfigError> { |
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.
pub fn update_env(&self) -> Result<(), ConfigError> { | |
pub fn update_env_var(&self) -> Result<(), ConfigError> { |
Nit, since the others are *_env_var
.
/// checks that resolved config written to [`MIRRORD_RESOLVED_CONFIG_ENV`] can be | ||
/// transformed back into a [`LayerConfig`] | ||
#[test] | ||
fn encode_and_decode_config() { |
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 have a test value with a filled config too, instead of just default values.
Wdyt?
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.
good idea, i can hit some more unusual cases 🫡
Ok(serde_json::from_str::<Self>(serialized)?) | ||
} | ||
|
||
pub fn to_env_var(&self) -> Result<String, ConfigError> { |
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.
Docs for this new friend.
Ok(BASE64_STANDARD.encode(serialized)) | ||
} | ||
|
||
pub fn update_env(&self) -> Result<(), ConfigError> { |
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.
Docs for this new friend.
/// Given an encoded complete config from the [`MIRRORD_RESOLVED_CONFIG_ENV`] | ||
/// env var, attempt to decode it into [`LayerConfig`]. | ||
/// Intended to avoid re-resolving the config in every process mirrord in loaded into | ||
pub fn from_env_var(encoded_value: String) -> Result<Self, ConfigError> { |
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.
Do we need this to be pub
?
Ok(serde_json::from_str::<Self>(serialized)?) | ||
} | ||
|
||
pub fn to_env_var(&self) -> Result<String, ConfigError> { |
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.
Do we need this to be pub
?
MIRRORD_CONNECT_TCP_ENV.to_string(), | ||
format!("127.0.0.1:{}", address.port()), | ||
); | ||
let mut config = config.clone(); |
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.
Instead of clone
to mut
here, why not take this as &mut
in the function args?
@meowjesty That's correct - the config template variables get resolved when the config file is rendered by Tera, which previously happened on every process. This causes an issue when a process tries to, for example, call |
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 would check mirrord container
due to changes to MIRRORD_CONNECT_TCP_ENV
in exec, it should work but I would double check
@@ -354,7 +354,7 @@ pub struct AgentConfig { | |||
/// Create an agent that returns an error after accepting the first client. For testing | |||
/// purposes. Only supported with job agents (not with ephemeral agents). | |||
#[cfg(all(debug_assertions, not(test)))] // not(test) so that it's not included in the schema json. | |||
#[serde(skip_serializing)] | |||
#[serde(skip_serializing, skip_deserializing)] |
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.
#[serde(skip_serializing, skip_deserializing)] | |
#[serde(skip)] |
MIRRORD_CONNECT_TCP_ENV.to_string(), | ||
format!("127.0.0.1:{}", address.port()), | ||
); | ||
let mut config = config.clone(); |
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.
Im a bit worried for container feature behaviour where we split up the env variables for sidecar and main container relying on MIRRORD_CONNECT_TCP_ENV
as env value
} | ||
|
||
pub fn update_env(&self) -> Result<(), ConfigError> { | ||
std::env::set_var(MIRRORD_RESOLVED_CONFIG_ENV, self.to_env_var()?); |
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.
There might be a problem with using env variables due to size (especially if tls certs are included),my local test macos can handle ~512mb
but can possibly cause a problem on some linux distribution
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.
Good point. Think we could save it to /tmp
and refresh it from there?
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.
Closes #2936