Skip to content

Commit 34bd2b4

Browse files
author
Samiur Arif
authored
added mongodb receiver into discovery mode (#4722)
* added mongodb receiver into discovery mode * fixed linting errors * addressing previous MR comment
1 parent 7a60d21 commit 34bd2b4

File tree

10 files changed

+162
-0
lines changed

10 files changed

+162
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#####################################################################################
2+
# This file is generated by the Splunk Distribution of the OpenTelemetry Collector. #
3+
# #
4+
# It reflects the default configuration bundled in the Collector executable for use #
5+
# in discovery mode (--discovery) and is provided for reference or customization. #
6+
# Please note that any changes made to this file will need to be reconciled during #
7+
# upgrades of the Collector. #
8+
#####################################################################################
9+
# mongodb:
10+
# enabled: true
11+
# rule:
12+
# docker_observer: type == "container" and any([name, image, command], {# matches "(?i)mongo"}) and not (command matches "splunk.discovery")
13+
# host_observer: type == "hostport" and command matches "(?i)mongo" and not (command matches "splunk.discovery")
14+
# k8s_observer: type == "port" and pod.name matches "(?i)mongo"
15+
# config:
16+
# default:
17+
# username: splunk.discovery.default
18+
# password: splunk.discovery.default
19+
# tls:
20+
# insecure: true
21+
# insecure_skip_verify: true
22+
# status:
23+
# metrics:
24+
# - status: successful
25+
# strict: mongodb.database.count
26+
# log_record:
27+
# body: mongodb receiver is working!
28+
# statements:
29+
# - status: failed
30+
# regexp: 'connect: network is unreachable'
31+
# log_record:
32+
# append_pattern: true
33+
# body: The container cannot be reached by the Collector. Make sure they're in the same network.
34+
# - status: failed
35+
# regexp: 'connect: connection refused'
36+
# log_record:
37+
# append_pattern: true
38+
# body: The container is refusing mongodb connections.
39+
# - status: partial
40+
# regexp: '.* unable to authenticate using mechanism .*'
41+
# log_record:
42+
# append_pattern: true
43+
# body: >-
44+
# Please ensure your user credentials are correctly specified with
45+
# `--set splunk.discovery.receivers.mongodb.config.username="<username>"` and
46+
# `--set splunk.discovery.receivers.mongodb.config.password="<password>"` or
47+
# `SPLUNK_DISCOVERY_RECEIVERS_mongodb_CONFIG_username="<username>"` and
48+
# `SPLUNK_DISCOVERY_RECEIVERS_mongodb_CONFIG_password="<password>"` environment variables.
49+
# - status: partial
50+
# regexp: '.* failed to fetch index stats metrics: (Unauthorized) not authorized on admin to execute command .*'
51+
# log_record:
52+
# append_pattern: true
53+
# body: >-
54+
# Make sure the account used to access Mongodb has been given a clusterMonitor role in order to collect metrics.
55+
# `db.grantRolesToUser('someUser', [{ role: 'clusterMonitor', db: 'admin' }])`

internal/confmapprovider/discovery/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ By default, the discovery mode is provided with pre-made discovery config compon
136136
The following components have bundled discovery configurations in the last Splunk OpenTelemetry Collector release:
137137

138138
I. Receivers
139+
* `mongodb` ([Linux and Windows](./bundle/bundle.d/receivers/mongodb.discovery.yaml))
139140
* `mysql` ([Linux and Windows](./bundle/bundle.d/receivers/mysql.discovery.yaml))
140141
* `oracledb` ([Linux and Windows](./bundle/bundle.d/receivers/oracledb.discovery.yaml))
141142
* `postgresql` ([Linux and Windows](./bundle/bundle.d/receivers/postgresql.discovery.yaml))
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#####################################################################################
2+
# Do not edit manually! #
3+
# All changes must be made to associated .tmpl file before running 'make bundle.d'. #
4+
#####################################################################################
5+
mongodb:
6+
enabled: true
7+
rule:
8+
docker_observer: type == "container" and any([name, image, command], {# matches "(?i)mongo"}) and not (command matches "splunk.discovery")
9+
host_observer: type == "hostport" and command matches "(?i)mongo" and not (command matches "splunk.discovery")
10+
k8s_observer: type == "port" and pod.name matches "(?i)mongo"
11+
config:
12+
default:
13+
username: splunk.discovery.default
14+
password: splunk.discovery.default
15+
tls:
16+
insecure: true
17+
insecure_skip_verify: true
18+
status:
19+
metrics:
20+
- status: successful
21+
strict: mongodb.database.count
22+
log_record:
23+
body: mongodb receiver is working!
24+
statements:
25+
- status: failed
26+
regexp: 'connect: network is unreachable'
27+
log_record:
28+
append_pattern: true
29+
body: The container cannot be reached by the Collector. Make sure they're in the same network.
30+
- status: failed
31+
regexp: 'connect: connection refused'
32+
log_record:
33+
append_pattern: true
34+
body: The container is refusing mongodb connections.
35+
- status: partial
36+
regexp: '.* unable to authenticate using mechanism .*'
37+
log_record:
38+
append_pattern: true
39+
body: >-
40+
Please ensure your user credentials are correctly specified with
41+
`--set splunk.discovery.receivers.mongodb.config.username="<username>"` and
42+
`--set splunk.discovery.receivers.mongodb.config.password="<password>"` or
43+
`SPLUNK_DISCOVERY_RECEIVERS_mongodb_CONFIG_username="<username>"` and
44+
`SPLUNK_DISCOVERY_RECEIVERS_mongodb_CONFIG_password="<password>"` environment variables.
45+
- status: partial
46+
regexp: '.* failed to fetch index stats metrics: (Unauthorized) not authorized on admin to execute command .*'
47+
log_record:
48+
append_pattern: true
49+
body: >-
50+
Make sure the account used to access Mongodb has been given a clusterMonitor role in order to collect metrics.
51+
`db.grantRolesToUser('someUser', [{ role: 'clusterMonitor', db: 'admin' }])`
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{{ receiver "mongodb" }}:
2+
enabled: true
3+
rule:
4+
docker_observer: type == "container" and any([name, image, command], {# matches "(?i)mongo"}) and not (command matches "splunk.discovery")
5+
host_observer: type == "hostport" and command matches "(?i)mongo" and not (command matches "splunk.discovery")
6+
k8s_observer: type == "port" and pod.name matches "(?i)mongo"
7+
config:
8+
default:
9+
username: {{ defaultValue }}
10+
password: {{ defaultValue }}
11+
tls:
12+
insecure: true
13+
insecure_skip_verify: true
14+
status:
15+
metrics:
16+
- status: successful
17+
strict: mongodb.database.count
18+
log_record:
19+
body: mongodb receiver is working!
20+
statements:
21+
- status: failed
22+
regexp: 'connect: network is unreachable'
23+
log_record:
24+
append_pattern: true
25+
body: The container cannot be reached by the Collector. Make sure they're in the same network.
26+
- status: failed
27+
regexp: 'connect: connection refused'
28+
log_record:
29+
append_pattern: true
30+
body: The container is refusing mongodb connections.
31+
- status: partial
32+
regexp: '.* unable to authenticate using mechanism .*'
33+
log_record:
34+
append_pattern: true
35+
body: >-
36+
Please ensure your user credentials are correctly specified with
37+
`--set {{ configProperty "username" "<username>" }}` and
38+
`--set {{ configProperty "password" "<password>" }}` or
39+
`{{ configPropertyEnvVar "username" "<username>" }}` and
40+
`{{ configPropertyEnvVar "password" "<password>" }}` environment variables.
41+
- status: partial
42+
regexp: '.* failed to fetch index stats metrics: (Unauthorized) not authorized on admin to execute command .*'
43+
log_record:
44+
append_pattern: true
45+
body: >-
46+
Make sure the account used to access Mongodb has been given a clusterMonitor role in order to collect metrics.
47+
`db.grantRolesToUser('someUser', [{ role: 'clusterMonitor', db: 'admin' }])`

internal/confmapprovider/discovery/bundle/bundle_gen.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
//go:generate discoverybundler -r -t bundle.d/extensions/k8s-observer.discovery.yaml.tmpl
2424
//go:generate discoverybundler -r -c -d ../../../../cmd/otelcol/config/collector/config.d.linux/extensions -t bundle.d/extensions/k8s-observer.discovery.yaml.tmpl
2525

26+
//go:generate discoverybundler -r -t bundle.d/receivers/mongodb.discovery.yaml.tmpl
27+
//go:generate discoverybundler -r -c -d ../../../../cmd/otelcol/config/collector/config.d.linux/receivers -t bundle.d/receivers/mongodb.discovery.yaml.tmpl
2628
//go:generate discoverybundler -r -t bundle.d/receivers/mysql.discovery.yaml.tmpl
2729
//go:generate discoverybundler -r -c -d ../../../../cmd/otelcol/config/collector/config.d.linux/receivers -t bundle.d/receivers/mysql.discovery.yaml.tmpl
2830
//go:generate discoverybundler -r -t bundle.d/receivers/oracledb.discovery.yaml.tmpl

internal/confmapprovider/discovery/bundle/bundledfs_other_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ func TestBundleDir(t *testing.T) {
2727
receivers, err := fs.Glob(BundledFS, "bundle.d/receivers/*.discovery.yaml")
2828
require.NoError(t, err)
2929
require.Equal(t, []string{
30+
"bundle.d/receivers/mongodb.discovery.yaml",
3031
"bundle.d/receivers/mysql.discovery.yaml",
3132
"bundle.d/receivers/oracledb.discovery.yaml",
3233
"bundle.d/receivers/postgresql.discovery.yaml",

internal/confmapprovider/discovery/bundle/bundledfs_others.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
//go:embed bundle.d/extensions/docker-observer.discovery.yaml
2626
//go:embed bundle.d/extensions/host-observer.discovery.yaml
2727
//go:embed bundle.d/extensions/k8s-observer.discovery.yaml
28+
//go:embed bundle.d/receivers/mongodb.discovery.yaml
2829
//go:embed bundle.d/receivers/mysql.discovery.yaml
2930
//go:embed bundle.d/receivers/oracledb.discovery.yaml
3031
//go:embed bundle.d/receivers/postgresql.discovery.yaml

internal/confmapprovider/discovery/bundle/bundledfs_windows.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
//go:embed bundle.d/extensions/docker-observer.discovery.yaml
2626
//go:embed bundle.d/extensions/host-observer.discovery.yaml
2727
//go:embed bundle.d/extensions/k8s-observer.discovery.yaml
28+
//go:embed bundle.d/receivers/mongodb.discovery.yaml
2829
//go:embed bundle.d/receivers/mysql.discovery.yaml
2930
//go:embed bundle.d/receivers/oracledb.discovery.yaml
3031
//go:embed bundle.d/receivers/postgresql.discovery.yaml

internal/confmapprovider/discovery/bundle/bundledfs_windows_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ func TestBundleDir(t *testing.T) {
2727
receivers, err := fs.Glob(BundledFS, "bundle.d/receivers/*.discovery.yaml")
2828
require.NoError(t, err)
2929
require.Equal(t, []string{
30+
"bundle.d/receivers/mongodb.discovery.yaml",
3031
"bundle.d/receivers/mysql.discovery.yaml",
3132
"bundle.d/receivers/oracledb.discovery.yaml",
3233
"bundle.d/receivers/postgresql.discovery.yaml",

internal/confmapprovider/discovery/bundle/components.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ var (
3131
// If they are desired for !windows BundledFS inclusion (and a default linux conf.d entry), ensure they are included
3232
// in Components.Linux. If desired in windows BundledFS, ensure they are included in Components.Windows.
3333
receivers = []string{
34+
"mongodb",
3435
"mysql",
3536
"oracledb",
3637
"postgresql",
@@ -61,6 +62,7 @@ var (
6162
}(),
6263
Windows: func() map[string]struct{} {
6364
windows := map[string]struct{}{
65+
"mongodb": {},
6466
"mysql": {},
6567
"oracledb": {},
6668
"postgresql": {},

0 commit comments

Comments
 (0)