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

[PoC]of attribute ref renaming #277

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[
{
"name": "file.name",
"type": "string",
"brief": "The name of the file.",
"examples": [
"log.txt",
"/var/log/messages"
],
"requirement_level": "recommended",
"note": "The name of the file"
},
{
"name": "log.file.name",
"type": "string",
"brief": "The name of the file.",
"examples": [
"log.txt",
"/var/log/messages"
],
"requirement_level": "recommended",
"note": "The name of the file"
},
{
"name": "log.error.file.name",
"type": "string",
"brief": "The name of the file.",
"examples": [
"log.txt",
"/var/log/messages"
],
"requirement_level": "recommended",
"note": "The name of the file"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"registry_url": "https://127.0.0.1",
"groups": [
{
"id": "logs.file",
"type": "attribute_group",
"brief": "Common log file attributes.",
"attributes": [
1,
2
],
"lineage": {
"source_file": "data/registry-test-12-rename/registry/logs-file.yaml",
"attributes": {
"log.error.file.name": {
"source_group": "registry.file",
"inherited_fields": [
"brief",
"examples",
"note",
"requirement_level"
]
},
"log.file.name": {
"source_group": "registry.file",
"inherited_fields": [
"brief",
"examples",
"note",
"requirement_level"
]
}
}
}
},
{
"id": "registry.file",
"type": "attribute_group",
"brief": "Attributes describing telemetry around files.",
"attributes": [
0
],
"lineage": {
"source_file": "data/registry-test-12-rename/registry/registry-file.yaml"
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
groups:
- id: logs.file
type: attribute_group
brief: "Common log file attributes."
attributes:
- ref: file.name
rename: log.file.name
- ref: file.name
rename: log.error.file.name

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
groups:
- id: registry.file
type: attribute_group
brief: 'Attributes describing telemetry around files.'
attributes:
- id: file.name
type: string
brief: 'The name of the file.'
note: 'The name of the file'
examples: ['log.txt', '/var/log/messages']
8 changes: 6 additions & 2 deletions crates/weaver_resolver/src/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,22 @@ impl AttributeCatalog {
stability,
deprecated,
prefix,
rename,
} => {
let name;
let root_attr = self.root_attributes.get(r#ref);
if let Some(root_attr) = root_attr {
let mut attr_lineage = AttributeLineage::new(&root_attr.group_id);

if *prefix {
Copy link
Contributor

Choose a reason for hiding this comment

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

fyi: prefix means that attribute will be embedded i.e. having parent prefix in his name

if let Some(rename) = rename {
// if there is a rename we need to update the name
name = rename.clone();
} else if *prefix {
// depending on the prefix we either create embedded attribute or normal reference
name = format!("{}.{}", group_prefix, r#ref);
} else {
name = r#ref.clone();
}
}

// Create a fully resolved attribute from an attribute spec
// (ref) and override the root attribute with the new
Expand Down
2 changes: 2 additions & 0 deletions crates/weaver_resolver/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,7 @@ fn resolve_inheritance_attr(
stability,
deprecated,
prefix,
..
} => {
match parent_attr {
AttributeSpec::Ref {
Expand Down Expand Up @@ -648,6 +649,7 @@ fn resolve_inheritance_attr(
stability: lineage.stability(stability, parent_stability),
deprecated: lineage.deprecated(deprecated, parent_deprecated),
prefix: lineage.prefix(prefix, parent_prefix),
rename: None,
}
}
AttributeSpec::Id {
Expand Down
5 changes: 5 additions & 0 deletions crates/weaver_semconv/src/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ pub enum AttributeSpec {
#[serde(default)]
#[serde(skip_serializing_if = "<&bool>::not")]
prefix: bool,
/// Specifies the rename of the attribute.
#[serde(skip_serializing_if = "Option::is_none")]
rename: Option<String>,

},
/// Attribute definition.
Id {
Expand Down Expand Up @@ -786,6 +790,7 @@ mod tests {
stability: Some(Stability::Stable),
deprecated: Some("deprecated".to_owned()),
prefix: false,
rename: None,
};
assert_eq!(attr.id(), "ref");
assert_eq!(attr.brief(), "brief");
Expand Down
Loading