Skip to content

Commit 5db118d

Browse files
authored
CLOUDP-321073: Handle logLevel in MongoDBSearch (mongodb#453)
# Summary This PR exposes logging configuration of mongot pods to MongoDBSearch CRD. ## Proof of Work ## Checklist - [ ] Have you linked a jira ticket and/or is the ticket in the title? - [ ] Have you checked whether your jira ticket required DOCSP changes? - [ ] Have you added changelog file? - use `skip-changelog` label if not needed - refer to [Changelog files and Release Notes](https://github.com/mongodb/mongodb-kubernetes/blob/master/CONTRIBUTING.md#changelog-files-and-release-notes) section in CONTRIBUTING.md for more details
1 parent 3976a78 commit 5db118d

File tree

8 files changed

+62
-9
lines changed

8 files changed

+62
-9
lines changed

api/v1/mdb/mongodb_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const (
4646
Warn LogLevel = "WARN"
4747
Error LogLevel = "ERROR"
4848
Fatal LogLevel = "FATAL"
49+
Trace LogLevel = "TRACE"
4950

5051
Standalone ResourceType = "Standalone"
5152
ReplicaSet ResourceType = "ReplicaSet"

api/v1/search/mongodbsearch_types.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1111

1212
v1 "github.com/mongodb/mongodb-kubernetes/api/v1"
13+
"github.com/mongodb/mongodb-kubernetes/api/v1/mdb"
1314
"github.com/mongodb/mongodb-kubernetes/api/v1/status"
1415
userv1 "github.com/mongodb/mongodb-kubernetes/api/v1/user"
1516
"github.com/mongodb/mongodb-kubernetes/mongodb-community-operator/api/v1/common"
@@ -46,6 +47,10 @@ type MongoDBSearchSpec struct {
4647
// Configure security settings of the MongoDB Search server that MongoDB database is connecting to when performing search queries.
4748
// +optional
4849
Security Security `json:"security"`
50+
// Configure verbosity of mongot logs. Defaults to INFO if not set.
51+
// +kubebuilder:validation:Enum=TRACE;DEBUG;INFO;WARN;ERROR
52+
// +optional
53+
LogLevel mdb.LogLevel `json:"logLevel,omitempty"`
4954
}
5055

5156
type MongoDBSource struct {
@@ -228,3 +233,11 @@ func (s *MongoDBSearch) GetMongotHealthCheckPort() int32 {
228233
func (s *MongoDBSearch) IsExternalMongoDBSource() bool {
229234
return s.Spec.Source != nil && s.Spec.Source.ExternalMongoDBSource != nil
230235
}
236+
237+
func (s *MongoDBSearch) GetLogLevel() mdb.LogLevel {
238+
if s.Spec.LogLevel == "" {
239+
return "INFO"
240+
}
241+
242+
return s.Spec.LogLevel
243+
}

config/crd/bases/mongodb.com_mongodbsearch.yaml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ spec:
4848
type: object
4949
spec:
5050
properties:
51+
logLevel:
52+
description: Configure verbosity of mongot logs. Defaults to INFO
53+
if not set.
54+
enum:
55+
- TRACE
56+
- DEBUG
57+
- INFO
58+
- WARN
59+
- ERROR
60+
type: string
5161
persistence:
5262
description: Configure MongoDB Search's persistent volume. If not
5363
defined, the operator will request 10GB of storage.
@@ -180,7 +190,7 @@ spec:
180190
type: object
181191
x-kubernetes-map-type: atomic
182192
required:
183-
- certificateKeySecretRef
193+
- certificateKeySecretRef
184194
type: object
185195
type: object
186196
source:
@@ -224,7 +234,7 @@ spec:
224234
type: object
225235
x-kubernetes-map-type: atomic
226236
required:
227-
- ca
237+
- ca
228238
type: object
229239
type: object
230240
mongodbResourceRef:

controllers/operator/mongodbsearch_controller_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ func buildExpectedMongotConfig(search *searchv1.MongoDBSearch, mdbc *mdbcv1.Mong
9595
for i := range mdbc.Spec.Members {
9696
hostAndPorts = append(hostAndPorts, fmt.Sprintf("%s-%d.%s.%s.svc.cluster.local:%d", mdbc.Name, i, mdbc.Name+"-svc", search.Namespace, 27017))
9797
}
98+
99+
logLevel := "INFO"
100+
if search.Spec.LogLevel != "" {
101+
logLevel = string(search.Spec.LogLevel)
102+
}
98103
return mongot.Config{
99104
SyncSource: mongot.ConfigSyncSource{
100105
ReplicaSet: mongot.ConfigReplicaSet{
@@ -127,7 +132,7 @@ func buildExpectedMongotConfig(search *searchv1.MongoDBSearch, mdbc *mdbcv1.Mong
127132
Address: fmt.Sprintf("0.0.0.0:%d", search.GetMongotHealthCheckPort()),
128133
},
129134
Logging: mongot.ConfigLogging{
130-
Verbosity: "TRACE",
135+
Verbosity: logLevel,
131136
LogPath: nil,
132137
},
133138
}
@@ -164,6 +169,8 @@ func TestMongoDBSearchReconcile_MissingSource(t *testing.T) {
164169
func TestMongoDBSearchReconcile_Success(t *testing.T) {
165170
ctx := context.Background()
166171
search := newMongoDBSearch("search", mock.TestNamespace, "mdb")
172+
search.Spec.LogLevel = "WARN"
173+
167174
mdbc := newMongoDBCommunity("mdb", mock.TestNamespace)
168175
reconciler, c := newSearchReconciler(mdbc, search)
169176

controllers/searchcontroller/mongodbsearch_reconcile_helper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ func createMongotConfig(search *searchv1.MongoDBSearch, db SearchSourceDBResourc
382382
Address: fmt.Sprintf("0.0.0.0:%d", search.GetMongotHealthCheckPort()),
383383
}
384384
config.Logging = mongot.ConfigLogging{
385-
Verbosity: "TRACE",
385+
Verbosity: string(search.GetLogLevel()),
386386
LogPath: nil,
387387
}
388388
}

docker/mongodb-kubernetes-tests/tests/search/fixtures/search-minimal.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ apiVersion: mongodb.com/v1
22
kind: MongoDBSearch
33
metadata:
44
name: mdbc-rs
5-
spec: {}
5+
spec:
6+
logLevel: DEBUG
7+

helm_chart/crds/mongodb.com_mongodbsearch.yaml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ spec:
4848
type: object
4949
spec:
5050
properties:
51+
logLevel:
52+
description: Configure verbosity of mongot logs. Defaults to INFO
53+
if not set.
54+
enum:
55+
- TRACE
56+
- DEBUG
57+
- INFO
58+
- WARN
59+
- ERROR
60+
type: string
5161
persistence:
5262
description: Configure MongoDB Search's persistent volume. If not
5363
defined, the operator will request 10GB of storage.
@@ -180,7 +190,7 @@ spec:
180190
type: object
181191
x-kubernetes-map-type: atomic
182192
required:
183-
- certificateKeySecretRef
193+
- certificateKeySecretRef
184194
type: object
185195
type: object
186196
source:
@@ -224,7 +234,7 @@ spec:
224234
type: object
225235
x-kubernetes-map-type: atomic
226236
required:
227-
- ca
237+
- ca
228238
type: object
229239
type: object
230240
mongodbResourceRef:

public/crds.yaml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4070,6 +4070,16 @@ spec:
40704070
type: object
40714071
spec:
40724072
properties:
4073+
logLevel:
4074+
description: Configure verbosity of mongot logs. Defaults to INFO
4075+
if not set.
4076+
enum:
4077+
- TRACE
4078+
- DEBUG
4079+
- INFO
4080+
- WARN
4081+
- ERROR
4082+
type: string
40734083
persistence:
40744084
description: Configure MongoDB Search's persistent volume. If not
40754085
defined, the operator will request 10GB of storage.
@@ -4202,7 +4212,7 @@ spec:
42024212
type: object
42034213
x-kubernetes-map-type: atomic
42044214
required:
4205-
- certificateKeySecretRef
4215+
- certificateKeySecretRef
42064216
type: object
42074217
type: object
42084218
source:
@@ -4246,7 +4256,7 @@ spec:
42464256
type: object
42474257
x-kubernetes-map-type: atomic
42484258
required:
4249-
- ca
4259+
- ca
42504260
type: object
42514261
type: object
42524262
mongodbResourceRef:

0 commit comments

Comments
 (0)