Skip to content

Commit

Permalink
Merge branch 'main' into lineage
Browse files Browse the repository at this point in the history
  • Loading branch information
lquerel authored Mar 29, 2024
2 parents 78b7c4c + 7273f92 commit 014f43f
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ tantivy = { version = "0.21.1", optional = true }
serde.workspace = true
serde_yaml.workspace = true
serde_json.workspace = true
walkdir.workspace = true

[package.metadata.cargo-machete]
# force cargo machete to ignore the following crates
Expand Down
1 change: 1 addition & 0 deletions crates/weaver_semconv_gen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ edition.workspace = true
rust-version.workspace = true

[dependencies]
weaver_cache = { path = "../weaver_cache" }
weaver_logger = { path = "../weaver_logger" }
weaver_resolver = { path = "../weaver_resolver" }
weaver_resolved_schema = { path = "../weaver_resolved_schema" }
Expand Down
1 change: 1 addition & 0 deletions crates/weaver_semconv_gen/allowed-external-types.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ allowed_external_types = [
"weaver_semconv::Error",
"weaver_resolver::Error",
"weaver_logger::Logger",
"weaver_cache::Cache",
]
26 changes: 26 additions & 0 deletions crates/weaver_semconv_gen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//! poorly porting the code into RUST. We expect to optimise and improve things over time.
use std::fs;
use weaver_cache::Cache;
use weaver_logger::Logger;
use weaver_resolved_schema::attribute::{Attribute, AttributeRef};
use weaver_resolved_schema::registry::{Group, Registry};
Expand Down Expand Up @@ -214,6 +215,31 @@ impl ResolvedSemconvRegistry {
Ok(lookup)
}

/// Resolve semconv registry (possibly from git), and make it available for rendering.
pub fn try_from_url(
// Local or GIT URL of semconv registry.
registry: String,
// Optional path where YAML files are located (default: model)
registry_sub_dir: Option<String>,
cache: &Cache,
log: impl Logger + Clone + Sync,
) -> Result<ResolvedSemconvRegistry, Error> {
let registry_id = "semantic_conventions";
let mut registry = SchemaResolver::load_semconv_registry(
registry_id,
registry,
registry_sub_dir,
cache,
log.clone(),
)?;
let schema = SchemaResolver::resolve_semantic_convention_registry(&mut registry, log)?;
let lookup = ResolvedSemconvRegistry {
schema,
registry_id: registry_id.into(),
};
Ok(lookup)
}

fn my_registry(&self) -> Option<&Registry> {
self.schema.registry(self.registry_id.as_str())
}
Expand Down
49 changes: 46 additions & 3 deletions src/registry/update_markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use clap::Args;
use weaver_cache::Cache;
use weaver_logger::Logger;
use weaver_semconv_gen::{update_markdown, ResolvedSemconvRegistry};

/// Parameters for the `registry update-markdown` sub-command
#[derive(Debug, Args)]
Expand All @@ -25,13 +26,55 @@ pub struct RegistryUpdateMarkdownArgs {
/// registry is located
#[arg(short = 'd', long, default_value = "model")]
pub registry_git_sub_dir: Option<String>,

/// Whether or not to run updates in dry-run mode.
#[arg(long, default_value = "false")]
pub dry_run: bool,
}

/// Update markdown files.
pub(crate) fn command(
_log: impl Logger + Sync + Clone,
_cache: &Cache,
log: impl Logger + Sync + Clone,
cache: &Cache,
args: &RegistryUpdateMarkdownArgs,
) {
println!("Args: {:#?}", args);
let registry = ResolvedSemconvRegistry::try_from_url(
args.registry.clone(),
args.registry_git_sub_dir.clone(),
cache,
log.clone(),
)
.unwrap_or_else(|e| {
panic!("Failed to resolve the semantic convention registry.\n{e}");
});
log.success("Registry resolved successfully");
fn is_markdown(entry: &walkdir::DirEntry) -> bool {
let path = entry.path();
let extension = path.extension().unwrap_or_else(|| std::ffi::OsStr::new(""));
path.is_file() && extension == "md"
}
let operation = if args.dry_run {
"Validating"
} else {
"Updating"
};
let mut has_error = false;
for entry in walkdir::WalkDir::new(args.markdown_dir.clone())
.into_iter()
.filter_map(|e| match e {
Ok(v) if is_markdown(&v) => Some(v),
_ => None,
})
{
log.info(&format!("{}: ${}", operation, entry.path().display()));
if let Err(error) =
update_markdown(&entry.path().display().to_string(), &registry, args.dry_run)
{
has_error = true;
log.error(&format!("{error}"));
}
}
if has_error {
panic!("weaver registry update-markdown failed.");
}
}

0 comments on commit 014f43f

Please sign in to comment.