Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 crates/weaver_common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ once_cell.workspace = true
schemars.workspace = true
ureq.workspace = true
log.workspace = true
url.workspace = true

tempfile.workspace = true
dirs = "6.0.0"
Expand Down
34 changes: 34 additions & 0 deletions crates/weaver_common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use miette::Diagnostic;
use paris::formatter::colorize_string;
use serde::Serialize;
use std::io::Write;
use std::path::Path;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::{Arc, Mutex};

Expand Down Expand Up @@ -295,3 +296,36 @@ pub fn warn_flare<T: std::fmt::Display>(message: T) -> String {
pub fn log_warn<T: std::fmt::Display>(message: T) {
log::warn!("{}", warn_flare(message));
}

/// Types of path strings we can support.
pub enum PathType {
/// A URL path, like http://server/
URL,
/// A relative path, like ../some-file
RelativePath,
/// An absolute path, like /my/file/location
AbsolutePath,
/// Weaver-special. A reference to a file
/// in a git repo or other.
WeaverPath,
}

/// Returns the type of path we're dealing with.
#[must_use]
pub fn get_path_type(input: &str) -> PathType {
match url::Url::parse(input) {
Ok(_) => PathType::URL,
Err(url::ParseError::RelativeUrlWithoutBase) => {
let test_path = Path::new(input);
if test_path.is_absolute() {
PathType::AbsolutePath
} else {
PathType::RelativePath
}
}
// TODO - we can learn more from error, we may be able
// to determine if this is a git-relative path or
// in-archive file reference.
Err(_) => PathType::WeaverPath,
}
}
54 changes: 53 additions & 1 deletion crates/weaver_common/src/vdir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,50 @@ pub enum VirtualDirectoryPath {
},
}

// Helper to allow mapping an Option<String> via a function that works with empty strings.
// Empty is replaced with None and vice versa.
fn map_option<F: FnOnce(String) -> String>(opt: Option<String>, f: F) -> Option<String> {
let result = f(opt.unwrap_or_default());
if result.is_empty() {
None
} else {
Some(result)
}
}

impl VirtualDirectoryPath {
/// Converts a virtual directory path by manipulating the "sub folder".
///
/// Returning an empty string means no sub_folder will be used in resulting path.
///
/// Sub folder will be modified as follows:
///
/// - LocalFolder: will see the entire path
/// - others: will see the path inside the archive or empty string if none.
pub fn map_sub_folder<F: FnOnce(String) -> String>(self, f: F) -> VirtualDirectoryPath {
match self {
LocalFolder { path } => LocalFolder { path: f(path) },
LocalArchive { path, sub_folder } => LocalArchive {
path,
sub_folder: map_option(sub_folder, f),
},
RemoteArchive { url, sub_folder } => RemoteArchive {
url,
sub_folder: map_option(sub_folder, f),
},
GitRepo {
url,
refspec,
sub_folder,
} => GitRepo {
url,
refspec,
sub_folder: map_option(sub_folder, f),
},
}
}
}

