Skip to content

Commit

Permalink
[receiver/mongodb] Add mongodb host resource attributes (#33714)
Browse files Browse the repository at this point in the history
The new attribute are added to the MongoDB receiver to distinguish
metrics coming from different MongoDB instances.
- `server.address`: The address of the MongoDB host, enabled by default.
  - `server.port`: The port of the MongoDB host, disabled by default.

Resolves
#32350
and
#32810

Co-authored-by: Curtis Robert <[email protected]>
  • Loading branch information
dmitryax and crobert-1 authored Jun 25, 2024
1 parent 9aed744 commit 0ab1b74
Show file tree
Hide file tree
Showing 20 changed files with 507 additions and 32 deletions.
30 changes: 30 additions & 0 deletions .chloggen/mongodb_add_address_res_attr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Use this changelog template to create an entry for release notes.

# 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/mongodbreceiver

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Add `server.address` and `server.port` resource attributes to MongoDB receiver.

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [32810, 32350]

# (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: |
The new resource attributes are added to the MongoDB receiver to distinguish metrics coming from different MongoDB instances.
- `server.address`: The address of the MongoDB host, enabled by default.
- `server.port`: The port of the MongoDB host, disabled by default.
# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
8 changes: 4 additions & 4 deletions receiver/mongodbreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func TestBadTLSConfigs(t *testing.T) {
Password: "pword",
Hosts: []confignet.TCPAddrConfig{
{
Endpoint: "localhost:27017",
Endpoint: defaultEndpoint,
},
},
ControllerConfig: scraperhelper.NewDefaultControllerConfig(),
Expand All @@ -156,7 +156,7 @@ func TestOptions(t *testing.T) {
cfg := &Config{
Hosts: []confignet.TCPAddrConfig{
{
Endpoint: "localhost:27017",
Endpoint: defaultEndpoint,
},
},
Username: "uname",
Expand All @@ -181,7 +181,7 @@ func TestOptionsTLS(t *testing.T) {
cfg := &Config{
Hosts: []confignet.TCPAddrConfig{
{
Endpoint: "localhost:27017",
Endpoint: defaultEndpoint,
},
},
ClientConfig: configtls.ClientConfig{
Expand Down Expand Up @@ -209,7 +209,7 @@ func TestLoadConfig(t *testing.T) {
expected := factory.CreateDefaultConfig().(*Config)
expected.Hosts = []confignet.TCPAddrConfig{
{
Endpoint: "localhost:27017",
Endpoint: defaultEndpoint,
},
}
expected.Username = "otel"
Expand Down
2 changes: 2 additions & 0 deletions receiver/mongodbreceiver/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -353,3 +353,5 @@ The amount of time that the server has been running.
| Name | Description | Values | Enabled |
| ---- | ----------- | ------ | ------- |
| database | The name of a database. | Any Str | true |
| server.address | The address of the MongoDB host. | Any Str | true |
| server.port | The port of the MongoDB host. | Any Int | false |
7 changes: 6 additions & 1 deletion receiver/mongodbreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package mongodbreceiver // import "github.com/open-telemetry/opentelemetry-colle

import (
"context"
"strconv"
"time"

"go.opentelemetry.io/collector/component"
Expand All @@ -17,6 +18,10 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/mongodbreceiver/internal/metadata"
)

const defaultMongoDBPort = 27017

var defaultEndpoint = "localhost:" + strconv.Itoa(defaultMongoDBPort)

// NewFactory creates a factory for mongodb receiver.
func NewFactory() receiver.Factory {
return receiver.NewFactory(
Expand All @@ -31,7 +36,7 @@ func createDefaultConfig() component.Config {
Timeout: time.Minute,
Hosts: []confignet.TCPAddrConfig{
{
Endpoint: "localhost:27017",
Endpoint: defaultEndpoint,
},
},
MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
Expand Down
1 change: 1 addition & 0 deletions receiver/mongodbreceiver/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func integrationTest(name string, script []string, cfgMod func(*Config)) func(*t
pmetrictest.IgnoreMetricDataPointsOrder(),
pmetrictest.IgnoreStartTimestamp(),
pmetrictest.IgnoreTimestamp(),
pmetrictest.IgnoreResourceAttributeValue("server.address"),
),
).Run
}
10 changes: 9 additions & 1 deletion receiver/mongodbreceiver/internal/metadata/generated_config.go

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.

12 changes: 12 additions & 0 deletions receiver/mongodbreceiver/internal/metadata/generated_metrics.go

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.

14 changes: 14 additions & 0 deletions receiver/mongodbreceiver/internal/metadata/generated_resource.go

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.

24 changes: 24 additions & 0 deletions receiver/mongodbreceiver/internal/metadata/testdata/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ all_set:
resource_attributes:
database:
enabled: true
server.address:
enabled: true
server.port:
enabled: true
none_set:
metrics:
mongodb.cache.operations:
Expand Down Expand Up @@ -129,15 +133,35 @@ none_set:
resource_attributes:
database:
enabled: false
server.address:
enabled: false
server.port:
enabled: false
filter_set_include:
resource_attributes:
database:
enabled: true
metrics_include:
- regexp: ".*"
server.address:
enabled: true
metrics_include:
- regexp: ".*"
server.port:
enabled: true
metrics_include:
- regexp: ".*"
filter_set_exclude:
resource_attributes:
database:
enabled: true
metrics_exclude:
- strict: "database-val"
server.address:
enabled: true
metrics_exclude:
- strict: "server.address-val"
server.port:
enabled: true
metrics_exclude:
- regexp: ".*"
8 changes: 8 additions & 0 deletions receiver/mongodbreceiver/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ status:
seeking_new: true

resource_attributes:
server.address:
description: The address of the MongoDB host.
enabled: true
type: string
server.port:
description: The port of the MongoDB host.
enabled: false
type: int
database:
description: The name of a database.
enabled: true
Expand Down
Loading

0 comments on commit 0ab1b74

Please sign in to comment.