Previously, node matching was used as a part of sources which are now deprecated.
When Sovereign received a discovery request, it would use a configured "node match key" to look at a value inside the nested discovery request.
It would then compare this value with a value in each item in the data retrieved via the source, using a configured "source match key".
If the two values matched, the item would be included in the context passed into templates.
This filtering and matching is computationally expensive, and makes caching difficult.
For this reason we now advise using a template context plugin.
You need to do a few things to replicate the same behavior
1 2import requests from typing import Any from collections import defaultdict from sovereign.dynamic_config.loaders import CustomLoader class GroupedInstances(CustomLoader): def load(self, path: str) -> Any: ret = list() source_match_key = "service_clusters" response = requests.get(path).json() groups = defaultdict(list) for item in response: clusters = item[source_match_key] if len(clusters) == 0: raise ValueError("Cant group this item!") elif len(clusters) == 1: group = clusters[0] groups[group].append(item) else: for group in clusters: groups[group].append(item) return ret
and then in your template
1 2def call(discovery_request, items, **kwargs): node_key = discovery_request.node.cluster filtered = items[node_key] for item in filtered: yield ...
Rate this page: