From 3dbc304005b73ada68ae6470ce6b58d50fb3daf6 Mon Sep 17 00:00:00 2001 From: ritalwar Date: Tue, 21 Feb 2023 12:37:10 +0530 Subject: [PATCH 01/14] Fix mongodb multiple hosts connection issue --- metricbeat/module/mongodb/mongodb.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/metricbeat/module/mongodb/mongodb.go b/metricbeat/module/mongodb/mongodb.go index d1c3df0ca8b..5539d84131f 100644 --- a/metricbeat/module/mongodb/mongodb.go +++ b/metricbeat/module/mongodb/mongodb.go @@ -123,7 +123,7 @@ func ParseURL(module mb.Module, host string) (mb.HostData, error) { Username: c.Username, Password: c.Password, } - clientOptions.SetDirect(true) + clientOptions.ApplyURI(host) // https://docs.mongodb.com/manual/reference/connection-string/ @@ -154,7 +154,6 @@ func NewClient(config ModuleConfig, timeout time.Duration, mode readpref.Mode) ( clientOptions.Auth.AuthMechanismProperties = config.Credentials.AuthMechanismProperties } } - clientOptions.SetHosts(config.Hosts) if mode == 0 { mode = readpref.NearestMode @@ -165,7 +164,6 @@ func NewClient(config ModuleConfig, timeout time.Duration, mode readpref.Mode) ( return nil, err } clientOptions.SetReadPreference(readPreference) - clientOptions.SetDirect(true) clientOptions.SetConnectTimeout(timeout) if config.TLS.IsEnabled() { From 9a7e6deaf4221b90fd24880b85f3d99d28cb1a8e Mon Sep 17 00:00:00 2001 From: ritalwar Date: Wed, 22 Feb 2023 23:50:14 +0530 Subject: [PATCH 02/14] Update docker image for mongodb --- .../mongodb/dbstats/dbstats_integration_test.go | 14 ++++++++------ metricbeat/module/mongodb/docker-compose.yml | 9 ++++----- .../mongodb/status/status_integration_test.go | 6 ++---- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/metricbeat/module/mongodb/dbstats/dbstats_integration_test.go b/metricbeat/module/mongodb/dbstats/dbstats_integration_test.go index 4ac22da12e8..a3d96cb3a92 100644 --- a/metricbeat/module/mongodb/dbstats/dbstats_integration_test.go +++ b/metricbeat/module/mongodb/dbstats/dbstats_integration_test.go @@ -51,22 +51,24 @@ func TestFetch(t *testing.T) { assert.True(t, collections > 0) objects := metricsetFields["objects"].(int32) - assert.True(t, objects > 0) + assert.True(t, objects >= 0) avgObjSize, err := metricsetFields.GetValue("avg_obj_size.bytes") assert.NoError(t, err) - assert.True(t, avgObjSize.(float64) > 0) + assert.True(t, avgObjSize.(float64) >= 0) dataSize, err := metricsetFields.GetValue("data_size.bytes") assert.NoError(t, err) - assert.True(t, dataSize.(float64) > 0) + assert.True(t, dataSize.(float64) >= 0) storageSize, err := metricsetFields.GetValue("storage_size.bytes") assert.NoError(t, err) - assert.True(t, storageSize.(float64) > 0) + assert.True(t, storageSize.(float64) >= 0) - numExtents := metricsetFields["num_extents"].(int32) - assert.True(t, numExtents >= 0) + if metricsetFields["num_extents"] != nil { + numExtents := metricsetFields["num_extents"].(int32) + assert.True(t, numExtents >= 0) + } indexes := metricsetFields["indexes"].(int32) assert.True(t, indexes >= 0) diff --git a/metricbeat/module/mongodb/docker-compose.yml b/metricbeat/module/mongodb/docker-compose.yml index cee7fdb13ad..5108a5927bc 100644 --- a/metricbeat/module/mongodb/docker-compose.yml +++ b/metricbeat/module/mongodb/docker-compose.yml @@ -1,12 +1,11 @@ -version: "2.3" +version: '2.3' services: mongodb: - image: docker.elastic.co/integrations-ci/beats-mongodb:${MONGODB_VERSION:-3.4}-1 + image: docker.elastic.co/integrations-ci/beats-mongodb:${MONGODB_VERSION:-5.0}-1 build: context: ./_meta args: - MONGODB_VERSION: "${MONGODB_VERSION:-3.4}" - command: mongod --replSet beats + MONGODB_VERSION: ${MONGODB_VERSION:-5.0} ports: - - 27017 + - 27017:27017 diff --git a/metricbeat/module/mongodb/status/status_integration_test.go b/metricbeat/module/mongodb/status/status_integration_test.go index 967573409f1..cf1aa8bc49f 100644 --- a/metricbeat/module/mongodb/status/status_integration_test.go +++ b/metricbeat/module/mongodb/status/status_integration_test.go @@ -21,9 +21,8 @@ package status import ( - "testing" - "github.com/stretchr/testify/assert" + "testing" "github.com/elastic/beats/v7/libbeat/tests/compose" mbtest "github.com/elastic/beats/v7/metricbeat/mb/testing" @@ -31,7 +30,6 @@ import ( func TestFetch(t *testing.T) { service := compose.EnsureUp(t, "mongodb") - f := mbtest.NewReportingMetricSetV2Error(t, getConfig(service.Host())) events, errs := mbtest.ReportingFetchV2Error(f) @@ -53,7 +51,7 @@ func TestFetch(t *testing.T) { assert.True(t, available.(int32) > 0) pageFaults, _ := event.GetValue("mongodb.status.extra_info.page_faults") - assert.True(t, pageFaults.(int32) >= 0) + assert.True(t, pageFaults.(int64) >= 0) } func TestData(t *testing.T) { From cc345098670c23f6802c634e6d4c91196b9a3094 Mon Sep 17 00:00:00 2001 From: ritalwar Date: Thu, 23 Feb 2023 10:11:44 +0530 Subject: [PATCH 03/14] Update status_integration_test.go --- metricbeat/module/mongodb/status/status_integration_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/metricbeat/module/mongodb/status/status_integration_test.go b/metricbeat/module/mongodb/status/status_integration_test.go index cf1aa8bc49f..dfbe08e9544 100644 --- a/metricbeat/module/mongodb/status/status_integration_test.go +++ b/metricbeat/module/mongodb/status/status_integration_test.go @@ -21,9 +21,10 @@ package status import ( - "github.com/stretchr/testify/assert" "testing" + "github.com/stretchr/testify/assert" + "github.com/elastic/beats/v7/libbeat/tests/compose" mbtest "github.com/elastic/beats/v7/metricbeat/mb/testing" ) From 784212d24c0c725f132a504906cd4f23ce01e5f1 Mon Sep 17 00:00:00 2001 From: ritalwar Date: Thu, 23 Feb 2023 10:23:34 +0530 Subject: [PATCH 04/14] Update changelog --- CHANGELOG-developer.next.asciidoc | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG-developer.next.asciidoc b/CHANGELOG-developer.next.asciidoc index e9cdb6be060..bdfda9c7d59 100644 --- a/CHANGELOG-developer.next.asciidoc +++ b/CHANGELOG-developer.next.asciidoc @@ -78,6 +78,7 @@ The list below covers the major changes between 7.0.0-rc2 and main only. - Setting DEV=true when running `mage build` now correctly generates binaries without optimisations and with debug symbols {pull}31955[31955] - The beat.cgroup.memory.mem.usage.bytes metric is now a gauge {issue}31582[31582] {pull}32652[32652] - Fix the integration testcase docker port mapping for sql and oracle modules {pull}34221[34221] +- Fix the multiple host support for mongodb module {pull}34624[34624] ==== Added From 533815a8247248bc7024e91d061affac1b177fab Mon Sep 17 00:00:00 2001 From: ritalwar Date: Thu, 23 Feb 2023 23:57:58 +0530 Subject: [PATCH 05/14] Update doc --- metricbeat/docs/modules/mongodb.asciidoc | 4 ++-- metricbeat/module/mongodb/_meta/docs.asciidoc | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/metricbeat/docs/modules/mongodb.asciidoc b/metricbeat/docs/modules/mongodb.asciidoc index 0ebcd193666..c546ef595cb 100644 --- a/metricbeat/docs/modules/mongodb.asciidoc +++ b/metricbeat/docs/modules/mongodb.asciidoc @@ -60,8 +60,8 @@ The default metricsets are `collstats`, `dbstats` and `status`. [float] === Compatibility -The MongoDB metricsets were tested with MongoDB 3.4 and 3.0 and are expected to -work with all versions >= 2.8. +The MongoDB metricsets were tested with MongoDB 5.0 and are expected to +work with all versions >= 5.0. [float] === MongoDB Privileges diff --git a/metricbeat/module/mongodb/_meta/docs.asciidoc b/metricbeat/module/mongodb/_meta/docs.asciidoc index 2788a096d4e..cade39ceca7 100644 --- a/metricbeat/module/mongodb/_meta/docs.asciidoc +++ b/metricbeat/module/mongodb/_meta/docs.asciidoc @@ -49,8 +49,8 @@ The default metricsets are `collstats`, `dbstats` and `status`. [float] === Compatibility -The MongoDB metricsets were tested with MongoDB 3.4 and 3.0 and are expected to -work with all versions >= 2.8. +The MongoDB metricsets were tested with MongoDB 5.0 and are expected to +work with all versions >= 5.0. [float] === MongoDB Privileges From 2d1cfbf1e90a0ec5034598fe3e21b8cece25814a Mon Sep 17 00:00:00 2001 From: ritalwar Date: Fri, 10 Mar 2023 14:33:09 +0530 Subject: [PATCH 06/14] Update test cases and documentation --- metricbeat/module/mongodb/_meta/docs.asciidoc | 21 +++++++++++++++++++ metricbeat/module/mongodb/mongodb_test.go | 10 +++++++++ 2 files changed, 31 insertions(+) diff --git a/metricbeat/module/mongodb/_meta/docs.asciidoc b/metricbeat/module/mongodb/_meta/docs.asciidoc index cade39ceca7..4a79cbdf216 100644 --- a/metricbeat/module/mongodb/_meta/docs.asciidoc +++ b/metricbeat/module/mongodb/_meta/docs.asciidoc @@ -31,6 +31,27 @@ Or more complex like: hosts: ["mongodb://myuser:mypass@localhost:40001", "otherhost:40001"] ---------------------------------------------------------------------- +some more supported URLS are: + +[source,yaml] +---------------------------------------------------------------------- +- module: mongodb + hosts: ["mongodb://localhost:27017,localhost:27022,localhost:27023"] +---------------------------------------------------------------------- + +[source,yaml] +---------------------------------------------------------------------- +- module: mongodb + hosts: ["mongodb://localhost:27017/?directConnection=true"] +---------------------------------------------------------------------- + +[source,yaml] +---------------------------------------------------------------------- +- module: mongodb + hosts: ["mongodb://localhost:27017,localhost:27022,localhost:27023/?replicaSet=dbrs"] +---------------------------------------------------------------------- + + The username and password can be included in the URL or they can be set using the respective configuration options. The credentials in the URL take precedence over the username and password configuration options. diff --git a/metricbeat/module/mongodb/mongodb_test.go b/metricbeat/module/mongodb/mongodb_test.go index 61756b1e6bd..51d3b761020 100644 --- a/metricbeat/module/mongodb/mongodb_test.go +++ b/metricbeat/module/mongodb/mongodb_test.go @@ -95,6 +95,16 @@ func TestParseMongoURL(t *testing.T) { ExpectedUsername: "", ExpectedPassword: "", }, + { + Name: "with options replicaset", + URL: "mongodb://localhost:40001/?replicaSet=dbrs", + Username: "anotheruser", + Password: "anotherpass", + + ExpectedAddr: "localhost:40001", + ExpectedUsername: "anotheruser", + ExpectedPassword: "anotherpass", + }, } for _, test := range tests { From 7583fef2892bd6b92ed5399dca9032c5f15a958f Mon Sep 17 00:00:00 2001 From: ritalwar Date: Fri, 10 Mar 2023 14:45:30 +0530 Subject: [PATCH 07/14] update doc --- metricbeat/docs/modules/mongodb.asciidoc | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/metricbeat/docs/modules/mongodb.asciidoc b/metricbeat/docs/modules/mongodb.asciidoc index c546ef595cb..5b475ce21be 100644 --- a/metricbeat/docs/modules/mongodb.asciidoc +++ b/metricbeat/docs/modules/mongodb.asciidoc @@ -42,6 +42,27 @@ Or more complex like: hosts: ["mongodb://myuser:mypass@localhost:40001", "otherhost:40001"] ---------------------------------------------------------------------- +some more supported URLS are: + +[source,yaml] +---------------------------------------------------------------------- +- module: mongodb + hosts: ["mongodb://localhost:27017,localhost:27022,localhost:27023"] +---------------------------------------------------------------------- + +[source,yaml] +---------------------------------------------------------------------- +- module: mongodb + hosts: ["mongodb://localhost:27017/?directConnection=true"] +---------------------------------------------------------------------- + +[source,yaml] +---------------------------------------------------------------------- +- module: mongodb + hosts: ["mongodb://localhost:27017,localhost:27022,localhost:27023/?replicaSet=dbrs"] +---------------------------------------------------------------------- + + The username and password can be included in the URL or they can be set using the respective configuration options. The credentials in the URL take precedence over the username and password configuration options. From ff1802b978fd4f3c0faa85b4aac1c364e2538cc5 Mon Sep 17 00:00:00 2001 From: ritalwar Date: Mon, 3 Apr 2023 13:05:59 +0530 Subject: [PATCH 08/14] Update mongodb_test.go --- metricbeat/module/mongodb/mongodb_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/metricbeat/module/mongodb/mongodb_test.go b/metricbeat/module/mongodb/mongodb_test.go index 51d3b761020..865e3164284 100644 --- a/metricbeat/module/mongodb/mongodb_test.go +++ b/metricbeat/module/mongodb/mongodb_test.go @@ -77,7 +77,7 @@ func TestParseMongoURL(t *testing.T) { }, { Name: "with options", - URL: "mongodb://localhost:40001?connect=direct&authSource=me", + URL: "mongodb://localhost:40001/directConnection=true&authSource=me", Username: "anotheruser", Password: "anotherpass", @@ -97,11 +97,11 @@ func TestParseMongoURL(t *testing.T) { }, { Name: "with options replicaset", - URL: "mongodb://localhost:40001/?replicaSet=dbrs", + URL: "mongodb://localhost:40001,localhost:40002/?replicaSet=dbrs", Username: "anotheruser", Password: "anotherpass", - ExpectedAddr: "localhost:40001", + ExpectedAddr: "localhost:40001,localhost:40002", ExpectedUsername: "anotheruser", ExpectedPassword: "anotherpass", }, From 3848bd7894fa8a88e998e3c8d9d3f3521366a475 Mon Sep 17 00:00:00 2001 From: ritalwar Date: Sun, 14 May 2023 13:02:19 +0530 Subject: [PATCH 09/14] code refactoring --- .../module/mongodb/collstats/collstats.go | 2 +- metricbeat/module/mongodb/dbstats/dbstats.go | 2 +- metricbeat/module/mongodb/metrics/metrics.go | 2 +- metricbeat/module/mongodb/mongodb.go | 23 ++++--------------- .../module/mongodb/replstatus/replstatus.go | 2 +- metricbeat/module/mongodb/status/status.go | 2 +- 6 files changed, 9 insertions(+), 24 deletions(-) diff --git a/metricbeat/module/mongodb/collstats/collstats.go b/metricbeat/module/mongodb/collstats/collstats.go index 5df4a52c595..43b05ed30ec 100644 --- a/metricbeat/module/mongodb/collstats/collstats.go +++ b/metricbeat/module/mongodb/collstats/collstats.go @@ -59,7 +59,7 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) { // format. It publishes the event which is then forwarded to the output. In case // of an error set the Error field of mb.Event or simply call report.Error(). func (m *Metricset) Fetch(reporter mb.ReporterV2) error { - client, err := mongodb.NewClient(m.Metricset.Config, m.Module().Config().Timeout, 0) + client, err := mongodb.NewClient(m.Metricset.Config, m.HostData().URI, m.Module().Config().Timeout, 0) if err != nil { return fmt.Errorf("could not create mongodb client: %w", err) } diff --git a/metricbeat/module/mongodb/dbstats/dbstats.go b/metricbeat/module/mongodb/dbstats/dbstats.go index 3fb6c8db3ea..d696448a2b4 100644 --- a/metricbeat/module/mongodb/dbstats/dbstats.go +++ b/metricbeat/module/mongodb/dbstats/dbstats.go @@ -62,7 +62,7 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) { // format. It publishes the event which is then forwarded to the output. In case // of an error set the Error field of mb.Event or simply call report.Error(). func (m *MetricSet) Fetch(reporter mb.ReporterV2) error { - client, err := mongodb.NewClient(m.Metricset.Config, m.Module().Config().Timeout, 0) + client, err := mongodb.NewClient(m.Metricset.Config, m.HostData().URI, m.Module().Config().Timeout, 0) if err != nil { return fmt.Errorf("could not create mongodb client: %w", err) } diff --git a/metricbeat/module/mongodb/metrics/metrics.go b/metricbeat/module/mongodb/metrics/metrics.go index 79a8cd436fb..124c81c0443 100644 --- a/metricbeat/module/mongodb/metrics/metrics.go +++ b/metricbeat/module/mongodb/metrics/metrics.go @@ -58,7 +58,7 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) { // format. It publishes the event which is then forwarded to the output. In case // of an error set the Error field of mb.Event or simply call report.Error(). func (m *MetricSet) Fetch(reporter mb.ReporterV2) error { - client, err := mongodb.NewClient(m.Metricset.Config, m.Module().Config().Timeout, 0) + client, err := mongodb.NewClient(m.Metricset.Config, m.HostData().URI, m.Module().Config().Timeout, 0) if err != nil { return fmt.Errorf("could not create mongodb client: %w", err) } diff --git a/metricbeat/module/mongodb/mongodb.go b/metricbeat/module/mongodb/mongodb.go index 5539d84131f..50a97e0df00 100644 --- a/metricbeat/module/mongodb/mongodb.go +++ b/metricbeat/module/mongodb/mongodb.go @@ -114,28 +114,11 @@ func ParseURL(module mb.Module, host string) (mb.HostData, error) { parse.SetURLUser(u, c.Username, c.Password) - clientOptions := options.Client() - clientOptions.Auth = &options.Credential{ - AuthMechanism: c.Credentials.AuthMechanism, - AuthMechanismProperties: c.Credentials.AuthMechanismProperties, - AuthSource: c.Credentials.AuthSource, - PasswordSet: c.Credentials.PasswordSet, - Username: c.Username, - Password: c.Password, - } - - clientOptions.ApplyURI(host) - - // https://docs.mongodb.com/manual/reference/connection-string/ - _, err = url.Parse(clientOptions.GetURI()) - if err != nil { - return mb.HostData{}, fmt.Errorf("error parsing URL: %w", err) - } - return parse.NewHostDataFromURL(u), nil } -func NewClient(config ModuleConfig, timeout time.Duration, mode readpref.Mode) (*mongo.Client, error) { +func NewClient(config ModuleConfig, uri string, timeout time.Duration, mode readpref.Mode) (*mongo.Client, error) { + clientOptions := options.Client() // options.Credentials must be nil for the driver to work properly if no auth is provided. Zero values breaks @@ -155,6 +138,8 @@ func NewClient(config ModuleConfig, timeout time.Duration, mode readpref.Mode) ( } } + clientOptions.ApplyURI(uri) + if mode == 0 { mode = readpref.NearestMode } diff --git a/metricbeat/module/mongodb/replstatus/replstatus.go b/metricbeat/module/mongodb/replstatus/replstatus.go index 05c66d80dbc..5f43efd251d 100644 --- a/metricbeat/module/mongodb/replstatus/replstatus.go +++ b/metricbeat/module/mongodb/replstatus/replstatus.go @@ -55,7 +55,7 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) { // format. It publishes the event which is then forwarded to the output. In case // of an error set the Error field of mb.Event or simply call report.Error(). func (m *MetricSet) Fetch(reporter mb.ReporterV2) error { - client, err := mongodb.NewClient(m.Metricset.Config, m.Module().Config().Timeout, readpref.PrimaryMode) + client, err := mongodb.NewClient(m.Metricset.Config, m.HostData().URI, m.Module().Config().Timeout, readpref.PrimaryMode) if err != nil { return fmt.Errorf("could not create mongodb client: %w", err) } diff --git a/metricbeat/module/mongodb/status/status.go b/metricbeat/module/mongodb/status/status.go index 1c7f8c6a863..6f3014d440b 100644 --- a/metricbeat/module/mongodb/status/status.go +++ b/metricbeat/module/mongodb/status/status.go @@ -61,7 +61,7 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) { // It returns the event which is then forward to the output. In case of an error, a // descriptive error must be returned. func (m *MetricSet) Fetch(r mb.ReporterV2) error { - client, err := mongodb.NewClient(m.Metricset.Config, m.Module().Config().Timeout, readpref.PrimaryMode) + client, err := mongodb.NewClient(m.Metricset.Config, m.HostData().URI, m.Module().Config().Timeout, readpref.PrimaryMode) if err != nil { return fmt.Errorf("could not create mongodb client: %w", err) } From 6015e2757d048638f216bc16e3702db2cff2136c Mon Sep 17 00:00:00 2001 From: ritalwar Date: Sun, 14 May 2023 13:16:02 +0530 Subject: [PATCH 10/14] address review comments --- metricbeat/module/mongodb/_meta/docs.asciidoc | 8 +++++++- metricbeat/module/mongodb/mongodb_test.go | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/metricbeat/module/mongodb/_meta/docs.asciidoc b/metricbeat/module/mongodb/_meta/docs.asciidoc index 4a79cbdf216..c02c30e56ee 100644 --- a/metricbeat/module/mongodb/_meta/docs.asciidoc +++ b/metricbeat/module/mongodb/_meta/docs.asciidoc @@ -15,6 +15,12 @@ format: [mongodb://][user:pass@]host[:port][?options] ----------------------------------- +Or + +----------------------------------------------------------------------------------------- +mongodb://[username:password@]host1[:port1][,...hostN[:portN]][/[defaultauthdb][?options]] +----------------------------------------------------------------------------------------- + The URL can be as simple as: [source,yaml] @@ -31,7 +37,7 @@ Or more complex like: hosts: ["mongodb://myuser:mypass@localhost:40001", "otherhost:40001"] ---------------------------------------------------------------------- -some more supported URLS are: +Some more supported URLs are: [source,yaml] ---------------------------------------------------------------------- diff --git a/metricbeat/module/mongodb/mongodb_test.go b/metricbeat/module/mongodb/mongodb_test.go index 865e3164284..dc926304bbe 100644 --- a/metricbeat/module/mongodb/mongodb_test.go +++ b/metricbeat/module/mongodb/mongodb_test.go @@ -96,7 +96,7 @@ func TestParseMongoURL(t *testing.T) { ExpectedPassword: "", }, { - Name: "with options replicaset", + Name: "with replicaSet option", URL: "mongodb://localhost:40001,localhost:40002/?replicaSet=dbrs", Username: "anotheruser", Password: "anotherpass", From 2d9b929bcb0d767b44a84c4908e4b165f51eac62 Mon Sep 17 00:00:00 2001 From: ritalwar Date: Sun, 14 May 2023 13:58:59 +0530 Subject: [PATCH 11/14] rebuild --- metricbeat/docs/modules/mongodb.asciidoc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/metricbeat/docs/modules/mongodb.asciidoc b/metricbeat/docs/modules/mongodb.asciidoc index 5b475ce21be..d972c28586c 100644 --- a/metricbeat/docs/modules/mongodb.asciidoc +++ b/metricbeat/docs/modules/mongodb.asciidoc @@ -26,6 +26,12 @@ format: [mongodb://][user:pass@]host[:port][?options] ----------------------------------- +Or + +----------------------------------------------------------------------------------------- +mongodb://[username:password@]host1[:port1][,...hostN[:portN]][/[defaultauthdb][?options]] +----------------------------------------------------------------------------------------- + The URL can be as simple as: [source,yaml] @@ -42,7 +48,7 @@ Or more complex like: hosts: ["mongodb://myuser:mypass@localhost:40001", "otherhost:40001"] ---------------------------------------------------------------------- -some more supported URLS are: +Some more supported URLs are: [source,yaml] ---------------------------------------------------------------------- From 599f74199aff9194ab28018d96c01ea85104527f Mon Sep 17 00:00:00 2001 From: ritalwar Date: Sun, 14 May 2023 23:20:00 +0530 Subject: [PATCH 12/14] fixing test call --- .../module/mongodb/replstatus/replstatus_integration_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/metricbeat/module/mongodb/replstatus/replstatus_integration_test.go b/metricbeat/module/mongodb/replstatus/replstatus_integration_test.go index 018e81b9fdc..4284beccc39 100644 --- a/metricbeat/module/mongodb/replstatus/replstatus_integration_test.go +++ b/metricbeat/module/mongodb/replstatus/replstatus_integration_test.go @@ -105,9 +105,10 @@ func getConfig(host string) map[string]interface{} { } func initiateReplicaSet(t *testing.T, host string) error { + uri := "mongodb://" + host client, err := mongodb.NewClient(mongodb.ModuleConfig{ Hosts: []string{host}, - }, time.Second*5, readpref.PrimaryMode) + }, uri, time.Second*5, readpref.PrimaryMode) if err != nil { return fmt.Errorf("could not create mongodb client: %w", err) } From e038e88dbc54b6888a7fa4dcc3b1541a80f50089 Mon Sep 17 00:00:00 2001 From: ritalwar Date: Mon, 22 May 2023 09:59:30 +0530 Subject: [PATCH 13/14] update docs --- metricbeat/docs/modules/mongodb.asciidoc | 5 +++++ metricbeat/module/mongodb/_meta/docs.asciidoc | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/metricbeat/docs/modules/mongodb.asciidoc b/metricbeat/docs/modules/mongodb.asciidoc index d972c28586c..d8bf043a62a 100644 --- a/metricbeat/docs/modules/mongodb.asciidoc +++ b/metricbeat/docs/modules/mongodb.asciidoc @@ -62,6 +62,11 @@ Some more supported URLs are: hosts: ["mongodb://localhost:27017/?directConnection=true"] ---------------------------------------------------------------------- +When the parameter directConnection=true is included in the connection URI, +all operations are executed on the host specified in the URI. +It's important to note that directConnection=true must be explicitly specified in the URI, +as it won't be added automatically unless specified. + [source,yaml] ---------------------------------------------------------------------- - module: mongodb diff --git a/metricbeat/module/mongodb/_meta/docs.asciidoc b/metricbeat/module/mongodb/_meta/docs.asciidoc index c02c30e56ee..933f6082142 100644 --- a/metricbeat/module/mongodb/_meta/docs.asciidoc +++ b/metricbeat/module/mongodb/_meta/docs.asciidoc @@ -51,6 +51,11 @@ Some more supported URLs are: hosts: ["mongodb://localhost:27017/?directConnection=true"] ---------------------------------------------------------------------- +When the parameter directConnection=true is included in the connection URI, +all operations are executed on the host specified in the URI. +It's important to note that directConnection=true must be explicitly specified in the URI, +as it won't be added automatically unless specified. + [source,yaml] ---------------------------------------------------------------------- - module: mongodb From 8393bc2d82127498ad32d8db1a2b1ff6ebb5f7bf Mon Sep 17 00:00:00 2001 From: ritalwar Date: Mon, 22 May 2023 11:54:53 +0530 Subject: [PATCH 14/14] address comments --- metricbeat/docs/modules/mongodb.asciidoc | 4 ++-- metricbeat/module/mongodb/_meta/docs.asciidoc | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/metricbeat/docs/modules/mongodb.asciidoc b/metricbeat/docs/modules/mongodb.asciidoc index d8bf043a62a..3d2b70e6cc7 100644 --- a/metricbeat/docs/modules/mongodb.asciidoc +++ b/metricbeat/docs/modules/mongodb.asciidoc @@ -62,9 +62,9 @@ Some more supported URLs are: hosts: ["mongodb://localhost:27017/?directConnection=true"] ---------------------------------------------------------------------- -When the parameter directConnection=true is included in the connection URI, +When the parameter `directConnection=true` is included in the connection URI, all operations are executed on the host specified in the URI. -It's important to note that directConnection=true must be explicitly specified in the URI, +It's important to note that `directConnection=true` must be explicitly specified in the URI, as it won't be added automatically unless specified. [source,yaml] diff --git a/metricbeat/module/mongodb/_meta/docs.asciidoc b/metricbeat/module/mongodb/_meta/docs.asciidoc index 933f6082142..6616ff8ab4d 100644 --- a/metricbeat/module/mongodb/_meta/docs.asciidoc +++ b/metricbeat/module/mongodb/_meta/docs.asciidoc @@ -51,9 +51,9 @@ Some more supported URLs are: hosts: ["mongodb://localhost:27017/?directConnection=true"] ---------------------------------------------------------------------- -When the parameter directConnection=true is included in the connection URI, +When the parameter `directConnection=true` is included in the connection URI, all operations are executed on the host specified in the URI. -It's important to note that directConnection=true must be explicitly specified in the URI, +It's important to note that `directConnection=true` must be explicitly specified in the URI, as it won't be added automatically unless specified. [source,yaml]