envoyproxy / envoy

Cloud-native high-performance edge/middle/service proxy
https://www.envoyproxy.io
Apache License 2.0
24.76k stars 4.76k forks source link

[envoy moblie]error:Didn't find a registered implementation for name: 'envoy.listener_manager_impl.default' #30344

Closed kdsunset closed 9 months ago

kdsunset commented 11 months ago

title:error:Didn't find a registered implementation for name: 'envoy.listener_manager_impl.default' Description: I'm attempting to create a proxy service example using Envoy Mobile on an Android application . I've tried both the official YAML example and my own, but I keep encountering this error. It seems like there might be an issue with my configuration.
Thanks for your help!

//build.gradle.kts
api("io.envoyproxy.envoymobile:envoy:0.5.0.20231016")
//MainActivity
 engine = AndroidEngineBuilder(application, Custom(readEnvoyConfig()))
            .addLogLevel(LogLevel.DEBUG)
            .setLogger { Log.d("MainActivity", it) }
            .build()
//envoy_config_example.yaml
static_resources:
  listeners:
    - address:
        socket_address:
          address: 0.0.0.0
          port_value: 80
      filter_chains:
        - filters:
            - name: envoy.filters.network.http_connection_manager
              typed_config:
                "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
                codec_type: AUTO
                stat_prefix: ingress_http
                route_config:
                  name: local_route
                  virtual_hosts:
                    - name: app
                      domains:
                        - "*"
                      routes:
                        - match:
                            prefix: "/"
                          route:
                            cluster: service-https
                http_filters:
                  - name: envoy.filters.http.router
                    typed_config:
                      "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
  clusters:
    - name: service-https
      connect_timeout: 0.25s
      type: STRICT_DNS
      lb_policy: ROUND_ROBIN
      load_assignment:
        cluster_name: service-https
        endpoints:
          - lb_endpoints:
              - endpoint:
                  address:
                    socket_address:
                      address: 220.181.38.148
                      port_value: 80

error logs :

[2023-10-20 14:56:10.521][4895][critical][main] [external/envoy/source/server/server.cc:133] 
error initializing config ' static_resources:
  listeners:
    - address:
        socket_address:
          address: 0.0.0.0
          port_value: 80
      filter_chains:
        - filters:
            - name: envoy.filters.network.http_connection_manager
              typed_config:
                "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
                codec_type: AUTO
                stat_prefix: ingress_http
                route_config:
                  name: local_route
                  virtual_hosts:
                    - name: app
                      domains:
                        - "*"
                      routes:
                        - match:
                            prefix: "/"
                          route:
                            cluster: service-https
                http_filters:
                  - name: envoy.filters.http.router
                    typed_config:
                      "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
  clusters:
    - name: service-https
      connect_timeout: 0.25s
      type: STRICT_DNS
      lb_policy: ROUND_ROBIN
      load_assignment:
        cluster_name: service-https
        endpoints:
          - lb_endpoints:
              - endpoint:
                  address:
                    socket_address:
                      address: 220.181.38.148
                      port_value: 80
 ': Didn't find a registered implementation for name: 'envoy.listener_manager_impl.default'
[2023-10-20 14:56:10.531][4895][info][main] [external/envoy/source/server/server.cc:997] exiting
[2023-10-20 14:56:10.532][4895][debug][main] [external/envoy/source/common/access_log/access_log_manager_impl.cc:21] destroyed access loggers
[2023-10-20 14:56:10.532][4895][debug][main] [external/envoy/source/common/event/dispatcher_impl.cc:89] destroying dispatcher main_thread
[2023-10-20 14:56:10.533][4895][debug][init] [external/envoy/source/common/init/watcher_impl.cc:31] init manager Server destroyed
[2023-10-20 14:56:10.534][4895][critical][assert] [library/common/engine.cc:80] panic: Didn't find a registered implementation for name: 'envoy.listener_manager_impl.default'
abeyad commented 11 months ago

Hi, if you're passing in the bootstrap on your own, you will want to use the ApiListenerManager in your bootstrap config, similar to what is done here: https://github.com/envoyproxy/envoy/blob/dc841d18fd45ff8043dcc0d3bb9e7f8e84768d55/mobile/library/cc/engine_builder.cc#L929C1-L932

This is how the YAML config looks: https://github.com/envoyproxy/envoy/blob/dc841d18fd45ff8043dcc0d3bb9e7f8e84768d55/mobile/test/java/io/envoyproxy/envoymobile/engine/testing/QuicTestServerTest.java#L98C1-L101.

