Skip to content

[pkg/ottl] Add instrumentation scope context #14892

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

Merged
merged 6 commits into from
Oct 14, 2022
Merged
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
16 changes: 16 additions & 0 deletions .chloggen/ottl-instrumentation-context.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: pkg/ottl

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Add new Instrumentation Scope context to allow for efficient transformation of Instrumentation Scope telemetry.

# One or more tracking issues related to the change
issues: [14892]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
4 changes: 2 additions & 2 deletions pkg/ottl/contexts/internal/ottlcommon/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func ResourcePathGetSetter[K ResourceContext](path []ottl.Field) (ottl.GetSetter
}
return accessResourceAttributesKey[K](mapKey), nil
case "dropped_attributes_count":
return accessDroppedAttributesCount[K](), nil
return accessResourceDroppedAttributesCount[K](), nil
}

return nil, fmt.Errorf("invalid resource path expression %v", path)
Expand Down Expand Up @@ -81,7 +81,7 @@ func accessResourceAttributesKey[K ResourceContext](mapKey *string) ottl.Standar
}
}

func accessDroppedAttributesCount[K ResourceContext]() ottl.StandardGetSetter[K] {
func accessResourceDroppedAttributesCount[K ResourceContext]() ottl.StandardGetSetter[K] {
return ottl.StandardGetSetter[K]{
Getter: func(ctx K) interface{} {
return int64(ctx.GetResource().DroppedAttributesCount())
Expand Down
15 changes: 15 additions & 0 deletions pkg/ottl/contexts/internal/ottlcommon/scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ func ScopePathGetSetter[K InstrumentationScopeContext](path []ottl.Field) (ottl.
return accessInstrumentationScopeAttributes[K](), nil
}
return accessInstrumentationScopeAttributesKey[K](mapKey), nil
case "dropped_attributes_count":
return accessInstrumentationScopeDroppedAttributesCount[K](), nil
}

return nil, fmt.Errorf("invalid scope path expression %v", path)
Expand Down Expand Up @@ -109,3 +111,16 @@ func accessInstrumentationScopeVersion[K InstrumentationScopeContext]() ottl.Sta
},
}
}

