-
Notifications
You must be signed in to change notification settings - Fork 23
CLOUDP-321076: expose prometheus metrics settings in MongoDBSearch #578
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
base: master
Are you sure you want to change the base?
Changes from all commits
069997e
f17e896
ff1dfa2
d41c71e
6ab6bd6
6fc1067
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| --- | ||
| kind: feature | ||
| date: 2025-10-30 | ||
| --- | ||
|
|
||
| * **MongoDBSearch**: | ||
| * Switched to gRPC and mTLS for internal communication between mongod and mongot. | ||
| * Since MCK 1.4 the `mongod` and `mongot` processess communicated using the MongoDB Wire Protocol and used keyfile authentication. This release switches that to gRPC with mTLS authentication. gRPC will allow for load-balancing search queries against multiple `mongot` processes in the future, and mTLS decouples the internal cluster authentication mode and credentials among `mongod` processes from the connection to the `mongot` process. The Operator will automatically enable gRPC for existing and new workloads, and will enable mTLS authentication if both Database Server and `MongoDBSearch` resource are configured for TLS. | ||
| * Exposed configuration settings for mongot's prometheus metrics endpoint. | ||
| * By default, if `spec.prometheus` field is not provided then metrics endpoint in mongot is disabled. **This is a breaking change**. Previously the metrics endpoing was always enabled on port 9946. | ||
| * To enable prometheus metrics endpoint specify empty `spec.prometheus:` field. It will enable metrics endpoint on a default port (9946). To change the port, set it in `spec.prometheus.port` field. | ||
| * Simplified MongoDB Search setup: Removed the custom Search Coordinator polyfill (a piece of compatibility code previously needed to add the required permissions), as MongoDB 8.2.0 and later now include the necessary permissions via the built-in searchCoordinator role. | ||
| * Updated the default `mongodb/mongodb-search` image version to 0.55.0. This is the version MCK uses if `.spec.version` is not specified. | ||
| * MongoDB deployments using X509 internal cluster authentication are now supported. Previously MongoDB Search required SCRAM authentication among members of a MongoDB replica set. Note: SCRAM client authentication is still required, this change merely relaxes the requirements on internal cluster authentication. |
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,10 +3,10 @@ package operator | |
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "errors" | ||
| "fmt" | ||
| "os" | ||
| "path/filepath" | ||
| "strings" | ||
| "testing" | ||
| "time" | ||
|
|
||
|
|
@@ -54,15 +54,14 @@ func init() { | |
|
|
||
| // getReleaseJsonPath searches for a specified target directory by traversing the directory tree backwards from the current working directory | ||
| func getReleaseJsonPath() (string, error) { | ||
| repositoryRootDirName := "mongodb-kubernetes" | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this failed tests when running from a different dir, e.g. a git worktree |
||
| releaseFileName := "release.json" | ||
|
|
||
| currentDir, err := os.Getwd() | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
| for currentDir != "/" { | ||
| if strings.HasSuffix(currentDir, repositoryRootDirName) { | ||
| if _, err := os.Stat(filepath.Join(currentDir, releaseFileName)); !errors.Is(err, os.ErrNotExist) { | ||
| return filepath.Join(currentDir, releaseFileName), nil | ||
| } | ||
| currentDir = filepath.Dir(currentDir) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ import ( | |
|
|
||
| "github.com/ghodss/yaml" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| "k8s.io/apimachinery/pkg/types" | ||
| "k8s.io/utils/ptr" | ||
| "sigs.k8s.io/controller-runtime/pkg/client" | ||
|
|
@@ -22,12 +23,12 @@ import ( | |
| "github.com/mongodb/mongodb-kubernetes/api/v1/status" | ||
| userv1 "github.com/mongodb/mongodb-kubernetes/api/v1/user" | ||
| "github.com/mongodb/mongodb-kubernetes/controllers/operator/mock" | ||
| "github.com/mongodb/mongodb-kubernetes/controllers/operator/workflow" | ||
| "github.com/mongodb/mongodb-kubernetes/controllers/searchcontroller" | ||
| mdbcv1 "github.com/mongodb/mongodb-kubernetes/mongodb-community-operator/api/v1" | ||
| "github.com/mongodb/mongodb-kubernetes/mongodb-community-operator/api/v1/common" | ||
| "github.com/mongodb/mongodb-kubernetes/mongodb-community-operator/pkg/mongot" | ||
| "github.com/mongodb/mongodb-kubernetes/mongodb-community-operator/pkg/util/constants" | ||
| "github.com/mongodb/mongodb-kubernetes/pkg/util" | ||
| ) | ||
|
|
||
| func newMongoDBCommunity(name, namespace string) *mdbcv1.MongoDBCommunity { | ||
|
|
@@ -135,10 +136,6 @@ func buildExpectedMongotConfig(search *searchv1.MongoDBSearch, mdbc *mdbcv1.Mong | |
| }, | ||
| Wireproto: wireprotoServer, | ||
| }, | ||
| Metrics: mongot.ConfigMetrics{ | ||
| Enabled: true, | ||
| Address: fmt.Sprintf("0.0.0.0:%d", search.GetMongotMetricsPort()), | ||
| }, | ||
| HealthCheck: mongot.ConfigHealthCheck{ | ||
| Address: fmt.Sprintf("0.0.0.0:%d", search.GetMongotHealthCheckPort()), | ||
| }, | ||
|
|
@@ -205,22 +202,16 @@ func TestMongoDBSearchReconcile_Success(t *testing.T) { | |
| mdbc := newMongoDBCommunity("mdb", mock.TestNamespace) | ||
| reconciler, c := newSearchReconciler(mdbc, search) | ||
|
|
||
| res, err := reconciler.Reconcile( | ||
| ctx, | ||
| reconcile.Request{NamespacedName: types.NamespacedName{Name: search.Name, Namespace: search.Namespace}}, | ||
| ) | ||
| expected, _ := workflow.OK().ReconcileResult() | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks to the fix here it started to fail. In order to reconcile successfully it must be always done by two steps: first reconcile is Pending (sts not ready), second time we simulate sts readiness and then it's Running. This is what checkSearchReconcileSuccessful is doing here. |
||
| assert.NoError(t, err) | ||
| assert.Equal(t, expected, res) | ||
| checkSearchReconcileSuccessful(ctx, t, reconciler, c, search) | ||
|
|
||
| svc := &corev1.Service{} | ||
| err = c.Get(ctx, search.SearchServiceNamespacedName(), svc) | ||
| err := c.Get(ctx, search.SearchServiceNamespacedName(), svc) | ||
| assert.NoError(t, err) | ||
| servicePortNames := []string{} | ||
| for _, port := range svc.Spec.Ports { | ||
| servicePortNames = append(servicePortNames, port.Name) | ||
| } | ||
| expectedPortNames := []string{"mongot-grpc", "metrics", "healthcheck"} | ||
| expectedPortNames := []string{"mongot-grpc", "healthcheck"} | ||
| if tc.withWireproto { | ||
| expectedPortNames = append(expectedPortNames, "mongot-wireproto") | ||
| } | ||
|
|
@@ -254,14 +245,42 @@ func checkSearchReconcileFailed( | |
| reconcile.Request{NamespacedName: types.NamespacedName{Name: search.Name, Namespace: search.Namespace}}, | ||
| ) | ||
| assert.NoError(t, err) | ||
| assert.True(t, res.RequeueAfter > 0) | ||
| assert.Less(t, res.RequeueAfter, util.TWENTY_FOUR_HOURS) | ||
|
|
||
| updated := &searchv1.MongoDBSearch{} | ||
| assert.NoError(t, c.Get(ctx, types.NamespacedName{Name: search.Name, Namespace: search.Namespace}, updated)) | ||
| assert.Equal(t, status.PhaseFailed, updated.Status.Phase) | ||
| assert.Contains(t, updated.Status.Message, expectedMsg) | ||
| } | ||
|
|
||
| // checkSearchReconcileSuccessful performs reconcile to check if it gets to a Running state. | ||
| // In case it's a first reconcile and still Pending it's retried with mocked sts simulated as ready. | ||
| func checkSearchReconcileSuccessful( | ||
| ctx context.Context, | ||
| t *testing.T, | ||
| reconciler *MongoDBSearchReconciler, | ||
| c client.Client, | ||
| search *searchv1.MongoDBSearch, | ||
| ) { | ||
| namespacedName := types.NamespacedName{Name: search.Name, Namespace: search.Namespace} | ||
| res, err := reconciler.Reconcile(ctx, reconcile.Request{NamespacedName: namespacedName}) | ||
| require.NoError(t, err) | ||
| mdbs := &searchv1.MongoDBSearch{} | ||
| require.NoError(t, c.Get(ctx, namespacedName, mdbs)) | ||
| if mdbs.Status.Phase == status.PhasePending { | ||
| // mark mocked search statefulset as ready to not return Pending this time | ||
| require.NoError(t, mock.MarkAllStatefulSetsAsReady(ctx, search.Namespace, c)) | ||
|
|
||
| res, err = reconciler.Reconcile(ctx, reconcile.Request{NamespacedName: namespacedName}) | ||
| require.NoError(t, err) | ||
| mdbs = &searchv1.MongoDBSearch{} | ||
| require.NoError(t, c.Get(ctx, namespacedName, mdbs)) | ||
| } | ||
|
|
||
| require.Equal(t, util.TWENTY_FOUR_HOURS, res.RequeueAfter) | ||
| require.Equal(t, status.PhaseRunning, mdbs.Status.Phase) | ||
| } | ||
|
|
||
| func TestMongoDBSearchReconcile_InvalidVersion(t *testing.T) { | ||
| ctx := context.Background() | ||
| search := newMongoDBSearch("search", mock.TestNamespace, "mdb") | ||
|
|
||
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.
@vinilage I've aggregated all the search-related change logs for this release under one point as those were scattered randomly across release notes. We might think about adding some additional grouping per CRD for example to make it automatic.
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.
The new entry for this PR is the one starting from "Exposed configuration settings..."