Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
4625798
reagg on record
shalper2 Jul 21, 2025
4e92e45
chlog
shalper2 Jul 21, 2025
daedfc6
simplify reagg
shalper2 Jul 22, 2025
adc067d
added default values for gauge and sum type
shalper2 Jul 22, 2025
a6505a2
simplified record
shalper2 Jul 23, 2025
4566efb
gogenerate
shalper2 Jul 23, 2025
78d18fc
fix original tests
shalper2 Jul 23, 2025
ccc3311
updated record
shalper2 Jul 24, 2025
17643a6
validation
shalper2 Jul 24, 2025
1606658
make gogenerate and update metadata.yaml
shalper2 Jul 24, 2025
bb2c56f
fixed renamed variable
shalper2 Jul 24, 2025
78632d5
removed broked validation
shalper2 Jul 24, 2025
a6cfa89
check valid aggregation strategy at unmarshal
shalper2 Jul 25, 2025
205d29a
fixed existing tests
shalper2 Jul 27, 2025
6f3a182
fixed optional attributes
shalper2 Jul 28, 2025
10607e9
removed generated testresults
shalper2 Jul 28, 2025
d2c17c3
updating tests
shalper2 Jul 29, 2025
d49b0af
removing testresults artifacts
shalper2 Jul 29, 2025
4f20a57
constants for sum and average
shalper2 Jul 29, 2025
b84e7ba
fixed typo
shalper2 Jul 29, 2025
927298f
added min/max
shalper2 Jul 29, 2025
4a66754
cleaned up if statements
shalper2 Jul 29, 2025
4cdea20
changes to testing
shalper2 Jul 31, 2025
9d5eb44
rm junit stuff
shalper2 Jul 31, 2025
c1e7d73
Revert "rm junit stuff"
shalper2 Aug 4, 2025
d762a10
Reapply "rm junit stuff"
shalper2 Aug 4, 2025
4a032c7
Revert "rm junit stuff"
shalper2 Aug 4, 2025
81fa4b9
Revert "changes to testing"
shalper2 Aug 4, 2025
c8cddc3
fixed most tests
shalper2 Aug 21, 2025
f9ade84
fixed lint
shalper2 Aug 21, 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]
14 changes: 12 additions & 2 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 Down Expand Up @@ -454,7 +464,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 +494,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
33 changes: 33 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,13 @@ type Attribute struct {
Optional bool `mapstructure:"optional"`
}

func (a *Attribute) Unmarshal(parser *confmap.Conf) error {
if !parser.IsSet("enabled") {
return errors.New("missing required field for attribute: `enabled`")
}
return parser.Unmarshal(a)
}

// 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 +351,31 @@ func (a Attribute) TestValue() string {
return ""
}

func (a Attribute) TestValueTwo() string {
if len(a.Enum) >= 2 {
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 Down

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

Loading
Loading