Skip to content

Commit

Permalink
Add enabled flag to resource attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
hughesjj committed Jan 17, 2023
1 parent 7ec7f14 commit d86b651
Show file tree
Hide file tree
Showing 143 changed files with 3,545 additions and 831 deletions.
18 changes: 18 additions & 0 deletions .chloggen/add_resource_attribute_settings.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# 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: Adds ability to enable/disable resource attributes in output and sets all existing resource attributes to enabled by default.

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

# (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: |
We may change NewMetricBuilder in the future from taking in ResourceMetrics to taking in a MetricsBuildingConfiguration,
but for now changing the settings requires a call to WithResourceAttributeSettings.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ generate:
mdatagen-test:
cd cmd/mdatagen && $(GOCMD) install .
cd cmd/mdatagen && $(GOCMD) generate ./...
cd cmd/mdatagen && $(GOCMD) test ./...

.PHONY: chlog-install
chlog-install:
Expand Down
5 changes: 3 additions & 2 deletions cmd/mdatagen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ See [metric-metadata.yaml](metric-metadata.yaml) for file format documentation.

If adding a new receiver a `doc.go` file should also be added to trigger the generation. See below for details.

## Build
## Generating

`make generate` triggers the following actions:

Expand All @@ -33,4 +33,5 @@ In order to introduce support of a new functionality in metadata.yaml:
2. Add usage of the new functionality in (metadata.yaml)[./metadata.yaml].
3. Run `make mdatagen-test`.
4. Make sure all tests are passing including (generated tests)[./internal/metadata/generated_metrics_test.go].
5. Run `make generate`.
5. Run `make generate`.

9 changes: 5 additions & 4 deletions cmd/mdatagen/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ metrics:
## Resource Attributes
| Name | Description | Values |
| ---- | ----------- | ------ |
| string.enum.resource.attr | Resource attribute with a known set of string values. | Str: ``one``, ``two`` |
| string.resource.attr | Resource attribute with any string value. | Any Str |
| Name | Description | Values | Enabled |
| ---- | ----------- | ------ | ------- |
| optional.resource.attr | explicitly disabled ResourceAttribute | Any Str | false |
| 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 |
83 changes: 74 additions & 9 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.

33 changes: 25 additions & 8 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.

2 changes: 2 additions & 0 deletions cmd/mdatagen/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ type attribute struct {
Description string `mapstructure:"description"`
// NameOverride can be used to override the attribute name.
NameOverride string `mapstructure:"name_override"`
// Enabled defines whether the attribute is enabled by default.
Enabled bool `yaml:"enabled" validate:"required"`
// Enum can optionally describe the set of values to which the attribute can belong.
Enum []string
// Type is an attribute type.
Expand Down
9 changes: 9 additions & 0 deletions cmd/mdatagen/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,26 @@ func Test_loadMetadata(t *testing.T) {
ResourceAttributes: map[attributeName]attribute{
"string.resource.attr": {
Description: "Resource attribute with any string value.",
Enabled: true,
Type: ValueType{
ValueType: pcommon.ValueTypeStr,
},
},
"string.enum.resource.attr": {
Description: "Resource attribute with a known set of string values.",
Enabled: true,
Enum: []string{"one", "two"},
Type: ValueType{
ValueType: pcommon.ValueTypeStr,
},
},
"optional.resource.attr": {
Description: "explicitly disabled ResourceAttribute",
Enabled: false,
Type: ValueType{
ValueType: pcommon.ValueTypeStr,
},
},
},
Attributes: map[attributeName]attribute{
"enum_attr": {
Expand Down
7 changes: 7 additions & 0 deletions cmd/mdatagen/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,18 @@ resource_attributes:
string.resource.attr:
description: Resource attribute with any string value.
type: string
enabled: true

string.enum.resource.attr:
description: Resource attribute with a known set of string values.
type: string
enum: [one, two]
enabled: true

optional.resource.attr:
description: explicitly disabled ResourceAttribute
type: string
enabled: false

attributes:
string_attr:
Expand Down
2 changes: 2 additions & 0 deletions cmd/mdatagen/metric-metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ resource_attributes:
<attribute.name>:
# Required: description of the attribute.
description:
# Optional: Whether the resource attribute is emitted by default.
enabled: bool
# Required: attribute value type.
type: <string|int|double|bool|bytes>

Expand Down
6 changes: 3 additions & 3 deletions cmd/mdatagen/templates/documentation.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ metrics:

## Resource Attributes

| Name | Description | Values |
| ---- | ----------- | ------ |
| Name | Description | Values | Enabled |
| ---- | ----------- | ------ | ------- |
{{- range $attributeName, $attribute := .ResourceAttributes }}
| {{ $attributeName }} | {{ $attribute.Description }} |
{{- if $attribute.Enum }} {{ $attribute.Type }}: ``{{ stringsJoin $attribute.Enum "``, ``" }}``{{ else }} Any {{ $attribute.Type }}{{ end }} |
{{- if $attribute.Enum }} {{ $attribute.Type }}: ``{{ stringsJoin $attribute.Enum "``, ``" }}``{{ else }} Any {{ $attribute.Type }}{{ end }} | {{ $attribute.Enabled }} |
{{- end }}

{{- end }}
Loading

0 comments on commit d86b651

Please sign in to comment.