Skip to content

Commit

Permalink
Merge branch 'metrics-don't-require-attributes' of https://github.com…
Browse files Browse the repository at this point in the history
…/jerbly/weaver into metrics-don't-require-attributes
  • Loading branch information
jerbly committed Nov 30, 2024
2 parents 9297170 + 1a91ee7 commit fa8a42f
Show file tree
Hide file tree
Showing 18 changed files with 405 additions and 181 deletions.
267 changes: 133 additions & 134 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ walkdir = "2.5.0"
anyhow = "1.0.93"
itertools = "0.13.0"
globset = { version = "0.4.15", features = ["serde1"] }
miette = { version = "7.2.0", features = ["fancy", "serde"] }
miette = { version = "7.4.0", features = ["fancy", "serde"] }
include_dir = "0.7.4"
tempdir = "0.3.7"
schemars = "0.8.21"
dirs = "5.0.1"
once_cell = "1.20.2"
opentelemetry = { version = "0.27.0", features = ["trace", "metrics", "logs", "otel_unstable"] }
opentelemetry = { version = "0.27.1", features = ["trace", "metrics", "logs", "otel_unstable"] }
rouille = "3.6.2"

# Features definition =========================================================
Expand Down
2 changes: 1 addition & 1 deletion crates/weaver_cache/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ weaver_common = { path = "../weaver_common" }

