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

make better use of namespace storage #263

Closed
wants to merge 4 commits into from
Closed

Conversation

macovedj
Copy link
Collaborator

Rather than updating the state at the beginning of a client interaction to use a specific url, the client expects to check the namespace storage for a url and pass it as an arg, better enabling consumers to fetch packages across multiple namespaces.

There is also updated logic for encouraging standard ways of retrying with Warg-Hint-Header responses from the registry after using the hint to update local namespace mappings.

@macovedj macovedj force-pushed the namespace-enhancements branch from ba387f8 to dce70d8 Compare April 15, 2024 19:04
@macovedj macovedj force-pushed the namespace-enhancements branch from dce70d8 to 78a5571 Compare April 15, 2024 19:14
@calvinrp calvinrp requested a review from lann April 16, 2024 12:36
Copy link
Collaborator

@lann lann left a comment

Choose a reason for hiding this comment

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

Only maybe-blocker is question about error handling.

Comment on lines 114 to 123
let namespace_state = op.state.namespace_state(namespace);
if let Ok(Some(warg_protocol::operator::NamespaceState::Imported { registry })) =
namespace_state
{
return Ok(Some(RegistryDomain::from_str(registry)?));
} else if let Ok(Some(warg_protocol::operator::NamespaceState::Defined)) =
namespace_state
{
return Ok(None);
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: You'd typically use match here:

Suggested change
let namespace_state = op.state.namespace_state(namespace);
if let Ok(Some(warg_protocol::operator::NamespaceState::Imported { registry })) =
namespace_state
{
return Ok(Some(RegistryDomain::from_str(registry)?));
} else if let Ok(Some(warg_protocol::operator::NamespaceState::Defined)) =
namespace_state
{
return Ok(None);
};
match op.state.namespace_state(namespace) {
Ok(Some(warg_protocol::operator::NamespaceState::Imported { registry })) => {
return Ok(Some(RegistryDomain::from_str(registry)?));
}
Ok(Some(warg_protocol::operator::NamespaceState::Defined)) => {
return Ok(None);
}
_ => (),
}

.load_operator(Some(&RegistryDomain::from_str(namespace)?))
.await?;
if let Some(op) = operator {
let namespace_state = op.state.namespace_state(namespace);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are Errs expected here? Should probably at least log them if not propagating, unless there is a specific reason to completely suppress.

Comment on lines 498 to 503
let namespace_packages = namespaced.get_mut(namespace);
if let Some(nm_pkgs) = namespace_packages {
nm_pkgs.push(package);
} else {
namespaced.insert(namespace, vec![package]);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: There is a nice pattern for this:

Suggested change
let namespace_packages = namespaced.get_mut(namespace);
if let Some(nm_pkgs) = namespace_packages {
nm_pkgs.push(package);
} else {
namespaced.insert(namespace, vec![package]);
}
namespaced.entry(namespace).or_default().push(package);

src/bin/warg.rs Outdated
WargCli::Info(cmd) => cmd.clone().exec().await?,
WargCli::Key(cmd) => cmd.clone().exec().await?,
WargCli::Lock(cmd) => {
with_interactive_retry(|retry: Option<Retry>| async {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can this go outside the match? The commands that don't support retry shouldn't be returning this error anyway and can just ignore the retry variable?

Comment on lines 117 to 131
match op.state.namespace_state(namespace) {
Ok(Some(warg_protocol::operator::NamespaceState::Imported { registry })) => {
return Ok(Some(RegistryDomain::from_str(registry)?));
}
Ok(Some(warg_protocol::operator::NamespaceState::Defined)) => {
return Ok(None);
}
Ok(None) => return Ok(None),
Err(e) => {
return Err(ClientError::SimilarNamespace {
namespace: namespace.to_string(),
e: e.to_string(),
});
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

minor: its difficult to see that this if block always returns

Suggested change
match op.state.namespace_state(namespace) {
Ok(Some(warg_protocol::operator::NamespaceState::Imported { registry })) => {
return Ok(Some(RegistryDomain::from_str(registry)?));
}
Ok(Some(warg_protocol::operator::NamespaceState::Defined)) => {
return Ok(None);
}
Ok(None) => return Ok(None),
Err(e) => {
return Err(ClientError::SimilarNamespace {
namespace: namespace.to_string(),
e: e.to_string(),
});
}
}
return match op.state.namespace_state(namespace) {
Ok(Some(warg_protocol::operator::NamespaceState::Imported { registry })) => {
Ok(Some(RegistryDomain::from_str(registry)?))
}
Ok(Some(warg_protocol::operator::NamespaceState::Defined)) => {
Ok(None)
}
Ok(None) => return Ok(None),
Err(e) => {
Err(ClientError::SimilarNamespace {
namespace: namespace.to_string(),
e: e.to_string(),
})
}
}

@@ -995,6 +1059,15 @@ pub struct PackageDownload {
/// Represents an error returned by Warg registry clients.
#[derive(Debug, Error)]
pub enum ClientError {
/// Similar Namespace
#[error("Namespace `{namespace}` not found in operator log but found namespace `{e}`, which has alternative casing.")]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are we not enforcing lowercase namespaces? I think we should be... WebAssembly/component-model#338

Copy link
Collaborator

@calvinrp calvinrp Apr 24, 2024

Choose a reason for hiding this comment

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

Yeah, that is outstanding. Probably better as a separate PR. Found the open issue #245

Comment on lines 1290 to 1297
/// Interactively retry when hint header received from warg server
pub async fn with_interactive_retry<F>(f: impl Fn(Option<Retry>) -> F) -> Result<()>
where
F: Future<Output = Result<()>>,
{
f(None).await?;
Ok(())
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This doesn't appear to do what it claims to do?

@calvinrp
Copy link
Collaborator

calvinrp commented May 3, 2024

Collaborated with @macovedj to rework these changes into PR #268 which was merged. Thus closing this PR.

@calvinrp calvinrp closed this May 3, 2024
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