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

Support for loading templates from the file system or from an embedded representation in the app's binary. #171

Merged
merged 23 commits into from
May 28, 2024

Conversation

lquerel
Copy link
Contributor

@lquerel lquerel commented May 23, 2024

This PR contains the following changes:

  • Integration of default diagnostic templates into the application binary.
  • A new command weaver diagnostic init to locally create diagnostic templates, allowing the user to override them or define new targets.
  • A mechanism to detect the presence of local templates for rendering diagnostic messages.
  • An infrastructure to test the execution of CLI commands, their outputs, and their exit codes.

Closing: #167

@lquerel lquerel added the enhancement New feature or request label May 23, 2024
@lquerel lquerel self-assigned this May 23, 2024
@@ -10,7 +10,6 @@ COPY crates /build/crates
COPY data /build/data
COPY src /build/src
COPY tests build/tests
COPY diagnostic_templates /build/diagnostic_templates
Copy link
Contributor Author

Choose a reason for hiding this comment

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

No longer needed as the default templates are now embedded into the app's binary.

Copy link

codecov bot commented May 24, 2024

Codecov Report

Attention: Patch coverage is 60.93023% with 84 lines in your changes are missing coverage. Please review.

Project coverage is 75.5%. Comparing base (da892c2) to head (1277731).

Files Patch % Lines
crates/weaver_diff/src/lib.rs 56.0% 22 Missing ⚠️
crates/weaver_forge/src/file_loader.rs 85.7% 12 Missing ⚠️
crates/weaver_semconv_gen/src/lib.rs 0.0% 11 Missing ⚠️
crates/weaver_checker/src/lib.rs 0.0% 7 Missing ⚠️
crates/weaver_forge/src/error.rs 0.0% 7 Missing ⚠️
crates/weaver_resolver/src/lib.rs 0.0% 7 Missing ⚠️
crates/weaver_common/src/diagnostic.rs 68.7% 5 Missing ⚠️
crates/weaver_forge/src/config.rs 50.0% 4 Missing ⚠️
crates/weaver_semconv/src/lib.rs 50.0% 4 Missing ⚠️
crates/weaver_forge/src/lib.rs 80.0% 3 Missing ⚠️
... and 1 more
Additional details and impacted files
@@           Coverage Diff           @@
##            main    #171     +/-   ##
=======================================
+ Coverage   75.0%   75.5%   +0.4%     
=======================================
  Files         43      44      +1     
  Lines       2729    2849    +120     
=======================================
+ Hits        2049    2153    +104     
- Misses       680     696     +16     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


/// The file loader function with a 'static lifetime (required by MiniJinja).
loader_function:
Arc<dyn for<'a> Fn(&'a str) -> Result<Option<String>, Error> + Send + Sync + 'static>,
Copy link
Contributor Author

@lquerel lquerel May 24, 2024

Choose a reason for hiding this comment

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

Used Arc because templates are loaded in parallel.

Copy link
Contributor

Choose a reason for hiding this comment

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

I get that, but the design feels awkward to me.

  1. This is exposing A LOT of details publicly - Arc, Error, Send/Sync, etc.
  2. I'd prefer keeping raw types e.g. (T) with a trait you can use.

For example, instead of returning a loader-function, why not just expose the function itself and keep the loader in an Arc if you want? Then the owner of the Loader is responsible for keeping it in an arc/safely and generates their own thread-safe closure.

pub trait FileLoader {
    /// Returns a textual representation of the root path of the loader.
    /// This representation is mostly used for debugging and logging purposes.
    fn root(&self) -> &Path;

    /// Returns a list of all files in the loader's root directory.
    fn all_files(&self) -> Vec<PathBuf>;

    /// Loads a file from a given name
    fn load_file<'a>(
        &self,
        &'a str
    ) -> Result<Option<String>, Error>;
}

(caveat you may need to sprinkle some Send+Sync in there)

Then, in weaver_forge you can have an Arc<dyn FileLoader> if you need it, or you can otherwise synchronize threading access to the trait as you want.

TL;DR; If this is a public trait, I think its impl is way too tiightly coupled to how we're doing threading today with little flexibility.

Copy link
Contributor Author

@lquerel lquerel May 28, 2024

Choose a reason for hiding this comment

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

I agree, the interface is too complex. I'm going to simplify this as much as possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, see 3d86ccd3d86ccd

@lquerel lquerel marked this pull request as ready for review May 24, 2024 23:27
@lquerel lquerel requested a review from jsuereth as a code owner May 24, 2024 23:27
@lquerel lquerel changed the title [WIP] Support for loading templates from the file system or from an embedded representation in the app's binary. Support for loading templates from the file system or from an embedded representation in the app's binary. May 24, 2024
Copy link
Contributor

@jsuereth jsuereth left a comment

Choose a reason for hiding this comment

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

Just a nit.

use crate::error::Error::TargetNotSupported;

/// An abstraction for loading files from a file system, embedded directory, etc.
pub trait FileLoader: Send + Sync {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Can you add the Send + Sync requirement only in the weaver_forge where you need the type to be send+sync?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See 9b8e7a7

crates/weaver_forge/src/file_loader.rs Show resolved Hide resolved
/// Template path
path: PathBuf,
/// File loader used by the engine.
file_loader: Arc<dyn FileLoader + 'static>,
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Here can you add the +Send + Sync?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See 9b8e7a7

@jsuereth
Copy link
Contributor

Looks like the docker build also needs tobe updated for the rename of the templates.

@lquerel lquerel merged commit 29387f5 into open-telemetry:main May 28, 2024
19 of 20 checks passed
@lquerel lquerel deleted the embedded-diag-templates branch May 29, 2024 00:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants