Skip to content
Open
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
4360d05
reagg on record
shalper2 Jul 21, 2025
7c0cf5e
chlog
shalper2 Jul 21, 2025
35bbea3
simplify reagg
shalper2 Jul 22, 2025
b586ac7
added default values for gauge and sum type
shalper2 Jul 22, 2025
46b4f08
simplified record
shalper2 Jul 23, 2025
89abc2e
gogenerate
shalper2 Jul 23, 2025
3152269
fix original tests
shalper2 Jul 23, 2025
f446bd7
updated record
shalper2 Jul 24, 2025
38e3202
validation
shalper2 Jul 24, 2025
a96aa50
make gogenerate and update metadata.yaml
shalper2 Jul 24, 2025
8a34414
fixed renamed variable
shalper2 Jul 24, 2025
a10bce1
removed broked validation
shalper2 Jul 24, 2025
a62c37e
check valid aggregation strategy at unmarshal
shalper2 Jul 25, 2025
cb6f773
fixed existing tests
shalper2 Jul 27, 2025
22cb283
fixed optional attributes
shalper2 Jul 28, 2025
6370d0b
removed generated testresults
shalper2 Jul 28, 2025
8c25665
updating tests
shalper2 Jul 29, 2025
83d6a48
removing testresults artifacts
shalper2 Jul 29, 2025
79fc792
constants for sum and average
shalper2 Jul 29, 2025
a9a4180
fixed typo
shalper2 Jul 29, 2025
6c6ac4b
added min/max
shalper2 Jul 29, 2025
d3deb99
cleaned up if statements
shalper2 Jul 29, 2025
64ed5c4
changes to testing
shalper2 Jul 31, 2025
e1b8492
rm junit stuff
shalper2 Jul 31, 2025
9568c45
Revert "rm junit stuff"
shalper2 Aug 4, 2025
53f9727
Reapply "rm junit stuff"
shalper2 Aug 4, 2025
2f088d3
Revert "rm junit stuff"
shalper2 Aug 4, 2025
2afb202
Revert "changes to testing"
shalper2 Aug 4, 2025
a61e0f0
fixed most tests
shalper2 Aug 21, 2025
5964165
fixed lint
shalper2 Aug 21, 2025
be95636
optional attributes before agg
shalper2 Sep 24, 2025
de2b34a
default enabled attribute to true
shalper2 Sep 24, 2025
70d7548
update metadata-schema
shalper2 Sep 24, 2025
37ca3d3
make gogenerate
shalper2 Sep 24, 2025
af4235f
make gogenerate
shalper2 Sep 24, 2025
0de401f
extened tests to cover different agg strategies
shalper2 Sep 24, 2025
4f8e424
make gogenerate/rebase
shalper2 Sep 24, 2025
7396a47
make gogenerate
shalper2 Sep 24, 2025
2b62d85
Update cmd/mdatagen/internal/templates/metrics_test.go.tmpl
shalper2 Sep 24, 2025
e32d0c8
fixed comments
shalper2 Sep 24, 2025
5bcf1a8
fixed generated consts
shalper2 Sep 24, 2025
7c45208
rm junit
shalper2 Sep 24, 2025
3cf891e
work on contrib tests
shalper2 Sep 25, 2025
69f7ba7
fixes attribute overwrite and enforces enabled for resource
shalper2 Sep 25, 2025
4c964c7
deleted junit
shalper2 Sep 25, 2025
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
25 changes: 25 additions & 0 deletions .chloggen/10726-reag.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Use this changelog template to create an entry for release notes.

# 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. otlpreceiver)
component: mdatagen

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "Add support for metric re-aggregation by disabling attributes in metadata.yaml and user config"

# One or more tracking issues or pull requests related to the change
issues: [10726]

# (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:

# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
30 changes: 22 additions & 8 deletions cmd/mdatagen/internal/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ func TestLoadMetadata(t *testing.T) {
ValueType: pcommon.ValueTypeStr,
},
FullName: "enum_attr",
Enabled: true,
},
"string_attr": {
Description: "Attribute with any string value.",
Expand All @@ -161,6 +162,7 @@ func TestLoadMetadata(t *testing.T) {
ValueType: pcommon.ValueTypeStr,
},
FullName: "string_attr",
Enabled: false,
},
"overridden_int_attr": {
Description: "Integer attribute with overridden name.",
Expand All @@ -169,34 +171,39 @@ func TestLoadMetadata(t *testing.T) {
ValueType: pcommon.ValueTypeInt,
},
FullName: "overridden_int_attr",
Enabled: true,
},
"boolean_attr": {
Description: "Attribute with a boolean value.",
Type: ValueType{
ValueType: pcommon.ValueTypeBool,
},
FullName: "boolean_attr",
Enabled: true,
},
"boolean_attr2": {
Description: "Another attribute with a boolean value.",
Type: ValueType{
ValueType: pcommon.ValueTypeBool,
},
FullName: "boolean_attr2",
Enabled: true,
},
"slice_attr": {
Description: "Attribute with a slice value.",
Type: ValueType{
ValueType: pcommon.ValueTypeSlice,
},
FullName: "slice_attr",
Enabled: true,
},
"map_attr": {
Description: "Attribute with a map value.",
Type: ValueType{
ValueType: pcommon.ValueTypeMap,
},
FullName: "map_attr",
Enabled: true,
},
"optional_int_attr": {
Description: "An optional attribute with an integer value",
Expand All @@ -205,6 +212,7 @@ func TestLoadMetadata(t *testing.T) {
},
FullName: "optional_int_attr",
Optional: true,
Enabled: true,
},
"optional_string_attr": {
Description: "An optional attribute with any string value",
Expand All @@ -213,8 +221,10 @@ func TestLoadMetadata(t *testing.T) {
},
FullName: "optional_string_attr",
Optional: true,
Enabled: true,
},
},

Metrics: map[MetricName]Metric{
"default.metric": {
Signal: Signal{
Expand All @@ -224,7 +234,8 @@ func TestLoadMetadata(t *testing.T) {
Warnings: Warnings{
IfEnabledNotSet: "This metric will be disabled by default soon.",
},
Attributes: []AttributeName{"string_attr", "overridden_int_attr", "enum_attr", "slice_attr", "map_attr", "optional_int_attr", "optional_string_attr"},
Attributes: []AttributeName{"string_attr", "overridden_int_attr", "enum_attr", "slice_attr", "map_attr", "optional_int_attr", "optional_string_attr"},
NumAttributes: 7,
},
Unit: strPtr("s"),
Sum: &Sum{
Expand All @@ -240,7 +251,8 @@ func TestLoadMetadata(t *testing.T) {
Warnings: Warnings{
IfConfigured: "This metric is deprecated and will be removed soon.",
},
Attributes: []AttributeName{"string_attr", "boolean_attr", "boolean_attr2", "optional_string_attr"},
Attributes: []AttributeName{"string_attr", "boolean_attr", "boolean_attr2", "optional_string_attr"},
NumAttributes: 4,
},
Unit: strPtr("1"),
Gauge: &Gauge{
Expand All @@ -254,7 +266,8 @@ func TestLoadMetadata(t *testing.T) {
Warnings: Warnings{
IfConfigured: "This metric is deprecated and will be removed soon.",
},
Attributes: []AttributeName{"string_attr", "boolean_attr"},
Attributes: []AttributeName{"string_attr", "boolean_attr"},
NumAttributes: 2,
},
Unit: strPtr(""),
Gauge: &Gauge{
Expand All @@ -280,9 +293,10 @@ func TestLoadMetadata(t *testing.T) {
},
"metric.input_type": {
Signal: Signal{
Enabled: true,
Description: "Monotonic cumulative sum int metric with string input_type enabled by default.",
Attributes: []AttributeName{"string_attr", "overridden_int_attr", "enum_attr", "slice_attr", "map_attr"},
Enabled: true,
Description: "Monotonic cumulative sum int metric with string input_type enabled by default.",
Attributes: []AttributeName{"string_attr", "overridden_int_attr", "enum_attr", "slice_attr", "map_attr"},
NumAttributes: 5,
},
Unit: strPtr("s"),
Sum: &Sum{
Expand Down Expand Up @@ -454,7 +468,7 @@ func TestLoadMetadata(t *testing.T) {
{
name: "testdata/invalid_type_rattr.yaml",
want: Metadata{},
wantErr: "decoding failed due to the following error(s):\n\n'resource_attributes[string.resource.attr].type' invalid type: \"invalidtype\"",
wantErr: "decoding failed due to the following error(s):\n\n'type' invalid type: \"invalidtype\"",
},
{
name: "testdata/no_enabled.yaml",
Expand Down Expand Up @@ -484,7 +498,7 @@ func TestLoadMetadata(t *testing.T) {
{
name: "testdata/invalid_type_attr.yaml",
want: Metadata{},
wantErr: "decoding failed due to the following error(s):\n\n'attributes[used_attr].type' invalid type: \"invalidtype\"",
wantErr: "decoding failed due to the following error(s):\n\n'type' invalid type: \"invalidtype\"",
},
{
name: "testdata/~~this file doesn't exist~~.yaml",
Expand Down
44 changes: 44 additions & 0 deletions cmd/mdatagen/internal/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strconv"
"strings"

"go.opentelemetry.io/collector/confmap"
"go.opentelemetry.io/collector/filter"
"go.opentelemetry.io/collector/pdata/pcommon"
)
Expand Down Expand Up @@ -310,6 +311,20 @@ type Attribute struct {
Optional bool `mapstructure:"optional"`
}

func (a *Attribute) Unmarshal(parser *confmap.Conf) error {
err := parser.Unmarshal(a)
if err != nil {
return err
}

// default enabled to true
if !parser.IsSet("enabled") {
Copy link
Member

Choose a reason for hiding this comment

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

looks like this is also applied to the resource attributes. The resource attributes with missing enabled fields now get enabled=true. That's why tests are failing.

I think we should make the enabled required and fill all missing spots in contrib to unblock this PR

a.Enabled = true
}

return nil
}

// Name returns actual name of the attribute that is set on the metric after applying NameOverride.
func (a Attribute) Name() AttributeName {
if a.NameOverride != "" {
Expand Down Expand Up @@ -343,6 +358,32 @@ func (a Attribute) TestValue() string {
return ""
}

func (a Attribute) TestValueTwo() string {
if len(a.Enum) > 2 {
fmt.Printf("second %q", a.Enum[1])
return fmt.Sprintf(`%q`, a.Enum[1])
}
switch a.Type.ValueType {
case pcommon.ValueTypeEmpty:
return ""
case pcommon.ValueTypeStr:
return fmt.Sprintf(`"%s-val-2"`, a.FullName)
case pcommon.ValueTypeInt:
return strconv.Itoa(len(a.FullName) + 1)
case pcommon.ValueTypeDouble:
return fmt.Sprintf("%f", 1.1+float64(len(a.FullName)))
case pcommon.ValueTypeBool:
return strconv.FormatBool(len(a.FullName)%2 == 1)
case pcommon.ValueTypeMap:
return fmt.Sprintf(`map[string]any{"key3": "%s-val3", "key4": "%s-val4"}`, a.FullName, a.FullName)
case pcommon.ValueTypeSlice:
return fmt.Sprintf(`[]any{"%s-item3", "%s-item4"}`, a.FullName, a.FullName)
case pcommon.ValueTypeBytes:
return fmt.Sprintf(`[]byte("%s-val-2")`, a.FullName)
}
return ""
}

type Signal struct {
// Enabled defines whether the signal is enabled by default.
Enabled bool `mapstructure:"enabled"`
Expand All @@ -361,6 +402,9 @@ type Signal struct {

// Attributes is the list of attributes that the signal emits.
Attributes []AttributeName `mapstructure:"attributes"`

// NumAttributes is the length of the attribtues field.
NumAttributes int
}

func (s Signal) HasOptionalAttribute(attrs map[AttributeName]Attribute) bool {
Expand Down
10 changes: 9 additions & 1 deletion cmd/mdatagen/internal/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,15 @@ func (m *Metric) Unmarshal(parser *confmap.Conf) error {
if !parser.IsSet("enabled") {
return errors.New("missing required field: `enabled`")
}
return parser.Unmarshal(m)

err := parser.Unmarshal(m)
if err != nil {
return err
}

m.NumAttributes = len(m.Attributes)

return nil
}

func (m Metric) Data() MetricData {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading