Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(kubernetes): Only create applications for some kinds (#3829)
* perf(kubernetes): Use a more efficient data structure for cache data The current logic to build the Kubernetes cache data first creates a list of CacheData objects representing each of the objects to be cached (including its attributes and relationships). At the end of the caching process, we want only a single CacheData object for each cache key and also all relationships to be bidirectional. Bidirectionality is currently enforced by calling a function invertRelationships to look up all relationships and create entries representing their inverses. Uniqueness is enforced by calling dedupCacheData to detect duplicate entries and merge their attributes and relationships. Both invertRelationships and dedupCacheData are fairly expensive as they involve traversing the entire list of relationships (which are stored on CacheData as a generic Collection) and building new objects based on these. These functions also need parse keys as they encounter them, leading to each key being parsed multiple times. It would be more efficient to store the entries and relationships in a data structure that guarantees uniqueness and bidrectionality of relationships (and can do so efficiently). Create a class KubernetesCacheData that stores cache items as we are processing them and that supports adding items or (bidirectional) relationships between items. Update the caching logic to add items to this structure instead of creating individual CacheData entries, and then ask the structure to give us a full list of CacheData entries at the end. * refactor(kubernetes): Remove duplicated code in cache conversion For each manifest we encounter, we call both convertAsResource to create an infrastructure cache key as well as convertAsArtifact to create a logical cache key. There is fair amount of duplication between the two methods. Make the following changes: (1) Move convertAsArtifact to be a called from convertAsResource and remove the duplicated code (2) Remove the code to add artifact relationships from annotatedRelationships and instead add the necessary relationship right after calling convertAsArtifact (if that call produced an artifact). This avoids needing to generate the artifact twice (once for the actual cache entry and once for the relationship) and also keeps the artifact code in one place. * perf(kubernetes): Only create applications for some kinds After generating all of the cache data keys, we currently call getClusterRelationships to populate application-cluster relationships. This call ends up creating an application for every kubernetes manifest instead of only those that have a cluster relationship. Instead of calling getClusterRelationships after generating the CacheData entries, update the code that creates the manifest-cluster and manifest-application relationships to also create an application-cluster relationship. In addition to increasing performance of caching itself, this change should also greatly improve the performance of some cache lookups (such as the search endpoint) as it will greatly reduce the number of applications in the cache. * refactor(kubernetes): Remove unused functions Remove functions that are now unused after the changes here.
- Loading branch information