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

grpc / grpc-java / #20391

05 Aug 2026 08:00AM UTC coverage: 89.175% (+0.03%) from 89.149%
#20391

push

github

web-flow
xds: Add Http11ProxyUpstreamTransport to MessagePrinter (#12971)

Printer falls back to outputting the `@error` indicating that the type
is not recognized. So because we are unpacking
`Http11ProxyUpstreamTransport ` from `any`, we need to add it to the
registry.
Here is the example cds resource:
```   
 "transportSocket": {
      "name": "envoy.transport_sockets.http_11_proxy",
      "typedConfig": {
        "@error": "envoy.extensions.transport_sockets.http_11_proxy.v3.Http11ProxyUpstreamTransport is not recognized; see @value for raw binary message data",
        "@type": "type.googleapis.com/envoy.extensions.transport_sockets.http_11_proxy.v3.Http11ProxyUpstreamTransport",
        "@value": ""
      }
    },
```

cc: @sergiitk

38321 of 42973 relevant lines covered (89.17%)

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/MessagePrinter.java
1
/*
2
 * Copyright 2020 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.github.xds.type.v3.TypedStruct;
20
import com.google.protobuf.Descriptors.Descriptor;
21
import com.google.protobuf.InvalidProtocolBufferException;
22
import com.google.protobuf.Message;
23
import com.google.protobuf.MessageOrBuilder;
24
import com.google.protobuf.TypeRegistry;
25
import com.google.protobuf.util.JsonFormat;
26
import io.envoyproxy.envoy.config.cluster.v3.Cluster;
27
import io.envoyproxy.envoy.config.endpoint.v3.ClusterLoadAssignment;
28
import io.envoyproxy.envoy.config.listener.v3.Listener;
29
import io.envoyproxy.envoy.config.route.v3.RouteConfiguration;
30
import io.envoyproxy.envoy.extensions.clusters.aggregate.v3.ClusterConfig;
31
import io.envoyproxy.envoy.extensions.filters.http.fault.v3.HTTPFault;
32
import io.envoyproxy.envoy.extensions.filters.http.rbac.v3.RBAC;
33
import io.envoyproxy.envoy.extensions.filters.http.rbac.v3.RBACPerRoute;
34
import io.envoyproxy.envoy.extensions.filters.http.router.v3.Router;
35
import io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager;
36
import io.envoyproxy.envoy.extensions.load_balancing_policies.round_robin.v3.RoundRobin;
37
import io.envoyproxy.envoy.extensions.load_balancing_policies.wrr_locality.v3.WrrLocality;
38
import io.envoyproxy.envoy.extensions.transport_sockets.http_11_proxy.v3.Http11ProxyUpstreamTransport;
39
import io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.DownstreamTlsContext;
40
import io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext;
41
import io.envoyproxy.envoy.service.discovery.v3.Resource;
42
import io.grpc.xds.client.MessagePrettyPrinter;
43

44
/**
45
 * Converts protobuf message to human readable String format. Useful for protobuf messages
46
 * containing {@link com.google.protobuf.Any} fields.
47
 */
48
final class MessagePrinter implements MessagePrettyPrinter {
49
  public static final MessagePrinter INSTANCE = new MessagePrinter();
1✔
50

51
  private MessagePrinter() {}
52

53
  // The initialization-on-demand holder idiom.
54
  private static class LazyHolder {
55
    static final JsonFormat.Printer printer = newPrinter();
1✔
56

57
    private static JsonFormat.Printer newPrinter() {
58
      TypeRegistry.Builder registry =
59
          TypeRegistry.newBuilder()
1✔
60
              .add(Resource.getDescriptor())
1✔
61
              .add(Listener.getDescriptor())
1✔
62
              .add(HttpConnectionManager.getDescriptor())
1✔
63
              .add(HTTPFault.getDescriptor())
1✔
64
              .add(RBAC.getDescriptor())
1✔
65
              .add(RBACPerRoute.getDescriptor())
1✔
66
              .add(Router.getDescriptor())
1✔
67
              // UpstreamTlsContext and DownstreamTlsContext in v3 are not transitively imported
68
              // by top-level resource types.
69
              .add(UpstreamTlsContext.getDescriptor())
1✔
70
              .add(DownstreamTlsContext.getDescriptor())
1✔
71
              .add(RouteConfiguration.getDescriptor())
1✔
72
              .add(Cluster.getDescriptor())
1✔
73
              .add(ClusterConfig.getDescriptor())
1✔
74
              .add(ClusterLoadAssignment.getDescriptor())
1✔
75
              .add(WrrLocality.getDescriptor())
1✔
76
              .add(TypedStruct.getDescriptor())
1✔
77
              .add(RoundRobin.getDescriptor())
1✔
78
              .add(Http11ProxyUpstreamTransport.getDescriptor());
1✔
79
      try {
80
        @SuppressWarnings("unchecked")
81
        Class<? extends Message> routeLookupClusterSpecifierClass =
1✔
82
            (Class<? extends Message>)
83
                Class.forName("io.grpc.lookup.v1.RouteLookupClusterSpecifier");
1✔
84
        Descriptor descriptor =
1✔
85
            (Descriptor)
86
                routeLookupClusterSpecifierClass.getDeclaredMethod("getDescriptor").invoke(null);
1✔
87
        registry.add(descriptor);
1✔
88
      } catch (Exception e) {
×
89
        // Ignore. In most cases RouteLookup is not required.
90
      }
1✔
91
      return JsonFormat.printer().usingTypeRegistry(registry.build());
1✔
92
    }
93
  }
94

95
  @Override
96
  public String print(MessageOrBuilder message) {
97
    String res;
98
    try {
99
      res = LazyHolder.printer.print(message);
1✔
100
    } catch (InvalidProtocolBufferException e) {
×
101
      res = message + " (failed to pretty-print: " + e + ")";
×
102
    }
1✔
103
    return res;
1✔
104
  }
105
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc