Skip to content
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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

gememma
Copy link
Member

@gememma gememma commented Jan 10, 2025

Closes #2936

@gememma gememma force-pushed the gemma/config-resolution-hang branch from 64265cd to 16d7df1 Compare January 10, 2025 15:00
@gememma gememma force-pushed the gemma/config-resolution-hang branch from 1affb5f to 2aa9588 Compare January 14, 2025 13:45
@meowjesty meowjesty self-assigned this Jan 14, 2025
@Razz4780 Razz4780 requested a review from DmitryDodzin January 14, 2025 14:43
Copy link
Member

@meowjesty meowjesty left a 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?

mirrord/config/Cargo.toml Show resolved Hide resolved
@@ -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
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// 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> {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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() {
Copy link
Member

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?

Copy link
Member Author

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> {
Copy link
Member

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> {
Copy link
Member

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> {
Copy link
Member

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> {
Copy link
Member

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();
Copy link
Member

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?

@gememma
Copy link
Member Author

gememma commented Jan 14, 2025

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?

@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 get_env() to render the config but the process doesnt have access to the same env as previous ones - doing the get_env() call only once will solve this :) plus I think this way is more sensible in terms of reducing pointless recalculation and having fewer sources of truth

Copy link
Member

@DmitryDodzin DmitryDodzin left a 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)]
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
#[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();
Copy link
Member

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()?);
Copy link
Member

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

Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

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

this honestly didnt even occur to me 🙃 @aviramha @Razz4780 any opinions on this? i feel like there was maybe a reason to avoid using /tmp ?

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.

mirrord + vscode + templating seems to get ide to hang
3 participants