Skip to content

Commit

Permalink
[mdatagen] allow adding resource_attribute warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
povilasv committed Oct 5, 2023
1 parent 14375a3 commit 27d0914
Show file tree
Hide file tree
Showing 113 changed files with 1,017 additions and 37 deletions.
27 changes: 27 additions & 0 deletions .chloggen/main-mdatagen-resource-warnings.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# 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. filelogreceiver)
component: mdatagen

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "allows adding warning section to resource_attribute configuration"

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [19174]

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

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# 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: [api]
3 changes: 3 additions & 0 deletions cmd/mdatagen/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,6 @@ metrics:
| slice.resource.attr | Resource attribute with a slice value. | Any Slice | true |
| string.enum.resource.attr | Resource attribute with a known set of string values. | Str: ``one``, ``two`` | true |
| string.resource.attr | Resource attribute with any string value. | Any Str | true |
| string.resource.attr_disable_warning | Resource attribute with any string value. | Any Str | true |
| string.resource.attr_remove_warning | Resource attribute with any string value. | Any Str | false |
| string.resource.attr_to_be_removed | Resource attribute with any string value. | Any Str | true |
36 changes: 31 additions & 5 deletions cmd/mdatagen/internal/metadata/generated_config.go

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

52 changes: 32 additions & 20 deletions cmd/mdatagen/internal/metadata/generated_config_test.go

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

9 changes: 9 additions & 0 deletions cmd/mdatagen/internal/metadata/generated_metrics.go

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

16 changes: 16 additions & 0 deletions cmd/mdatagen/internal/metadata/generated_metrics_test.go

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

21 changes: 21 additions & 0 deletions cmd/mdatagen/internal/metadata/generated_resource.go

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

22 changes: 20 additions & 2 deletions cmd/mdatagen/internal/metadata/generated_resource_test.go

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

12 changes: 12 additions & 0 deletions cmd/mdatagen/internal/metadata/testdata/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ all_set:
enabled: true
string.resource.attr:
enabled: true
string.resource.attr_disable_warning:
enabled: true
string.resource.attr_remove_warning:
enabled: true
string.resource.attr_to_be_removed:
enabled: true
none_set:
metrics:
default.metric:
Expand All @@ -41,3 +47,9 @@ none_set:
enabled: false
string.resource.attr:
enabled: false
string.resource.attr_disable_warning:
enabled: false
string.resource.attr_remove_warning:
enabled: false
string.resource.attr_to_be_removed:
enabled: false
6 changes: 4 additions & 2 deletions cmd/mdatagen/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ func (m metric) Data() MetricData {
}

type warnings struct {
// A warning that will be displayed if the metric is enabled in user config.
// A warning that will be displayed if the field is enabled in user config.
IfEnabled string `mapstructure:"if_enabled"`
// A warning that will be displayed if `enabled` field is not set explicitly in user config.
IfEnabledNotSet string `mapstructure:"if_enabled_not_set"`
// A warning that will be displayed if the metrics is configured by user in any way.
// A warning that will be displayed if the field is configured by user in any way.
IfConfigured string `mapstructure:"if_configured"`
}

Expand All @@ -162,6 +162,8 @@ type attribute struct {
Type ValueType `mapstructure:"type"`
// FullName is the attribute name populated from the map key.
FullName attributeName `mapstructure:"-"`
// Warnings that will be shown to user under specified conditions.
Warnings warnings `mapstructure:"warnings"`
}

// Name returns actual name of the attribute that is set on the metric after applying NameOverride.
Expand Down
34 changes: 34 additions & 0 deletions cmd/mdatagen/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,41 @@ func Test_loadMetadata(t *testing.T) {
},
FullName: "map.resource.attr",
},
"string.resource.attr_disable_warning": {
Description: "Resource attribute with any string value.",
Warnings: warnings{
IfEnabledNotSet: "This resource_attribute will be disabled by default soon.",
},
Enabled: true,
Type: ValueType{
ValueType: pcommon.ValueTypeStr,
},
FullName: "string.resource.attr_disable_warning",
},
"string.resource.attr_remove_warning": {
Description: "Resource attribute with any string value.",
Warnings: warnings{
IfConfigured: "This resource_attribute is deprecated and will be removed soon.",
},
Enabled: false,
Type: ValueType{
ValueType: pcommon.ValueTypeStr,
},
FullName: "string.resource.attr_remove_warning",
},
"string.resource.attr_to_be_removed": {
Description: "Resource attribute with any string value.",
Warnings: warnings{
IfEnabled: "This resource_attribute is deprecated and will be removed soon.",
},
Enabled: true,
Type: ValueType{
ValueType: pcommon.ValueTypeStr,
},
FullName: "string.resource.attr_to_be_removed",
},
},

Attributes: map[attributeName]attribute{
"enum_attr": {
Description: "Attribute with a known set of string values.",
Expand Down
21 changes: 21 additions & 0 deletions cmd/mdatagen/metadata-sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,27 @@ resource_attributes:
type: map
enabled: true

string.resource.attr_disable_warning:
description: Resource attribute with any string value.
type: string
enabled: true
warnings:
if_enabled_not_set: This resource_attribute will be disabled by default soon.

string.resource.attr_remove_warning:
description: Resource attribute with any string value.
type: string
enabled: false
warnings:
if_configured: This resource_attribute is deprecated and will be removed soon.

string.resource.attr_to_be_removed:
description: Resource attribute with any string value.
type: string
enabled: true
warnings:
if_enabled: This resource_attribute is deprecated and will be removed soon.

attributes:
string_attr:
description: Attribute with any string value.
Expand Down
Loading

0 comments on commit 27d0914

Please sign in to comment.