From 19665621bb227fd9d49d515d35b3642dce83a847 Mon Sep 17 00:00:00 2001 From: arjun-mw <166687775+arjun-mw@users.noreply.github.com> Date: Tue, 30 Apr 2024 15:23:21 +0530 Subject: [PATCH] Added missing resource attributes (#51) --- receiver/k8sclusterreceiver/documentation.md | 16 ++++++------ receiver/mongodbreceiver/documentation.md | 2 +- .../internal/metadata/generated_config.go | 2 +- .../metadata/generated_resource_test.go | 4 +-- receiver/mongodbreceiver/metadata.yaml | 1 + receiver/mongodbreceiver/scraper.go | 26 +++++++++++++++++-- receiver/postgresqlreceiver/scraper.go | 5 ++++ 7 files changed, 42 insertions(+), 14 deletions(-) diff --git a/receiver/k8sclusterreceiver/documentation.md b/receiver/k8sclusterreceiver/documentation.md index 676325fcd29f..2bc56289ad09 100644 --- a/receiver/k8sclusterreceiver/documentation.md +++ b/receiver/k8sclusterreceiver/documentation.md @@ -469,14 +469,14 @@ Current status reason of the pod (1 - Evicted, 2 - NodeAffinity, 3 - NodeLost, 4 | k8s.deployment.uid | The UID of the Deployment. | Any Str | true | | k8s.hpa.name | The k8s hpa name. | Any Str | true | | k8s.hpa.uid | The k8s hpa uid. | Any Str | true | -| k8s.ingress.annotations | Annotations of the Role. | Any Str | true | -| k8s.ingress.labels | Labels of the Role. | Any Str | true | -| k8s.ingress.name | The name of the Role. | Any Str | true | -| k8s.ingress.namespace | The namespace of the Role. | Any Str | true | -| k8s.ingress.rules | Rules of the Role. | Any Str | true | -| k8s.ingress.start_time | The start time of the Role. | Any Str | true | -| k8s.ingress.type | The type of the Role. | Any Str | true | -| k8s.ingress.uid | The UID of the Role. | Any Str | true | +| k8s.ingress.annotations | Annotations of the Ingress. | Any Str | true | +| k8s.ingress.labels | Labels of the Ingress. | Any Str | true | +| k8s.ingress.name | The name of the Ingress. | Any Str | true | +| k8s.ingress.namespace | The namespace of the Ingress. | Any Str | true | +| k8s.ingress.rules | Rules of the Ingress. | Any Str | true | +| k8s.ingress.start_time | The start time of the Ingress. | Any Str | true | +| k8s.ingress.type | The type of the Ingress. | Any Str | true | +| k8s.ingress.uid | The UID of the Ingress. | Any Str | true | | k8s.job.name | The k8s pod name. | Any Str | true | | k8s.job.uid | The k8s job uid. | Any Str | true | | k8s.kubelet.version | The version of Kubelet running on the node. | Any Str | false | diff --git a/receiver/mongodbreceiver/documentation.md b/receiver/mongodbreceiver/documentation.md index cd4ceb1ca3da..84857eeb554e 100644 --- a/receiver/mongodbreceiver/documentation.md +++ b/receiver/mongodbreceiver/documentation.md @@ -353,4 +353,4 @@ The amount of time that the server has been running. | Name | Description | Values | Enabled | | ---- | ----------- | ------ | ------- | | database | The name of a database. | Any Str | true | -| mongodb.database.name | The name of a database (redundant). | Any Str | false | +| mongodb.database.name | The name of a database (redundant). | Any Str | true | diff --git a/receiver/mongodbreceiver/internal/metadata/generated_config.go b/receiver/mongodbreceiver/internal/metadata/generated_config.go index 754089808083..ac226ab0f72a 100644 --- a/receiver/mongodbreceiver/internal/metadata/generated_config.go +++ b/receiver/mongodbreceiver/internal/metadata/generated_config.go @@ -193,7 +193,7 @@ func DefaultResourceAttributesConfig() ResourceAttributesConfig { Enabled: true, }, MongodbDatabaseName: ResourceAttributeConfig{ - Enabled: false, + Enabled: true, }, } } diff --git a/receiver/mongodbreceiver/internal/metadata/generated_resource_test.go b/receiver/mongodbreceiver/internal/metadata/generated_resource_test.go index 1e4efaf3cae8..e2af3792abfc 100644 --- a/receiver/mongodbreceiver/internal/metadata/generated_resource_test.go +++ b/receiver/mongodbreceiver/internal/metadata/generated_resource_test.go @@ -21,7 +21,7 @@ func TestResourceBuilder(t *testing.T) { switch test { case "default": - assert.Equal(t, 1, res.Attributes().Len()) + assert.Equal(t, 2, res.Attributes().Len()) case "all_set": assert.Equal(t, 2, res.Attributes().Len()) case "none_set": @@ -37,7 +37,7 @@ func TestResourceBuilder(t *testing.T) { assert.EqualValues(t, "database-val", val.Str()) } val, ok = res.Attributes().Get("mongodb.database.name") - assert.Equal(t, test == "all_set", ok) + assert.True(t, ok) if ok { assert.EqualValues(t, "mongodb.database.name-val", val.Str()) } diff --git a/receiver/mongodbreceiver/metadata.yaml b/receiver/mongodbreceiver/metadata.yaml index 887c00b566c1..ad0da3e41fc0 100644 --- a/receiver/mongodbreceiver/metadata.yaml +++ b/receiver/mongodbreceiver/metadata.yaml @@ -17,6 +17,7 @@ resource_attributes: type: string mongodb.database.name: description: The name of a database (redundant). + enabled: true type: string attributes: diff --git a/receiver/mongodbreceiver/scraper.go b/receiver/mongodbreceiver/scraper.go index e8d005794732..cdad4adffd21 100644 --- a/receiver/mongodbreceiver/scraper.go +++ b/receiver/mongodbreceiver/scraper.go @@ -159,7 +159,14 @@ func (s *mongodbScraper) collectAdminDatabase(ctx context.Context, now pcommon.T return } s.recordAdminStats(now, serverStatus, errs) - s.mb.EmitForResource() + + rb := s.mb.NewResourceBuilder() + rb.SetDatabase("N/A") + rb.SetMongodbDatabaseName("N/A") + + s.mb.EmitForResource( + metadata.WithResource(rb.Emit()), + ) } func (s *mongodbScraper) collectTopStats(ctx context.Context, now pcommon.Timestamp, errs *scrapererror.ScrapeErrors) { @@ -169,7 +176,14 @@ func (s *mongodbScraper) collectTopStats(ctx context.Context, now pcommon.Timest return } s.recordOperationTime(now, topStats, errs) - s.mb.EmitForResource() + + rb := s.mb.NewResourceBuilder() + rb.SetDatabase("N/A") + rb.SetMongodbDatabaseName("N/A") + + s.mb.EmitForResource( + metadata.WithResource(rb.Emit()), + ) } func (s *mongodbScraper) collectIndexStats(ctx context.Context, now pcommon.Timestamp, databaseName string, collectionName string, errs *scrapererror.ScrapeErrors) { @@ -183,6 +197,14 @@ func (s *mongodbScraper) collectIndexStats(ctx context.Context, now pcommon.Time } s.recordIndexStats(now, indexStats, databaseName, collectionName, errs) + rb := s.mb.NewResourceBuilder() + rb.SetDatabase("N/A") + rb.SetMongodbDatabaseName("N/A") + + s.mb.EmitForResource( + metadata.WithResource(rb.Emit()), + ) + if s.removeDatabaseAttr { rb := s.mb.NewResourceBuilder() rb.SetDatabase(databaseName) diff --git a/receiver/postgresqlreceiver/scraper.go b/receiver/postgresqlreceiver/scraper.go index 710249830ae7..91bfe6d42e2e 100644 --- a/receiver/postgresqlreceiver/scraper.go +++ b/receiver/postgresqlreceiver/scraper.go @@ -162,6 +162,11 @@ func (p *postgreSQLScraper) scrape(ctx context.Context) (pmetric.Metrics, error) p.collectMaxConnections(ctx, now, listClient, &errs) p.collectDatabaseLocks(ctx, now, listClient, &errs) + + rb := p.mb.NewResourceBuilder() + rb.SetPostgresqlDatabaseName("N/A") + p.mb.EmitForResource(metadata.WithResource(rb.Emit())) + return p.mb.Emit(), errs.combine() }