Skip to content

Commit 6e273f4

Browse files
authored
CLOUDP-321067: update health check (#268)
# Summary This pull request introduces health check functionality for the `mongot` service, updates readiness and liveness probes, and removes a test decorator for local testing. The changes enhance the monitoring and reliability of the `mongot` service and simplify the test suite. ### Enhancements to `mongot` service health checks: * Added a new constant `MongotDefautHealthCheckPort` set to port `8080` in `mongodbsearch_types.go`. A helper method `GetMongotHealthCheckPort` was also introduced to retrieve this value. * Updated the `buildSearchHeadlessService` function to include a new service port for health checks, using the `GetMongotHealthCheckPort` method. * Modified the `createMongotConfig` function to dynamically set the health check address using the new health check port. ### Readiness and liveness probe improvements: * Introduced constants for probe paths (`SearchLivenessProbePath` and `SearchReadinessProbePath`) in `search_construction.go`. * Replaced the existing readiness probe configuration with new methods `mongotLivenessProbe` and `mongotReadinessProbe`. These methods configure HTTP-based probes using the health check port and paths. ### Test suite simplifications: * Removed the `@skip_if_local` decorator from several `test_om_connectivity` test cases in `om_appdb_scale_up_down.py`, enabling them to run in all environments.
1 parent 060ad1f commit 6e273f4

File tree

4 files changed

+55
-7
lines changed

4 files changed

+55
-7
lines changed

api/v1/search/mongodbsearch_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
const (
1919
MongotDefaultPort = 27027
2020
MongotDefaultMetricsPort = 9946
21+
MongotDefautHealthCheckPort = 8080
2122
MongotDefaultSyncSourceUsername = "mongot-user"
2223
)
2324

@@ -189,3 +190,7 @@ func (s *MongoDBSearch) TLSSecretNamespacedName() types.NamespacedName {
189190
func (s *MongoDBSearch) TLSOperatorSecretNamespacedName() types.NamespacedName {
190191
return types.NamespacedName{Name: s.Name + "-search-certificate-key", Namespace: s.Namespace}
191192
}
193+
194+
func (s *MongoDBSearch) GetMongotHealthCheckPort() int32 {
195+
return MongotDefautHealthCheckPort
196+
}

controllers/search_controller/mongodbsearch_reconcile_helper.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,13 @@ func buildSearchHeadlessService(search *searchv1.MongoDBSearch) corev1.Service {
313313
TargetPort: intstr.FromInt32(search.GetMongotMetricsPort()),
314314
})
315315

316+
serviceBuilder.AddPort(&corev1.ServicePort{
317+
Name: "healthcheck",
318+
Protocol: corev1.ProtocolTCP,
319+
Port: search.GetMongotHealthCheckPort(),
320+
TargetPort: intstr.FromInt32(search.GetMongotHealthCheckPort()),
321+
})
322+
316323
return serviceBuilder.Build()
317324
}
318325

@@ -350,7 +357,7 @@ func createMongotConfig(search *searchv1.MongoDBSearch, db SearchSourceDBResourc
350357
Address: fmt.Sprintf("localhost:%d", search.GetMongotMetricsPort()),
351358
}
352359
config.HealthCheck = mongot.ConfigHealthCheck{
353-
Address: "0.0.0.0:8080",
360+
Address: fmt.Sprintf("localhost:%d", search.GetMongotHealthCheckPort()),
354361
}
355362
config.Logging = mongot.ConfigLogging{
356363
Verbosity: "TRACE",

controllers/search_controller/search_construction.go

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ import (
1919
)
2020

2121
const (
22-
MongotContainerName = "mongot"
22+
MongotContainerName = "mongot"
23+
SearchLivenessProbePath = "/health"
24+
SearchReadinessProbePath = "/health" // Todo: Update this when search GA is available
2325
)
2426

2527
// SearchSourceDBResource is an object wrapping a MongoDBCommunity object
@@ -183,11 +185,8 @@ func mongodbSearchContainer(mdbSearch *searchv1.MongoDBSearch, volumeMounts []co
183185
container.WithName(MongotContainerName),
184186
container.WithImage(searchImage),
185187
container.WithImagePullPolicy(corev1.PullAlways),
186-
container.WithReadinessProbe(probes.Apply(
187-
probes.WithTCPSocket("", intstr.FromInt32(mdbSearch.GetMongotPort())),
188-
probes.WithInitialDelaySeconds(20),
189-
probes.WithPeriodSeconds(10),
190-
)),
188+
container.WithLivenessProbe(mongotLivenessProbe(mdbSearch)),
189+
container.WithReadinessProbe(mongotReadinessProbe(mdbSearch)),
191190
container.WithResourceRequirements(createSearchResourceRequirements(mdbSearch.Spec.ResourceRequirements)),
192191
container.WithVolumeMounts(volumeMounts),
193192
container.WithCommand([]string{"sh"}),
@@ -209,6 +208,42 @@ chmod 0600 /tmp/sourceUserPassword
209208
)
210209
}
211210

211+
func mongotLivenessProbe(search *searchv1.MongoDBSearch) func(*corev1.Probe) {
212+
return probes.Apply(
213+
probes.WithHandler(corev1.ProbeHandler{
214+
HTTPGet: &corev1.HTTPGetAction{
215+
Scheme: corev1.URISchemeHTTP,
216+
Port: intstr.FromInt32(search.GetMongotHealthCheckPort()),
217+
Path: SearchLivenessProbePath,
218+
},
219+
}),
220+
probes.WithInitialDelaySeconds(10),
221+
probes.WithPeriodSeconds(10),
222+
probes.WithTimeoutSeconds(5),
223+
probes.WithSuccessThreshold(1),
224+
probes.WithFailureThreshold(10),
225+
)
226+
}
227+
228+
// mongotReadinessProbe just uses the endpoint intended for liveness checks;
229+
// readiness check endpoint may be available in search GA.
230+
func mongotReadinessProbe(search *searchv1.MongoDBSearch) func(*corev1.Probe) {
231+
return probes.Apply(
232+
probes.WithHandler(corev1.ProbeHandler{
233+
HTTPGet: &corev1.HTTPGetAction{
234+
Scheme: corev1.URISchemeHTTP,
235+
Port: intstr.FromInt32(search.GetMongotHealthCheckPort()),
236+
Path: SearchReadinessProbePath,
237+
},
238+
}),
239+
probes.WithInitialDelaySeconds(20),
240+
probes.WithPeriodSeconds(10),
241+
probes.WithTimeoutSeconds(5),
242+
probes.WithSuccessThreshold(1),
243+
probes.WithFailureThreshold(3),
244+
)
245+
}
246+
212247
func createSearchResourceRequirements(requirements *corev1.ResourceRequirements) corev1.ResourceRequirements {
213248
if requirements != nil {
214249
return *requirements

docker/mongodb-kubernetes-tests/tests/opsmanager/withMonitoredAppDB/om_appdb_scale_up_down.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from pytest import fixture
99
from tests.conftest import is_multi_cluster
1010

11+
1112
# Important - you need to ensure that OM and Appdb images are build and pushed into your current docker registry before
1213
# running tests locally - use "make om-image" and "make appdb" to do this
1314

0 commit comments

Comments
 (0)