Last updated Jan 2, 2025

Filtering the generated resources

Background

When envoy requests resources, sometimes it specifies a finite list of the resources that it wants.

Currently, Sovereign looks at the resource_names supplied in the discovery request from envoy, and then iterates over all the resources generated by the template for the request, and removes items that don't match the names that envoy asked for. This behavior is deprecated.

Problems

While this is convenient, it adds a computation cost on every request, and makes caching difficult.

In the 1.0.0 release of Sovereign this will no longer be performed, and so your template logic will need to account for the resource names requested by envoy.

Example

Every template receives the resource_names as an argument. This is a special list, which contains either specific items, or contains all items.

To illustrate this working, consider the following:

1
2
resource_names = []
assert "foobar" in resource_names # True

resource_names = ["helloworld"]
assert "helloworld" in resource_names # True
assert "foobar" in resource_names     # False

Usage in templates

1
2
def call(discovery_request, resource_names, items, **kwargs):
    for item in items:
        if item.get("name") in resource_names:
            yield ...

Clusters are a slightly different case, they don't have a name field. In this case it is cluster_name

Rate this page: