Add authenticated database readiness check for Astra and Cassandra - #2527
Add authenticated database readiness check for Astra and Cassandra#2527erichare wants to merge 5 commits into
Conversation
Unit Test Coverage Report
|
Integration Test Coverage Report (dse69-it)
|
Integration Test Coverage Report (hcd-it)
|
amorton
left a comment
There was a problem hiding this comment.
-1 this only works in non-astra, uses blocking IO, and reads from a non replicated table so why the C* node will need to be marked as UP to respond it will not verify that its able to communicate with enough nodes to achieve quourm
need to rethink what we are trying to do here
| import org.slf4j.LoggerFactory; | ||
|
|
||
| /** | ||
| * Health check that verifies Cassandra connectivity for the Data API readiness probe. |
There was a problem hiding this comment.
-1 comments should explain how this is registered, what url it is under etc.
the AI generated comments dont help
There was a problem hiding this comment.
Cleaned it up and talked about how its registered
| * types. In those deployments it reports UP without accessing the Cassandra session cache. | ||
| */ | ||
| @Readiness | ||
| @ApplicationScoped |
There was a problem hiding this comment.
we are trying to remove CDI injection, is there a way to do this without it ?
There was a problem hiding this comment.
I did some reading, correct me if i'm wrong about any of this... but Quarkus’s standard application health-check mechanism is CDI-based. There is an alternative tho, SmallRye’s programmatic HealthRegistry. https://quarkus.io/guides/smallrye-health https://smallrye.io/docs/smallrye-health/3.0.0/health-registry.html. giving it a try
|
|
||
| @VisibleForTesting | ||
| CassandraConnectionHealthCheck( | ||
| CQLSessionCache sessionCache, OperationsConfig operationsConfig, Duration timeout) { |
There was a problem hiding this comment.
prefer to abstract out the OperationsConfig properties if we can, again trying to remove the CDI things
There was a problem hiding this comment.
yep, good call. updated
| public HealthCheckResponse call() { | ||
| var responseBuilder = HealthCheckResponse.named(HEALTH_CHECK_NAME); | ||
|
|
||
| if (operationsConfig.databaseConfig().type() != DatabaseType.CASSANDRA) { |
There was a problem hiding this comment.
this means it will not run for astra, is this correct ? Confusing that we are adding this but not using it
There was a problem hiding this comment.
this was my mistake, i was misunderstanding the intent of the original issue. This now does get more complicated a bit though.... ahh, i see you already responded in the original GH issue as to why it gets more complicated.
I have a plan and ill update and explain it...
| sessionCache | ||
| .getSession(healthCheckTenant, authToken, HEALTH_CHECK_USER_AGENT) | ||
| .await() | ||
| .atMost(timeout); |
There was a problem hiding this comment.
await() is blocking for the caller thread, we generally want to avoid making blocking calls. This should be using the UNI framework.
| .setConsistencyLevel(operationsConfig.queriesConfig().consistency().reads()) | ||
| .build(); | ||
|
|
||
| var resultSet = session.execute(statement); |
There was a problem hiding this comment.
-1 for blocking IO call, we need to use async calls in the Uni framework
|
|
||
| private static String createAuthToken(OperationsConfig.DatabaseConfig databaseConfig) { | ||
| return databaseConfig | ||
| .fixedToken() |
There was a problem hiding this comment.
-1 - the code comments for fixedToken explain what this is for it's not something we want to include in actual prod code its for testing
| return false; | ||
| } | ||
|
|
||
| private void evictSession(Tenant tenant) { |
There was a problem hiding this comment.
-1 , the sessionCache evicts sessions when they TTL. It is also designed to evist sessions faster when they use the SLA checker user agent. Because this is not using the sla user agent they will be treated like regular user sessions and last for 10mins (by default I think).
Better to use the SLA checker user agent and not do this
There was a problem hiding this comment.
Explained the new approach as a separate comment
| /** | ||
| * Username when connecting to cassandra database (when type is {@link DatabaseType#CASSANDRA}) | ||
| * and fixedToken is used | ||
| * Username used for Cassandra connections when fixedToken is configured, and by the Cassandra |
There was a problem hiding this comment.
-1 - do not want to overload this
|
|
||
| private static final Logger LOGGER = | ||
| LoggerFactory.getLogger(SessionEvictionIntegrationTest.class); | ||
| private static final String READINESS_PATH = "/stargate/health/ready"; |
There was a problem hiding this comment.
-1 for anything using stargate in a path name
|
this needs a rethink about what we are trying to do |
understood! i'll address the specific comments you made just for the practice, but yeah understood about rethinking the purpose |
|
Okay, @amorton , so here's what i did... First of all, renamed the endpoint to The endpoint executes Switched everything to async, response would look like I'll push shortly |
What this PR does:
Adds an authenticated, database-backed readiness endpoint shared by Astra and Cassandra deployments.
GET /v1/health/readythrough Quarkus JAX-RS discovery; the existing/v1/*security policy requires authentication.CQLSessionCache. No separate readiness credentials are stored in application configuration.SELECT * FROM datastax_sla.check LIMIT 1asynchronously at explicitLOCAL_QUORUM, using thetable-readprofile for the remaining read settings.await()or synchronous driver calls.{"status":"UP"}after a successful read, HTTP 401 for missing or invalid authentication, and HTTP 503 with{"status":"DOWN"}for database failures or timeouts.datastax_sla.checkand verifyUP→DOWN→UPbehavior using the authenticated endpoint.datastax_sla.checktable, the Astra database hostname inHost, the exact configured SLA User-Agent, and a trusted per-pod caller.Which issue(s) this PR fixes:
Fixes #2526
Validation:
./mvnw -Dtest=DatabaseReadinessCheckTest,TenantRequestMetricsFilterTest test— 6 tests passed../mvnw -q -Dtest=DatabaseReadinessResourceTest test— 5 tests passed.SessionEvictionIntegrationTestwas updated and compiled, but its Docker-backed run could not start locally because this host had no Docker socket. CI must validate the container outage/recovery path.Checklist