• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

grpc / grpc-java / #19827

23 May 2025 10:54AM UTC coverage: 88.613% (-0.002%) from 88.615%
#19827

push

github

web-flow
xds: Change how xDS filters are created by introducing Filter.Provider (#11883) (#12089)

This is the first step towards supporting filter state retention in
Java. The mechanism will be similar to the one described in [A83]
(https://github.com/grpc/proposal/blob/master/A83-xds-gcp-authn-filter.md#filter-call-credentials-cache)
for C-core, and will serve the same purpose. However, the
implementation details are very different due to the different nature
of xDS HTTP filter support in C-core and Java.

In Java, xDS HTTP filters are backed by classes implementing
`io.grpc.xds.Filter`, from here just called "Filters". To support
Filter state retention (next PR), Java's xDS implementation must be
able to create unique Filter instances per:
- Per HCM
  `envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager`
- Per filter name as specified in
  `envoy.extensions.filters.network.http_connection_manager.v3.HttpFilter.name`

This PR **does not** implements Filter state retention, but lays the
groundwork for it by changing how filters are registered and
instantiated. To achieve this, all existing Filter classes had to be
updated to the new instantiation mechanism described below.

Prior to these this PR, Filters had no livecycle. FilterRegistry
provided singleton instances for a given typeUrl. This PR introduces
a new interface `Filter.Provider`, which instantiates Filter classes.
All functionality that doesn't need an instance of a Filter is moved
to the Filter.Provider. This includes parsing filter config proto
into FilterConfig and determining the filter kind
(client-side, server-side, or both).

This PR is limited to refactoring, and there's no changes to the
existing behavior. Note that all Filter Providers still return
singleton Filter instances. However, with this PR, it is now possible
to create Providers that return a new Filter instance each time
`newInstance` is called.

Co-authored-by: Sergii Tkachenko <sergiitk@google.com>

34286 of 38692 relevant lines covered (88.61%)

0.89 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.91
/../xds/src/main/java/io/grpc/xds/RouterFilter.java
1
/*
2
 * Copyright 2021 The gRPC Authors
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16

17
package io.grpc.xds;
18

19
import com.google.protobuf.Message;
20

21
/**
22
 * Router filter implementation. Currently this filter does not parse any field in the config.
23
 */
24
final class RouterFilter implements Filter {
25
  private static final RouterFilter INSTANCE = new RouterFilter();
1✔
26

27
  static final String TYPE_URL =
28
      "type.googleapis.com/envoy.extensions.filters.http.router.v3.Router";
29

30
  static final FilterConfig ROUTER_CONFIG = new FilterConfig() {
1✔
31
    @Override
32
    public String typeUrl() {
33
      return TYPE_URL;
1✔
34
    }
35

36
    @Override
37
    public String toString() {
38
      return "ROUTER_CONFIG";
1✔
39
    }
40
  };
41

42
  static final class Provider implements Filter.Provider {
1✔
43
    @Override
44
    public String[] typeUrls() {
45
      return new String[]{TYPE_URL};
1✔
46
    }
47

48
    @Override
49
    public boolean isClientFilter() {
50
      return true;
1✔
51
    }
52

53
    @Override
54
    public boolean isServerFilter() {
55
      return true;
1✔
56
    }
57

58
    @Override
59
    public RouterFilter newInstance() {
60
      return INSTANCE;
1✔
61
    }
62

63
    @Override
64
    public ConfigOrError<? extends FilterConfig> parseFilterConfig(Message rawProtoMessage) {
65
      return ConfigOrError.fromConfig(ROUTER_CONFIG);
1✔
66
    }
67

68
    @Override
69
    public ConfigOrError<? extends FilterConfig> parseFilterConfigOverride(
70
        Message rawProtoMessage) {
71
      return ConfigOrError.fromError("Router Filter should not have override config");
×
72
    }
73
  }
74

75
  private RouterFilter() {}
76
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc