diff --git a/.chloggen/mongodbatlasreceiver-add-attribute.yaml b/.chloggen/mongodbatlasreceiver-add-attribute.yaml new file mode 100755 index 000000000000..4db8c41a7466 --- /dev/null +++ b/.chloggen/mongodbatlasreceiver-add-attribute.yaml @@ -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: receiver/mongodbatlasreceiver + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: emit "`mongodb_atlas.user.alias`" attribute which is the user-friendly hostname of the cluster node as displayed in the Atlas portal. + This attribute is disabled by default, if you want to emit it, you'll need to explicitly enable it. + +# One or more tracking issues related to the change +issues: [18881] + +# (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: diff --git a/receiver/mongodbatlasreceiver/documentation.md b/receiver/mongodbatlasreceiver/documentation.md index 5f7725c02a5c..05ded413ac26 100644 --- a/receiver/mongodbatlasreceiver/documentation.md +++ b/receiver/mongodbatlasreceiver/documentation.md @@ -972,3 +972,4 @@ Aggregate of MongoDB Metrics MAX_SWAP_USAGE_FREE, MAX_SWAP_USAGE_USED | mongodb_atlas.process.type_name | Process type | Any Str | true | | mongodb_atlas.project.id | Project ID | Any Str | true | | mongodb_atlas.project.name | Project Name | Any Str | true | +| mongodb_atlas.user.alias | User-friendly hostname of the cluster node | Any Str | false | diff --git a/receiver/mongodbatlasreceiver/internal/metadata/generated_metrics.go b/receiver/mongodbatlasreceiver/internal/metadata/generated_metrics.go index 027508f1f58b..f297ae0c3cc7 100644 --- a/receiver/mongodbatlasreceiver/internal/metadata/generated_metrics.go +++ b/receiver/mongodbatlasreceiver/internal/metadata/generated_metrics.go @@ -308,6 +308,7 @@ type ResourceAttributesSettings struct { MongodbAtlasProcessTypeName ResourceAttributeSettings `mapstructure:"mongodb_atlas.process.type_name"` MongodbAtlasProjectID ResourceAttributeSettings `mapstructure:"mongodb_atlas.project.id"` MongodbAtlasProjectName ResourceAttributeSettings `mapstructure:"mongodb_atlas.project.name"` + MongodbAtlasUserAlias ResourceAttributeSettings `mapstructure:"mongodb_atlas.user.alias"` } func DefaultResourceAttributesSettings() ResourceAttributesSettings { @@ -339,6 +340,9 @@ func DefaultResourceAttributesSettings() ResourceAttributesSettings { MongodbAtlasProjectName: ResourceAttributeSettings{ Enabled: true, }, + MongodbAtlasUserAlias: ResourceAttributeSettings{ + Enabled: false, + }, } } @@ -4540,6 +4544,15 @@ func WithMongodbAtlasProjectName(val string) ResourceMetricsOption { } } +// WithMongodbAtlasUserAlias sets provided value as "mongodb_atlas.user.alias" attribute for current resource. +func WithMongodbAtlasUserAlias(val string) ResourceMetricsOption { + return func(ras ResourceAttributesSettings, rm pmetric.ResourceMetrics) { + if ras.MongodbAtlasUserAlias.Enabled { + rm.Resource().Attributes().PutStr("mongodb_atlas.user.alias", val) + } + } +} + // WithStartTimeOverride overrides start time for all the resource metrics data points. // This option should be only used if different start time has to be set on metrics coming from different resources. func WithStartTimeOverride(start pcommon.Timestamp) ResourceMetricsOption { diff --git a/receiver/mongodbatlasreceiver/internal/metadata/generated_metrics_test.go b/receiver/mongodbatlasreceiver/internal/metadata/generated_metrics_test.go index e49c1537cdd6..e082f77b088c 100644 --- a/receiver/mongodbatlasreceiver/internal/metadata/generated_metrics_test.go +++ b/receiver/mongodbatlasreceiver/internal/metadata/generated_metrics_test.go @@ -310,7 +310,7 @@ func TestMetricsBuilder(t *testing.T) { allMetricsCount++ mb.RecordMongodbatlasSystemPagingUsageMaxDataPoint(ts, 1, AttributeMemoryState(1)) - metrics := mb.Emit(WithMongodbAtlasDbName("attr-val"), WithMongodbAtlasDiskPartition("attr-val"), WithMongodbAtlasHostName("attr-val"), WithMongodbAtlasOrgName("attr-val"), WithMongodbAtlasProcessID("attr-val"), WithMongodbAtlasProcessPort("attr-val"), WithMongodbAtlasProcessTypeName("attr-val"), WithMongodbAtlasProjectID("attr-val"), WithMongodbAtlasProjectName("attr-val")) + metrics := mb.Emit(WithMongodbAtlasDbName("attr-val"), WithMongodbAtlasDiskPartition("attr-val"), WithMongodbAtlasHostName("attr-val"), WithMongodbAtlasOrgName("attr-val"), WithMongodbAtlasProcessID("attr-val"), WithMongodbAtlasProcessPort("attr-val"), WithMongodbAtlasProcessTypeName("attr-val"), WithMongodbAtlasProjectID("attr-val"), WithMongodbAtlasProjectName("attr-val"), WithMongodbAtlasUserAlias("attr-val")) if test.configSet == testSetNone { assert.Equal(t, 0, metrics.ResourceMetrics().Len()) @@ -384,8 +384,15 @@ func TestMetricsBuilder(t *testing.T) { enabledAttrCount++ assert.EqualValues(t, "attr-val", attrVal.Str()) } + attrVal, ok = rm.Resource().Attributes().Get("mongodb_atlas.user.alias") + attrCount++ + assert.Equal(t, mb.resourceAttributesSettings.MongodbAtlasUserAlias.Enabled, ok) + if mb.resourceAttributesSettings.MongodbAtlasUserAlias.Enabled { + enabledAttrCount++ + assert.EqualValues(t, "attr-val", attrVal.Str()) + } assert.Equal(t, enabledAttrCount, rm.Resource().Attributes().Len()) - assert.Equal(t, attrCount, 9) + assert.Equal(t, attrCount, 10) assert.Equal(t, 1, rm.ScopeMetrics().Len()) ms := rm.ScopeMetrics().At(0).Metrics() diff --git a/receiver/mongodbatlasreceiver/internal/metadata/testdata/config.yaml b/receiver/mongodbatlasreceiver/internal/metadata/testdata/config.yaml index d8b80fdf12df..1e652fd7c0b3 100644 --- a/receiver/mongodbatlasreceiver/internal/metadata/testdata/config.yaml +++ b/receiver/mongodbatlasreceiver/internal/metadata/testdata/config.yaml @@ -146,6 +146,8 @@ all_set: enabled: true mongodb_atlas.project.name: enabled: true + mongodb_atlas.user.alias: + enabled: true none_set: metrics: mongodbatlas.db.counts: @@ -293,3 +295,5 @@ none_set: enabled: false mongodb_atlas.project.name: enabled: false + mongodb_atlas.user.alias: + enabled: false diff --git a/receiver/mongodbatlasreceiver/metadata.yaml b/receiver/mongodbatlasreceiver/metadata.yaml index 8e127cd79502..b521e3ebcb09 100644 --- a/receiver/mongodbatlasreceiver/metadata.yaml +++ b/receiver/mongodbatlasreceiver/metadata.yaml @@ -17,6 +17,10 @@ resource_attributes: description: Hostname of the process enabled: true type: string + mongodb_atlas.user.alias: + description: User-friendly hostname of the cluster node + enabled: false + type: string mongodb_atlas.process.port: description: Port process is bound to enabled: true diff --git a/receiver/mongodbatlasreceiver/receiver.go b/receiver/mongodbatlasreceiver/receiver.go index dc14e8fb8ed5..714ad10576e0 100644 --- a/receiver/mongodbatlasreceiver/receiver.go +++ b/receiver/mongodbatlasreceiver/receiver.go @@ -117,6 +117,7 @@ func (s *receiver) poll(ctx context.Context, time timeconstraints) error { metadata.WithMongodbAtlasProjectName(project.Name), metadata.WithMongodbAtlasProjectID(project.ID), metadata.WithMongodbAtlasHostName(process.Hostname), + metadata.WithMongodbAtlasUserAlias(process.UserAlias), metadata.WithMongodbAtlasProcessPort(strconv.Itoa(process.Port)), metadata.WithMongodbAtlasProcessTypeName(process.TypeName), metadata.WithMongodbAtlasProcessID(process.ID), @@ -195,6 +196,7 @@ func (s *receiver) extractProcessDatabaseMetrics( metadata.WithMongodbAtlasProjectName(project.Name), metadata.WithMongodbAtlasProjectID(project.ID), metadata.WithMongodbAtlasHostName(process.Hostname), + metadata.WithMongodbAtlasUserAlias(process.UserAlias), metadata.WithMongodbAtlasProcessPort(strconv.Itoa(process.Port)), metadata.WithMongodbAtlasProcessTypeName(process.TypeName), metadata.WithMongodbAtlasProcessID(process.ID), @@ -230,6 +232,7 @@ func (s *receiver) extractProcessDiskMetrics( metadata.WithMongodbAtlasProjectName(project.Name), metadata.WithMongodbAtlasProjectID(project.ID), metadata.WithMongodbAtlasHostName(process.Hostname), + metadata.WithMongodbAtlasUserAlias(process.UserAlias), metadata.WithMongodbAtlasProcessPort(strconv.Itoa(process.Port)), metadata.WithMongodbAtlasProcessTypeName(process.TypeName), metadata.WithMongodbAtlasProcessID(process.ID),