kedacore / keda

KEDA is a Kubernetes-based Event Driven Autoscaling component. It provides event driven scale for any container running in Kubernetes
https://keda.sh
Apache License 2.0
8.5k stars 1.08k forks source link

Version 2.14 - MongoDB Atlas scheme #5760

Closed lsteinberg-r7 closed 6 months ago

lsteinberg-r7 commented 6 months ago

Report

I'm trying to use the latest version's feature of MongoDB Atlas scheme support (mongodb+srv), and getting conflicting requirements -

Keda scale-handler requires a port to be given, otherwise it's failing with: failed to parsing mongoDB metadata, because of missing required field in scaler config: no port given

But if I'm supplying a port, MongoDB driver itself is failing with the following message: URI with srv must not include a port number which comes from this piece of code - https://github.com/kedacore/keda/blob/c55e306af94bf41d69c4f3d43744398fa07a358e/vendor/go.mongodb.org/mongo-driver/x/mongo/driver/topology/topology.go#L390-L403

Expected Behavior

Scaler defined with the +srv scheme should not require a port number.

Actual Behavior

Scaler defined with the +srv scheme requires a port number, even though it conflicts with the driver's requirements.

Steps to Reproduce the Problem

  1. Define a real Atlas host
  2. Define a scaler that uses the host, with a port number
  3. See the error event in the scaler definition in k8s.

Logs from KEDA operator

example

KEDA Version

2.14.0

Kubernetes Version

None

Platform

Google Cloud

Scaler Details

MongoDB

Anything else?

No response

JorTurFer commented 6 months ago

Nice catch! Are you willing to open a PR with the fix?

lsteinberg-r7 commented 6 months ago

Nice catch! Are you willing to open a PR with the fix?

@JorTurFer I would love to but I'm not sure I have the time, many tasks ahead in my company 😅

JorTurFer commented 6 months ago

no worries! Let's see if anyone wants to help here, I'd say that it should be easy

Rishikesh01 commented 6 months ago

Hi @JorTurFer I was able to replicate OP error in mongo_scaler_test.go,after doing the following changes. Will make PR shortly :)

diff --git a/pkg/scalers/mongo_scaler_test.go b/pkg/scalers/mongo_scaler_test.go
index 02f1e947..fd9f54f8 100644
--- a/pkg/scalers/mongo_scaler_test.go
+++ b/pkg/scalers/mongo_scaler_test.go
@@ -73,7 +73,7 @@ var testMONGODBMetadata = []parseMongoDBMetadataTestData{
        // mongodb srv support
        {
                metadata:    map[string]string{"query": `{"name":"John"}`, "collection": "demo", "queryValue": "12"},
-               authParams:  map[string]string{"dbName": "test", "scheme": "mongodb+srv", "host": "localhost", "port": "1234", "username":$
+               authParams:  map[string]string{"dbName": "test", "scheme": "mongodb+srv", "host": "localhost", "port": "", "username": "sa$
                resolvedEnv: testMongoDBResolvedEnv,
                raisesError: false,
        },
@@ -90,7 +90,7 @@ var mongoDBConnectionStringTestDatas = []mongoDBConnectionStringTestData{
        {metadataTestData: &testMONGODBMetadata[2], connectionString: "mongodb://mongodb0.example.com:27017"},
        {metadataTestData: &testMONGODBMetadata[3], connectionString: "mongodb://sample:test%40password@localhost:1234/test"},
        {metadataTestData: &testMONGODBMetadata[4], connectionString: "mongodb://sample:sec%40ure@localhost:1234/test"},
-       {metadataTestData: &testMONGODBMetadata[5], connectionString: "mongodb+srv://sample:sec%40ure@localhost:1234/test"},
+       {metadataTestData: &testMONGODBMetadata[5], connectionString: "mongodb+srv://sample:sec%40ure@localhost/test"},
 }

 var mongoDBMetricIdentifiers = []mongoDBMetricIdentifier{
Rishikesh01 commented 6 months ago

Have opened an pr: https://github.com/kedacore/keda/pull/5773 please take a look when you have time :)