func accessInstrumentationScopeDroppedAttributesCount[K InstrumentationScopeContext]() ottl.StandardGetSetter[K] {
return ottl.StandardGetSetter[K]{
Getter: func(ctx K) interface{} {
return int64(ctx.GetInstrumentationScope().DroppedAttributesCount())
},
Setter: func(ctx K, val interface{}) {
if i, ok := val.(int64); ok {
ctx.GetInstrumentationScope().SetDroppedAttributesCount(uint32(i))
}
},
}
}
14 changes: 14 additions & 0 deletions pkg/ottl/contexts/internal/ottlcommon/scope_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,19 @@ func TestScopePathGetSetter(t *testing.T) {
is.Attributes().PutStr("str", "newVal")
},
},
{
name: "dropped_attributes_count",
path: []ottl.Field{
{
Name: "dropped_attributes_count",
},
},
orig: int64(10),
newVal: int64(20),
modified: func(is pcommon.InstrumentationScope) {
is.SetDroppedAttributesCount(20)
},
},
{
name: "attributes bool",
path: []ottl.Field{
Expand Down Expand Up @@ -269,6 +282,7 @@ func createInstrumentationScope() pcommon.InstrumentationScope {
is := pcommon.NewInstrumentationScope()
is.SetName("library")
is.SetVersion("version")
is.SetDroppedAttributesCount(10)

is.Attributes().PutStr("str", "val")
is.Attributes().PutBool("bool", true)
Expand Down
52 changes: 27 additions & 25 deletions pkg/ottl/contexts/ottldatapoints/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,33 @@ In general, the DataPoints Context supports accessing pdata using the field name

The following fields are the exception.

| path | field accessed | type |
|----------------------------------------|---------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------|
| resource | resource of the data point being processed | pcommon.Resource |
| resource.attributes | resource attributes of the data point being processed | pcommon.Map |
| resource.attributes\[""\] | the value of the resource attribute of the data point being processed | string, bool, int64, float64, pcommon.Map, pcommon.Slice, []byte or nil |
| instrumentation_scope | instrumentation scope of the data point being processed | pcommon.InstrumentationScope |
| instrumentation_scope.name | name of the instrumentation scope of the data point being processed | string |
| instrumentation_scope.version | version of the instrumentation scope of the data point being processed | string |
| instrumentation_scope.attributes | instrumentation scope attributes of the data point being processed | pcommon.Map |
| instrumentation_scope.attributes\[""\] | the value of the instrumentation scope attribute of the data point being processed | string, bool, int64, float64, pcommon.Map, pcommon.Slice, []byte or nil |
| attributes | attributes of the data point being processed | pcommon.Map |
| attributes\[""\] | the value of the attribute of the data point being processed | string, bool, int64, float64, pcommon.Map, pcommon.Slice, []byte or nil |
| metric | the metric to which the data point being processed belongs | pmetric.Metric |
| metric.name | the name of the metric to which the data point being processed belongs | string |
| metric.description | the description of the metric to which the data point being processed belongs | string |
| metric.unit | the unit of the metric to which the data point being processed belongs | string |
| metric.type | the type of the metric to which the data point being processed belongs. See enums below for integer mapping. | int64 |
| metric.aggregation_temporality | the aggregation temporality of the metric to which the data point being processed belongs | int64 |
| metric.is_monotonic | the monotonicity of the metric to which the data point being processed belongs | bool |
| positive | the positive buckets of the data point being processed | pmetric.ExponentialHistogramDataPoint |
| positive.offset | the offset of the positive buckets of the data point being processed | int64 |
| positive.bucket_counts | the bucket_counts of the positive buckets of the data point being processed | uint64 |
| negative | the negative buckets of the data point being processed | pmetric.ExponentialHistogramDataPoint |
| negative.offset | the offset of the negative buckets of the data point being processed | int64 |
| negative.bucket_counts | the bucket_counts of the negative buckets of the data point being processed | uint64 |
| path | field accessed | type |
|------------------------------------------------|---------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------|
| resource | resource of the data point being processed | pcommon.Resource |
| resource.attributes | resource attributes of the data point being processed | pcommon.Map |
| resource.attributes\[""\] | the value of the resource attribute of the data point being processed | string, bool, int64, float64, pcommon.Map, pcommon.Slice, []byte or nil |
| resource.dropped_attributes_count | number of dropped attributes of the resource of the data point being processed | int64 |
| instrumentation_scope | instrumentation scope of the data point being processed | pcommon.InstrumentationScope |
| instrumentation_scope.name | name of the instrumentation scope of the data point being processed | string |
| instrumentation_scope.version | version of the instrumentation scope of the data point being processed | string |
| instrumentation_scope.dropped_attributes_count | number of dropped attributes of the instrumentation scope of the data point being processed | int64 |
| instrumentation_scope.attributes | instrumentation scope attributes of the data point being processed | pcommon.Map |
| instrumentation_scope.attributes\[""\] | the value of the instrumentation scope attribute of the data point being processed | string, bool, int64, float64, pcommon.Map, pcommon.Slice, []byte or nil |
| attributes | attributes of the data point being processed | pcommon.Map |
| attributes\[""\] | the value of the attribute of the data point being processed | string, bool, int64, float64, pcommon.Map, pcommon.Slice, []byte or nil |
| metric | the metric to which the data point being processed belongs | pmetric.Metric |
| metric.name | the name of the metric to which the data point being processed belongs | string |
| metric.description | the description of the metric to which the data point being processed belongs | string |
| metric.unit | the unit of the metric to which the data point being processed belongs | string |
| metric.type | the type of the metric to which the data point being processed belongs. See enums below for integer mapping. | int64 |
| metric.aggregation_temporality | the aggregation temporality of the metric to which the data point being processed belongs | int64 |
| metric.is_monotonic | the monotonicity of the metric to which the data point being processed belongs | bool |
| positive | the positive buckets of the data point being processed | pmetric.ExponentialHistogramDataPoint |
| positive.offset | the offset of the positive buckets of the data point being processed | int64 |
| positive.bucket_counts | the bucket_counts of the positive buckets of the data point being processed | uint64 |
| negative | the negative buckets of the data point being processed | pmetric.ExponentialHistogramDataPoint |
| negative.offset | the offset of the negative buckets of the data point being processed | int64 |
| negative.bucket_counts | the bucket_counts of the negative buckets of the data point being processed | uint64 |

## Enums

Expand Down
Loading