Note that you can also not pass in the Bootstrap YAML to the EngineBuilder and instead, use the EngineBuilder's functions (plus its defaults) to configure your Envoy Mobile instance.

But to get things working with your current setup, adding the ApiListenerManager as shown in https://github.com/envoyproxy/envoy/blob/dc841d18fd45ff8043dcc0d3bb9e7f8e84768d55/mobile/test/java/io/envoyproxy/envoymobile/engine/testing/QuicTestServerTest.java#L98C1-L101 should work.

Let me know if that doesn't help solve your problem!

kdsunset commented 11 months ago

@abeyad I added the listener_manager field to the configuration, and now it reports the following error (I tried all Cluster.DiscoveryType values and still the same) //added in configuration

listener_manager:
  name: envoy.listener_manager_impl.api
  typed_config:
    "@type": type.googleapis.com/envoy.config.listener.v3.ApiListenerManager

error logs:

  ': Didn't find a registered cluster factory implementation for name: 'envoy.cluster.static'
 D  [2023-10-22 07:30:50.947][16754][info][main] [external/envoy/source/server/server.cc:997] exiting
 D  [2023-10-22 07:30:50.948][16754][debug][init] [external/envoy/source/common/init/watcher_impl.cc:31] init manager RTDS destroyed
 D  [2023-10-22 07:30:50.948][16754][debug][init] [external/envoy/source/common/init/watcher_impl.cc:31] RTDS destroyed

My purpose is to implement a front-proxy on the android application to forward the request to the specified server. Thank you very much for your reply

abeyad commented 11 months ago

You'll need to include https://github.com/envoyproxy/envoy/blob/34a4961de31a3aae4859846fa1e505a8c61d9e58/source/extensions/clusters/static/BUILD#L12 in your build.

But to get to your desired setup more directly, I would suggest not passing in custom YAML (unless you need it). If you're just looking to use Envoy Mobile as a networking library that forwards requests to a specific server, you can just use the EngineBuilder without passing in YAML. It will use the defaults, which will give you the DFP cluster (https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_filters/dynamic_forward_proxy_filter) by default, and give you the set up you need to send requests via the library. If you need to add filters (e.g. HTTP filters https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_filters/http_filters), you can do so via the addPlatformFilter and addNativeFilter APIs on EngineBuilder.

So you shouldn't need to pass in YAML config to EngineBuilder unless you're doing something very custom that the APIs don't (yet) support.

abeyad commented 11 months ago

This shows an example of how to set it up: https://github.com/envoyproxy/envoy/blob/34a4961de31a3aae4859846fa1e505a8c61d9e58/mobile/examples/kotlin/hello_world/MainActivity.kt#L50-L68

kdsunset commented 11 months ago

@abeyad Hi!I tried both methods.My project may require more custom configurations,so I try to use this method. I think Ihave include "static_cluster_lib" into my build as you suggested, but I still get the same error "Didn't find a registered cluster factory implementation for name: 'envoy.cluster.static'". Is my configuration method wrong?

#/envoy/mobile/library/common/jni BUILD file
cc_library(
    name = "envoy_jni_lib",
    linkopts = select({
        "@envoy//bazel:dbg_build": ["-Wl,--build-id=sha1"],
        "//conditions:default": [],
    }),
    deps = [
        ":android_jni_interface_lib",
        ":android_network_utility_lib",
        ":jni_interface_lib",
        ":jni_support_lib",
        ":jni_utility_lib",
         "@envoy//source/extensions/clusters/static:static_cluster_lib",
    ],
    # We need this to ensure that we link this into the .so even though there are no code references.
    alwayslink = True,
)
# bulid command  
#/envoy/mobile
./bazelw build android_dist --config=release-android --fat_apk_cpu=x86,armeabi-v7a,arm64-v8a

Also, I looked at the official documentation ,ProxyInfoIntentPerformHTTPRequestUsingProxyTest,,and the "hello_envoy" example , it seems to only show how to intercept and filter requests, without covering the how to configure the proxy server part, and I still don't know how to configure a proxy server and forwards requests to a specific server, such as how to set the proxy server IP address and port using the APIs

abeyad commented 11 months ago

but I still get the same error "Didn't find a registered cluster factory implementation for name: 'envoy.cluster.static'".

