Repository navigation
Fix the integration tests failing on every main run (MCP outage hang, SAML adopt 500, cache markers, stale expectations) #38013
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
Changes from all commits
352f655
9e9588a
e069f46
81e5d9b
9da7afc
4c2794e
9bb844b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,18 @@ | ||
| package org.openmetadata.mcp; | ||
|
|
||
| import com.google.common.cache.CacheBuilder; | ||
| import com.google.common.cache.CacheLoader; | ||
| import com.google.common.cache.LoadingCache; | ||
| import jakarta.servlet.Filter; | ||
| import jakarta.servlet.FilterChain; | ||
| import jakarta.servlet.ServletException; | ||
| import jakarta.servlet.ServletRequest; | ||
| import jakarta.servlet.ServletResponse; | ||
| import jakarta.servlet.http.HttpServletResponse; | ||
| import java.io.IOException; | ||
| import java.util.concurrent.Executors; | ||
| import java.util.concurrent.ScheduledExecutorService; | ||
| import java.util.concurrent.TimeUnit; | ||
| import org.openmetadata.schema.api.configuration.MCPConfiguration; | ||
| import org.openmetadata.schema.entity.app.App; | ||
| import org.openmetadata.schema.type.Include; | ||
|
|
@@ -21,6 +27,23 @@ | |
| */ | ||
| public class McpAvailabilityFilter implements Filter { | ||
|
|
||
| private static final long APP_STATE_REFRESH_SECONDS = 2; | ||
| private static final ScheduledExecutorService APP_STATE_REFRESHER = | ||
| Executors.newSingleThreadScheduledExecutor( | ||
| Thread.ofPlatform().daemon().name("mcp-availability").factory()); | ||
|
|
||
| /** | ||
| * The app's state is served from memory and re-read in the background, so a request never waits | ||
| * on the database: during an outage MCP keeps the last state it read, and its auth answers 503 | ||
| * instead of the request hanging on this read. A failed re-read keeps the previous state. | ||
| */ | ||
| private static final LoadingCache<String, Boolean> APP_ACTIVE = | ||
| CacheBuilder.newBuilder() | ||
| .maximumSize(1) | ||
| .build( | ||
| CacheLoader.asyncReloading( | ||
| CacheLoader.from(McpAvailabilityFilter::readAppActive), APP_STATE_REFRESHER)); | ||
|
|
||
| @Override | ||
| public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) | ||
| throws IOException, ServletException { | ||
|
|
@@ -50,14 +73,25 @@ private static boolean isEnabledInSettings() { | |
| return config == null || Boolean.TRUE.equals(config.getEnabled()); | ||
| } | ||
|
|
||
| /** Starts re-reading the app's state in the background, beginning while the database is up. */ | ||
| public static void startAppStateRefresh() { | ||
| APP_STATE_REFRESHER.scheduleWithFixedDelay( | ||
| () -> APP_ACTIVE.refresh(McpAppConstants.MCP_APP_NAME), | ||
| 0, | ||
| APP_STATE_REFRESH_SECONDS, | ||
| TimeUnit.SECONDS); | ||
|
Comment on lines
+77
to
+82
Contributor
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.
|
||
| } | ||
|
|
||
| private static boolean isAppActive() { | ||
| return APP_ACTIVE.getUnchecked(McpAppConstants.MCP_APP_NAME); | ||
| } | ||
|
|
||
| /** | ||
| * Through the entity cache. Disabling the app soft-deletes it; uninstalling removes it until a | ||
| * restart re-seeds it. | ||
| */ | ||
| private static boolean isAppActive() { | ||
| App app = | ||
| Entity.findEntityByNameOrNull( | ||
| Entity.APPLICATION, McpAppConstants.MCP_APP_NAME, Include.ALL); | ||
| private static boolean readAppActive(String appName) { | ||
| App app = Entity.findEntityByNameOrNull(Entity.APPLICATION, appName, Include.ALL); | ||
| return app != null && !Boolean.TRUE.equals(app.getDeleted()); | ||
| } | ||
| } | ||
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.
awaitCompletion()returnsfalseon timeout or interruption, but this call ignores the result. The test can pass while the released exchange is still running, leaving the late ID token free to affect the next test—the race this change aims to remove. Assert that the wait succeeds so a failed cleanup is reported here.