/// Enables parsing a [`VirtualDirectoryPath`] from a string representation.
///
/// This implementation allows easy deserialization from strings (e.g. configuration files, command-line arguments).
Expand Down Expand Up @@ -686,10 +730,18 @@ impl VirtualDirectory {

/// Returns the original string representation that was used to create this `VirtualDirectory`.
#[must_use]
pub fn vdir_path(&self) -> &str {
pub fn vdir_path_str(&self) -> &str {
&self.vdir_path
}

/// Returns the original `VirtualDirectoryRef` that was used to create this `VirtualDirectory`.
#[must_use]
pub fn vdir_path(&self) -> VirtualDirectoryPath {
self.vdir_path_str()
.try_into()
.expect("VirtualDirectory should not have invalid `vdir_path`.")
}

/// Creates and returns a new temporary directory within `.weaver/vdir_cache`.
///
/// The created directory and its contents are automatically deleted when dropped.
Expand Down
4 changes: 2 additions & 2 deletions crates/weaver_resolved_schema/src/catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ use weaver_semconv::stability::Stability;
/// Attribute references are used to refer to attributes in the catalog.
///
/// Note : In the future, this catalog could be extended with other entities.
#[derive(Serialize, Deserialize, Debug, Clone, JsonSchema, Default)]
#[derive(Serialize, Deserialize, Debug, Clone, JsonSchema, Default, PartialEq, Eq)]
#[serde(deny_unknown_fields)]
#[must_use]
pub struct Catalog {
/// Catalog of attributes used in the schema.
#[serde(skip_serializing_if = "Vec::is_empty")]
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub(crate) attributes: Vec<Attribute>,
}

Expand Down
2 changes: 2 additions & 0 deletions crates/weaver_resolved_schema/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ pub mod tags;
pub mod v2;
pub mod value;

pub use error::Error;

/// The registry ID for the OpenTelemetry semantic conventions.
/// This ID is reserved and should not be used by any other registry.
pub const OTEL_REGISTRY_ID: &str = "OTEL";
Expand Down
1 change: 1 addition & 0 deletions crates/weaver_resolver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ thiserror.workspace = true
rayon.workspace = true
serde.workspace = true
serde_json.workspace = true
serde_yaml.workspace = true
walkdir.workspace = true
miette.workspace = true
itertools.workspace = true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
[
{
"name": "messaging.destination.name",
"type": "string",
"brief": "The message destination name",
"examples": [
"MyQueue",
"MyTopic"
],
"requirement_level": "recommended",
"note": "Destination name SHOULD uniquely identify a specific queue, topic or other entity within the broker. If\nthe broker doesn't have such notion, the destination name SHOULD uniquely identify the broker.\n",
"stability": "stable"
},
{
"name": "messaging.destination.name",
"type": "string",
"brief": "The message destination name",
"examples": [
"MyQueue",
"MyTopic"
],
"requirement_level": {
"conditionally_required": "if and only if `messaging.destination.name` is known to have low cardinality. Otherwise, `messaging.destination.template` MAY be populated."
{
"attributes": [
{
"name": "messaging.destination.name",
"type": "string",
"brief": "The message destination name",
"examples": [
"MyQueue",
"MyTopic"
],
"requirement_level": "recommended",
"note": "Destination name SHOULD uniquely identify a specific queue, topic or other entity within the broker. If\nthe broker doesn't have such notion, the destination name SHOULD uniquely identify the broker.\n",
"stability": "stable"
},
"note": "Destination name SHOULD uniquely identify a specific queue, topic or other entity within the broker. If\nthe broker doesn't have such notion, the destination name SHOULD uniquely identify the broker.\n",
"stability": "stable"
}
]
{
"name": "messaging.destination.name",
"type": "string",
"brief": "The message destination name",
"examples": [
"MyQueue",
"MyTopic"
],
"requirement_level": {
"conditionally_required": "if and only if `messaging.destination.name` is known to have low cardinality. Otherwise, `messaging.destination.template` MAY be populated."
},
"note": "Destination name SHOULD uniquely identify a specific queue, topic or other entity within the broker. If\nthe broker doesn't have such notion, the destination name SHOULD uniquely identify the broker.\n",
"stability": "stable"
}
]
}
Original file line number Diff line number Diff line change
@@ -1,63 +1,65 @@
[
{
"name": "client.geo.lat",
"type": "string",
"brief": "My own latitude",
"examples": [
"123.456"
],
"requirement_level": "recommended",
"stability": "development",
"prefix": true
},
{
"name": "client.geo.lat",
"type": "string",
"brief": "this is embedded attribute",
"examples": [
"123.456"
],
"requirement_level": "recommended",
"stability": "development"
},
{
"name": "client.id",
"type": "string",
"brief": "some client id\n",
"examples": [
"a.einstein"
],
"requirement_level": "recommended",
"stability": "development"
},
{
"name": "geo.lat",
"type": "string",
"brief": "latitude of the geo coordinates.\n",
"examples": [
"123.456"
],
"requirement_level": "recommended",
"stability": "development"
},
{
"name": "geo.lat",
"type": "string",
"brief": "this is ref attribute",
"examples": [
"123.456"
],
"requirement_level": "recommended",
"stability": "development"
},
{
"name": "geo.lon",
"type": "string",
"brief": "longitude of the geo coordinates.\n",
"examples": [
"234.456"
],
"requirement_level": "recommended",
"stability": "development"
}
]
{
"attributes": [
{
"name": "client.geo.lat",
"type": "string",
"brief": "My own latitude",
"examples": [
"123.456"
],
"requirement_level": "recommended",
"stability": "development",
"prefix": true
},
{
"name": "client.geo.lat",
"type": "string",
"brief": "this is embedded attribute",
"examples": [
"123.456"
],
"requirement_level": "recommended",
"stability": "development"
},
{
"name": "client.id",
"type": "string",
"brief": "some client id\n",
"examples": [
"a.einstein"
],
"requirement_level": "recommended",
"stability": "development"
},
{
"name": "geo.lat",
"type": "string",
"brief": "latitude of the geo coordinates.\n",
"examples": [
"123.456"
],
"requirement_level": "recommended",
"stability": "development"
},
{
"name": "geo.lat",
"type": "string",
"brief": "this is ref attribute",
"examples": [
"123.456"
],
"requirement_level": "recommended",
"stability": "development"
},
{
"name": "geo.lon",
"type": "string",
"brief": "longitude of the geo coordinates.\n",
"examples": [
"234.456"
],
"requirement_level": "recommended",
"stability": "development"
}
]
}
Loading