Search code examples
grpcgrpc-java

Forcer refresh on DNSNameResolver


We're using ManagedChannel, and at some point we need to have a DNSResolution refresh to get new pods on the cluster.

so far we try to use max_connection_age_grace_ms and we can see GO_AWAY calls from server but client did not receive this since we have isito side-car in front of him.

Our next idea was try to force the refresh invoking.

https://github.com/grpc/grpc-java/blob/master/core/src/main/java/io/grpc/internal/DnsNameResolver.java#L210

Any idea what is the standard way to do it now without have to implement our own DnsNameResolver

Regards.


Solution

  • You want the server the client connects to to manage the connection lifetime. So in this case, you want to configure the proxies with Istio.

    This is possible using EnvoyFilter. The first example in its documentation adjusts http_connection_manager to set idle_timeout. The same approach would work to set max_connection_duration:

    apiVersion: networking.istio.io/v1alpha3
    kind: EnvoyFilter
    metadata:
      name: hcm-connection-duration
      namespace: srv-namespace
    spec:
      workloadSelector:
        labels:
          app: myapp
      configPatches:
      - applyTo: NETWORK_FILTER
        match:
          context: SIDECAR_INBOUND
          listener:
            filterChain:
              filter:
                name: "envoy.filters.network.http_connection_manager"
        patch:
          operation: MERGE
          value:
            name: "envoy.filters.network.http_connection_manager"
            typed_config:
              "@type": "type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager"
              common_http_protocol_options:
                max_connection_duration: 300s