-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add MongoDB scaler #1467
Add MongoDB scaler #1467
Conversation
Can you fix DCO & our static checks please? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if we should call it mongo
or mongodb
?
CHANGELOG.md
Outdated
@@ -19,6 +19,7 @@ | |||
### New | |||
- Can use Pod Identity with Azure Event Hub scaler ([#994](https://github.com/kedacore/keda/issues/994)) | |||
- Introducing InfluxDB scaler ([#1239](https://github.com/kedacore/keda/issues/1239)) | |||
- Introducing Mongo scaler ([#1465](https://github.com/kedacore/keda/issues/1465)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Introducing Mongo scaler ([#1465](https://github.com/kedacore/keda/issues/1465)) | |
- Introducing MongoDB scaler ([#1465](https://github.com/kedacore/keda/issues/1465)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think it's better to call it mongodb
scaler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should keep that naming consistent, in the go code all the references to the scaler are as mongo
not mongodb
. Shouldn't we change that as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, i will change them to mongoDB,at the same time,add e2e tests for this scaler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
143197b
to
f17a965
Compare
|
@tomkerkhove Could we trigger the pre-commit re-test. |
@NUCsimple thanks for the contribution! I'll get to the proper review later. Could you please add e2e tests for this scaler? |
dc989e6
to
974ed74
Compare
Hi, @zroubalik .Coud you please check it again? I have changed all the non-standard contents mentioned above. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor formating related nits and mongoDB
-> mongodb
for consistency
pkg/scalers/mongo.go
Outdated
@@ -0,0 +1,286 @@ | |||
package scalers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please name this file mongodb_scaler.go
so it is consistent with other scalers in the package.
pkg/scalers/mongo.go
Outdated
defaultQueryValue = 1 | ||
) | ||
|
||
var mongoDBLog = logf.Log.WithName("mongoDB_scaler") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var mongoDBLog = logf.Log.WithName("mongoDB_scaler") | |
var mongoDBLog = logf.Log.WithName("mongodb_scaler") |
pkg/scalers/mongo_test.go
Outdated
@@ -0,0 +1,87 @@ | |||
package scalers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please name this file mongodb_scaler_test.go
so it is consistent with other tests in the package.
pkg/scaling/scale_handler.go
Outdated
@@ -474,6 +474,8 @@ func buildScaler(triggerType string, config *scalers.ScalerConfig) (scalers.Scal | |||
return scalers.NewCPUMemoryScaler(corev1.ResourceMemory, config) | |||
case "metrics-api": | |||
return scalers.NewMetricsAPIScaler(config) | |||
case "mongoDB": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
case "mongoDB": | |
case "mongodb": |
I'd make this lowercase, to be consistent with other scalers
pkg/scalers/mongo.go
Outdated
func (s *mongoDBScaler) GetMetrics(ctx context.Context, metricName string, metricSelector labels.Selector) ([]external_metrics.ExternalMetricValue, error) { | ||
num, err := s.getQueryResult() | ||
if err != nil { | ||
return []external_metrics.ExternalMetricValue{}, fmt.Errorf("failed to inspect momgo,because of %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return []external_metrics.ExternalMetricValue{}, fmt.Errorf("failed to inspect momgo,because of %v", err) | |
return []external_metrics.ExternalMetricValue{}, fmt.Errorf("failed to inspect mongoDB, because of %v", err) |
pkg/scalers/mongo.go
Outdated
} | ||
|
||
if err = client.Ping(ctx, readpref.Primary()); err != nil { | ||
return nil, fmt.Errorf("failed to ping mongoDB,because of %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return nil, fmt.Errorf("failed to ping mongoDB,because of %v", err) | |
return nil, fmt.Errorf("failed to ping mongoDB, because of %v", err) |
pkg/scalers/mongo.go
Outdated
if val, ok := config.TriggerMetadata["queryValue"]; ok { | ||
queryValue, err := strconv.Atoi(val) | ||
if err != nil { | ||
return nil, "", fmt.Errorf("failed to convert %v to int,because of %v", queryValue, err.Error()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return nil, "", fmt.Errorf("failed to convert %v to int,because of %v", queryValue, err.Error()) | |
return nil, "", fmt.Errorf("failed to convert %v to int, because of %v", queryValue, err.Error()) |
pkg/scalers/mongo.go
Outdated
if s.client != nil { | ||
err := s.client.Disconnect(context.TODO()) | ||
if err != nil { | ||
mongoDBLog.Error(err, fmt.Sprintf("failed to close mongoDB connection,because of %v", err)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mongoDBLog.Error(err, fmt.Sprintf("failed to close mongoDB connection,because of %v", err)) | |
mongoDBLog.Error(err, fmt.Sprintf("failed to close mongoDB connection, because of %v", err)) |
pkg/scalers/mongo.go
Outdated
|
||
filter, err := json2BsonDoc(s.metadata.query) | ||
if err != nil { | ||
mongoDBLog.Error(err, fmt.Sprintf("failed to convert query param to bson.Doc,because of %v", err)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mongoDBLog.Error(err, fmt.Sprintf("failed to convert query param to bson.Doc,because of %v", err)) | |
mongoDBLog.Error(err, fmt.Sprintf("failed to convert query param to bson.Doc, because of %v", err)) |
pkg/scalers/mongo.go
Outdated
|
||
docsNum, err := s.client.Database(s.metadata.dbName).Collection(s.metadata.collection).CountDocuments(ctx, filter) | ||
if err != nil { | ||
mongoDBLog.Error(err, fmt.Sprintf("failed to query %v in %v,because of %v", s.metadata.dbName, s.metadata.collection, err)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mongoDBLog.Error(err, fmt.Sprintf("failed to query %v in %v,because of %v", s.metadata.dbName, s.metadata.collection, err)) | |
mongoDBLog.Error(err, fmt.Sprintf("failed to query %v in %v, because of %v", s.metadata.dbName, s.metadata.collection, err)) |
Signed-off-by: 高强 <wb-gq555900@alibaba-inc.com>
d709486
to
3fb066e
Compare
Signed-off-by: 高强 <wb-gq555900@alibaba-inc.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for the contribution!
Signed-off-by: carson carson_192@163.com
This PR adds a new scaler for the mongo.
Checklist
Related to #1465.