Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/v1/mdb/mongodb_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const (
Warn LogLevel = "WARN"
Error LogLevel = "ERROR"
Fatal LogLevel = "FATAL"
Trace LogLevel = "TRACE"

Standalone ResourceType = "Standalone"
ReplicaSet ResourceType = "ReplicaSet"
Expand Down
13 changes: 13 additions & 0 deletions api/v1/search/mongodbsearch_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

v1 "github.com/mongodb/mongodb-kubernetes/api/v1"
"github.com/mongodb/mongodb-kubernetes/api/v1/mdb"
"github.com/mongodb/mongodb-kubernetes/api/v1/status"
userv1 "github.com/mongodb/mongodb-kubernetes/api/v1/user"
"github.com/mongodb/mongodb-kubernetes/mongodb-community-operator/api/v1/common"
Expand Down Expand Up @@ -46,6 +47,10 @@ type MongoDBSearchSpec struct {
// Configure security settings of the MongoDB Search server that MongoDB database is connecting to when performing search queries.
// +optional
Security Security `json:"security"`
// Configure verbosity of mongot logs. Defaults to INFO if not set.
// +kubebuilder:validation:Enum=TRACE;DEBUG;INFO;WARN;ERROR
// +optional
LogLevel mdb.LogLevel `json:"logLevel,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

q: would users potentially be able to configure log level of any other components in future? For example mongos or anything like that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do have already. Look for other logLevel instances in our crd types:

// +kubebuilder:validation:Enum=DEBUG;INFO;WARN;ERROR;FATAL
LogLevel LogLevel `json:"logLevel,omitempty"`
// ExternalAccessConfiguration provides external access configuration.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant would we be able to configure LogLevel of any other component using MongoDBSearch api. I was asking that because if that's the case just LogLevel as field name might not be sufficient right?

}

type MongoDBSource struct {
Expand Down Expand Up @@ -228,3 +233,11 @@ func (s *MongoDBSearch) GetMongotHealthCheckPort() int32 {
func (s *MongoDBSearch) IsExternalMongoDBSource() bool {
return s.Spec.Source != nil && s.Spec.Source.ExternalMongoDBSource != nil
}

func (s *MongoDBSearch) GetLogLevel() mdb.LogLevel {
if s.Spec.LogLevel == "" {
return "INFO"
}

return s.Spec.LogLevel
}
14 changes: 12 additions & 2 deletions config/crd/bases/mongodb.com_mongodbsearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ spec:
type: object
spec:
properties:
logLevel:
description: Configure verbosity of mongot logs. Defaults to INFO
if not set.
enum:
- TRACE
- DEBUG
- INFO
- WARN
- ERROR
type: string
persistence:
description: Configure MongoDB Search's persistent volume. If not
defined, the operator will request 10GB of storage.
Expand Down Expand Up @@ -180,7 +190,7 @@ spec:
type: object
x-kubernetes-map-type: atomic
required:
- certificateKeySecretRef
- certificateKeySecretRef
type: object
type: object
source:
Expand Down Expand Up @@ -224,7 +234,7 @@ spec:
type: object
x-kubernetes-map-type: atomic
required:
- ca
- ca
type: object
type: object
mongodbResourceRef:
Expand Down
9 changes: 8 additions & 1 deletion controllers/operator/mongodbsearch_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ func buildExpectedMongotConfig(search *searchv1.MongoDBSearch, mdbc *mdbcv1.Mong
for i := range mdbc.Spec.Members {
hostAndPorts = append(hostAndPorts, fmt.Sprintf("%s-%d.%s.%s.svc.cluster.local:%d", mdbc.Name, i, mdbc.Name+"-svc", search.Namespace, 27017))
}

logLevel := "INFO"
if search.Spec.LogLevel != "" {
logLevel = string(search.Spec.LogLevel)
}
return mongot.Config{
SyncSource: mongot.ConfigSyncSource{
ReplicaSet: mongot.ConfigReplicaSet{
Expand Down Expand Up @@ -127,7 +132,7 @@ func buildExpectedMongotConfig(search *searchv1.MongoDBSearch, mdbc *mdbcv1.Mong
Address: fmt.Sprintf("0.0.0.0:%d", search.GetMongotHealthCheckPort()),
},
Logging: mongot.ConfigLogging{
Verbosity: "TRACE",
Verbosity: logLevel,
LogPath: nil,
},
}
Expand Down Expand Up @@ -164,6 +169,8 @@ func TestMongoDBSearchReconcile_MissingSource(t *testing.T) {
func TestMongoDBSearchReconcile_Success(t *testing.T) {
ctx := context.Background()
search := newMongoDBSearch("search", mock.TestNamespace, "mdb")
search.Spec.LogLevel = "WARN"

mdbc := newMongoDBCommunity("mdb", mock.TestNamespace)
reconciler, c := newSearchReconciler(mdbc, search)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ func createMongotConfig(search *searchv1.MongoDBSearch, db SearchSourceDBResourc
Address: fmt.Sprintf("0.0.0.0:%d", search.GetMongotHealthCheckPort()),
}
config.Logging = mongot.ConfigLogging{
Verbosity: "TRACE",
Verbosity: string(search.GetLogLevel()),
LogPath: nil,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ apiVersion: mongodb.com/v1
kind: MongoDBSearch
metadata:
name: mdbc-rs
spec: {}
spec:
logLevel: DEBUG

14 changes: 12 additions & 2 deletions helm_chart/crds/mongodb.com_mongodbsearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ spec:
type: object
spec:
properties:
logLevel:
description: Configure verbosity of mongot logs. Defaults to INFO
if not set.
enum:
- TRACE
- DEBUG
- INFO
- WARN
- ERROR
type: string
persistence:
description: Configure MongoDB Search's persistent volume. If not
defined, the operator will request 10GB of storage.
Expand Down Expand Up @@ -180,7 +190,7 @@ spec:
type: object
x-kubernetes-map-type: atomic
required:
- certificateKeySecretRef
- certificateKeySecretRef
type: object
type: object
source:
Expand Down Expand Up @@ -224,7 +234,7 @@ spec:
type: object
x-kubernetes-map-type: atomic
required:
- ca
- ca
type: object
type: object
mongodbResourceRef:
Expand Down
14 changes: 12 additions & 2 deletions public/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4070,6 +4070,16 @@ spec:
type: object
spec:
properties:
logLevel:
description: Configure verbosity of mongot logs. Defaults to INFO
if not set.
enum:
- TRACE
- DEBUG
- INFO
- WARN
- ERROR
type: string
persistence:
description: Configure MongoDB Search's persistent volume. If not
defined, the operator will request 10GB of storage.
Expand Down Expand Up @@ -4202,7 +4212,7 @@ spec:
type: object
x-kubernetes-map-type: atomic
required:
- certificateKeySecretRef
- certificateKeySecretRef
type: object
type: object
source:
Expand Down Expand Up @@ -4246,7 +4256,7 @@ spec:
type: object
x-kubernetes-map-type: atomic
required:
- ca
- ca
type: object
type: object
mongodbResourceRef:
Expand Down
Loading