Skip to content

Commit

Permalink
[mdatagen] Rename metadata.yaml attribute field value -> name_override (
Browse files Browse the repository at this point in the history
#16561)

`value` is a confusing name for an optional field that is used to override the attribute name defined in the key
  • Loading branch information
dmitryax authored Dec 1, 2022
1 parent 7f9cb88 commit c6977ca
Show file tree
Hide file tree
Showing 26 changed files with 153 additions and 151 deletions.
11 changes: 11 additions & 0 deletions .chloggen/mdatagen-rename-attribute-value-field.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

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

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Rename metadata.yaml attribute field from `value` to `name_override`

# One or more tracking issues related to the change
issues: [16561]
6 changes: 2 additions & 4 deletions cmd/mdatagen/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,8 @@ func (m metric) IsEnabled() bool {
type attribute struct {
// Description describes the purpose of the attribute.
Description string `validate:"notblank"`
// Value can optionally specify the value this attribute will have.
// For example, the attribute may have the identifier `MemState` to its
// value may be `state` when used.
Value string
// NameOverride can be used to override the attribute name.
NameOverride string `mapstructure:"name_override"`
// Enum can optionally describe the set of values to which the attribute can belong.
Enum []string
// Type is an attribute type.
Expand Down
18 changes: 9 additions & 9 deletions cmd/mdatagen/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,30 +38,30 @@ func Test_loadMetadata(t *testing.T) {
SemConvVersion: "1.9.0",
Attributes: map[attributeName]attribute{
"enumAttribute": {
Description: "Attribute with a known set of values.",
Value: "",
Enum: []string{"red", "green", "blue"},
Description: "Attribute with a known set of values.",
NameOverride: "",
Enum: []string{"red", "green", "blue"},
Type: ValueType{
ValueType: pcommon.ValueTypeStr,
},
},
"freeFormAttribute": {
Description: "Attribute that can take on any value.",
Value: "",
Description: "Attribute that can take on any value.",
NameOverride: "",
Type: ValueType{
ValueType: pcommon.ValueTypeStr,
},
},
"freeFormAttributeWithValue": {
Description: "Attribute that has alternate value set.",
Value: "state",
Description: "Attribute that has alternate value set.",
NameOverride: "state",
Type: ValueType{
ValueType: pcommon.ValueTypeStr,
},
},
"booleanValueType": {
Description: "Attribute with a boolean value.",
Value: "0",
Description: "Attribute with a boolean value.",
NameOverride: "0",
Type: ValueType{
ValueType: pcommon.ValueTypeBool,
},
Expand Down
6 changes: 3 additions & 3 deletions cmd/mdatagen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ func generateFile(tmplFile string, outputFile string, md metadata) error {
"attributeInfo": func(an attributeName) attribute {
return md.Attributes[an]
},
"attributeKey": func(an attributeName) string {
if md.Attributes[an].Value != "" {
return md.Attributes[an].Value
"attributeName": func(an attributeName) string {
if md.Attributes[an].NameOverride != "" {
return md.Attributes[an].NameOverride
}
return string(an)
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/mdatagen/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const (
name: metricreceiver
attributes:
cpu_type:
value: type
name_override: type
description: The type of CPU consumption
type: string
enum:
Expand Down
6 changes: 3 additions & 3 deletions cmd/mdatagen/metric-metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ resource_attributes:
# being described below.
attributes:
<attribute.name>:
# Optional: if the attribute name as described by the key is not the actual attribute
# value to be reported that value can be overridden here.
value:
# Optional: this field can be used to override the actual attribute name defined by the key.
# It should be used if multiple metrics have different attributes with the same name.
name_override:
# Required: description of the attribute.
description:
# Optional: array of attribute values if they are static values.
Expand Down
2 changes: 1 addition & 1 deletion cmd/mdatagen/templates/documentation.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
| ---- | ----------- | ------ |
{{- range $metric.Attributes }}
{{- $attribute := . | attributeInfo }}
| {{ . | attributeKey }} | {{ $attribute.Description }} |
| {{ attributeName . }} | {{ $attribute.Description }} |
{{- if $attribute.Enum }} {{ $attribute.Type }}: ``{{ stringsJoin $attribute.Enum "``, ``" }}``{{ else }} Any {{ $attribute.Type }}{{ end }} |
{{- end }}

Expand Down
10 changes: 5 additions & 5 deletions cmd/mdatagen/templates/metrics.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ func (m *metric{{ $name.Render }}) recordDataPoint(start pcommon.Timestamp, ts p
dp.Set{{ $metric.Data.MetricValueType }}Value(val)
{{- range $metric.Attributes }}
{{- if eq (attributeInfo .).Type.Primitive "[]byte" }}
dp.Attributes().PutEmptyBytes("{{ attributeKey .}}").FromRaw({{ .RenderUnexported }}AttributeValue)
dp.Attributes().PutEmptyBytes("{{ attributeName . }}").FromRaw({{ .RenderUnexported }}AttributeValue)
{{- else }}
dp.Attributes().Put{{ (attributeInfo .).Type }}("{{ attributeKey .}}", {{ .RenderUnexported }}AttributeValue)
dp.Attributes().Put{{ (attributeInfo .).Type }}("{{ attributeName .}}", {{ .RenderUnexported }}AttributeValue)
{{- end }}
{{- end }}
}
Expand Down Expand Up @@ -216,16 +216,16 @@ type ResourceMetricsOption func(pmetric.ResourceMetrics)
{{- range $attr.Enum }}
// With{{ $name.Render }}{{ . | publicVar }} sets "{{ $name }}={{ . }}" attribute for current resource.
func With{{ $name.Render }}{{ . | publicVar }}(rm pmetric.ResourceMetrics) {
rm.Resource().Attributes().PutStr("{{ attributeKey $name}}", "{{ . }}")
rm.Resource().Attributes().PutStr("{{ attributeName $name}}", "{{ . }}")
}
{{- else }}
// With{{ $name.Render }} sets provided value as "{{ $name }}" attribute for current resource.
func With{{ $name.Render }}(val {{ $attr.Type.Primitive }}) ResourceMetricsOption {
return func(rm pmetric.ResourceMetrics) {
{{- if eq $attr.Type.Primitive "[]byte" }}
rm.Resource().Attributes().PutEmptyBytes("{{ attributeKey $name}}").FromRaw(val)
rm.Resource().Attributes().PutEmptyBytes("{{ attributeName $name}}").FromRaw(val)
{{- else }}
rm.Resource().Attributes().Put{{ $attr.Type }}("{{ attributeKey $name}}", val)
rm.Resource().Attributes().Put{{ $attr.Type }}("{{ attributeName $name}}", val)
{{- end }}
}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/mdatagen/templates/metrics_test.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func TestAllMetrics(t *testing.T) {
assert.Equal(t, pmetric.NumberDataPointValueType{{ $metric.Data.MetricValueType }}, dp.ValueType())
assert.Equal(t, {{ $metric.Data.MetricValueType.BasicType }}(1), dp.{{ $metric.Data.MetricValueType }}Value())
{{- range $i, $attr := $metric.Attributes }}
attrVal, ok {{ if eq $i 0 }}:{{ end }}= dp.Attributes().Get("{{ attributeKey $attr }}")
attrVal, ok {{ if eq $i 0 }}:{{ end }}= dp.Attributes().Get("{{ attributeName $attr }}")
assert.True(t, ok)
{{- if (attributeInfo $attr).Enum }}
assert.Equal(t, "{{ index (attributeInfo $attr).Enum 0 }}", attrVal.Str())
Expand Down
4 changes: 2 additions & 2 deletions cmd/mdatagen/testdata/all_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ attributes:
type: string

freeFormAttributeWithValue:
value: state
name_override: state
description: Attribute that has alternate value set.
type: string

Expand All @@ -18,9 +18,9 @@ attributes:
enum: [red, green, blue]

booleanValueType:
name_override: false
description: Attribute with a boolean value.
type: bool
value: false

metrics:
# A metric enabled by default.
Expand Down
12 changes: 6 additions & 6 deletions receiver/activedirectorydsreceiver/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,44 @@ attributes:
- sent
- received
network_data_type:
value: type
name_override: type
description: The type of network data sent.
type: string
enum:
- compressed
- uncompressed
value_type:
value: type
name_override: type
description: The type of value sent.
type: string
enum:
- distingushed_names
- other
operation_type:
value: type
name_override: type
description: The type of operation.
type: string
enum:
- read
- write
- search
suboperation_type:
value: type
name_override: type
description: The type of suboperation.
type: string
enum:
- security_descriptor_propagations_event
- search
sync_result:
value: result
name_override: result
description: The result status of the sync request.
type: string
enum:
- success
- schema_mismatch
- other
bind_type:
value: type
name_override: type
description: The type of bind to the domain server.
type: string
enum:
Expand Down
20 changes: 10 additions & 10 deletions receiver/aerospikereceiver/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ resource_attributes:

attributes:
namespace_component:
value: component
name_override: component
description: Individual component of a namespace
type: string
enum:
Expand All @@ -19,7 +19,7 @@ attributes:
- set_index
- secondary_index
scan_type:
value: type
name_override: type
description: Type of scan operation performed on a namespace
type: string
enum:
Expand All @@ -28,22 +28,22 @@ attributes:
- ops_background
- udf_background
scan_result:
value: result
name_override: result
description: Result of a scan operation performed on a namespace
type: string
enum:
- abort
- complete
- error
index_type:
value: index
name_override: index
description: Type of index the operation was performed on
type: string
enum:
- primary
- secondary
query_type:
value: type
name_override: type
description: Type of query operation performed on a namespace
type: string
enum:
Expand All @@ -55,7 +55,7 @@ attributes:
- ops_background
- udf_background
query_result:
value: result
name_override: result
description: Result of a query operation performed on a namespace
type: string
enum:
Expand All @@ -64,7 +64,7 @@ attributes:
- error
- timeout # short_basic queries only
transaction_type:
value: type
name_override: type
description: Type of transaction performed on a namespace
type: string
enum:
Expand All @@ -73,7 +73,7 @@ attributes:
- udf
- write
transaction_result:
value: result
name_override: result
description: Result of a transaction performed on a namespace
type: string
enum:
Expand All @@ -83,15 +83,15 @@ attributes:
- success
- timeout
connection_type:
value: type
name_override: type
description: Type of connection to an Aerospike node
type: string
enum:
- client
- fabric
- heartbeat
connection_op:
value: operation
name_override: operation
description: Operation performed with a connection (open or close)
type: string
enum:
Expand Down
8 changes: 4 additions & 4 deletions receiver/apachereceiver/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,28 @@ resource_attributes:

attributes:
workers_state:
value: state
name_override: state
description: The state of workers.
type: string
enum:
- busy
- idle
cpu_level:
value: level
name_override: level
description: Level of processes.
type: string
enum:
- self
- children
cpu_mode:
value: mode
name_override: mode
description: Mode of processes.
type: string
enum:
- system
- user
scoreboard_state:
value: state
name_override: state
description: The state of a connection.
type: string
enum:
Expand Down
7 changes: 3 additions & 4 deletions receiver/bigipreceiver/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,28 @@ resource_attributes:

attributes:
direction:
value: direction
description: The direction of data.
type: string
enum:
- sent
- received
availability.status:
value: status
name_override: status
description: The availability status.
type: string
enum:
- offline
- unknown
- available
enabled.status:
value: status
name_override: status
description: The enabled status.
type: string
enum:
- disabled
- enabled
active.status:
value: status
name_override: status
description: The active status.
type: string
enum:
Expand Down
Loading

0 comments on commit c6977ca

Please sign in to comment.