Skip to content

Commit

Permalink
Merge pull request #212 from trisch-me/embed
Browse files Browse the repository at this point in the history
  • Loading branch information
lquerel authored Jun 28, 2024
2 parents 77d0d9b + f489b30 commit 98fe349
Show file tree
Hide file tree
Showing 19 changed files with 622 additions and 3 deletions.
15 changes: 15 additions & 0 deletions crates/weaver_forge/src/extensions/otel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,7 @@ mod tests {
deprecated: None,
tags: None,
value: None,
prefix: false,
},
Attribute {
name: "rec.b".into(),
Expand All @@ -680,6 +681,7 @@ mod tests {
deprecated: None,
tags: None,
value: None,
prefix: false,
},
Attribute {
name: "crec.a".into(),
Expand All @@ -694,6 +696,7 @@ mod tests {
deprecated: None,
tags: None,
value: None,
prefix: false,
},
Attribute {
name: "crec.b".into(),
Expand All @@ -708,6 +711,7 @@ mod tests {
deprecated: None,
tags: None,
value: None,
prefix: false,
},
Attribute {
name: "rec.c".into(),
Expand All @@ -722,6 +726,7 @@ mod tests {
deprecated: None,
tags: None,
value: None,
prefix: false,
},
Attribute {
name: "rec.d".into(),
Expand All @@ -736,6 +741,7 @@ mod tests {
deprecated: None,
tags: None,
value: None,
prefix: false,
},
Attribute {
name: "opt.a".into(),
Expand All @@ -750,6 +756,7 @@ mod tests {
deprecated: None,
tags: None,
value: None,
prefix: false,
},
Attribute {
name: "opt.b".into(),
Expand All @@ -764,6 +771,7 @@ mod tests {
deprecated: None,
tags: None,
value: None,
prefix: false,
},
Attribute {
name: "req.a".into(),
Expand All @@ -778,6 +786,7 @@ mod tests {
deprecated: None,
tags: None,
value: None,
prefix: false,
},
Attribute {
name: "req.b".into(),
Expand All @@ -792,6 +801,7 @@ mod tests {
deprecated: None,
tags: None,
value: None,
prefix: false,
},
];
let json =
Expand Down Expand Up @@ -849,6 +859,7 @@ mod tests {
deprecated: None,
tags: None,
value: None,
prefix: false,
},
Attribute {
name: "attr2".to_owned(),
Expand All @@ -863,6 +874,7 @@ mod tests {
deprecated: None,
tags: None,
value: None,
prefix: false,
},
Attribute {
name: "attr3".to_owned(),
Expand All @@ -877,6 +889,7 @@ mod tests {
deprecated: None,
tags: None,
value: None,
prefix: false,
},
];

Expand Down Expand Up @@ -1163,6 +1176,7 @@ mod tests {
deprecated: None,
tags: None,
value: None,
prefix: false,
};

add_tests_and_filters(&mut env);
Expand All @@ -1189,6 +1203,7 @@ mod tests {
deprecated: None,
tags: None,
value: None,
prefix: false,
};

add_tests_and_filters(&mut env);
Expand Down
8 changes: 8 additions & 0 deletions crates/weaver_resolved_schema/src/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::value::Value;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::fmt::Display;
use std::ops::Not;
use weaver_semconv::attribute::{AttributeSpec, AttributeType, Examples, RequirementLevel};
use weaver_semconv::stability::Stability;

Expand Down Expand Up @@ -64,6 +65,13 @@ pub struct Attribute {
/// to use instead. See also stability.
#[serde(skip_serializing_if = "Option::is_none")]
pub deprecated: Option<String>,
/// Specifies the prefix of the attribute.
/// If this parameter is set, the resolved id of the referenced attribute will
/// have group prefix added to it.
/// It defaults to false.
#[serde(default)]
#[serde(skip_serializing_if = "<&bool>::not")]
pub prefix: bool,
/// A set of tags for the attribute.
#[serde(skip_serializing_if = "Option::is_none")]
pub tags: Option<Tags>,
Expand Down
19 changes: 19 additions & 0 deletions crates/weaver_resolved_schema/src/lineage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ impl AttributeLineage {
note,
stability,
deprecated,
prefix,
..
} => {
if brief.is_some() {
Expand Down Expand Up @@ -106,6 +107,9 @@ impl AttributeLineage {
.inherited_fields
.insert("deprecated".to_owned());
}
if *prefix {
_ = attr_lineage.inherited_fields.insert("prefix".to_owned());
}
}
AttributeSpec::Id {
brief,
Expand Down Expand Up @@ -394,6 +398,21 @@ impl AttributeLineage {
*parent_value
}
}

/// This method updates the lineage information for the prefix field to
/// reflect the source of its value.
pub fn prefix(&mut self, local_value: &bool, parent_value: &bool) -> bool {
if *local_value {
_ = self.locally_overridden_fields.insert("prefix".to_owned());
_ = self.inherited_fields.remove("prefix");
*local_value
} else {
if *parent_value {
_ = self.inherited_fields.insert("prefix".to_owned());
}
*parent_value
}
}
}

impl GroupLineage {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Test adding a prefix to the references in attributes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
[
{
"name": "client.id",
"type": "string",
"brief": "some client id\n",
"examples": [
"a.einstein"
],
"requirement_level": "recommended",
"stability": "experimental"
},
{
"name": "geo.lat",
"type": "string",
"brief": "latitude of the geo coordinates.\n",
"examples": [
"123.456"
],
"requirement_level": "recommended",
"stability": "experimental"
},
{
"name": "geo.lon",
"type": "string",
"brief": "longitude of the geo coordinates.\n",
"examples": [
"234.456"
],
"requirement_level": "recommended",
"stability": "experimental"
},
{
"name": "geo.lat",
"type": "string",
"brief": "this is ref attribute",
"examples": [
"123.456"
],
"requirement_level": "recommended",
"stability": "experimental"
},
{
"name": "client.geo.lat",
"type": "string",
"brief": "My own latitude",
"examples": [
"123.456"
],
"requirement_level": "recommended",
"stability": "experimental",
"prefix": true
},
{
"name": "client.geo.lat",
"type": "string",
"brief": "this is embedded attribute",
"examples": [
"123.456"
],
"requirement_level": "recommended",
"stability": "experimental"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
{
"registry_url": "https://127.0.0.1",
"groups": [
{
"id": "registry.client",
"type": "attribute_group",
"brief": "Describes information about the client.",
"prefix": "client",
"attributes": [
0,
4
],
"lineage": {
"source_file": "data/registry-test-10-prefix-refs/registry/client.yaml",
"attributes": {
"client.geo.lat": {
"source_group": "registry.geo",
"inherited_fields": [
"examples",
"note",
"requirement_level",
"stability"
],
"locally_overridden_fields": [
"brief"
]
}
}
}
},
{
"id": "registry.geo",
"type": "attribute_group",
"brief": "Attributes describing geo.",
"prefix": "geo",
"attributes": [
1,
2
],
"lineage": {
"source_file": "data/registry-test-10-prefix-refs/registry/geo.yaml"
}
},
{
"id": "usage",
"type": "attribute_group",
"brief": "Attributes for test.",
"prefix": "usage",
"attributes": [
0,
2,
3,
5
],
"lineage": {
"source_file": "data/registry-test-10-prefix-refs/registry/usage.yaml",
"attributes": {
"client.geo.lat": {
"source_group": "registry.client",
"inherited_fields": [
"examples",
"note",
"requirement_level",
"stability"
],
"locally_overridden_fields": [
"brief"
]
},
"client.id": {
"source_group": "registry.client",
"inherited_fields": [
"brief",
"examples",
"note",
"requirement_level",
"stability"
]
},
"geo.lat": {
"source_group": "registry.geo",
"inherited_fields": [
"examples",
"note",
"requirement_level",
"stability"
],
"locally_overridden_fields": [
"brief"
]
},
"geo.lon": {
"source_group": "registry.geo",
"inherited_fields": [
"brief",
"examples",
"note",
"requirement_level",
"stability"
]
}
}
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
groups:
- id: registry.client
prefix: client
type: attribute_group
brief: "Describes information about the client."
attributes:
- id: id
type: string
stability: experimental
brief: >
some client id
examples: ['a.einstein']
- ref: geo.lat
prefix: true
brief: My own latitude
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
groups:
- id: registry.geo
brief: Attributes describing geo.
type: attribute_group
prefix: geo
attributes:
- id: lat
type: string
stability: experimental
brief: >
latitude of the geo coordinates.
examples: ["123.456"]
- id: lon
type: string
stability: experimental
brief: >
longitude of the geo coordinates.
examples: [ "234.456" ]
Loading

0 comments on commit 98fe349

Please sign in to comment.