I think I'm not understanding your set up. Do you have a piece of Java/Kotlin code for your app that is using Envoy Mobile that is failing b/c of the static cluster registry not found issue? Which library are you linking into your application when building? Or are you just trying to build the Envoy Mobile binary (i.e. the android_dist target) and encountering failures out of the box when running android_dist?

it seems to only show how to intercept and filter requests, without covering the how to configure the proxy server part, and I still don't know how to configure a proxy server and forwards requests to a specific server, such as how to set the proxy server IP address and port using the APIs

There might be some confusion: Envoy Mobile is a mobile networking library. It uses parts of Envoy to build a mobile networking library that takes the app's network requests and sends them over the wire to the destination. It sounds like you want to run Envoy as a service proxy on an Android device? That's different from Envoy Mobile and I don't believe that's supported. If you're looking to run Envoy Mobile on a mobile device (like Android) and have it send requests to a backend which has a reverse proxy serving requests, also using Envoy, then you need to set up two distinct things: Envoy Mobile on the client side, and Envoy the service proxy.

kdsunset commented 11 months ago

I'm sorry that I didn't describe it clearly. It is failing b/c of the static cluster registry not found issue.My kotlin code and error logs are at the beginning of thisissues , I tried using the command to build the aar file and using maven dependencies, but the same problem occurred:

': Didn't find a registered cluster factory implementation for name: 'envoy.cluster.static' D [2023-10-22 07:30:50.947][16754][info][main] [external/envoy/source/server/server.cc:997] exiting D [2023-10-22 07:30:50.948][16754][debug][init] [external/envoy/source/common/init/watcher_impl.cc:31] init manager RTDS destroyed D [2023-10-22 07:30:50.948][16754][debug][init] [external/envoy/source/common/init/watcher_impl.cc:31] RTDS destroyed

Yes,we use envoy as the server proxy on Windows, and then I want to use envoy mobile as a front proxy on Android to listen requests on the mobile device and forward them to my backend server proxy. Does envoy mobile support such a function?

abeyad commented 11 months ago

I'm sorry that I didn't describe it clearly. It is failing b/c of the static cluster registry not found issue.My kotlin code and error logs are at https://github.com/envoyproxy/envoy/issues/30344#issue-1953693874 , I tried using the command to build the aar file and using maven dependencies, but the same problem occurred:

For Envoy Mobile use cases, it actually already registers two DFP (dynamic forward proxy) clusters: one for cleartext (http) requests, one for secure requests (https). These clusters are called base for https and base_clear for http. These two clusters enable an app to use Envoy Mobile to send regular HTTP requests to their destinations using DNS resolution to resolve hostnames. So Envoy Mobile users don't really need to add their own clusters and indeed, the EngineBuilder APIs don't have any facility to add additional static clusters. Users can use the EngineBuilder's setXds API to set up xDS with CDS to fetch dynamic clusters, but I would need to understand your use case better to see if you really need this. Note that to use xDS with Envoy Mobile from Android, you'll need the envoy-xds artifact: https://central.sonatype.com/artifact/io.envoyproxy.envoymobile/envoy-xds.

Yes,we use envoy as the server proxy on Windows, and then I want to use envoy mobile as a front proxy on Android to listen requests on the mobile device and forward them to my backend server proxy. Does envoy mobile support such a function?

Envoy Mobile won't "listen" for requests in the traditional sense. It isn't run as a sidecar proxy on the mobile device, and it doesn't open listener sockets. It is a mobile networking library - it has APIs through which you can send HTTP requests and receive responses for those HTTP requests, and under the covers it uses Envoy's underlying network stack, so that you can configure protocols and set up filter chains on your mobile HTTP request handling the same as you would in your Envoy-as-a-backend-proxy setup. That's why Envoy Mobile set up through the EngineBuilder APIs provides you with the two clusters automatically, both of which are DFP clusters - those clusters don't register static endpoints, but rather use DNS to resolve the HTTP request's destination host to send the requests over the public internet to the desired endpoint.

Does that make sense?

github-actions[bot] commented 9 months ago

This issue has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in the next 7 days unless it is tagged "help wanted" or "no stalebot" or other activity occurs. Thank you for your contributions.

github-actions[bot] commented 9 months ago

This issue has been automatically closed because it has not had activity in the last 37 days. If this issue is still valid, please ping a maintainer and ask them to label it as "help wanted" or "no stalebot". Thank you for your contributions.