tempdir = "0.3.7"
dirs = "5.0.1"
gix = { version = "0.67.0", default-features = false, features = [
gix = { version = "0.68.0", default-features = false, features = [
"comfort",
"blocking-http-transport-reqwest",
"max-performance-safe",
Expand Down
3 changes: 2 additions & 1 deletion crates/weaver_codegen_test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const SEMCONV_REGISTRY_PATH: &str = "./semconv_registry/";
const TEMPLATES_PATH: &str = "./templates/registry/";
const REGISTRY_ID: &str = "test";
const TARGET: &str = "rust";
const FOLLOW_SYMLINKS: bool = false;

fn main() {
// Tell Cargo when to rerun this build script
Expand All @@ -45,7 +46,7 @@ fn main() {
};
let registry_repo =
RegistryRepo::try_new("main", &registry_path).unwrap_or_else(|e| process_error(&logger, e));
let semconv_specs = SchemaResolver::load_semconv_specs(&registry_repo)
let semconv_specs = SchemaResolver::load_semconv_specs(&registry_repo, FOLLOW_SYMLINKS)
.ignore(|e| matches!(e.severity(), Some(miette::Severity::Warning)))
.into_result_failing_non_fatal()
.unwrap_or_else(|e| process_error(&logger, e));
Expand Down
2 changes: 1 addition & 1 deletion crates/weaver_forge/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ dirs.workspace = true

[dev-dependencies]
opentelemetry.workspace = true
opentelemetry_sdk = { version = "0.27.0", features = ["trace", "metrics", "logs"] }
opentelemetry_sdk = { version = "0.27.1", features = ["trace", "metrics", "logs"] }
opentelemetry-stdout = { version = "0.27.0", features = ["trace", "metrics", "logs"] }

4 changes: 4 additions & 0 deletions crates/weaver_resolver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,12 @@ impl SchemaResolver {
/// * `registry_repo` - The registry repository containing the semantic convention files.
pub fn load_semconv_specs(
registry_repo: &RegistryRepo,
follow_symlinks: bool,
) -> WResult<Vec<(String, SemConvSpec)>, weaver_semconv::Error> {
Self::load_semconv_from_local_path(
registry_repo.path().to_path_buf(),
registry_repo.registry_path_repr(),
follow_symlinks,
)
}

Expand All @@ -285,6 +287,7 @@ impl SchemaResolver {
fn load_semconv_from_local_path(
local_path: PathBuf,
registry_path_repr: &str,
follow_symlinks: bool,
) -> WResult<Vec<(String, SemConvSpec)>, weaver_semconv::Error> {
fn is_hidden(entry: &DirEntry) -> bool {
entry
Expand All @@ -306,6 +309,7 @@ impl SchemaResolver {
// All yaml files are recursively loaded and parsed in parallel from
// the given path.
let result = walkdir::WalkDir::new(local_path.clone())
.follow_links(follow_symlinks)
.into_iter()
.filter_entry(|e| !is_hidden(e))
.par_bridge()
Expand Down
18 changes: 14 additions & 4 deletions crates/weaver_semconv_gen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,13 @@ impl SnippetGenerator {
registry_repo: &RegistryRepo,
template_engine: TemplateEngine,
diag_msgs: &mut DiagnosticMessages,
follow_symlinks: bool,
) -> Result<SnippetGenerator, Error> {
let registry = ResolvedSemconvRegistry::try_from_registry_repo(registry_repo, diag_msgs)?;
let registry = ResolvedSemconvRegistry::try_from_registry_repo(
registry_repo,
diag_msgs,
follow_symlinks,
)?;
Ok(SnippetGenerator {
lookup: registry,
template_engine,
Expand All @@ -327,9 +332,10 @@ impl ResolvedSemconvRegistry {
fn try_from_registry_repo(
registry_repo: &RegistryRepo,
diag_msgs: &mut DiagnosticMessages,
follow_symlinks: bool,
) -> Result<ResolvedSemconvRegistry, Error> {
let registry_id = "semantic_conventions";
let semconv_specs = SchemaResolver::load_semconv_specs(registry_repo)
let semconv_specs = SchemaResolver::load_semconv_specs(registry_repo, follow_symlinks)
.capture_non_fatal_errors(diag_msgs)?;
let mut registry = SemConvRegistry::from_semconv_specs(registry_id, semconv_specs);
let schema = SchemaResolver::resolve_semantic_convention_registry(&mut registry)?;
Expand Down Expand Up @@ -382,8 +388,12 @@ mod tests {
};
let mut diag_msgs = DiagnosticMessages::empty();
let registry_repo = RegistryRepo::try_new("main", &registry_path)?;
let generator =
SnippetGenerator::try_from_registry_repo(&registry_repo, template, &mut diag_msgs)?;
let generator = SnippetGenerator::try_from_registry_repo(
&registry_repo,
template,
&mut diag_msgs,
false,
)?;
let attribute_registry_url = "/docs/attributes-registry";
// Now we should check a snippet.
let test = "data/templates.md";
Expand Down
1 change: 1 addition & 0 deletions data/symbolic_test/semconv_registry
12 changes: 12 additions & 0 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ Options:
[default: diagnostic_templates]
-s, --follow-symlinks
Boolean flag to specify whether to follow symlinks when loading the registry. Default is false
-h, --help
Print help (see a summary with '-h')
```
Expand Down Expand Up @@ -112,8 +115,12 @@ Options:
[default: diagnostic_templates]
-s, --follow-symlinks
Boolean flag to specify whether to follow symlinks when loading the registry. Default is false
-h, --help
Print help (see a summary with '-h')
```

## registry resolve
Expand Down Expand Up @@ -171,6 +178,9 @@ Options:
[default: diagnostic_templates]
-s, --follow-symlinks
Boolean flag to specify whether to follow symlinks when loading the registry. Default is false
-h, --help
Print help (see a summary with '-h')
```
Expand All @@ -194,6 +204,8 @@ Options:
Whether or not to run updates in dry-run mode
--attribute-registry-base-url <ATTRIBUTE_REGISTRY_BASE_URL>
Optional path to the attribute registry. If provided, all attributes will be linked here
-s, --follow-symlinks
Boolean flag to specify whether to follow symlinks when loading the registry. Default is false
-h, --help
Print help
```
Expand Down
36 changes: 29 additions & 7 deletions src/registry/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use weaver_common::Logger;
use weaver_forge::registry::ResolvedRegistry;
use weaver_semconv::registry::SemConvRegistry;

use crate::registry::RegistryArgs;
use crate::registry::{CommonRegistryArgs, RegistryArgs};
use crate::util::{
check_policy, check_policy_stage, init_policy_engine, load_semconv_specs, resolve_semconv_specs,
};
Expand Down Expand Up @@ -47,6 +47,10 @@ pub struct RegistryCheckArgs {
/// Parameters to specify the diagnostic format.
#[command(flatten)]
pub diagnostic: DiagnosticArgs,

/// Common weaver registry parameters
#[command(flatten)]
pub common_registry_args: CommonRegistryArgs,
}

/// Check a semantic convention registry.
Expand Down Expand Up @@ -78,17 +82,25 @@ pub(crate) fn command(

// Load the semantic convention registry into a local registry repo.
// No parsing errors should be observed.
let main_semconv_specs = load_semconv_specs(&main_registry_repo, logger.clone())
.capture_non_fatal_errors(&mut diag_msgs)?;
let main_semconv_specs = load_semconv_specs(
&main_registry_repo,
logger.clone(),
args.common_registry_args.follow_symlinks,
)
.capture_non_fatal_errors(&mut diag_msgs)?;
let baseline_semconv_specs = baseline_registry_repo
.as_ref()
.map(|repo| {
// Baseline registry resolution should allow non-future features
// and warnings against it should be suppressed when evaluating
// against it as a "baseline".
load_semconv_specs(repo, logger.clone())
.ignore(|e| matches!(e.severity(), Some(miette::Severity::Warning)))
.capture_non_fatal_errors(&mut diag_msgs)
load_semconv_specs(
repo,
logger.clone(),
args.common_registry_args.follow_symlinks,
)
.ignore(|e| matches!(e.severity(), Some(miette::Severity::Warning)))
.capture_non_fatal_errors(&mut diag_msgs)
})
.transpose()?;

Expand Down Expand Up @@ -219,7 +231,8 @@ mod tests {
use crate::cli::{Cli, Commands};
use crate::registry::check::RegistryCheckArgs;
use crate::registry::{
semconv_registry, RegistryArgs, RegistryCommand, RegistryPath, RegistrySubCommand,
semconv_registry, CommonRegistryArgs, RegistryArgs, RegistryCommand, RegistryPath,
RegistrySubCommand,
};
use crate::run_command;

Expand All @@ -243,6 +256,9 @@ mod tests {
skip_policies: true,
display_policy_coverage: false,
diagnostic: Default::default(),
common_registry_args: CommonRegistryArgs {
follow_symlinks: false,
},
}),
})),
};
Expand All @@ -269,6 +285,9 @@ mod tests {
skip_policies: false,
display_policy_coverage: false,
diagnostic: Default::default(),
common_registry_args: CommonRegistryArgs {
follow_symlinks: false,
},
}),
})),
};
Expand All @@ -295,6 +314,9 @@ mod tests {
skip_policies: false,
display_policy_coverage: false,
diagnostic: Default::default(),
common_registry_args: CommonRegistryArgs {
follow_symlinks: false,
},
}),
};

Expand Down
Loading

0 comments on commit fa8a42f

Please sign in to comment.