Skip to content

Commit

Permalink
refactor: Remove experimental code
Browse files Browse the repository at this point in the history
  • Loading branch information
lquerel committed Apr 21, 2024
1 parent f03e8c2 commit 96e2c13
Show file tree
Hide file tree
Showing 54 changed files with 64 additions and 7,316 deletions.
966 changes: 21 additions & 945 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 1 addition & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ anyhow = "1.0.81"

# Features definition =========================================================
[features]
experimental = ["tantivy", "weaver_schema", "weaver_template"]
experimental = []

# Crate definitions ===========================================================
[[bin]]
Expand All @@ -51,20 +51,14 @@ name = "weaver"
# local crates dependencies
weaver_common = { path = "crates/weaver_common" }
weaver_resolver = { path = "crates/weaver_resolver" }
weaver_template = { path = "crates/weaver_template", optional = true }
weaver_semconv = { path = "crates/weaver_semconv" }
weaver_resolved_schema = { path = "crates/weaver_resolved_schema" }
weaver_semconv_gen = { path = "crates/weaver_semconv_gen" }
weaver_schema = { path = "crates/weaver_schema", optional = true }
weaver_cache = { path = "crates/weaver_cache" }
weaver_forge = { path = "crates/weaver_forge" }
weaver_checker = { path = "crates/weaver_checker" }

clap = { version = "4.5.4", features = ["derive"] }
crossterm = "0.27.0"
ratatui = "0.26.1"
tui-textarea = "0.4.0"
tantivy = { version = "0.22.0", optional = true }

# workspace dependencies
serde.workspace = true
Expand Down
6 changes: 1 addition & 5 deletions crates/weaver_resolver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,16 @@ workspace = true
weaver_common = { path = "../weaver_common" }
weaver_diff = { path = "../weaver_diff" }
weaver_semconv = { path = "../weaver_semconv" }
weaver_schema = { path = "../weaver_schema" }
weaver_version = { path = "../weaver_version" }
weaver_cache = { path = "../weaver_cache" }
weaver_resolved_schema = { path = "../weaver_resolved_schema" }
weaver_schema = { path = "../weaver_schema" }
weaver_checker = { path = "../weaver_checker" }

regex.workspace = true
thiserror.workspace = true
rayon.workspace = true
serde.workspace = true
serde_json.workspace = true
walkdir.workspace = true

url = "2.5.0"

[dev-dependencies]
glob = "0.3.1"
114 changes: 1 addition & 113 deletions crates/weaver_resolver/src/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@

//! Attribute resolution.
use std::collections::{BTreeMap, HashMap, HashSet};
use std::collections::{HashMap, HashSet};

use serde::Deserialize;

use weaver_resolved_schema::attribute;
use weaver_resolved_schema::attribute::AttributeRef;
use weaver_resolved_schema::lineage::{AttributeLineage, GroupLineage};
use weaver_schema::attribute::Attribute;
use weaver_schema::tags::Tags;
use weaver_semconv::attribute::{AttributeSpec, ValueSpec};
use weaver_semconv::group::GroupType;
use weaver_semconv::registry::SemConvRegistry;
use weaver_version::VersionAttributeChanges;

use crate::Error;

Expand Down Expand Up @@ -175,115 +172,6 @@ impl AttributeCatalog {
}
}

/// Resolves a collection of attributes (i.e. `Attribute::Ref`, `Attribute::AttributeGroupRef`,
/// and `Attribute::SpanRef`) from the given semantic convention catalog and local attributes
/// (i.e. `Attribute::Id`).
/// `Attribute::AttributeGroupRef` are first resolved, then `Attribute::SpanRef`, then
/// `Attribute::Ref`, and finally `Attribute::Id` are added.
/// An `Attribute::Ref` can override an attribute contained in an `Attribute::AttributeGroupRef`
/// or an `Attribute::SpanRef`.
/// An `Attribute::Id` can override an attribute contains in an `Attribute::Ref`, an
/// `Attribute::AttributeGroupRef`, or an `Attribute::SpanRef`.
///
/// Note: Version changes are used during the resolution process to determine the names of the
/// attributes.
pub fn resolve_attributes(
attributes: &[Attribute],
semconv_registry: &SemConvRegistry,
version_changes: impl VersionAttributeChanges,
) -> Result<Vec<Attribute>, Error> {
let mut resolved_attrs = BTreeMap::new();
let mut copy_into_resolved_attrs =
|attrs: HashMap<&String, &AttributeSpec>, tags: &Option<Tags>| {
for (attr_id, attr) in attrs {
let mut attr: Attribute = attr.into();
attr.set_tags(tags);
_ = resolved_attrs.insert(attr_id.clone(), attr);
}
};

// Resolve `Attribute::AttributeGroupRef`
for attribute in attributes.iter() {
if let Attribute::AttributeGroupRef {
attribute_group_ref,
tags,
} = attribute
{
let attrs = semconv_registry
.attributes(attribute_group_ref, GroupType::AttributeGroup)
.map_err(|e| Error::FailToResolveAttributes {
ids: vec![attribute_group_ref.clone()],
error: e.to_string(),
})?;
copy_into_resolved_attrs(attrs, tags);
}
}

// Resolve `Attribute::ResourceRef`
for attribute in attributes.iter() {
if let Attribute::ResourceRef { resource_ref, tags } = attribute {
let attrs = semconv_registry
.attributes(resource_ref, GroupType::Resource)
.map_err(|e| Error::FailToResolveAttributes {
ids: vec![resource_ref.clone()],
error: e.to_string(),
})?;
copy_into_resolved_attrs(attrs, tags);
}
}

// Resolve `Attribute::SpanRef`
for attribute in attributes.iter() {
if let Attribute::SpanRef { span_ref, tags } = attribute {
let attrs = semconv_registry
.attributes(span_ref, GroupType::Span)
.map_err(|e| Error::FailToResolveAttributes {
ids: vec![span_ref.clone()],
error: e.to_string(),
})?;
copy_into_resolved_attrs(attrs, tags);
}
}

// Resolve `Attribute::EventRef`
for attribute in attributes.iter() {
if let Attribute::EventRef { event_ref, tags } = attribute {
let attrs = semconv_registry
.attributes(event_ref, GroupType::Event)
.map_err(|e| Error::FailToResolveAttributes {
ids: vec![event_ref.clone()],
error: e.to_string(),
})?;
copy_into_resolved_attrs(attrs, tags);
}
}

// Resolve `Attribute::Ref`
for attribute in attributes.iter() {
if let Attribute::Ref { r#ref, .. } = attribute {
let normalized_ref = version_changes.get_attribute_name(r#ref);
let sem_conv_attr = semconv_registry.attribute(&normalized_ref);
let resolved_attribute = attribute.resolve_from(sem_conv_attr).map_err(|e| {
Error::FailToResolveAttributes {
ids: vec![r#ref.clone()],
error: e.to_string(),
}
})?;
_ = resolved_attrs.insert(normalized_ref, resolved_attribute);
}
}

// Resolve `Attribute::Id`
// Note: any resolved attributes with the same id will be overridden.
for attribute in attributes.iter() {
if let Attribute::Id { id, .. } = attribute {
_ = resolved_attrs.insert(id.clone(), attribute.clone());
}
}

Ok(resolved_attrs.into_values().collect())
}

/// Merges the given main attributes with the inherited attributes.
/// Main attributes have precedence over inherited attributes.
#[must_use]
Expand Down
32 changes: 0 additions & 32 deletions crates/weaver_resolver/src/events.rs

This file was deleted.

Loading

0 comments on commit 96e2c13

Please sign in to comment.