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

Allow capturing logging endpoint messages #397

Merged
merged 1 commit into from
Jun 28, 2024

Conversation

jameysharp
Copy link
Contributor

Some integration tests need to capture log output in order to verify that logging endpoints work correctly from guests, but it's also potentially useful for people using Viceroy as a library.

The previous way that the integration tests did this was not reliable when multiple tests ran in parallel, because there was only one global hook for capturing logs. Exposing this as a configuration option on execution contexts instead allows each test to set independent capture buffers.

I guess this should be considered a breaking API change since viceroy_lib::logging::LOG_WRITER was exported publicly from the crate.

@jameysharp jameysharp requested a review from elliottt June 28, 2024 19:54
elliottt
elliottt previously approved these changes Jun 28, 2024
Copy link
Contributor

@elliottt elliottt left a comment

Choose a reason for hiding this comment

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

That global mutex has bothered me for a long time, thank you for fixing this!

#[derive(Clone)]
pub struct LogEndpoint {
name: Vec<u8>,
writer: Arc<Mutex<dyn Write + Send>>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this escapes out now, would it be worth adding a synonym for Arc<Mutex<dyn Write + Send>> for readability elsewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question. While trying to decide how to answer it, I've stared at the places this is visible, and I think my answer is that it shouldn't actually be visible in most of those places. In particular, I don't think either the LogEndpoint or Session types should be exported. The only place library users should encounter this type is in the ExecuteCtx::with_capture_logs method, and I don't think a type alias is necessary for that.

It's a little annoying naming this type multiple places within the library, but I think it's a little better to keep the details visible so that, for example, it's clear that using clone is cheap.

So I guess I'm not inclined to introduce a type alias for this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Reasonable!

Some integration tests need to capture log output in order to verify
that logging endpoints work correctly from guests, but it's also
potentially useful for people using Viceroy as a library.

The previous way that the integration tests did this was not reliable
when multiple tests ran in parallel, because there was only one global
hook for capturing logs. Exposing this as a configuration option on
execution contexts instead allows each test to set independent capture
buffers.

I guess this should be considered a breaking API change since
`viceroy_lib::logging::LOG_WRITER` was exported publicly from the crate.
@jameysharp jameysharp merged commit a4bc8c1 into fastly:main Jun 28, 2024
7 checks passed
@jameysharp jameysharp deleted the capture-logs branch June 28, 2024 21:21
GeeWee pushed a commit to GeeWee/Viceroy that referenced this pull request Jul 25, 2024
Some integration tests need to capture log output in order to verify
that logging endpoints work correctly from guests, but it's also
potentially useful for people using Viceroy as a library.

The previous way that the integration tests did this was not reliable
when multiple tests ran in parallel, because there was only one global
hook for capturing logs. Exposing this as a configuration option on
execution contexts instead allows each test to set independent capture
buffers.

I guess this should be considered a breaking API change since
`viceroy_lib::logging::LOG_WRITER` was exported publicly from the crate.
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.

2 participants