Skip to content

MongoHealthIndicator not compliant with Mongo stable API with strict setting #41101

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

Closed
jorgelc opened this issue Jun 14, 2024 · 21 comments
Closed
Assignees
Labels
type: bug A general bug
Milestone

Comments

@jorgelc
Copy link

jorgelc commented Jun 14, 2024

MongoHealthIndicator uses isMaster command, which is not part of Mongo's stable API https://www.mongodb.com/docs/v5.0/reference/stable-api-changelog/

If the underlying Mongo connection is configured to use the stable API and strict setting, the health indicator yields an error, as Mongo rejects the isMaster command.

Affected versions: Tested with sprinboot 3.3.0, potentially since 3.0.0

To reproduce it, create a blank springboot project including spring-boot-starter-data-mongodb, spring-boot-starter-web and spring-boot-starter-actuator dependencies. Then, set up both Mongo stable API version and strict to true by creating the following bean:

	@Bean
	public MongoClientSettings mongoClientSettings() {
		return MongoClientSettings.builder()
			.applicationName("testApp")
			.serverApi(ServerApi.builder()
				.strict(true)
				.version(ServerApiVersion.V1)
				.build())
			.build();
	}

For reference, such project has been created here https://github.com/jorgelc/mongo-stable-api-springboot-health, with steps about how to reproduced the error and compare the behaviour with when strict is set to false.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 14, 2024
@wilkinsona wilkinsona added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Jun 14, 2024
@wilkinsona wilkinsona added this to the 3.2.x milestone Jun 14, 2024
@wilkinsona
Copy link
Member

Thank you. I've reproduced the problem.

I think we should switch to the hello command. It's supported in MongoDB 5.0 and later and Mongo 4.x reached end of life in February 2024.

@jorgelc
Copy link
Author

jorgelc commented Jun 14, 2024

Thanks @wilkinsona

We implemented that as a temporary workaround locally and it worked for us, but it would be nice to have that supported out of the box.

@jyemin
Copy link

jyemin commented Jun 14, 2024

Just FYI, the hello command was backported all the way to MongoDB 3.6, so this should be a safe change even for EOL'd MongoDB releases.

@pkunk
Copy link

pkunk commented Jun 20, 2024

FYI: This is not compatible with Azure Cosmos MongoDB API:
https://learn.microsoft.com/en-us/azure/cosmos-db/mongodb/feature-support-60#database-commands

@wilkinsona
Copy link
Member

wilkinsona commented Jun 20, 2024

Thanks, @pkunk, but I'm not sure there's much we can do about that. I don't see any mention of isMaster in the list of supported database commands either so it's not clear that this would have worked before. I'd recommend raising this with Microsoft to see if they can improve Cosmos' compliance with the MongoDB API.

In the meantime, anyone who's affected can work around the non-compliance by defining their own bean named mongoHealthIndicator or mongoHealthContributor.

@SimonedeGijt
Copy link

We have the same @pkunk . Did you already raise this with Microsoft? Would be great if I can follow the progress on this item :)

@pkunk
Copy link

pkunk commented Sep 9, 2024

We have the same @pkunk . Did you already raise this with Microsoft?

No. We just use custom mongoHealthIndicator bean.

@SimonedeGijt
Copy link

I created a post now, would be great if many people can vote on it 😄 : https://feedback.azure.com/d365community/idea/c7b19748-9276-ef11-a4e6-000d3a059eeb

@gahl-levy
Copy link

Hey @pkunk @SimonedeGijt @wilkinsona . I'm Gahl from the Cosmos DB Product Team. The hello command is already supported in Cosmos DB for MongoDB vCore and Cosmos DB for MongoDB RU. We're adding it to our docs now. Sorry for the confusion here and thanks for pointing this out!

@wilkinsona
Copy link
Member

Good news! Thanks very much, @gahl-levy.

@ashishrky
Copy link

ashishrky commented Oct 21, 2024

@gahl-levy is there any setting to enable hello command for Cosmos DB for MongoDB RU? I am running Spring Boot v3.3.4 application, and its actuator health endpoint is still failing with the error...

        "mongo": {
            "status": "DOWN",
            "details": {
                "error": "org.springframework.dao.InvalidDataAccessApiUsageException: Command failed with error 115 (CommandNotSupported): 'Command hello not supported.' on server xxxxxxx-centralus.mongo.cosmos.azure.com:10255. The full response is {\"ok\": 0.0, \"errmsg\": \"Command hello not supported.\", \"code\": 115, \"codeName\": \"CommandNotSupported\"}"
            }
        },

My spring boot app is running in App Service, and everything is located in Central US data center.

@miguelrq
Copy link

miguelrq commented Nov 1, 2024

@gahl-levy looks like the way actuator does health checks is with
mongoTemplate.executeCommand"{ hello: 1 }"
which cosmosdb doesn't support

Against a mongo shell
db.runCommand({isMaster:1}) //works
db.runCommand({hello:1}) //doesn't work

@arm749
Copy link

arm749 commented Nov 25, 2024

@wilkinsona @gahl-levy This issue should not be closed. The actuator health check still fails on a startup of Springboot 3.4.0 while using Azure Cosmos DB Mongo. This is breaking behavior for all Mongo CosmosDB users.

@wilkinsona
Copy link
Member

@arm749 Unfortunately, re-opening this issue won't achieve anything as there's no change that can be made in Spring Boot to improve the situation.

We do not want to switch back to { isMaster: 1 } as our health indicator when then be incompatible with Mongo's stable API, undoing the goal of this issue. We also can't affect CosmosDB's support for the stable API.

A workaround has already been suggested above:

In the meantime, anyone who's affected can work around the non-compliance by defining their own bean named mongoHealthIndicator or mongoHealthContributor.

I think this is the best that we can do on the Spring Boot side until Microsoft have a chance to clarify their support for Mongo's stable API.

@arm749
Copy link

arm749 commented Nov 25, 2024

@wilkinsona Thanks. Is Microsoft aware of this? By the looks of above, it doesn't seem like they have any action items on this.

@wilkinsona
Copy link
Member

They should be given the existence of https://feedback.azure.com/d365community/idea/c7b19748-9276-ef11-a4e6-000d3a059eeb and @gahl-levy's involvement in this issue.

@kubav182
Copy link

kubav182 commented Dec 9, 2024

@gahl-levy is there any chance cosmos db will support db.runCommand({hello:1}) soon?

@dafnenavita
Copy link

Hi @gahl-levy @thekid - is there a fix expected soon for this ? I see some developments but I’m still facing the same issue for any springboot version 3.2.7 and above

@gahl-levy
Copy link

So sorry folks, these reply notifications were getting filtered. I'm following up on this now and will have an update soon.

@gahl-levy
Copy link

Hey Folks- Unfortunately, only db.hello was working in Azure Cosmos DB for MongoDB RU, but that was not enough for the health check. Confirmed that the fix to fully support "hello" is being deployed to production in Azure Cosmos DB for MongoDB RU. We are expecting it'll be out there for everyone in roughly two months or sooner. Thanks again for your patience.

Just FYI: "hello" is already fully supported in Azure Cosmos DB for MongoDB vCore in case you need something sooner. Thanks!

@SimonedeGijt
Copy link

Thank you so much @gahl-levy !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests