Skip to content

Commit

Permalink
[mdatagen] Add support of enum field in resource attributes (open-tel…
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitryax authored and shalper2 committed Dec 6, 2022
1 parent 0285e87 commit 0d8dfca
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 21 deletions.
17 changes: 17 additions & 0 deletions .chloggen/mdatagen-enum-resource-attrs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# 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: cmd/mdatagen

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Add support for `resource_attributes::enum` field

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

# (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: |
`resource_attributes::enum` values in metadata.yaml are now properly supported in metrics builder developer interface.
7 changes: 7 additions & 0 deletions cmd/mdatagen/metrics.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,12 @@ func (mb *MetricsBuilder) updateCapacity(rm pmetric.ResourceMetrics) {
type ResourceMetricsOption func(pmetric.ResourceMetrics)

{{- range $name, $attr := .ResourceAttributes }}
{{- 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}}", "{{ . }}")
}
{{- 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) {
Expand All @@ -223,6 +229,7 @@ func With{{ $name.Render }}(val {{ $attr.Type.Primitive }}) ResourceMetricsOptio
{{- end }}
}
}
{{- end }}
{{ end }}

// WithStartTimeOverride overrides start time for all the resource metrics data points.
Expand Down
11 changes: 6 additions & 5 deletions cmd/mdatagen/metrics_test.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,12 @@ func TestAllMetrics(t *testing.T) {
{{- end }}

metrics := mb.Emit(
{{- $sep := "" }}
{{- range $name, $info := .ResourceAttributes -}}
{{ $sep }}With{{ $name.Render }}({{- if $info.Enum }}Attribute{{ $name.Render }}(1){{ else }}{{ $info.Type.TestValue }}{{ end }})
{{- $sep = ", " }}
{{- end -}}
{{- $sep := "" }}
{{- range $name, $info := .ResourceAttributes -}}
{{- $sep }}With{{ $name.Render }}
{{- if $info.Enum }}{{ index $info.Enum 0 | publicVar }}{{ else }}({{- $info.Type.TestValue }}){{ end }}
{{- $sep = ", " }}
{{- end -}}
)

assert.Equal(t, 1, metrics.ResourceMetrics().Len())
Expand Down

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

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

3 changes: 1 addition & 2 deletions receiver/flinkmetricsreceiver/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ resource_attributes:
flink.resource.type:
description: The flink scope type in which a metric belongs to.
type: string
# TODO: Add enum support to resource attributes
# enum: [ jobmanager, taskmanager ]
enum: [ jobmanager, taskmanager ]

attributes:
operator_name:
Expand Down
4 changes: 2 additions & 2 deletions receiver/flinkmetricsreceiver/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (s *flinkmetricsScraper) processJobmanagerMetrics(now pcommon.Timestamp, jo
}
s.mb.EmitForResource(
metadata.WithHostName(jobmanagerMetrics.Host),
metadata.WithFlinkResourceType("jobmanager"),
metadata.WithFlinkResourceTypeJobmanager,
)
}

Expand Down Expand Up @@ -135,7 +135,7 @@ func (s *flinkmetricsScraper) processTaskmanagerMetrics(now pcommon.Timestamp, t
s.mb.EmitForResource(
metadata.WithHostName(taskmanagerMetrics.Host),
metadata.WithFlinkTaskmanagerID(taskmanagerMetrics.TaskmanagerID),
metadata.WithFlinkResourceType("taskmanager"),
metadata.WithFlinkResourceTypeTaskmanager,
)
}
}
Expand Down
5 changes: 0 additions & 5 deletions receiver/nsxtreceiver/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ resource_attributes:
nsxt.node.type:
description: The type of NSX Node.
type: string
# TODO: Add support for enum in resource attributes
# enum:
# - manager
# - host
# - edge
device.id:
description: The name of the network interface.
type: string
Expand Down

0 comments on commit 0d8dfca

Please sign in to comment.