[Konflux] improve backend performance with targeted catalog lookups and response caching#2630
Conversation
…okup getRelatedEntities was calling catalog.getEntities() with no filter, fetching the entire catalog on every request. Now uses the parent entity's hasPart relations with catalog.getEntitiesByRefs() to fetch only the needed subcomponents.
…elds - Cache CustomObjectsApi instances per cluster instead of creating new KubeConfig + client on every request. Auth headers are injected per-request via middleware, so cached clients are safe to share. - Add a 30s TTL cache for catalog entity/config/combination lookups to avoid duplicate calls across parallel resource requests. - Strip metadata.managedFields from K8s and Kubearchive responses to reduce payload size (~50% reduction).
Increase react-query staleTime from 30s to 5min and disable refetchOnWindowFocus to reduce unnecessary re-fetches when switching browser tabs.
Add changesets with the changes made for both konflux and konflux-backend plugins.
Changed Packages
|
Review Summary by QodoImprove Konflux backend performance with targeted catalog lookups and response caching
WalkthroughsDescription• Replace unfiltered catalog scan with targeted entity lookup using hasPart relations • Cache K8s API clients per cluster to avoid recreating connections • Add 30s TTL cache for catalog lookups to prevent duplicate parallel requests • Strip metadata.managedFields from K8s responses to reduce payload size • Increase react-query staleTime to 5min and disable refetchOnWindowFocus Diagramflowchart LR
A["Catalog Scan"] -->|Before: getEntities| B["Full Catalog"]
B -->|Filter in-memory| C["Related Entities"]
D["Catalog Scan"] -->|After: hasPart relations| E["Entity Refs"]
E -->|getEntitiesByRefs| F["Targeted Entities"]
G["API Client"] -->|Before: New per request| H["KubeConfig + TLS"]
I["API Client"] -->|After: Cached per cluster| J["Reused Connection"]
K["Response"] -->|Before: Full metadata| L["Large Payload"]
M["Response"] -->|After: Strip managedFields| N["Reduced Payload"]
File Changes1. workspaces/konflux/plugins/konflux-backend/src/helpers/config.ts
|
Code Review by Qodo
1.
|
workspaces/konflux/plugins/konflux-backend/src/services/konflux-service.ts
Show resolved
Hide resolved
|



Fixes
Fixes https://redhat.atlassian.net/browse/KFLUXUI-1159
Summary
The Konflux plugin backend was experiencing slow API responses (~14-17s) in the RHDH stage instance (https://inscope.corp.stage.redhat.com/). The issue is not reproducible locally, my assumption is that it seems it only happens in environments with large catalogs (thousands of entities).
Root cause (likely):
getRelatedEntitieswas callingcatalog.getEntities()with no filter, fetching the entire catalog on every resource request. This was called multiple times per page load, which could be blocking the node.js event loop.main changes
Backend:
hasPartrelations andcatalog.getEntitiesByRefs()CustomObjectsApiclients per cluster to avoid recreating KubeConfig and TLS connections on every requestmetadata.managedFieldsfrom K8s and Kubearchive responses to reduce payload sizeFrontend:
staleTimefrom 30s to 5minrefetchOnWindowFocusto reduce unnecessary re-fetchesThese changes should improve performance, but since the issue is environment-specific, further investigation may be needed if the problem persists in the stage instance ☕
Visual references
This is just to show that the plugin continues working with the new changes.
konflux-plugin-after-changes-all-good.mov
Plan
My idea is to try to simulate this into their ephemeral environment once we have a new OCI image published for testing 🙏
✔️ Checklist