[
  {
    "path": ".github/workflows/release.yml",
    "content": "name: Release\n\non:\n  release:\n    types: [published]\n\njobs:\n  release:\n    name: Release grpcdebug\n    runs-on: ubuntu-latest\n    strategy:\n      matrix:\n        goos: [linux, darwin, windows]\n        goarch: [386, amd64, arm64]\n        exclude:\n          - goos: darwin\n            goarch: 386\n\n    steps:\n      - name: Checkout code\n        uses: actions/checkout@v2\n\n      - name: Set up Go\n        uses: actions/setup-go@v2\n\n      - name: Prepare build directory\n        run: |\n          mkdir -p build/\n          cp README.md build/\n          cp LICENSE build/\n      - name: Build\n        env:\n          GOOS: ${{ matrix.goos }}\n          GOARCH: ${{ matrix.goarch }}\n        run: |\n          go build -trimpath -o $GITHUB_WORKSPACE/build\n      - name: Create package\n        id: package\n        run: |\n          PACKAGE_NAME=grpcdebug.${GITHUB_REF#refs/tags/}.${{ matrix.goos }}.${{ matrix.goarch }}.tar.gz\n          tar -czvf $PACKAGE_NAME -C build .\n          echo ::set-output name=name::${PACKAGE_NAME}\n      - name: Upload asset\n        uses: actions/upload-release-asset@v1\n        env:\n          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}\n        with:\n          upload_url: ${{ github.event.release.upload_url }}\n          asset_path: ./${{ steps.package.outputs.name }}\n          asset_name: ${{ steps.package.outputs.name }}\n          asset_content_type: application/gzip\n"
  },
  {
    "path": ".gitignore",
    "content": "# Binaries for programs and plugins\n*.exe\n*.exe~\n*.dll\n*.so\n*.dylib\n\n# Test binary, built with `go test -c`\n*.test\n\n# Output of the go coverage tool, specifically when used with LiteIDE\n*.out\n\n# Dependency directories (remove the comment below to include it)\n# vendor/\n"
  },
  {
    "path": "LICENSE",
    "content": "                                 Apache License\n                           Version 2.0, January 2004\n                        http://www.apache.org/licenses/\n\n   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n   1. Definitions.\n\n      \"License\" shall mean the terms and conditions for use, reproduction,\n      and distribution as defined by Sections 1 through 9 of this document.\n\n      \"Licensor\" shall mean the copyright owner or entity authorized by\n      the copyright owner that is granting the License.\n\n      \"Legal Entity\" shall mean the union of the acting entity and all\n      other entities that control, are controlled by, or are under common\n      control with that entity. For the purposes of this definition,\n      \"control\" means (i) the power, direct or indirect, to cause the\n      direction or management of such entity, whether by contract or\n      otherwise, or (ii) ownership of fifty percent (50%) or more of the\n      outstanding shares, or (iii) beneficial ownership of such entity.\n\n      \"You\" (or \"Your\") shall mean an individual or Legal Entity\n      exercising permissions granted by this License.\n\n      \"Source\" form shall mean the preferred form for making modifications,\n      including but not limited to software source code, documentation\n      source, and configuration files.\n\n      \"Object\" form shall mean any form resulting from mechanical\n      transformation or translation of a Source form, including but\n      not limited to compiled object code, generated documentation,\n      and conversions to other media types.\n\n      \"Work\" shall mean the work of authorship, whether in Source or\n      Object form, made available under the License, as indicated by a\n      copyright notice that is included in or attached to the work\n      (an example is provided in the Appendix below).\n\n      \"Derivative Works\" shall mean any work, whether in Source or Object\n      form, that is based on (or derived from) the Work and for which the\n      editorial revisions, annotations, elaborations, or other modifications\n      represent, as a whole, an original work of authorship. For the purposes\n      of this License, Derivative Works shall not include works that remain\n      separable from, or merely link (or bind by name) to the interfaces of,\n      the Work and Derivative Works thereof.\n\n      \"Contribution\" shall mean any work of authorship, including\n      the original version of the Work and any modifications or additions\n      to that Work or Derivative Works thereof, that is intentionally\n      submitted to Licensor for inclusion in the Work by the copyright owner\n      or by an individual or Legal Entity authorized to submit on behalf of\n      the copyright owner. For the purposes of this definition, \"submitted\"\n      means any form of electronic, verbal, or written communication sent\n      to the Licensor or its representatives, including but not limited to\n      communication on electronic mailing lists, source code control systems,\n      and issue tracking systems that are managed by, or on behalf of, the\n      Licensor for the purpose of discussing and improving the Work, but\n      excluding communication that is conspicuously marked or otherwise\n      designated in writing by the copyright owner as \"Not a Contribution.\"\n\n      \"Contributor\" shall mean Licensor and any individual or Legal Entity\n      on behalf of whom a Contribution has been received by Licensor and\n      subsequently incorporated within the Work.\n\n   2. Grant of Copyright License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      copyright license to reproduce, prepare Derivative Works of,\n      publicly display, publicly perform, sublicense, and distribute the\n      Work and such Derivative Works in Source or Object form.\n\n   3. Grant of Patent License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      (except as stated in this section) patent license to make, have made,\n      use, offer to sell, sell, import, and otherwise transfer the Work,\n      where such license applies only to those patent claims licensable\n      by such Contributor that are necessarily infringed by their\n      Contribution(s) alone or by combination of their Contribution(s)\n      with the Work to which such Contribution(s) was submitted. If You\n      institute patent litigation against any entity (including a\n      cross-claim or counterclaim in a lawsuit) alleging that the Work\n      or a Contribution incorporated within the Work constitutes direct\n      or contributory patent infringement, then any patent licenses\n      granted to You under this License for that Work shall terminate\n      as of the date such litigation is filed.\n\n   4. Redistribution. You may reproduce and distribute copies of the\n      Work or Derivative Works thereof in any medium, with or without\n      modifications, and in Source or Object form, provided that You\n      meet the following conditions:\n\n      (a) You must give any other recipients of the Work or\n          Derivative Works a copy of this License; and\n\n      (b) You must cause any modified files to carry prominent notices\n          stating that You changed the files; and\n\n      (c) You must retain, in the Source form of any Derivative Works\n          that You distribute, all copyright, patent, trademark, and\n          attribution notices from the Source form of the Work,\n          excluding those notices that do not pertain to any part of\n          the Derivative Works; and\n\n      (d) If the Work includes a \"NOTICE\" text file as part of its\n          distribution, then any Derivative Works that You distribute must\n          include a readable copy of the attribution notices contained\n          within such NOTICE file, excluding those notices that do not\n          pertain to any part of the Derivative Works, in at least one\n          of the following places: within a NOTICE text file distributed\n          as part of the Derivative Works; within the Source form or\n          documentation, if provided along with the Derivative Works; or,\n          within a display generated by the Derivative Works, if and\n          wherever such third-party notices normally appear. The contents\n          of the NOTICE file are for informational purposes only and\n          do not modify the License. You may add Your own attribution\n          notices within Derivative Works that You distribute, alongside\n          or as an addendum to the NOTICE text from the Work, provided\n          that such additional attribution notices cannot be construed\n          as modifying the License.\n\n      You may add Your own copyright statement to Your modifications and\n      may provide additional or different license terms and conditions\n      for use, reproduction, or distribution of Your modifications, or\n      for any such Derivative Works as a whole, provided Your use,\n      reproduction, and distribution of the Work otherwise complies with\n      the conditions stated in this License.\n\n   5. Submission of Contributions. Unless You explicitly state otherwise,\n      any Contribution intentionally submitted for inclusion in the Work\n      by You to the Licensor shall be under the terms and conditions of\n      this License, without any additional terms or conditions.\n      Notwithstanding the above, nothing herein shall supersede or modify\n      the terms of any separate license agreement you may have executed\n      with Licensor regarding such Contributions.\n\n   6. Trademarks. This License does not grant permission to use the trade\n      names, trademarks, service marks, or product names of the Licensor,\n      except as required for reasonable and customary use in describing the\n      origin of the Work and reproducing the content of the NOTICE file.\n\n   7. Disclaimer of Warranty. Unless required by applicable law or\n      agreed to in writing, Licensor provides the Work (and each\n      Contributor provides its Contributions) on an \"AS IS\" BASIS,\n      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n      implied, including, without limitation, any warranties or conditions\n      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n      PARTICULAR PURPOSE. You are solely responsible for determining the\n      appropriateness of using or redistributing the Work and assume any\n      risks associated with Your exercise of permissions under this License.\n\n   8. Limitation of Liability. In no event and under no legal theory,\n      whether in tort (including negligence), contract, or otherwise,\n      unless required by applicable law (such as deliberate and grossly\n      negligent acts) or agreed to in writing, shall any Contributor be\n      liable to You for damages, including any direct, indirect, special,\n      incidental, or consequential damages of any character arising as a\n      result of this License or out of the use or inability to use the\n      Work (including but not limited to damages for loss of goodwill,\n      work stoppage, computer failure or malfunction, or any and all\n      other commercial damages or losses), even if such Contributor\n      has been advised of the possibility of such damages.\n\n   9. Accepting Warranty or Additional Liability. While redistributing\n      the Work or Derivative Works thereof, You may choose to offer,\n      and charge a fee for, acceptance of support, warranty, indemnity,\n      or other liability obligations and/or rights consistent with this\n      License. However, in accepting such obligations, You may act only\n      on Your own behalf and on Your sole responsibility, not on behalf\n      of any other Contributor, and only if You agree to indemnify,\n      defend, and hold each Contributor harmless for any liability\n      incurred by, or claims asserted against, such Contributor by reason\n      of your accepting any such warranty or additional liability.\n\n   END OF TERMS AND CONDITIONS\n\n   APPENDIX: How to apply the Apache License to your work.\n\n      To apply the Apache License to your work, attach the following\n      boilerplate notice, with the fields enclosed by brackets \"[]\"\n      replaced with your own identifying information. (Don't include\n      the brackets!)  The text should be enclosed in the appropriate\n      comment syntax for the file format. We also recommend that a\n      file or class name and description of purpose be included on the\n      same \"printed page\" as the copyright notice for easier\n      identification within third-party archives.\n\n   Copyright [yyyy] [name of copyright owner]\n\n   Licensed under the Apache License, Version 2.0 (the \"License\");\n   you may not use this file except in compliance with the License.\n   You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n   Unless required by applicable law or agreed to in writing, software\n   distributed under the License is distributed on an \"AS IS\" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n   See the License for the specific language governing permissions and\n   limitations under the License.\n"
  },
  {
    "path": "README.md",
    "content": "# grpcdebug\n[![Go Report\nCard](https://goreportcard.com/badge/github.com/grpc-ecosystem/grpcdebug)](https://goreportcard.com/report/github.com/grpc-ecosystem/grpcdebug)\n\ngrpcdebug is a command line interface focusing on simplifying the debugging\nprocess of gRPC applications. grpcdebug fetches the internal states of the gRPC\nlibrary from the application via gRPC protocol and provide a human-friendly UX\nto browse them. Currently, it supports Channelz/Health Checking/CSDS (aka. admin\nservices). In other words, it can fetch statistics about how many RPCs has being\nsent or failed on a given gRPC channel, it can inspect address resolution\nresults, it can dump the in-effective xDS configuration that directs the routing\nof RPCs.\n\nIf you are looking for a tool to send gRPC requests and interact with a gRPC\nserver, please checkout https://github.com/fullstorydev/grpcurl.\n\n```\ngrpcdebug is an gRPC service admin CLI\n\nUsage:\n  grpcdebug <target address> [flags] <command>\n\nAvailable Commands:\n  channelz    Display gRPC states in a human readable way.\n  health      Check health status of the target service (default \"\").\n  help        Help about any command\n  xds         Fetch xDS related information.\n\nFlags:\n      --credential_file string        Sets the path of the credential file; used in [tls] mode\n  -h, --help                          help for grpcdebug\n      --security string               Defines the type of credentials to use [tls, google-default, insecure] (default \"insecure\")\n      --server_name_override string   Overrides the peer server name if non empty; used in [tls] mode\n  -t, --timestamp                     Print timestamp as RFC3339 instead of human readable strings\n  -v, --verbose                       Print verbose information for debugging\n\nUse \"grpcdebug <target address>  [command] --help\" for more information about a command.\n```\n\n## Table of Contents\n- [grpcdebug](#grpcdebug)\n  - [Table of Contents](#table-of-contents)\n  - [Installation](#installation)\n    - [Use Compiled Binaries](#use-compiled-binaries)\n    - [Compile From Source](#compile-from-source)\n  - [Quick Start](#quick-start)\n    - [Connect & Security](#connect--security)\n      - [Insecure Connection](#insecure-connection)\n      - [TLS Connection - Flags](#tls-connection---flags)\n      - [Server Connection Config](#server-connection-config)\n    - [Health](#health)\n    - [Channelz](#channelz)\n      - [Usage 1: Raw Channelz Output](#usage-1-raw-channelz-output)\n      - [Usage 2: List Client Channels](#usage-2-list-client-channels)\n      - [Usage 3: List Servers](#usage-3-list-servers)\n      - [Usage 4: Inspect a Channel](#usage-4-inspect-a-channel)\n      - [Usage 5: Inspect a Subchannel](#usage-5-inspect-a-subchannel)\n      - [Usage 6: Inspect a Socket](#usage-6-inspect-a-socket)\n      - [Usage 7: Inspect a Server](#usage-7-inspect-a-server)\n      - [Usage 8: Pagination](#usage-8-pagination)\n    - [Debug xDS](#debug-xds)\n      - [Usage 1: xDS Resources Overview](#usage-1-xds-resources-overview)\n      - [Usage 2: Dump xDS Configs](#usage-2-dump-xds-configs)\n      - [Usage 3: Filter xDS Configs](#usage-3-filter-xds-configs)\n  - [Admin Services](#admin-services)\n    - [gRPC Java:](#grpc-java)\n    - [gRPC Go:](#grpc-go)\n    - [gRPC C++:](#grpc-c)\n\n## Installation\n\n### Use Compiled Binaries\n\nThe download links of the binaries can be found at\nhttps://github.com/grpc-ecosystem/grpcdebug/releases. You can find the\nprecompiled artifacts for `macOS`/`Linux`/`Windows`.\n\n### Compile From Source\n\nMinimum Golang Version 1.22. Official Golang install guide:\nhttps://golang.org/doc/install.\n\nYou can install the `grpcdebug` tool using command:\n\n```shell\ngo install -v github.com/grpc-ecosystem/grpcdebug@latest\n```\n\nYou can check your Golang version with:\n\n```shell\ngo version\n```\n\nDon't forget to add Golang binaries to your `PATH`:\n\n```shell\nexport PATH=$PATH:$(go env GOPATH)/bin\n```\n\n## Quick Start\n\nIf certain commands are confusing, please try to use `-h` to get more context.\nSuggestions and ideas are welcome, please post them to\nhttps://github.com/grpc-ecosystem/grpcdebug/issues!\n\nIf you haven't got your gRPC application instrumented, feel free to try out the\nmocking `testserver` which implemented admin services.\n\n```shell\ncd internal/testing/testserver\ngo run main.go\n# Serving Business Logic on :10001\n# Serving Insecure Admin Services on :50051\n# Serving Secure Admin Services on :50052\n# ...\n```\n\n### Connect & Security\n\n#### Insecure Connection\n\nTo connect to a gRPC endpoint without any credentials, we don't use any special\nflags. If the local network can connect to the given gRPC endpoint, it should\njust work. For example, if I have a gRPC application exposing admin services at\n`localhost:50051`:\n\n```shell\ngrpcdebug localhost:50051 channelz channels\n```\n\n#### TLS Connection - Flags\n\nOne way to establish a TLS connection with grpcdebug is by specifying the\ncredentials via command line flags. For example:\n\n```shell\ngrpcdebug localhost:50052 --security=tls --credential_file=./internal/testing/ca.pem --server_name_override=\"*.test.youtube.com\" channelz channels\n```\n\n#### Server Connection Config\n\nAlternatively, like OpenSSH clients, you can specify the security settings in a\n`grpcdebug_config.yaml` file. grpcdebug CLI will find matching connection config and\nthen use it to connect.\n\n```yaml\nservers:\n  \"pattern string\":\n    real_address: string\n    security: insecure/tls\n    credential_file: string\n    server_name_override: string\n```\n\nHere is an example config file\n[grpcdebug_config.yaml](internal/testing/grpcdebug_config.yaml).\n\nEach server config can have the following settings:\n\n* Pattern: the string right after `Server ` which dictates if this rule should\n  apply;\n* RealAddress: if present, override the given target address, which allows\n  giving nicknames/aliases to frequently used addresses;\n* Security: allows `insecure` or `tls`, expecting more in the future;\n* CredentialFile: path to the credential file;\n* ServerNameOverride: override the hostname, which is useful for local reproductions to\n  comply with the certificates' common name requirement.\n\ngrpcdebug searches the config file in the following order:\n\n1. Check if the environment variable `GRPCDEBUG_CONFIG` is set, if so, load from the\n   given path;\n2. Try to load the `grpcdebug_config.yaml` file in the current working directory;\n3. Try to load the `grpcdebug_config.yaml` file in the user config directory (Linux:\n   `$HOME/.config`, macOS: `$HOME/Library/Application Support`, Windows:\n   `%AppData%`, see\n   [`os.UserConfigDir()`](https://golang.org/pkg/os/#UserConfigDir)).\n\nFor example, we can connect to our mock test server's secure admin port via:\n\n```shell\nGRPCDEBUG_CONFIG=internal/testing/grpcdebug_config.yaml grpcdebug localhost:50052 channelz channels\n# Or\nGRPCDEBUG_CONFIG=internal/testing/grpcdebug_config.yaml grpcdebug prod channelz channels\n```\n\n### Health\n\ngrpcdebug can be used to fetch the health checking status of a peer gRPC\napplication (see\n[health.proto](https://github.com/grpc/grpc/blob/master/src/proto/grpc/health/v1/health.proto)).\ngRPC's health checking works at the service-level, meaning services registered on\nthe same gRPC server may have different health statuses. The health status of\nservice `\"\"` is used to represent the overall health status of the gRPC\napplication.\n\nTo simply fetch the overall health status:\n\n```shell\ngrpcdebug localhost:50051 health\n# <Overall>:  SERVING\n# or\n# <Overall>:  NOT_SERVING\n```\n\nOr fetch individual service's health status:\n\n```shell\ngrpcdebug localhost:50051 health helloworld.Greeter\n# <Overall>:            SERVING\n# helloworld.Greeter:   SERVING\n```\n\n### Channelz\n\n[Channelz](https://github.com/grpc/proposal/blob/master/A14-channelz.md) is a\nchannel tracing library that allows applications to remotely query gRPC internal\ndebug information. Also, Channelz has a web interface (see\n[gdebug](https://github.com/grpc/grpc-experiments/tree/master/gdebug)).\ngrpcdebug is able to fetch information and present it in a more readable way.\n\nGenerally, you wil start with either the `servers` or `channels` command and\nthen work down to the details.\n\n#### Usage 1: Raw Channelz Output\n\nFor all Channelz commands, you can add `--json` to get the raw Channelz output.\n\n```shell\ngrpcdebug localhost:50051 channelz servers --json\n#[\n#  {\n#    \"ref\": {\n#      \"server_id\": 2,\n#      \"name\": \"ServerImpl{logId=2, transportServer=NettyServer{logId=1, addresses=[0.0.0.0/0.0.0.0:50051]}}\"\n#    },\n#    \"data\": {\n#      \"calls_started\": 3,\n#      \"calls_succeeded\": 2,\n#      \"last_call_started_timestamp\": {\n#        \"seconds\": 1680220688,\n#        \"nanos\": 444000000\n#      }\n#    },\n#    \"listen_socket\": [\n#      {\n#        \"socket_id\": 3,\n#        \"name\": \"ListenSocket{logId=3, channel=[id: 0x05f9f16c, L:/0:0:0:0:0:0:0:0%0:50051]}\"\n#      }\n#    ]\n#  }\n#]\n\n```\n\n#### Usage 2: List Client Channels\n\n```shell\ngrpcdebug localhost:50051 channelz channels\n# Channel ID   Target            State     Calls(Started/Succeeded/Failed)   Created Time\n# 7            localhost:10001   READY     5136/4631/505                     8 minutes ago\n```\n\n#### Usage 3: List Servers\n\n```shell\ngrpcdebug localhost:50051 channelz servers\n# Server ID   Listen Addresses   Calls(Started/Succeeded/Failed)   Last Call Started\n# 1           [:::10001]         2852/2530/322                     now\n# 2           [:::50051]         29/28/0                           now\n# 3           [:::50052]         4/4/0                             26 seconds ago\n```\n\n#### Usage 4: Inspect a Channel\n\nYou can identify a channel via the Channel ID.\n\n```shell\ngrpcdebug localhost:50051 channelz channel 7\n# Channel ID:        7\n# Target:            localhost:10001\n# State:             READY\n# Calls Started:     3976\n# Calls Succeeded:   3520\n# Calls Failed:      456\n# Created Time:      6 minutes ago\n# ---\n# Subchannel ID   Target            State     Calls(Started/Succeeded/Failed)   CreatedTime\n# 8               localhost:10001   READY     3976/3520/456                     6 minutes ago\n# ---\n# Severity   Time            Child Ref                      Description\n# CT_INFO    6 minutes ago                                  Channel Created\n# CT_INFO    6 minutes ago                                  Resolver state updated: {Addresses:[{Addr:localhost:10001 ServerName: Attributes:<nil> Type:0 Metadata:<nil>}] ServiceConfig:<nil> Attributes:<nil>} (resolver returned new addresses)\n# CT_INFO    6 minutes ago                                  Channel switches to new LB policy \"pick_first\"\n# CT_INFO    6 minutes ago   subchannel(subchannel_id:8 )   Subchannel(id:8) created\n# CT_INFO    6 minutes ago                                  Channel Connectivity change to CONNECTING\n# CT_INFO    6 minutes ago                                  Channel Connectivity change to READY\n```\n\n#### Usage 5: Inspect a Subchannel\n\n```shell\ngrpcdebug localhost:50051 channelz subchannel 8\n# Subchannel ID:     8\n# Target:            localhost:10001\n# State:             READY\n# Calls Started:     4490\n# Calls Succeeded:   3966\n# Calls Failed:      524\n# Created Time:      7 minutes ago\n# ---\n# Socket ID   Local->Remote          Streams(Started/Succeeded/Failed)   Messages(Sent/Received)\n# 9           ::1:47436->::1:10001   4490/4490/0                         4490/3966\n```\n\n#### Usage 6: Inspect a Socket\n\n```shell\ngrpcdebug localhost:50051 channelz socket 9\n# Socket ID:                       9\n# Address:                         ::1:47436->::1:10001\n# Streams Started:                 4807\n# Streams Succeeded:               4807\n# Streams Failed:                  0\n# Messages Sent:                   4807\n# Messages Received:               4243\n# Keep Alives Sent:                0\n# Last Local Stream Created:       now\n# Last Remote Stream Created:      a long while ago\n# Last Message Sent Created:       now\n# Last Message Received Created:   now\n# Local Flow Control Window:       65535\n# Remote Flow Control Window:      65535\n# ---\n# Socket Options Name   Value\n# SO_LINGER             [type.googleapis.com/grpc.channelz.v1.SocketOptionLinger]:{duration:{}}\n# SO_RCVTIMEO           [type.googleapis.com/grpc.channelz.v1.SocketOptionTimeout]:{duration:{}}\n# SO_SNDTIMEO           [type.googleapis.com/grpc.channelz.v1.SocketOptionTimeout]:{duration:{}}\n# TCP_INFO              [type.googleapis.com/grpc.channelz.v1.SocketOptionTcpInfo]:{tcpi_state:1  tcpi_options:7  tcpi_rto:204000  tcpi_ato:40000  tcpi_snd_mss:32768  tcpi_rcv_mss:1093  tcpi_last_data_sent:16  tcpi_last_data_recv:16  tcpi_last_ack_recv:16  tcpi_pmtu:65536  tcpi_rcv_ssthresh:65476  tcpi_rtt:192  tcpi_rttvar:153  tcpi_snd_ssthresh:2147483647  tcpi_snd_cwnd:10  tcpi_advmss:65464  tcpi_reordering:3}\n# ---\n# Security Model:   TLS\n# Standard Name:    TLS_AES_128_GCM_SHA256\n```\n\n#### Usage 7: Inspect a Server\n\n```shell\ngrpcdebug localhost:50051 channelz server 1\n# Server Id:           1\n# Listen Addresses:    [:::10001]\n# Calls Started:       5250\n# Calls Succeeded:     4647\n# Calls Failed:        603\n# Last Call Started:   now\n# ---\n# Socket ID   Local->Remote          Streams(Started/Succeeded/Failed)   Messages(Sent/Received)\n# 10          ::1:10001->::1:47436   5250/5250/0                         4647/5250\n```\n\n#### Usage 8: Pagination\n\nIn production, there may be thousands of clients/servers/sockets. It would be very noisy to print all of them at once, so Channelz supports pagination through `start_id` and `max_results`\n\n```shell\ngrpcdebug localhost:50051 channelz servers --start_id=0 --max_results=1\n# Server ID   Listen Addresses   Calls(Started/Succeeded/Failed)   Last Call Started\n# 1           [:::10001]         2852/2530/322                     now\ngrpcdebug localhost:50051 channelz servers --start_id=2 --max_results=2\n# Server ID   Listen Addresses   Calls(Started/Succeeded/Failed)   Last Call Started\n# 2           [:::50051]         29/28/0                           now\n# 3           [:::50052]         4/4/0                             26 seconds ago\n```\n\nIt works similarly for printing channels via `channelz channels` and printing server sockets via `channelz server`.\n\n### Debug xDS\n\n[xDS](https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/operations/dynamic_configuration)\nis a data plane configuration API commonly used in service mesh projects. It's\ncreated by Envoy, used by Istio, Traffic Director, and gRPC.\n\n#### Usage 1: xDS Resources Overview\n\nThe xDS resources status might be `REQUESTED`/`DOES_NOT_EXIST`/`ACKED`/`NACKED` (see\n[config_dump.proto](https://github.com/envoyproxy/envoy/blob/b0ce15c96cebd89cf391869e49017325cd7faaa8/api/envoy/admin/v3/config_dump.proto#L22)).\nThis view is intended for a quick scan if a configuration is propagated from the\nservice mesh control plane.\n\n```shell\ngrpcdebug localhost:50051 xds status\n# Name                                                                   Status    Version               Type                                                                 LastUpdated\n# xds-test-server:1337                                                   ACKED     1617141154495058478   type.googleapis.com/envoy.config.listener.v3.Listener                2 days ago\n# URL_MAP/1040920224690_sergii-psm-test-url-map_0_xds-test-server:1337   ACKED     1617141154495058478   type.googleapis.com/envoy.config.route.v3.RouteConfiguration         2 days ago\n# cloud-internal-istio:cloud_mp_1040920224690_6530603179561593229        ACKED     1617141154495058478   type.googleapis.com/envoy.config.cluster.v3.Cluster                  2 days ago\n# cloud-internal-istio:cloud_mp_1040920224690_6530603179561593229        ACKED     1                     type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment   2 days ago\n```\n\n#### Usage 2: Dump xDS Configs\n\n```shell\ngrpcdebug localhost:50051 xds config\n# {\n#   \"config\":  [\n#     {\n#       \"node\":  {\n#         \"id\":  \"projects/1040920224690/networks/default/nodes/5cc9170c-d5b4-4061-b431-c1d43e6ac0ab\",\n#         \"cluster\":  \"cluster\",\n#         \"metadata\":  {\n#           \"INSTANCE_IP\":  \"192.168.120.31\",\n#           \"TRAFFICDIRECTOR_GCP_PROJECT_NUMBER\":  \"1040920224690\",\n#           \"TRAFFICDIRECTOR_NETWORK_NAME\":  \"default\"\n#         },\n# ...\n```\n\nFor an example config dump, see\n[csds_config_dump.json](internal/testing/testserver/csds_config_dump.json).\n\n#### Usage 3: Filter xDS Configs\n\nThe dumped xDS config can be quite verbose, if I only interested in certain xDS\ntype, grpcdebug can only print the selected section.\n\n```shell\ngrpcdebug localhost:50051 xds config --type=eds\n# {\n#   \"dynamicEndpointConfigs\":  [\n#     {\n#       \"versionInfo\":  \"1\",\n#       \"endpointConfig\":  {\n#         \"@type\":  \"type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment\",\n#         \"clusterName\":  \"cloud-internal-istio:cloud_mp_1040920224690_6530603179561593229\",\n#         \"endpoints\":  [\n#           {\n#             \"locality\":  {\n#               \"subZone\":  \"jf:us-central1-a_7062512536751318190_neg\"\n#             },\n#             \"lbEndpoints\":  [\n#               {\n#                 \"endpoint\":  {\n#                   \"address\":  {\n#                     \"socketAddress\":  {\n#                       \"address\":  \"192.168.120.26\",\n#                       \"portValue\":  8080\n#                     }\n#                   }\n#                 },\n#                 \"healthStatus\":  \"HEALTHY\"\n#               }\n#             ],\n#             \"loadBalancingWeight\":  100\n#           }\n#         ]\n#       },\n#       \"lastUpdated\":  \"2021-03-31T01:20:33.936Z\",\n#       \"clientStatus\":  \"ACKED\"\n#     }\n#   ]\n# }\n```\n\n## Admin Services\n\n### gRPC Java:\n\n```diff\n--- a/examples/src/main/java/io/grpc/examples/helloworld/HelloWorldServer.java\n+++ b/examples/src/main/java/io/grpc/examples/helloworld/HelloWorldServer.java\n@@ -18,6 +18,7 @@ package io.grpc.examples.helloworld;\n\n import io.grpc.Server;\n import io.grpc.ServerBuilder;\n+import io.grpc.services.AdminInterface;\n import io.grpc.stub.StreamObserver;\n import java.io.IOException;\n import java.util.concurrent.TimeUnit;\n@@ -36,6 +37,7 @@ public class HelloWorldServer {\n     int port = 50051;\n     server = ServerBuilder.forPort(port)\n         .addService(new GreeterImpl())\n+        .addServices(AdminInterface.getStandardServices())\n         .build()\n         .start();\n     logger.info(\"Server started, listening on \" + port);\n```\n\n\n### gRPC Go:\n\n```diff\n--- a/examples/helloworld/greeter_server/main.go\n+++ b/examples/helloworld/greeter_server/main.go\n@@ -27,6 +27,7 @@ import (\n        \"net\"\n\n        \"google.golang.org/grpc\"\n+       \"google.golang.org/grpc/admin\"\n        pb \"google.golang.org/grpc/examples/helloworld/helloworld\"\n )\n\n@@ -51,6 +52,11 @@ func main() {\n                log.Fatalf(\"failed to listen: %v\", err)\n        }\n        s := grpc.NewServer()\n+       cleanup, err := admin.Register(s)\n+       if err != nil {\n+               log.Fatalf(\"failed to register admin: %v\", err)\n+       }\n+       defer cleanup()\n        pb.RegisterGreeterServer(s, &server{})\n        if err := s.Serve(lis); err != nil {\n                log.Fatalf(\"failed to serve: %v\", err)\n```\n\n\n### gRPC C++:\n\n```diff\n--- a/examples/cpp/helloworld/greeter_server.cc\n+++ b/examples/cpp/helloworld/greeter_server.cc\n@@ -20,6 +20,7 @@\n #include <memory>\n #include <string>\n\n+#include <grpcpp/ext/admin_services.h>\n #include <grpcpp/ext/proto_server_reflection_plugin.h>\n #include <grpcpp/grpcpp.h>\n #include <grpcpp/health_check_service_interface.h>\n@@ -60,6 +61,7 @@ void RunServer() {\n   // Register \"service\" as the instance through which we'll communicate with\n   // clients. In this case it corresponds to an *synchronous* service.\n   builder.RegisterService(&service);\n+  grpc::AddAdminServices(&builder);\n   // Finally assemble the server.\n   std::unique_ptr<Server> server(builder.BuildAndStart());\n   std::cout << \"Server listening on \" << server_address << std::endl;\n```\n\n"
  },
  {
    "path": "cmd/channelz.go",
    "content": "package cmd\n\nimport (\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"net\"\n\t\"strconv\"\n\t\"time\"\n\n\t\"github.com/dustin/go-humanize\"\n\t\"github.com/grpc-ecosystem/grpcdebug/cmd/transport\"\n\t\"github.com/grpc-ecosystem/grpcdebug/cmd/verbose\"\n\t\"github.com/spf13/cobra\"\n\tzpb \"google.golang.org/grpc/channelz/grpc_channelz_v1\"\n\ttimestamppb \"google.golang.org/protobuf/types/known/timestamppb\"\n)\n\nvar (\n\tjsonOutputFlag bool\n\tstartIDFlag    int64\n\tmaxResultsFlag int64\n)\n\nfunc prettyTime(ts *timestamppb.Timestamp) string {\n\tif ts == nil || (ts.Seconds == 0 && ts.Nanos == 0) {\n\t\treturn \"\"\n\t}\n\tif timestampFlag {\n\t\treturn ts.AsTime().Format(time.RFC3339Nano)\n\t}\n\treturn humanize.Time(ts.AsTime())\n}\n\nfunc prettyAddress(addr *zpb.Address) string {\n\tif ipPort := addr.GetTcpipAddress(); ipPort != nil {\n\t\taddress := net.TCPAddr{IP: net.IP(ipPort.IpAddress), Port: int(ipPort.Port)}\n\t\treturn address.String()\n\t}\n\tpanic(fmt.Sprintf(\"Address type not supported for %s\", addr))\n}\n\nfunc printChannelTraceEvents(events []*zpb.ChannelTraceEvent) {\n\tfmt.Fprintln(w, \"Severity\\tTime\\tChild Ref\\tDescription\\t\")\n\tfor _, event := range events {\n\t\tvar childRef string\n\t\tswitch event.ChildRef.(type) {\n\t\tcase *zpb.ChannelTraceEvent_SubchannelRef:\n\t\t\tchildRef = fmt.Sprintf(\"subchannel(%v)\", event.GetSubchannelRef())\n\t\tcase *zpb.ChannelTraceEvent_ChannelRef:\n\t\t\tchildRef = fmt.Sprintf(\"channel(%v)\", event.GetChannelRef())\n\t\t}\n\t\tfmt.Fprintf(\n\t\t\tw, \"%v\\t%v\\t%v\\t%v\\t\\n\",\n\t\t\tevent.Severity,\n\t\t\tprettyTime(event.Timestamp),\n\t\t\tchildRef,\n\t\t\tevent.Description,\n\t\t)\n\t}\n\tw.Flush()\n}\n\nfunc printSockets(sockets []*zpb.Socket) {\n\tfmt.Fprintln(w, \"Socket ID\\tLocal->Remote\\tStreams(Started/Succeeded/Failed)\\tMessages(Sent/Received)\\t\")\n\tfor _, socket := range sockets {\n\t\tif socket.GetRef() == nil || socket.GetData() == nil {\n\t\t\tverbose.Debugf(\"failed to print socket: %s\", socket)\n\t\t\tcontinue\n\t\t}\n\t\tfmt.Fprintf(\n\t\t\tw, \"%v\\t%v\\t%v/%v/%v\\t%v/%v\\t\\n\",\n\t\t\tsocket.Ref.SocketId,\n\t\t\tfmt.Sprintf(\"%v->%v\", prettyAddress(socket.Local), prettyAddress(socket.Remote)),\n\t\t\tsocket.Data.StreamsStarted,\n\t\t\tsocket.Data.StreamsSucceeded,\n\t\t\tsocket.Data.StreamsFailed,\n\t\t\tsocket.Data.MessagesSent,\n\t\t\tsocket.Data.MessagesReceived,\n\t\t)\n\t}\n\tw.Flush()\n}\n\nfunc printObjectAsJSON(data any) error {\n\tjson, err := json.MarshalIndent(data, \"\", \"  \")\n\tif err != nil {\n\t\treturn err\n\t}\n\tfmt.Println(string(json))\n\treturn nil\n}\n\nfunc printCreationTimestamp(data *zpb.ChannelData) string {\n\treturn prettyTime(data.GetTrace().GetCreationTimestamp())\n}\n\nfunc channelzChannelsCommandRunWithError(cmd *cobra.Command, args []string) error {\n\tvar channels = transport.Channels(startIDFlag, maxResultsFlag)\n\t// Print as JSON\n\tif jsonOutputFlag {\n\t\treturn printObjectAsJSON(channels)\n\t}\n\t// Print as table\n\tfmt.Fprintln(w, \"Channel ID\\tTarget\\tState\\tCalls(Started/Succeeded/Failed)\\tCreated Time\\t\")\n\tfor _, channel := range channels {\n\t\tif channel.GetRef() == nil || channel.GetData() == nil {\n\t\t\tverbose.Debugf(\"failed to print channel: %s\", channel)\n\t\t\tcontinue\n\t\t}\n\t\tfmt.Fprintf(\n\t\t\tw, \"%v\\t%v\\t%v\\t%v/%v/%v\\t%v\\t\\n\",\n\t\t\tchannel.Ref.ChannelId,\n\t\t\tchannel.Data.Target,\n\t\t\tchannel.Data.GetState().GetState(),\n\t\t\tchannel.Data.CallsStarted,\n\t\t\tchannel.Data.CallsSucceeded,\n\t\t\tchannel.Data.CallsFailed,\n\t\t\tprintCreationTimestamp(channel.Data),\n\t\t)\n\t}\n\tw.Flush()\n\treturn nil\n}\n\nvar channelzChannelsCmd = &cobra.Command{\n\tUse:   \"channels\",\n\tShort: \"List client channels for the target application.\",\n\tArgs:  cobra.NoArgs,\n\tRunE:  channelzChannelsCommandRunWithError,\n}\n\nfunc channelzChannelCommandRunWithError(cmd *cobra.Command, args []string) error {\n\tid, err := strconv.ParseInt(args[0], 10, 64)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"Failed to parse ID=%v: %v\", args[0], err)\n\t}\n\tselected := transport.Channel(id)\n\t// Print as JSON\n\tif jsonOutputFlag {\n\t\treturn printObjectAsJSON(selected)\n\t}\n\t// Print as table\n\t// Print Channel information\n\tfmt.Fprintf(w, \"Channel ID:\\t%v\\t\\n\", selected.GetRef().GetChannelId())\n\tfmt.Fprintf(w, \"Target:\\t%v\\t\\n\", selected.GetData().GetTarget())\n\tfmt.Fprintf(w, \"State:\\t%v\\t\\n\", selected.GetData().GetState().GetState())\n\tfmt.Fprintf(w, \"Calls Started:\\t%v\\t\\n\", selected.GetData().GetCallsStarted())\n\tfmt.Fprintf(w, \"Calls Succeeded:\\t%v\\t\\n\", selected.GetData().GetCallsSucceeded())\n\tfmt.Fprintf(w, \"Calls Failed:\\t%v\\t\\n\", selected.GetData().GetCallsFailed())\n\tfmt.Fprintf(w, \"Created Time:\\t%v\\t\\n\", printCreationTimestamp(selected.GetData()))\n\tw.Flush()\n\t// Print Subchannel list\n\tif len(selected.GetSubchannelRef()) > 0 {\n\t\tfmt.Println(\"---\")\n\t\tfmt.Fprintln(w, \"Subchannel ID\\tTarget\\tState\\tCalls(Started/Succeeded/Failed)\\tCreatedTime\\t\")\n\t\tfor _, subchannelRef := range selected.GetSubchannelRef() {\n\t\t\tvar subchannel = transport.Subchannel(subchannelRef.GetSubchannelId())\n\t\t\tif subchannel.GetRef() == nil || subchannel.GetData() == nil {\n\t\t\t\tverbose.Debugf(\"failed to print subchannel: %s\", subchannel)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tfmt.Fprintf(\n\t\t\t\tw, \"%v\\t%.50s\\t%v\\t%v/%v/%v\\t%v\\t\\n\",\n\t\t\t\tsubchannel.Ref.SubchannelId,\n\t\t\t\tsubchannel.Data.Target,\n\t\t\t\tsubchannel.Data.State.State,\n\t\t\t\tsubchannel.Data.CallsStarted,\n\t\t\t\tsubchannel.Data.CallsSucceeded,\n\t\t\t\tsubchannel.Data.CallsFailed,\n\t\t\t\tprintCreationTimestamp(subchannel.Data),\n\t\t\t)\n\t\t}\n\t\tw.Flush()\n\t}\n\t// Print channel trace events\n\tif len(selected.GetData().GetTrace().GetEvents()) != 0 {\n\t\tfmt.Println(\"---\")\n\t\tprintChannelTraceEvents(selected.Data.Trace.Events)\n\t}\n\treturn nil\n}\n\nvar channelzChannelCmd = &cobra.Command{\n\tUse:   \"channel <channel id or URL>\",\n\tShort: \"Display channel states in a human readable way.\",\n\tArgs:  cobra.ExactArgs(1),\n\tRunE:  channelzChannelCommandRunWithError,\n}\n\nfunc channelzSubchannelCommandRunWithError(cmd *cobra.Command, args []string) error {\n\tid, err := strconv.ParseInt(args[0], 10, 64)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"Failed to parse ID=%v: %v\", args[0], err)\n\t}\n\tselected := transport.Subchannel(id)\n\t// Print as JSON\n\tif jsonOutputFlag {\n\t\treturn printObjectAsJSON(selected)\n\t}\n\t// Print as table\n\t// Print Subchannel information\n\tfmt.Fprintf(w, \"Subchannel ID:\\t%v\\t\\n\", selected.GetRef().GetSubchannelId())\n\tfmt.Fprintf(w, \"Target:\\t%v\\t\\n\", selected.GetData().GetTarget())\n\tfmt.Fprintf(w, \"State:\\t%v\\t\\n\", selected.GetData().GetState().GetState())\n\tfmt.Fprintf(w, \"Calls Started:\\t%v\\t\\n\", selected.GetData().GetCallsStarted())\n\tfmt.Fprintf(w, \"Calls Succeeded:\\t%v\\t\\n\", selected.GetData().GetCallsSucceeded())\n\tfmt.Fprintf(w, \"Calls Failed:\\t%v\\t\\n\", selected.GetData().GetCallsFailed())\n\tfmt.Fprintf(w, \"Created Time:\\t%v\\t\\n\", printCreationTimestamp(selected.GetData()))\n\tw.Flush()\n\tif len(selected.SocketRef) > 0 {\n\t\t// Print socket list\n\t\tfmt.Println(\"---\")\n\t\tvar sockets []*zpb.Socket\n\t\tfor _, socketRef := range selected.GetSocketRef() {\n\t\t\tsockets = append(sockets, transport.Socket(socketRef.GetSocketId()))\n\t\t}\n\t\tprintSockets(sockets)\n\t}\n\treturn nil\n}\n\nvar channelzSubchannelCmd = &cobra.Command{\n\tUse:   \"subchannel <id>\",\n\tShort: \"Display subchannel states in a human readable way.\",\n\tArgs:  cobra.ExactArgs(1),\n\tRunE:  channelzSubchannelCommandRunWithError,\n}\n\nfunc channelzSocketCommandRunWithError(cmd *cobra.Command, args []string) error {\n\tsocketID, err := strconv.ParseInt(args[0], 10, 64)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"Invalid socket ID %v\", socketID)\n\t}\n\tselected := transport.Socket(socketID)\n\t// Print as JSON\n\tif jsonOutputFlag {\n\t\treturn printObjectAsJSON(selected)\n\t}\n\t// Print as table\n\t// Print Socket information\n\tfmt.Fprintf(w, \"Socket ID:\\t%v\\t\\n\", selected.GetRef().GetSocketId())\n\tfmt.Fprintf(w, \"Address:\\t%v\\t\\n\", fmt.Sprintf(\"%v->%v\", prettyAddress(selected.GetLocal()), prettyAddress(selected.GetRemote())))\n\tfmt.Fprintf(w, \"Streams Started:\\t%v\\t\\n\", selected.GetData().GetStreamsStarted())\n\tfmt.Fprintf(w, \"Streams Succeeded:\\t%v\\t\\n\", selected.GetData().GetStreamsSucceeded())\n\tfmt.Fprintf(w, \"Streams Failed:\\t%v\\t\\n\", selected.GetData().GetStreamsFailed())\n\tfmt.Fprintf(w, \"Messages Sent:\\t%v\\t\\n\", selected.GetData().GetMessagesSent())\n\tfmt.Fprintf(w, \"Messages Received:\\t%v\\t\\n\", selected.GetData().GetMessagesReceived())\n\tfmt.Fprintf(w, \"Keep Alives Sent:\\t%v\\t\\n\", selected.GetData().GetKeepAlivesSent())\n\tfmt.Fprintf(w, \"Last Local Stream Created:\\t%v\\t\\n\", prettyTime(selected.GetData().GetLastLocalStreamCreatedTimestamp()))\n\tfmt.Fprintf(w, \"Last Remote Stream Created:\\t%v\\t\\n\", prettyTime(selected.GetData().GetLastRemoteStreamCreatedTimestamp()))\n\tfmt.Fprintf(w, \"Last Message Sent Created:\\t%v\\t\\n\", prettyTime(selected.GetData().GetLastMessageSentTimestamp()))\n\tfmt.Fprintf(w, \"Last Message Received Created:\\t%v\\t\\n\", prettyTime(selected.GetData().GetLastMessageReceivedTimestamp()))\n\tfmt.Fprintf(w, \"Local Flow Control Window:\\t%v\\t\\n\", selected.GetData().GetLocalFlowControlWindow().GetValue())\n\tfmt.Fprintf(w, \"Remote Flow Control Window:\\t%v\\t\\n\", selected.GetData().GetRemoteFlowControlWindow().GetValue())\n\tw.Flush()\n\tif len(selected.GetData().GetOption()) > 0 {\n\t\tfmt.Println(\"---\")\n\t\tfmt.Fprintln(w, \"Socket Options Name\\tValue\\t\")\n\t\tfor _, option := range selected.GetData().GetOption() {\n\t\t\tif option.GetValue() != \"\" {\n\t\t\t\t// Prefer human readable value than the Any proto\n\t\t\t\tfmt.Fprintf(w, \"%v\\t%v\\t\\n\", option.GetName(), option.GetValue())\n\t\t\t} else {\n\t\t\t\tfmt.Fprintf(w, \"%v\\t%v\\t\\n\", option.GetName(), option.GetAdditional())\n\t\t\t}\n\t\t}\n\t\tw.Flush()\n\t}\n\t// Print security information\n\tif security := selected.GetSecurity(); security != nil {\n\t\tfmt.Println(\"---\")\n\t\tswitch x := security.Model.(type) {\n\t\tcase *zpb.Security_Tls_:\n\t\t\tfmt.Fprintf(w, \"Security Model:\\t%v\\t\\n\", \"TLS\")\n\t\t\tswitch y := security.GetTls().GetCipherSuite().(type) {\n\t\t\tcase *zpb.Security_Tls_StandardName:\n\t\t\t\tfmt.Fprintf(w, \"Standard Name:\\t%v\\t\\n\", security.GetTls().GetStandardName())\n\t\t\tcase *zpb.Security_Tls_OtherName:\n\t\t\t\tfmt.Fprintf(w, \"Other Name:\\t%v\\t\\n\", security.GetTls().GetOtherName())\n\t\t\tdefault:\n\t\t\t\treturn fmt.Errorf(\"Unexpected Cipher suite name type %T\", y)\n\t\t\t}\n\t\t\t// fmt.Fprintf(w, \"Local Certificate:\\t%v\\t\\n\", security.GetTls().LocalCertificate)\n\t\t\t// fmt.Fprintf(w, \"Remote Certificate:\\t%v\\t\\n\", security.GetTls().RemoteCertificate)\n\t\tcase *zpb.Security_Other:\n\t\t\tfmt.Fprintf(w, \"Security Model:\\t%v\\t\\n\", \"Other\")\n\t\t\tfmt.Fprintf(w, \"Name:\\t%v\\t\\n\", security.GetOther().GetName())\n\t\t\t// fmt.Fprintf(w, \"Value:\\t%v\\t\\n\", security.GetOther().Value)\n\t\tdefault:\n\t\t\treturn fmt.Errorf(\"Unexpected security model type %T\", x)\n\t\t}\n\t\tw.Flush()\n\t}\n\treturn nil\n}\n\nvar channelzSocketCmd = &cobra.Command{\n\tUse:   \"socket <id>\",\n\tShort: \"Display socket states in a human readable way.\",\n\tArgs:  cobra.ExactArgs(1),\n\tRunE:  channelzSocketCommandRunWithError,\n}\n\nfunc channelzServersCommandRunWithError(cmd *cobra.Command, args []string) error {\n\tvar servers = transport.Servers(startIDFlag, maxResultsFlag)\n\t// Print as JSON\n\tif jsonOutputFlag {\n\t\treturn printObjectAsJSON(servers)\n\t}\n\t// Print as table\n\tfmt.Fprintln(w, \"Server ID\\tListen Addresses\\tCalls(Started/Succeeded/Failed)\\tLast Call Started\\t\")\n\tfor _, server := range servers {\n\t\tvar listenAddresses []string\n\t\tfor _, socketRef := range server.GetListenSocket() {\n\t\t\tsocket := transport.Socket(socketRef.SocketId)\n\t\t\tlistenAddresses = append(listenAddresses, prettyAddress(socket.GetLocal()))\n\t\t}\n\t\tfmt.Fprintf(\n\t\t\tw, \"%v\\t%v\\t%v/%v/%v\\t%v\\t\\n\",\n\t\t\tserver.GetRef().GetServerId(),\n\t\t\tlistenAddresses,\n\t\t\tserver.GetData().GetCallsStarted(),\n\t\t\tserver.GetData().GetCallsSucceeded(),\n\t\t\tserver.GetData().GetCallsFailed(),\n\t\t\tprettyTime(server.GetData().GetLastCallStartedTimestamp()),\n\t\t)\n\t}\n\tw.Flush()\n\treturn nil\n}\n\nvar channelzServersCmd = &cobra.Command{\n\tUse:   \"servers\",\n\tShort: \"List servers in a human readable way.\",\n\tArgs:  cobra.NoArgs,\n\tRunE:  channelzServersCommandRunWithError,\n}\n\nfunc channelzServerCommandRunWithError(cmd *cobra.Command, args []string) error {\n\tserverID, err := strconv.ParseInt(args[0], 10, 64)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"Invalid server ID %v\", serverID)\n\t}\n\tselected := transport.Server(serverID)\n\t// Print as JSON\n\tif jsonOutputFlag {\n\t\treturn printObjectAsJSON(selected)\n\t}\n\t// Print as table\n\tvar listenAddresses []string\n\tfor _, socketRef := range selected.GetListenSocket() {\n\t\tsocket := transport.Socket(socketRef.GetSocketId())\n\t\tlistenAddresses = append(listenAddresses, prettyAddress(socket.GetLocal()))\n\t}\n\tfmt.Fprintf(w, \"Server Id:\\t%v\\t\\n\", selected.GetRef().GetServerId())\n\tfmt.Fprintf(w, \"Listen Addresses:\\t%v\\t\\n\", listenAddresses)\n\tfmt.Fprintf(w, \"Calls Started:\\t%v\\t\\n\", selected.GetData().GetCallsStarted())\n\tfmt.Fprintf(w, \"Calls Succeeded:\\t%v\\t\\n\", selected.GetData().GetCallsSucceeded())\n\tfmt.Fprintf(w, \"Calls Failed:\\t%v\\t\\n\", selected.GetData().GetCallsFailed())\n\tfmt.Fprintf(w, \"Last Call Started:\\t%v\\t\\n\", prettyTime(selected.GetData().GetLastCallStartedTimestamp()))\n\tw.Flush()\n\tif sockets := transport.ServerSocket(selected.GetRef().GetServerId(), startIDFlag, maxResultsFlag); len(sockets) > 0 {\n\t\t// Print socket list\n\t\tfmt.Println(\"---\")\n\t\tprintSockets(sockets)\n\t}\n\treturn nil\n}\n\nvar channelzServerCmd = &cobra.Command{\n\tUse:   \"server <id>\",\n\tShort: \"Display the server state in a human readable way.\",\n\tArgs:  cobra.ExactArgs(1),\n\tRunE:  channelzServerCommandRunWithError,\n}\n\nvar channelzCmd = &cobra.Command{\n\tUse:   \"channelz\",\n\tShort: \"Display gRPC states in a human readable way.\",\n\tArgs:  cobra.NoArgs,\n}\n\nfunc init() {\n\trootCmd.AddCommand(channelzCmd)\n\tchannelzChannelsCmd.Flags().Int64VarP(&maxResultsFlag, \"max_results\", \"m\", 100, \"The maximum number of output channels\")\n\tchannelzChannelsCmd.Flags().Int64VarP(&startIDFlag, \"start_id\", \"s\", 0, \"The start channel ID\")\n\tchannelzServerCmd.Flags().Int64VarP(&maxResultsFlag, \"max_results\", \"m\", 100, \"The maximum number of the output sockets\")\n\tchannelzServerCmd.Flags().Int64VarP(&startIDFlag, \"start_id\", \"s\", 0, \"The start server socket ID\")\n\tchannelzServersCmd.Flags().Int64VarP(&maxResultsFlag, \"max_results\", \"m\", 100, \"The maximum number of output servers\")\n\tchannelzServersCmd.Flags().Int64VarP(&startIDFlag, \"start_id\", \"s\", 0, \"The start server ID\")\n\tchannelzCmd.PersistentFlags().BoolVarP(&jsonOutputFlag, \"json\", \"o\", false, \"Whether to print the result as JSON\")\n\tchannelzCmd.AddCommand(channelzChannelCmd)\n\tchannelzCmd.AddCommand(channelzChannelsCmd)\n\tchannelzCmd.AddCommand(channelzSubchannelCmd)\n\tchannelzCmd.AddCommand(channelzSocketCmd)\n\tchannelzCmd.AddCommand(channelzServersCmd)\n\tchannelzCmd.AddCommand(channelzServerCmd)\n}\n"
  },
  {
    "path": "cmd/config/config.go",
    "content": "package config\n\nimport (\n\t\"errors\"\n\t\"io\"\n\t\"os\"\n\t\"path\"\n\t\"runtime\"\n\n\t\"github.com/grpc-ecosystem/grpcdebug/cmd/verbose\"\n\t\"gopkg.in/yaml.v2\"\n)\n\n// SecurityType is the enum type of available security modes\ntype SecurityType string\n\nconst (\n\t// TypeInsecure is the insecure security mode and it is the default value\n\tTypeInsecure SecurityType = \"insecure\"\n\t// TypeTLS is the TLS security mode, which requires caller to provide\n\t// credentials to connect to peer\n\tTypeTLS = \"tls\"\n)\n\n// The environment variable name of getting the server configs\nconst grpcdebugServerConfigEnvName = \"GRPCDEBUG_CONFIG\"\n\n// ServerConfig is the configuration for how to connect to a target\ntype ServerConfig struct {\n\tRealAddress        string       `yaml:\"real_address\"`\n\tSecurity           SecurityType `yaml:\"security\"`\n\tCredentialFile     string       `yaml:\"credential_file\"`\n\tServerNameOverride string       `yaml:\"server_name_override\"`\n}\n\ntype grpcdebugConfig struct {\n\tServers map[string]ServerConfig `yaml:\"servers\"`\n}\n\nfunc loadServerConfigsFromFile(path string) map[string]ServerConfig {\n\tfile, err := os.Open(path)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tbytes, err := io.ReadAll(file)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tvar config grpcdebugConfig\n\terr = yaml.Unmarshal(bytes, &config)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tverbose.Debugf(\"Loaded grpcdebug config from %v: %v\", path, config)\n\treturn config.Servers\n}\n\n// userConfigDir is copied here, so we can support Go v1.12\nfunc userConfigDir() (string, error) {\n\tvar dir string\n\tswitch runtime.GOOS {\n\tcase \"windows\":\n\t\tdir = os.Getenv(\"AppData\")\n\t\tif dir == \"\" {\n\t\t\treturn \"\", errors.New(\"%AppData% is not defined\")\n\t\t}\n\n\tcase \"darwin\", \"ios\":\n\t\tdir = os.Getenv(\"HOME\")\n\t\tif dir == \"\" {\n\t\t\treturn \"\", errors.New(\"$HOME is not defined\")\n\t\t}\n\t\tdir += \"/Library/Application Support\"\n\n\tcase \"plan9\":\n\t\tdir = os.Getenv(\"home\")\n\t\tif dir == \"\" {\n\t\t\treturn \"\", errors.New(\"$home is not defined\")\n\t\t}\n\t\tdir += \"/lib\"\n\n\tdefault: // Unix\n\t\tdir = os.Getenv(\"XDG_CONFIG_HOME\")\n\t\tif dir == \"\" {\n\t\t\tdir = os.Getenv(\"HOME\")\n\t\t\tif dir == \"\" {\n\t\t\t\treturn \"\", errors.New(\"neither $XDG_CONFIG_HOME nor $HOME are defined\")\n\t\t\t}\n\t\t\tdir += \"/.config\"\n\t\t}\n\t}\n\treturn dir, nil\n}\n\nfunc loadServerConfigs() map[string]ServerConfig {\n\tif value := os.Getenv(grpcdebugServerConfigEnvName); value != \"\" {\n\t\treturn loadServerConfigsFromFile(value)\n\t}\n\t// Try to load from work directory, if exists\n\tif _, err := os.Stat(\"./grpcdebug_config.yaml\"); err == nil {\n\t\treturn loadServerConfigsFromFile(\"./grpcdebug_config.yaml\")\n\t}\n\t// Try to load from user config directory, if exists\n\tdir, _ := userConfigDir()\n\tdefaultUserConfig := path.Join(dir, \"grpcdebug_config.yaml\")\n\tif _, err := os.Stat(defaultUserConfig); err == nil {\n\t\treturn loadServerConfigsFromFile(defaultUserConfig)\n\t}\n\treturn nil\n}\n\n// GetServerConfig returns a connect configuration for the given target\nfunc GetServerConfig(target string) ServerConfig {\n\tfor pattern, config := range loadServerConfigs() {\n\t\t// TODO(lidiz): support wildcards\n\t\tif pattern == target {\n\t\t\tif config.RealAddress == \"\" {\n\t\t\t\tconfig.RealAddress = pattern\n\t\t\t}\n\t\t\treturn config\n\t\t}\n\t}\n\treturn ServerConfig{RealAddress: target}\n}\n"
  },
  {
    "path": "cmd/health.go",
    "content": "package cmd\n\nimport (\n\t\"fmt\"\n\t\"sort\"\n\n\t\"github.com/grpc-ecosystem/grpcdebug/cmd/transport\"\n\t\"github.com/spf13/cobra\"\n)\n\nvar healthCmd = &cobra.Command{\n\tUse:   \"health [service names]\",\n\tShort: \"Check health status of the target service (default \\\"\\\").\",\n\tRunE: func(cmd *cobra.Command, args []string) error {\n\t\tvar services []string\n\t\t// Ensure there's the overall health status\n\t\tservices = append(services, \"\")\n\t\tservices = append(services, args...)\n\t\t// Sort alphabetically, and deduplicate inputs\n\t\tsort.Strings(services)\n\t\tj := 0\n\t\tfor i := 1; i < len(services); i++ {\n\t\t\tif services[i] == services[j] {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tj++\n\t\t\tservices[j] = services[i]\n\t\t}\n\t\tservices = services[:j+1]\n\t\t// Print as table\n\t\tfor _, service := range services {\n\t\t\tvar serviceName string\n\t\t\tif service == \"\" {\n\t\t\t\tserviceName = \"<Overall>\"\n\t\t\t} else {\n\t\t\t\tserviceName = service\n\t\t\t}\n\t\t\tfmt.Fprintf(\n\t\t\t\tw, \"%v:\\t%v\\t\\n\",\n\t\t\t\tserviceName,\n\t\t\t\ttransport.GetHealthStatus(service),\n\t\t\t)\n\t\t}\n\t\tw.Flush()\n\t\treturn nil\n\t},\n}\n\nfunc init() {\n\trootCmd.AddCommand(healthCmd)\n}\n"
  },
  {
    "path": "cmd/root.go",
    "content": "// Defines the root command and global flags\n\npackage cmd\n\nimport (\n\t\"fmt\"\n\t\"log\"\n\t\"os\"\n\t\"text/tabwriter\"\n\n\t\"github.com/grpc-ecosystem/grpcdebug/cmd/config\"\n\t\"github.com/grpc-ecosystem/grpcdebug/cmd/transport\"\n\t\"github.com/grpc-ecosystem/grpcdebug/cmd/verbose\"\n\n\t\"github.com/spf13/cobra\"\n)\n\nvar verboseFlag, timestampFlag bool\nvar address, security, credFile, serverNameOverride string\n\n// The table formater\nvar w = tabwriter.NewWriter(os.Stdout, 10, 0, 3, ' ', 0)\n\nvar rootUsageTemplate = `Usage:{{if .Runnable}}\n  {{.UseLine}}{{end}}{{if .HasAvailableSubCommands}}\n  grpcdebug <target address> [flags] {{ .CommandPath | ChildCommandPath }} <command>{{end}}{{if gt (len .Aliases) 0}}\n\nAliases:\n  {{.NameAndAliases}}{{end}}{{if .HasExample}}\n\nExamples:\n{{.Example}}{{end}}{{if .HasAvailableSubCommands}}\n\nAvailable Commands:{{range .Commands}}{{if (or .IsAvailableCommand (eq .Name \"help\"))}}\n  {{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}{{end}}{{if .HasAvailableLocalFlags}}\n\nFlags:\n{{.LocalFlags.FlagUsages | trimTrailingWhitespaces}}{{end}}{{if .HasAvailableInheritedFlags}}\n\nGlobal Flags:\n{{.InheritedFlags.FlagUsages | trimTrailingWhitespaces}}{{end}}{{if .HasHelpSubCommands}}\n\nAdditional help topics:{{range .Commands}}{{if .IsAdditionalHelpTopicCommand}}\n  {{rpad .CommandPath .CommandPathPadding}} {{.Short}}{{end}}{{end}}{{end}}{{if .HasAvailableSubCommands}}\n\nUse \"grpcdebug <target address> {{ .CommandPath | ChildCommandPath }} [command] --help\" for more information about a command.{{end}}\n`\n\nvar rootCmd = &cobra.Command{\n\tUse:   \"grpcdebug\",\n\tShort: \"grpcdebug is a gRPC service admin CLI\",\n}\n\nfunc initConfig() {\n\tif verboseFlag {\n\t\tverbose.EnableDebugOutput()\n\t}\n\tc := config.GetServerConfig(address)\n\tif credFile != \"\" {\n\t\tc.CredentialFile = credFile\n\t}\n\tif serverNameOverride != \"\" {\n\t\tc.ServerNameOverride = serverNameOverride\n\t}\n\tif security == \"tls\" {\n\t\tc.Security = config.TypeTLS\n\t\tif c.CredentialFile == \"\" {\n\t\t\trootCmd.Usage()\n\t\t\tlog.Fatalf(\"Please specify credential file under [tls] mode.\")\n\t\t}\n\t} else if security != \"insecure\" {\n\t\trootCmd.Usage()\n\t\tlog.Fatalf(\"Unrecognized security mode: %v\", security)\n\t}\n\ttransport.Connect(c)\n}\n\n// ChildCommandPath used in template\nfunc ChildCommandPath(path string) string {\n\tif len(path) <= 10 {\n\t\treturn \"\"\n\t}\n\treturn path[10:]\n}\n\nfunc init() {\n\tcobra.AddTemplateFunc(\"ChildCommandPath\", ChildCommandPath)\n\tcobra.OnInitialize(initConfig)\n\trootCmd.SetUsageTemplate(rootUsageTemplate)\n\n\trootCmd.PersistentFlags().BoolVarP(&verboseFlag, \"verbose\", \"v\", false, \"Print verbose information for debugging\")\n\trootCmd.PersistentFlags().BoolVarP(&timestampFlag, \"timestamp\", \"t\", false, \"Print timestamp as RFC3339 instead of human readable strings\")\n\trootCmd.PersistentFlags().StringVar(&security, \"security\", \"insecure\", \"Defines the type of credentials to use [tls, google-default, insecure]\")\n\trootCmd.PersistentFlags().StringVar(&credFile, \"credential_file\", \"\", \"Sets the path of the credential file; used in [tls] mode\")\n\trootCmd.PersistentFlags().StringVar(&serverNameOverride, \"server_name_override\", \"\", \"Overrides the peer server name if non empty; used in [tls] mode\")\n}\n\n// Execute executes the root command.\nfunc Execute() {\n\tif len(os.Args) > 1 {\n\t\taddress = os.Args[1]\n\t\tos.Args = os.Args[1:]\n\t} else {\n\t\trootCmd.Usage()\n\t\tos.Exit(1)\n\t}\n\tif err := rootCmd.Execute(); err != nil {\n\t\tfmt.Println(err)\n\t\tos.Exit(1)\n\t}\n}\n"
  },
  {
    "path": "cmd/transport/grpc.go",
    "content": "package transport\n\nimport (\n\t\"context\"\n\t\"log\"\n\t\"time\"\n\n\tcsdspb \"github.com/envoyproxy/go-control-plane/envoy/service/status/v3\"\n\t\"github.com/grpc-ecosystem/grpcdebug/cmd/config\"\n\t\"github.com/grpc-ecosystem/grpcdebug/cmd/verbose\"\n\t\"google.golang.org/grpc\"\n\tzpb \"google.golang.org/grpc/channelz/grpc_channelz_v1\"\n\t\"google.golang.org/grpc/credentials\"\n\t\"google.golang.org/grpc/credentials/insecure\"\n\thealthpb \"google.golang.org/grpc/health/grpc_health_v1\"\n)\n\nvar conn *grpc.ClientConn\nvar channelzClient zpb.ChannelzClient\nvar csdsClient csdspb.ClientStatusDiscoveryServiceClient\nvar healthClient healthpb.HealthClient\n\nconst rpcTimeout = time.Second * 15\n\n// Connect connects to the service at address and creates stubs\nfunc Connect(c config.ServerConfig) {\n\tverbose.Debugf(\"Connecting with %v\", c)\n\tvar err error\n\tvar credOption grpc.DialOption\n\tif c.CredentialFile != \"\" {\n\t\tcred, err := credentials.NewClientTLSFromFile(c.CredentialFile, c.ServerNameOverride)\n\t\tif err != nil {\n\t\t\tlog.Fatalf(\"failed to create credential: %v\", err)\n\t\t}\n\t\tcredOption = grpc.WithTransportCredentials(cred)\n\t} else {\n\t\tcredOption = grpc.WithTransportCredentials(insecure.NewCredentials())\n\t}\n\tconn, err = grpc.NewClient(c.RealAddress, credOption)\n\tif err != nil {\n\t\tlog.Fatalf(\"failed to connect: %v\", err)\n\t}\n\tchannelzClient = zpb.NewChannelzClient(conn)\n\tcsdsClient = csdspb.NewClientStatusDiscoveryServiceClient(conn)\n\thealthClient = healthpb.NewHealthClient(conn)\n}\n\n// Channels returns all available channels\nfunc Channels(startID, maxResults int64) []*zpb.Channel {\n\tctx, cancel := context.WithTimeout(context.Background(), rpcTimeout)\n\tdefer cancel()\n\tchannels, err := channelzClient.GetTopChannels(ctx, &zpb.GetTopChannelsRequest{StartChannelId: startID, MaxResults: maxResults})\n\tif err != nil {\n\t\tlog.Fatalf(\"failed to fetch top channels: %v\", err)\n\t}\n\treturn channels.Channel\n}\n\n// Channel returns the channel with given channel ID\nfunc Channel(channelID int64) *zpb.Channel {\n\tctx, cancel := context.WithTimeout(context.Background(), rpcTimeout)\n\tdefer cancel()\n\tchannel, err := channelzClient.GetChannel(ctx, &zpb.GetChannelRequest{ChannelId: channelID})\n\tif err != nil {\n\t\tlog.Fatalf(\"failed to fetch channel id=%v: %v\", channelID, err)\n\t}\n\treturn channel.Channel\n}\n\n// Subchannel returns the queried subchannel\nfunc Subchannel(subchannelID int64) *zpb.Subchannel {\n\tctx, cancel := context.WithTimeout(context.Background(), rpcTimeout)\n\tdefer cancel()\n\tsubchannel, err := channelzClient.GetSubchannel(ctx, &zpb.GetSubchannelRequest{SubchannelId: subchannelID})\n\tif err != nil {\n\t\tlog.Fatalf(\"failed to fetch subchannel (id=%v): %v\", subchannelID, err)\n\t}\n\treturn subchannel.Subchannel\n}\n\n// Servers returns all available servers\nfunc Servers(startID, maxResults int64) []*zpb.Server {\n\tctx, cancel := context.WithTimeout(context.Background(), rpcTimeout)\n\tdefer cancel()\n\tservers, err := channelzClient.GetServers(ctx, &zpb.GetServersRequest{StartServerId: startID, MaxResults: maxResults})\n\tif err != nil {\n\t\tlog.Fatalf(\"failed to fetch servers: %v\", err)\n\t}\n\treturn servers.Server\n}\n\n// Server returns a server\nfunc Server(serverID int64) *zpb.Server {\n\tctx, cancel := context.WithTimeout(context.Background(), rpcTimeout)\n\tdefer cancel()\n\tserver, err := channelzClient.GetServer(ctx, &zpb.GetServerRequest{ServerId: serverID})\n\tif err != nil {\n\t\tlog.Fatalf(\"failed to fetch server (id=%v): %v\", serverID, err)\n\t}\n\treturn server.Server\n}\n\n// Socket returns a socket\nfunc Socket(socketID int64) *zpb.Socket {\n\tctx, cancel := context.WithTimeout(context.Background(), rpcTimeout)\n\tdefer cancel()\n\tsocket, err := channelzClient.GetSocket(ctx, &zpb.GetSocketRequest{SocketId: socketID})\n\tif err != nil {\n\t\tlog.Fatalf(\"failed to fetch socket (id=%v): %v\", socketID, err)\n\t}\n\treturn socket.Socket\n}\n\n// ServerSocket returns all sockets of this server\nfunc ServerSocket(serverID, startID, maxResults int64) []*zpb.Socket {\n\tctx, cancel := context.WithTimeout(context.Background(), rpcTimeout)\n\tdefer cancel()\n\tvar s []*zpb.Socket\n\tserverSocketResp, err := channelzClient.GetServerSockets(\n\t\tctx,\n\t\t&zpb.GetServerSocketsRequest{\n\t\t\tServerId:      serverID,\n\t\t\tStartSocketId: startID,\n\t\t\tMaxResults:    maxResults,\n\t\t},\n\t)\n\tif err != nil {\n\t\tlog.Fatalf(\"failed to fetch server sockets (id=%v): %v\", serverID, err)\n\t}\n\tfor _, socketRef := range serverSocketResp.SocketRef {\n\t\ts = append(s, Socket(socketRef.SocketId))\n\t}\n\treturn s\n}\n\n// FetchClientStatus fetches the xDS resources status\nfunc FetchClientStatus() *csdspb.ClientStatusResponse {\n\tctx, cancel := context.WithTimeout(context.Background(), rpcTimeout)\n\tdefer cancel()\n\tresp, err := csdsClient.FetchClientStatus(ctx, &csdspb.ClientStatusRequest{})\n\tif err != nil {\n\t\tlog.Fatalf(\"failed to fetch xds config: %v\", err)\n\t}\n\treturn resp\n}\n\n// GetHealthStatus fetches the health checking status of the service from peer\nfunc GetHealthStatus(service string) string {\n\tctx, cancel := context.WithTimeout(context.Background(), rpcTimeout)\n\tdefer cancel()\n\tresp, err := healthClient.Check(ctx, &healthpb.HealthCheckRequest{Service: service})\n\tif err != nil {\n\t\tverbose.Debugf(\"failed to fetch health status for \\\"%s\\\": %v\", service, err)\n\t\treturn healthpb.HealthCheckResponse_SERVICE_UNKNOWN.String()\n\t}\n\treturn resp.Status.String()\n}\n"
  },
  {
    "path": "cmd/verbose/verbose.go",
    "content": "package verbose\n\nimport \"log\"\n\nvar enableDebugOutput = false\n\n// EnableDebugOutput enables debugging output\nfunc EnableDebugOutput() {\n\tenableDebugOutput = true\n}\n\n// Debugf prints log if debugging is enabled\nfunc Debugf(format string, v ...any) {\n\tif enableDebugOutput {\n\t\tlog.Printf(format, v...)\n\t}\n}\n"
  },
  {
    "path": "cmd/xds.go",
    "content": "package cmd\n\nimport (\n\t\"fmt\"\n\t\"sort\"\n\t\"strings\"\n\n\t\"github.com/grpc-ecosystem/grpcdebug/cmd/transport\"\n\n\tadminpb \"github.com/envoyproxy/go-control-plane/envoy/admin/v3\"\n\tclusterpb \"github.com/envoyproxy/go-control-plane/envoy/config/cluster/v3\"\n\tendpointpb \"github.com/envoyproxy/go-control-plane/envoy/config/endpoint/v3\"\n\troutepb \"github.com/envoyproxy/go-control-plane/envoy/config/route/v3\"\n\tcsdspb \"github.com/envoyproxy/go-control-plane/envoy/service/status/v3\"\n\t\"github.com/spf13/cobra\"\n\ttimestamppb \"google.golang.org/protobuf/types/known/timestamppb\"\n\t\"google.golang.org/protobuf/encoding/protojson\"\n\t\"google.golang.org/protobuf/proto\"\n)\n\nvar (\n\txdsTypeFlag  string\n\txdsScopeFlag string\n)\n\nfunc printProtoBufMessageAsJSON(m proto.Message) error {\n\toption := protojson.MarshalOptions{\n\t\tMultiline:      true,\n\t\tIndent:         \"  \",\n\t\tUseProtoNames:  false,\n\t\tUseEnumNumbers: false,\n\t}\n\tjsonbytes, err := option.Marshal(m)\n\tif err != nil {\n\t\treturn err\n\t}\n\tfmt.Println(string(jsonbytes))\n\treturn nil\n}\n\nfunc priorityPerXdsConfig(x *csdspb.PerXdsConfig) int {\n\tswitch x.PerXdsConfig.(type) {\n\tcase *csdspb.PerXdsConfig_ListenerConfig:\n\t\treturn 0\n\tcase *csdspb.PerXdsConfig_RouteConfig:\n\t\treturn 1\n\tcase *csdspb.PerXdsConfig_ClusterConfig:\n\t\treturn 2\n\tcase *csdspb.PerXdsConfig_EndpointConfig:\n\t\treturn 3\n\tdefault:\n\t\treturn 4\n\t}\n}\n\nfunc sortPerXdsConfigs(clientStatus *csdspb.ClientStatusResponse) {\n\tfor _, cfg := range clientStatus.Config {\n\t\t// XdsConfig is deprecated but we support it for backward compatibility with older servers\n\t\tsort.Slice(cfg.XdsConfig, func(i, j int) bool {\n\t\t\treturn priorityPerXdsConfig(cfg.XdsConfig[i]) < priorityPerXdsConfig(cfg.XdsConfig[j])\n\t\t})\n\t}\n}\n\nfunc filterConfigsByScope(all []*csdspb.ClientConfig, scope string) ([]*csdspb.ClientConfig, error) {\n\tif scope == \"\" {\n\t\treturn all, nil\n\t}\n\tvar out []*csdspb.ClientConfig\n\tfor _, c := range all {\n\t\tif c.ClientScope == scope {\n\t\t\tout = append(out, c)\n\t\t}\n\t}\n\tif len(out) == 0 {\n\t\treturn nil, fmt.Errorf(\"no ClientConfig matched scope=%q\", scope)\n\t}\n\treturn out, nil\n}\n\nfunc xdsConfigCommandRunWithError(cmd *cobra.Command, args []string) error {\n\tclientStatus := transport.FetchClientStatus()\n\tif len(clientStatus.Config) == 0 {\n\t\treturn fmt.Errorf(\"no ClientConfig returned\")\n\t}\n\tsortPerXdsConfigs(clientStatus)\n\n\tconfigs, err := filterConfigsByScope(clientStatus.Config, xdsScopeFlag)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif xdsTypeFlag == \"\" {\n\t\t// Print whole response; if filtered by scope, print a shallow copy to reflect only filtered configs\n\t\tif len(configs) == len(clientStatus.Config) {\n\t\t\treturn printProtoBufMessageAsJSON(clientStatus)\n\t\t}\n\t\treturn printProtoBufMessageAsJSON(&csdspb.ClientStatusResponse{Config: configs})\n\t}\n\n\t// Parse --type and print resources for each selected config\n\twantXdsTypes := strings.Split(xdsTypeFlag, \",\")\n\tvar wantLDS, wantRDS, wantCDS, wantEDS bool\n\tfor _, t := range wantXdsTypes {\n\t\tswitch strings.ToLower(t) {\n\t\tcase \"lds\":\n\t\t\twantLDS = true\n\t\tcase \"rds\":\n\t\t\twantRDS = true\n\t\tcase \"cds\":\n\t\t\twantCDS = true\n\t\tcase \"eds\":\n\t\t\twantEDS = true\n\t\t}\n\t}\n\n\tmulti := len(configs) > 1\n\tfor _, cfg := range configs {\n\t\tif multi {\n\t\t\tfmt.Printf(\"== client_scope: %q ==\\n\", cfg.ClientScope)\n\t\t}\n\t\tif len(cfg.GenericXdsConfigs) > 0 {\n\t\t\tfor _, g := range cfg.GenericXdsConfigs {\n\t\t\t\tvar m proto.Message\n\t\t\t\ttokens := strings.Split(g.TypeUrl, \".\")\n\t\t\t\tswitch tokens[len(tokens)-1] {\n\t\t\t\tcase \"Listener\":\n\t\t\t\t\tif wantLDS {\n\t\t\t\t\t\tm = g.GetXdsConfig()\n\t\t\t\t\t}\n\t\t\t\tcase \"RouteConfiguration\":\n\t\t\t\t\tif wantRDS {\n\t\t\t\t\t\tm = g.GetXdsConfig()\n\t\t\t\t\t}\n\t\t\t\tcase \"Cluster\":\n\t\t\t\t\tif wantCDS {\n\t\t\t\t\t\tm = g.GetXdsConfig()\n\t\t\t\t\t}\n\t\t\t\tcase \"ClusterLoadAssignment\":\n\t\t\t\t\tif wantEDS {\n\t\t\t\t\t\tm = g.GetXdsConfig()\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif m != nil {\n\t\t\t\t\tif err := printProtoBufMessageAsJSON(m); err != nil {\n\t\t\t\t\t\treturn fmt.Errorf(\"Failed to print xDS config: %v\", err)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\t// XdsConfig is deprecated but we support it for backward compatibility with older servers\n\t\t\tfor _, x := range cfg.XdsConfig {\n\t\t\t\tvar m proto.Message\n\t\t\t\tswitch x.PerXdsConfig.(type) {\n\t\t\t\tcase *csdspb.PerXdsConfig_ListenerConfig:\n\t\t\t\t\tif wantLDS {\n\t\t\t\t\t\tm = x.GetListenerConfig()\n\t\t\t\t\t}\n\t\t\t\tcase *csdspb.PerXdsConfig_RouteConfig:\n\t\t\t\t\tif wantRDS {\n\t\t\t\t\t\tm = x.GetRouteConfig()\n\t\t\t\t\t}\n\t\t\t\tcase *csdspb.PerXdsConfig_ClusterConfig:\n\t\t\t\t\tif wantCDS {\n\t\t\t\t\t\tm = x.GetClusterConfig()\n\t\t\t\t\t}\n\t\t\t\tcase *csdspb.PerXdsConfig_EndpointConfig:\n\t\t\t\t\tif wantEDS {\n\t\t\t\t\t\tm = x.GetEndpointConfig()\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif m != nil {\n\t\t\t\t\tif err := printProtoBufMessageAsJSON(m); err != nil {\n\t\t\t\t\t\treturn fmt.Errorf(\"Failed to print xDS config: %v\", err)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn nil\n}\n\nvar xdsConfigCmd = &cobra.Command{\n\tUse:   \"config\",\n\tShort: \"Dump the operating xDS configs.\",\n\tRunE:  xdsConfigCommandRunWithError,\n\tArgs:  cobra.NoArgs,\n}\n\ntype xdsResourceStatusEntry struct {\n\tScope       string\n\tName        string\n\tStatus      adminpb.ClientResourceStatus\n\tVersion     string\n\tType        string\n\tLastUpdated *timestamppb.Timestamp\n}\n\nfunc printStatusEntry(entry *xdsResourceStatusEntry, includeScope bool) {\n\tif includeScope {\n\t\tfmt.Fprintf(\n\t\t\tw, \"%v\\t%v\\t%v\\t%v\\t%v\\t%v\\t\\n\",\n\t\t\tentry.Scope,\n\t\t\tentry.Name,\n\t\t\tentry.Status,\n\t\t\tentry.Version,\n\t\t\tentry.Type,\n\t\t\tprettyTime(entry.LastUpdated),\n\t\t)\n\t\treturn\n\t}\n\tfmt.Fprintf(\n\t\tw, \"%v\\t%v\\t%v\\t%v\\t%v\\t\\n\",\n\t\tentry.Name,\n\t\tentry.Status,\n\t\tentry.Version,\n\t\tentry.Type,\n\t\tprettyTime(entry.LastUpdated),\n\t)\n}\n\nfunc xdsStatusCommandRunWithError(cmd *cobra.Command, args []string) error {\n\tclientStatus := transport.FetchClientStatus()\n\tif len(clientStatus.Config) == 0 {\n\t\treturn fmt.Errorf(\"no ClientConfig returned\")\n\t}\n\tconfigs, err := filterConfigsByScope(clientStatus.Config, xdsScopeFlag)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tincludeScope := xdsScopeFlag == \"\"\n\tif includeScope {\n\t\tfmt.Fprintln(w, \"Scope\\tName\\tStatus\\tVersion\\tType\\tLastUpdated\")\n\t} else {\n\t\tfmt.Fprintln(w, \"Name\\tStatus\\tVersion\\tType\\tLastUpdated\")\n\t}\n\n\tfor _, config := range configs {\n\t\tscope := config.ClientScope\n\t\tfor _, g := range config.GenericXdsConfigs {\n\t\t\tentry := xdsResourceStatusEntry{\n\t\t\t\tScope:       scope,\n\t\t\t\tName:        g.Name,\n\t\t\t\tStatus:      g.ClientStatus,\n\t\t\t\tVersion:     g.VersionInfo,\n\t\t\t\tType:        g.TypeUrl,\n\t\t\t\tLastUpdated: g.LastUpdated,\n\t\t\t}\n\t\t\tprintStatusEntry(&entry, includeScope)\n\t\t}\n\t\tif len(config.GenericXdsConfigs) == 0 {\n\t\t\t// XdsConfig is deprecated but we support it for backward compatibility with older servers\n\t\t\tfor _, x := range config.XdsConfig {\n\t\t\t\tswitch x.PerXdsConfig.(type) {\n\t\t\t\tcase *csdspb.PerXdsConfig_ListenerConfig:\n\t\t\t\t\tfor _, dl := range x.GetListenerConfig().DynamicListeners {\n\t\t\t\t\t\te := xdsResourceStatusEntry{Scope: scope, Name: dl.Name, Status: dl.ClientStatus}\n\t\t\t\t\t\tif s := dl.GetActiveState(); s != nil {\n\t\t\t\t\t\t\te.Version = s.VersionInfo\n\t\t\t\t\t\t\te.Type = s.Listener.TypeUrl\n\t\t\t\t\t\t\te.LastUpdated = s.LastUpdated\n\t\t\t\t\t\t}\n\t\t\t\t\t\tprintStatusEntry(&e, includeScope)\n\t\t\t\t\t}\n\t\t\t\tcase *csdspb.PerXdsConfig_RouteConfig:\n\t\t\t\t\tfor _, dr := range x.GetRouteConfig().DynamicRouteConfigs {\n\t\t\t\t\t\te := xdsResourceStatusEntry{\n\t\t\t\t\t\t\tScope:       scope,\n\t\t\t\t\t\t\tStatus:      dr.ClientStatus,\n\t\t\t\t\t\t\tVersion:     dr.VersionInfo,\n\t\t\t\t\t\t\tType:        dr.RouteConfig.TypeUrl,\n\t\t\t\t\t\t\tLastUpdated: dr.LastUpdated,\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif packed := dr.GetRouteConfig(); packed != nil {\n\t\t\t\t\t\t\tvar rc routepb.RouteConfiguration\n\t\t\t\t\t\t\tif err := packed.UnmarshalTo(&rc); err != nil {\n\t\t\t\t\t\t\t\treturn err\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\te.Name = rc.Name\n\t\t\t\t\t\t}\n\t\t\t\t\t\tprintStatusEntry(&e, includeScope)\n\t\t\t\t\t}\n\t\t\t\tcase *csdspb.PerXdsConfig_ClusterConfig:\n\t\t\t\t\tfor _, dc := range x.GetClusterConfig().DynamicActiveClusters {\n\t\t\t\t\t\te := xdsResourceStatusEntry{\n\t\t\t\t\t\t\tScope:       scope,\n\t\t\t\t\t\t\tStatus:      dc.ClientStatus,\n\t\t\t\t\t\t\tVersion:     dc.VersionInfo,\n\t\t\t\t\t\t\tType:        dc.Cluster.TypeUrl,\n\t\t\t\t\t\t\tLastUpdated: dc.LastUpdated,\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif packed := dc.GetCluster(); packed != nil {\n\t\t\t\t\t\t\tvar c clusterpb.Cluster\n\t\t\t\t\t\t\tif err := packed.UnmarshalTo(&c); err != nil {\n\t\t\t\t\t\t\t\treturn err\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\te.Name = c.Name\n\t\t\t\t\t\t}\n\t\t\t\t\t\tprintStatusEntry(&e, includeScope)\n\t\t\t\t\t}\n\t\t\t\tcase *csdspb.PerXdsConfig_EndpointConfig:\n\t\t\t\t\tfor _, de := range x.GetEndpointConfig().GetDynamicEndpointConfigs() {\n\t\t\t\t\t\te := xdsResourceStatusEntry{\n\t\t\t\t\t\t\tScope:       scope,\n\t\t\t\t\t\t\tStatus:      de.ClientStatus,\n\t\t\t\t\t\t\tVersion:     de.VersionInfo,\n\t\t\t\t\t\t\tType:        de.EndpointConfig.TypeUrl,\n\t\t\t\t\t\t\tLastUpdated: de.LastUpdated,\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif packed := de.GetEndpointConfig(); packed != nil {\n\t\t\t\t\t\t\tvar ep endpointpb.ClusterLoadAssignment\n\t\t\t\t\t\t\tif err := packed.UnmarshalTo(&ep); err != nil {\n\t\t\t\t\t\t\t\treturn err\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\te.Name = ep.ClusterName\n\t\t\t\t\t\t}\n\t\t\t\t\t\tprintStatusEntry(&e, includeScope)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tw.Flush()\n\treturn nil\n}\n\nvar xdsStatusCmd = &cobra.Command{\n\tUse:   \"status\",\n\tShort: \"Print the config synchronization status.\",\n\tRunE:  xdsStatusCommandRunWithError,\n}\n\nvar xdsCmd = &cobra.Command{\n\tUse:   \"xds\",\n\tShort: \"Fetch xDS related information.\",\n}\n\nfunc init() {\n\txdsConfigCmd.Flags().StringVarP(&xdsTypeFlag, \"type\", \"y\", \"\", \"Filters the wanted type of xDS config to print (separated by commas) (available types: LDS,RDS,CDS,EDS) (by default, print all)\")\n\txdsConfigCmd.Flags().StringVarP(&xdsScopeFlag, \"scope\", \"s\", \"\", \"Filter by client_scope when multiple ClientConfig are present\")\n\txdsCmd.AddCommand(xdsConfigCmd)\n\txdsCmd.AddCommand(xdsStatusCmd)\n\trootCmd.AddCommand(xdsCmd)\n}\n"
  },
  {
    "path": "cmd/xds_test.go",
    "content": "package cmd\n\nimport (\n\t\"strings\"\n\t\"testing\"\n\n\tcsdspb \"github.com/envoyproxy/go-control-plane/envoy/service/status/v3\"\n)\n\nfunc TestFilterConfigsByScope(t *testing.T) {\n\tt.Parallel()\n\ttests := []struct {\n\t\tname       string\n\t\tconfigs    []*csdspb.ClientConfig\n\t\tscope      string\n\t\twantLen    int\n\t\twantErr    bool\n\t\twantErrMsg string\n\t}{\n\t\t{\n\t\t\tname: \"empty scope returns all\",\n\t\t\tconfigs: []*csdspb.ClientConfig{\n\t\t\t\t{ClientScope: \"primary\"},\n\t\t\t\t{ClientScope: \"fallback\"},\n\t\t\t},\n\t\t\tscope:   \"\",\n\t\t\twantLen: 2,\n\t\t\twantErr: false,\n\t\t},\n\t\t{\n\t\t\tname: \"filter by primary scope\",\n\t\t\tconfigs: []*csdspb.ClientConfig{\n\t\t\t\t{ClientScope: \"primary\"},\n\t\t\t\t{ClientScope: \"fallback\"},\n\t\t\t},\n\t\t\tscope:   \"primary\",\n\t\t\twantLen: 1,\n\t\t\twantErr: false,\n\t\t},\n\t\t{\n\t\t\tname: \"filter by fallback scope\",\n\t\t\tconfigs: []*csdspb.ClientConfig{\n\t\t\t\t{ClientScope: \"primary\"},\n\t\t\t\t{ClientScope: \"fallback\"},\n\t\t\t},\n\t\t\tscope:   \"fallback\",\n\t\t\twantLen: 1,\n\t\t\twantErr: false,\n\t\t},\n\t\t{\n\t\t\tname: \"no match returns error\",\n\t\t\tconfigs: []*csdspb.ClientConfig{\n\t\t\t\t{ClientScope: \"primary\"},\n\t\t\t\t{ClientScope: \"fallback\"},\n\t\t\t},\n\t\t\tscope:      \"nonexistent\",\n\t\t\twantLen:    0,\n\t\t\twantErr:    true,\n\t\t\twantErrMsg: \"no ClientConfig matched scope=\",\n\t\t},\n\t\t{\n\t\t\tname: \"multiple configs with same scope\",\n\t\t\tconfigs: []*csdspb.ClientConfig{\n\t\t\t\t{ClientScope: \"primary\"},\n\t\t\t\t{ClientScope: \"primary\"},\n\t\t\t\t{ClientScope: \"fallback\"},\n\t\t\t},\n\t\t\tscope:   \"primary\",\n\t\t\twantLen: 2,\n\t\t\twantErr: false,\n\t\t},\n\t\t{\n\t\t\tname: \"empty scope name in config\",\n\t\t\tconfigs: []*csdspb.ClientConfig{\n\t\t\t\t{ClientScope: \"\"},\n\t\t\t\t{ClientScope: \"primary\"},\n\t\t\t},\n\t\t\tscope:   \"\",\n\t\t\twantLen: 2,\n\t\t\twantErr: false,\n\t\t},\n\t}\n\n\tfor _, test := range tests {\n\t\tt.Run(test.name, func(t *testing.T) {\n\t\t\tt.Parallel()\n\t\t\tgot, err := filterConfigsByScope(test.configs, test.scope)\n\t\t\tif test.wantErr {\n\t\t\t\tif err == nil {\n\t\t\t\t\tt.Errorf(\"filterConfigsByScope() expected error but got none\")\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tif !strings.Contains(err.Error(), test.wantErrMsg) {\n\t\t\t\t\tt.Errorf(\"filterConfigsByScope() error = %v, want error containing %v\", err, test.wantErrMsg)\n\t\t\t\t}\n\t\t\t\treturn\n\t\t\t}\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"filterConfigsByScope() unexpected error = %v\", err)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tif len(got) != test.wantLen {\n\t\t\t\tt.Errorf(\"filterConfigsByScope() returned %d configs, want %d\", len(got), test.wantLen)\n\t\t\t}\n\t\t\t// Verify filtered results actually match the scope\n\t\t\tif test.scope != \"\" {\n\t\t\t\tfor _, c := range got {\n\t\t\t\t\tif c.ClientScope != test.scope {\n\t\t\t\t\t\tt.Errorf(\"filterConfigsByScope() returned config with scope %q, want %q\", c.ClientScope, test.scope)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n}\n\nfunc TestSortPerXdsConfigs(t *testing.T) {\n\tt.Parallel()\n\t// Test that sortPerXdsConfigs doesn't panic with multiple configs\n\t// XdsConfig is deprecated but we test it for backward compatibility\n\tclientStatus := &csdspb.ClientStatusResponse{\n\t\tConfig: []*csdspb.ClientConfig{\n\t\t\t{\n\t\t\t\tClientScope: \"primary\",\n\t\t\t\tXdsConfig: []*csdspb.PerXdsConfig{\n\t\t\t\t\t{PerXdsConfig: &csdspb.PerXdsConfig_ClusterConfig{}},\n\t\t\t\t\t{PerXdsConfig: &csdspb.PerXdsConfig_ListenerConfig{}},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tClientScope: \"fallback\",\n\t\t\t\tXdsConfig: []*csdspb.PerXdsConfig{\n\t\t\t\t\t{PerXdsConfig: &csdspb.PerXdsConfig_EndpointConfig{}},\n\t\t\t\t\t{PerXdsConfig: &csdspb.PerXdsConfig_RouteConfig{}},\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t}\n\n\t// Should not panic\n\tsortPerXdsConfigs(clientStatus)\n\n\t// Verify first config is sorted: Listener(0) < Cluster(2)\n\tif len(clientStatus.Config[0].XdsConfig) >= 2 {\n\t\tp0 := priorityPerXdsConfig(clientStatus.Config[0].XdsConfig[0])\n\t\tp1 := priorityPerXdsConfig(clientStatus.Config[0].XdsConfig[1])\n\t\tif p0 > p1 {\n\t\t\tt.Errorf(\"First config not sorted properly: priority[0]=%d > priority[1]=%d\", p0, p1)\n\t\t}\n\t}\n\n\t// Verify second config is sorted: Route(1) < Endpoint(3)\n\tif len(clientStatus.Config[1].XdsConfig) >= 2 {\n\t\tp0 := priorityPerXdsConfig(clientStatus.Config[1].XdsConfig[0])\n\t\tp1 := priorityPerXdsConfig(clientStatus.Config[1].XdsConfig[1])\n\t\tif p0 > p1 {\n\t\t\tt.Errorf(\"Second config not sorted properly: priority[0]=%d > priority[1]=%d\", p0, p1)\n\t\t}\n\t}\n}\n\nfunc TestSortPerXdsConfigsEmptyConfigs(t *testing.T) {\n\tt.Parallel()\n\t// Test with empty configs\n\tclientStatus := &csdspb.ClientStatusResponse{\n\t\tConfig: []*csdspb.ClientConfig{},\n\t}\n\tsortPerXdsConfigs(clientStatus)\n}\n\nfunc TestSortPerXdsConfigsSingleConfig(t *testing.T) {\n\tt.Parallel()\n\t// Test backward compatibility with single config\n\t// XdsConfig is deprecated but we test it for backward compatibility\n\tclientStatus := &csdspb.ClientStatusResponse{\n\t\tConfig: []*csdspb.ClientConfig{\n\t\t\t{\n\t\t\t\tClientScope: \"\",\n\t\t\t\tXdsConfig: []*csdspb.PerXdsConfig{\n\t\t\t\t\t{PerXdsConfig: &csdspb.PerXdsConfig_EndpointConfig{}},\n\t\t\t\t\t{PerXdsConfig: &csdspb.PerXdsConfig_ListenerConfig{}},\n\t\t\t\t\t{PerXdsConfig: &csdspb.PerXdsConfig_ClusterConfig{}},\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t}\n\n\tsortPerXdsConfigs(clientStatus)\n\n\t// Verify sorted: Listener(0) < Cluster(2) < Endpoint(3)\n\texpected := []int{0, 2, 3}\n\tfor i, cfg := range clientStatus.Config[0].XdsConfig {\n\t\tpriority := priorityPerXdsConfig(cfg)\n\t\tif priority != expected[i] {\n\t\t\tt.Errorf(\"Config[%d] priority = %d, want %d\", i, priority, expected[i])\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "go.mod",
    "content": "module github.com/grpc-ecosystem/grpcdebug\n\ngo 1.23.0\n\nrequire (\n\tgithub.com/dustin/go-humanize v1.0.1\n\tgithub.com/envoyproxy/go-control-plane/contrib v1.32.4\n\tgithub.com/envoyproxy/go-control-plane/envoy v1.32.4\n\tgithub.com/golang/protobuf v1.5.4\n\tgithub.com/spf13/cobra v1.8.1\n\tgoogle.golang.org/grpc v1.70.0\n\tgoogle.golang.org/grpc/examples v0.0.0-20241106195202-b3393d95a74e\n\tgoogle.golang.org/protobuf v1.36.4\n\tgopkg.in/yaml.v2 v2.4.0\n)\n\nrequire (\n\tcel.dev/expr v0.19.0 // indirect\n\tcloud.google.com/go/compute/metadata v0.5.2 // indirect\n\tgithub.com/cespare/xxhash/v2 v2.3.0 // indirect\n\tgithub.com/cncf/xds/go v0.0.0-20240905190251-b4127c9b8d78 // indirect\n\tgithub.com/envoyproxy/go-control-plane/ratelimit v0.1.0 // indirect\n\tgithub.com/envoyproxy/protoc-gen-validate v1.2.1 // indirect\n\tgithub.com/inconshreveable/mousetrap v1.1.0 // indirect\n\tgithub.com/kr/pretty v0.3.1 // indirect\n\tgithub.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect\n\tgithub.com/prometheus/client_model v0.6.1 // indirect\n\tgithub.com/rogpeppe/go-internal v1.13.1 // indirect\n\tgithub.com/spf13/pflag v1.0.5 // indirect\n\tgolang.org/x/net v0.34.0 // indirect\n\tgolang.org/x/oauth2 v0.24.0 // indirect\n\tgolang.org/x/sync v0.10.0 // indirect\n\tgolang.org/x/sys v0.29.0 // indirect\n\tgolang.org/x/text v0.21.0 // indirect\n\tgoogle.golang.org/genproto/googleapis/api v0.0.0-20241202173237-19429a94021a // indirect\n\tgoogle.golang.org/genproto/googleapis/rpc v0.0.0-20241202173237-19429a94021a // indirect\n\tgopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect\n)\n"
  },
  {
    "path": "go.sum",
    "content": "cel.dev/expr v0.19.0 h1:lXuo+nDhpyJSpWxpPVi5cPUwzKb+dsdOiw6IreM5yt0=\ncel.dev/expr v0.19.0/go.mod h1:MrpN08Q+lEBs+bGYdLxxHkZoUSsCp0nSKTs0nTymJgw=\ncloud.google.com/go/compute/metadata v0.5.2 h1:UxK4uu/Tn+I3p2dYWTfiX4wva7aYlKixAHn3fyqngqo=\ncloud.google.com/go/compute/metadata v0.5.2/go.mod h1:C66sj2AluDcIqakBq/M8lw8/ybHgOZqin2obFxa/E5k=\ngithub.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=\ngithub.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=\ngithub.com/cncf/xds/go v0.0.0-20240905190251-b4127c9b8d78 h1:QVw89YDxXxEe+l8gU8ETbOasdwEV+avkR75ZzsVV9WI=\ngithub.com/cncf/xds/go v0.0.0-20240905190251-b4127c9b8d78/go.mod h1:W+zGtBO5Y1IgJhy4+A9GOqVhqLpfZi+vwmdNXUehLA8=\ngithub.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=\ngithub.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=\ngithub.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=\ngithub.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=\ngithub.com/envoyproxy/go-control-plane v0.13.4 h1:zEqyPVyku6IvWCFwux4x9RxkLOMUL+1vC9xUFv5l2/M=\ngithub.com/envoyproxy/go-control-plane v0.13.4/go.mod h1:kDfuBlDVsSj2MjrLEtRWtHlsWIFcGyB2RMO44Dc5GZA=\ngithub.com/envoyproxy/go-control-plane/contrib v1.32.4 h1:/udV6s9xkDGe13WfrT2MHAxXTNDMBYBPxI1GkleCrmM=\ngithub.com/envoyproxy/go-control-plane/contrib v1.32.4/go.mod h1:gkGYoY7plfQg7FPBDhyKtP1cDA9frFR/3YsCx8taRvI=\ngithub.com/envoyproxy/go-control-plane/envoy v1.32.4 h1:jb83lalDRZSpPWW2Z7Mck/8kXZ5CQAFYVjQcdVIr83A=\ngithub.com/envoyproxy/go-control-plane/envoy v1.32.4/go.mod h1:Gzjc5k8JcJswLjAx1Zm+wSYE20UrLtt7JZMWiWQXQEw=\ngithub.com/envoyproxy/go-control-plane/ratelimit v0.1.0 h1:/G9QYbddjL25KvtKTv3an9lx6VBE2cnb8wp1vEGNYGI=\ngithub.com/envoyproxy/go-control-plane/ratelimit v0.1.0/go.mod h1:Wk+tMFAFbCXaJPzVVHnPgRKdUdwW/KdbRt94AzgRee4=\ngithub.com/envoyproxy/protoc-gen-validate v1.2.1 h1:DEo3O99U8j4hBFwbJfrz9VtgcDfUKS7KJ7spH3d86P8=\ngithub.com/envoyproxy/protoc-gen-validate v1.2.1/go.mod h1:d/C80l/jxXLdfEIhX1W2TmLfsJ31lvEjwamM4DxlWXU=\ngithub.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=\ngithub.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=\ngithub.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=\ngithub.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=\ngithub.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=\ngithub.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=\ngithub.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=\ngithub.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=\ngithub.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=\ngithub.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=\ngithub.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=\ngithub.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=\ngithub.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=\ngithub.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=\ngithub.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=\ngithub.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=\ngithub.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=\ngithub.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=\ngithub.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=\ngithub.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=\ngithub.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 h1:GFCKgmp0tecUJ0sJuv4pzYCqS9+RGSn52M3FUwPs+uo=\ngithub.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10/go.mod h1:t/avpk3KcrXxUnYOhZhMXJlSEyie6gQbtLq5NM3loB8=\ngithub.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E=\ngithub.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY=\ngithub.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=\ngithub.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=\ngithub.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=\ngithub.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=\ngithub.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=\ngithub.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=\ngithub.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=\ngithub.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=\ngo.opentelemetry.io/otel v1.32.0 h1:WnBN+Xjcteh0zdk01SVqV55d/m62NJLJdIyb4y/WO5U=\ngo.opentelemetry.io/otel v1.32.0/go.mod h1:00DCVSB0RQcnzlwyTfqtxSm+DRr9hpYrHjNGiBHVQIg=\ngo.opentelemetry.io/otel/metric v1.32.0 h1:xV2umtmNcThh2/a/aCP+h64Xx5wsj8qqnkYZktzNa0M=\ngo.opentelemetry.io/otel/metric v1.32.0/go.mod h1:jH7CIbbK6SH2V2wE16W05BHCtIDzauciCRLoc/SyMv8=\ngo.opentelemetry.io/otel/sdk v1.32.0 h1:RNxepc9vK59A8XsgZQouW8ue8Gkb4jpWtJm9ge5lEG4=\ngo.opentelemetry.io/otel/sdk v1.32.0/go.mod h1:LqgegDBjKMmb2GC6/PrTnteJG39I8/vJCAP9LlJXEjU=\ngo.opentelemetry.io/otel/sdk/metric v1.32.0 h1:rZvFnvmvawYb0alrYkjraqJq0Z4ZUJAiyYCU9snn1CU=\ngo.opentelemetry.io/otel/sdk/metric v1.32.0/go.mod h1:PWeZlq0zt9YkYAp3gjKZ0eicRYvOh1Gd+X99x6GHpCQ=\ngo.opentelemetry.io/otel/trace v1.32.0 h1:WIC9mYrXf8TmY/EXuULKc8hR17vE+Hjv2cssQDe03fM=\ngo.opentelemetry.io/otel/trace v1.32.0/go.mod h1:+i4rkvCraA+tG6AzwloGaCtkx53Fa+L+V8e9a7YvhT8=\ngolang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0=\ngolang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k=\ngolang.org/x/oauth2 v0.24.0 h1:KTBBxWqUa0ykRPLtV69rRto9TLXcqYkeswu48x/gvNE=\ngolang.org/x/oauth2 v0.24.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=\ngolang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=\ngolang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=\ngolang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=\ngolang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=\ngolang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=\ngolang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=\ngoogle.golang.org/genproto/googleapis/api v0.0.0-20241202173237-19429a94021a h1:OAiGFfOiA0v9MRYsSidp3ubZaBnteRUyn3xB2ZQ5G/E=\ngoogle.golang.org/genproto/googleapis/api v0.0.0-20241202173237-19429a94021a/go.mod h1:jehYqy3+AhJU9ve55aNOaSml7wUXjF9x6z2LcCfpAhY=\ngoogle.golang.org/genproto/googleapis/rpc v0.0.0-20241202173237-19429a94021a h1:hgh8P4EuoxpsuKMXX/To36nOFD7vixReXgn8lPGnt+o=\ngoogle.golang.org/genproto/googleapis/rpc v0.0.0-20241202173237-19429a94021a/go.mod h1:5uTbfoYQed2U9p3KIj2/Zzm02PYhndfdmML0qC3q3FU=\ngoogle.golang.org/grpc v1.70.0 h1:pWFv03aZoHzlRKHWicjsZytKAiYCtNS0dHbXnIdq7jQ=\ngoogle.golang.org/grpc v1.70.0/go.mod h1:ofIJqVKDXx/JiXrwr2IG4/zwdH9txy3IlF40RmcJSQw=\ngoogle.golang.org/grpc/examples v0.0.0-20241106195202-b3393d95a74e h1:LGj5F6Z+enJcJFa6sjBMwmJ1gnjHpV60bKrQ2ass/aE=\ngoogle.golang.org/grpc/examples v0.0.0-20241106195202-b3393d95a74e/go.mod h1:UxqwMHw3ntCGQS0LuHPmqkO+z9CyMtK1oN7xh6P+gw8=\ngoogle.golang.org/protobuf v1.36.4 h1:6A3ZDJHn/eNqc1i+IdefRzy/9PokBTPvcqMySR7NNIM=\ngoogle.golang.org/protobuf v1.36.4/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=\ngopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=\ngopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=\ngopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=\ngopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=\ngopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=\ngopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=\n"
  },
  {
    "path": "internal/testing/ca.pem",
    "content": "-----BEGIN CERTIFICATE-----\nMIICSjCCAbOgAwIBAgIJAJHGGR4dGioHMA0GCSqGSIb3DQEBCwUAMFYxCzAJBgNV\nBAYTAkFVMRMwEQYDVQQIEwpTb21lLVN0YXRlMSEwHwYDVQQKExhJbnRlcm5ldCBX\naWRnaXRzIFB0eSBMdGQxDzANBgNVBAMTBnRlc3RjYTAeFw0xNDExMTEyMjMxMjla\nFw0yNDExMDgyMjMxMjlaMFYxCzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpTb21lLVN0\nYXRlMSEwHwYDVQQKExhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQxDzANBgNVBAMT\nBnRlc3RjYTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAwEDfBV5MYdlHVHJ7\n+L4nxrZy7mBfAVXpOc5vMYztssUI7mL2/iYujiIXM+weZYNTEpLdjyJdu7R5gGUu\ng1jSVK/EPHfc74O7AyZU34PNIP4Sh33N+/A5YexrNgJlPY+E3GdVYi4ldWJjgkAd\nQah2PH5ACLrIIC6tRka9hcaBlIECAwEAAaMgMB4wDAYDVR0TBAUwAwEB/zAOBgNV\nHQ8BAf8EBAMCAgQwDQYJKoZIhvcNAQELBQADgYEAHzC7jdYlzAVmddi/gdAeKPau\nsPBG/C2HCWqHzpCUHcKuvMzDVkY/MP2o6JIW2DBbY64bO/FceExhjcykgaYtCH/m\noIU63+CFOTtR7otyQAWHqXa7q4SbCDlG7DyRFxqG0txPtGvy12lgldA2+RgcigQG\nDfcog5wrJytaQ6UA0wE=\n-----END CERTIFICATE-----\n"
  },
  {
    "path": "internal/testing/grpcdebug_config.yaml",
    "content": "servers:\n  dev:\n    real_address: localhost:50051\n    security: insecure\n  prod:\n    real_address: \"localhost:50052\"\n    security: tls\n    credential_file: ./internal/testing/ca.pem\n    server_name_override: \"*.test.youtube.com\"\n  \"localhost:50052\":\n    security: tls\n    credential_file: ./internal/testing/ca.pem\n    server_name_override: \"*.test.youtube.com\"\n"
  },
  {
    "path": "internal/testing/testserver/csds_config_dump.json",
    "content": "{\n  \"config\": [\n    {\n      \"node\": {\n        \"id\": \"projects/1040920224690/networks/default/nodes/5cc9170c-d5b4-4061-b431-c1d43e6ac0ab\",\n        \"cluster\": \"cluster\",\n        \"metadata\": {\n            \"INSTANCE_IP\": \"192.168.120.31\",\n            \"TRAFFICDIRECTOR_GCP_PROJECT_NUMBER\": \"1040920224690\",\n            \"TRAFFICDIRECTOR_NETWORK_NAME\": \"default\"\n          },\n        \"locality\": {\n          \"zone\": \"us-central1-a\"\n        },\n        \"userAgentName\": \"gRPC Java\",\n        \"userAgentVersion\": \"1.38.0-SNAPSHOT\",\n        \"clientFeatures\": [\n          \"envoy.lb.does_not_support_overprovisioning\"\n        ]\n      },\n      \"xdsConfig\": [\n        {\n          \"listenerConfig\": {\n            \"versionInfo\": \"1617141154495058478\",\n            \"dynamicListeners\": [\n              {\n                \"name\": \"xds-test-server:1337\",\n                \"activeState\": {\n                  \"versionInfo\": \"1617141154495058478\",\n                  \"listener\": {\n                    \"@type\": \"type.googleapis.com/envoy.config.listener.v3.Listener\",\n                    \"apiListener\": {\n                      \"apiListener\": {\n                        \"@type\": \"type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager\",\n                        \"httpFilters\": [\n                          {\n                            \"name\": \"envoy.filters.http.fault\",\n                            \"typedConfig\": {\n                              \"@type\": \"type.googleapis.com/envoy.extensions.filters.http.fault.v3.HTTPFault\"\n                            }\n                          },\n                          {\n                            \"name\": \"envoy.filters.http.router\",\n                            \"typedConfig\": {\n                              \"@type\": \"type.googleapis.com/envoy.extensions.filters.http.router.v3.Router\",\n                              \"suppressEnvoyHeaders\": true\n                            }\n                          }\n                        ],\n                        \"rds\": {\n                          \"configSource\": {\n                            \"ads\": {},\n                            \"resourceApiVersion\": \"V3\"\n                          },\n                          \"routeConfigName\": \"URL_MAP/1040920224690_sergii-psm-test-url-map_0_xds-test-server:1337\"\n                        },\n                        \"statPrefix\": \"trafficdirector\"\n                      }\n                    },\n                    \"name\": \"xds-test-server:1337\"\n                  },\n                  \"lastUpdated\": \"2021-03-31T01:20:33.144Z\"\n                },\n                \"clientStatus\": \"ACKED\"\n              }\n            ]\n          }\n        },\n        {\n          \"routeConfig\": {\n            \"dynamicRouteConfigs\": [\n              {\n                \"versionInfo\": \"1617141154495058478\",\n                \"routeConfig\": {\n                  \"@type\": \"type.googleapis.com/envoy.config.route.v3.RouteConfiguration\",\n                  \"name\": \"URL_MAP/1040920224690_sergii-psm-test-url-map_0_xds-test-server:1337\",\n                  \"virtualHosts\": [\n                    {\n                      \"domains\": [\n                        \"xds-test-server:1337\"\n                      ],\n                      \"routes\": [\n                        {\n                          \"match\": {\n                            \"prefix\": \"\"\n                          },\n                          \"route\": {\n                            \"cluster\": \"cloud-internal-istio:cloud_mp_1040920224690_6530603179561593229\",\n                            \"timeout\": \"30s\",\n                            \"retryPolicy\": {\n                              \"retryOn\": \"gateway-error\",\n                              \"numRetries\": 1,\n                              \"perTryTimeout\": \"30s\"\n                            }\n                          }\n                        }\n                      ]\n                    }\n                  ]\n                },\n                \"lastUpdated\": \"2021-03-31T01:20:33.302Z\",\n                \"clientStatus\": \"ACKED\"\n              }\n            ]\n          }\n        },\n        {\n          \"clusterConfig\": {\n            \"versionInfo\": \"1617141154495058478\",\n            \"dynamicActiveClusters\": [\n              {\n                \"versionInfo\": \"1617141154495058478\",\n                \"cluster\": {\n                  \"@type\": \"type.googleapis.com/envoy.config.cluster.v3.Cluster\",\n                  \"circuitBreakers\": {\n                    \"thresholds\": [\n                      {\n                        \"maxConnections\": 2147483647,\n                        \"maxPendingRequests\": 2147483647,\n                        \"maxRequests\": 2147483647,\n                        \"maxRetries\": 2147483647\n                      }\n                    ]\n                  },\n                  \"commonLbConfig\": {\n                    \"healthyPanicThreshold\": {\n                      \"value\": 1\n                    },\n                    \"localityWeightedLbConfig\": {}\n                  },\n                  \"connectTimeout\": \"30s\",\n                  \"edsClusterConfig\": {\n                    \"edsConfig\": {\n                      \"ads\": {},\n                      \"initialFetchTimeout\": \"15s\",\n                      \"resourceApiVersion\": \"V3\"\n                    }\n                  },\n                  \"http2ProtocolOptions\": {\n                    \"maxConcurrentStreams\": 100\n                  },\n                  \"lrsServer\": {\n                    \"self\": {}\n                  },\n                  \"metadata\": {\n                    \"filterMetadata\": {\n                      \"com.google.trafficdirector\": {\n                        \"backend_service_name\": \"sergii-psm-test-backend-service\"\n                      }\n                    }\n                  },\n                  \"name\": \"cloud-internal-istio:cloud_mp_1040920224690_6530603179561593229\",\n                  \"type\": \"EDS\"\n                },\n                \"lastUpdated\": \"2021-03-31T01:20:33.853Z\",\n                \"clientStatus\": \"ACKED\"\n              }\n            ]\n          }\n        },\n        {\n          \"endpointConfig\": {\n            \"dynamicEndpointConfigs\": [\n              {\n                \"versionInfo\": \"1\",\n                \"endpointConfig\": {\n                  \"@type\": \"type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment\",\n                  \"clusterName\": \"cloud-internal-istio:cloud_mp_1040920224690_6530603179561593229\",\n                  \"endpoints\": [\n                    {\n                      \"locality\": {\n                        \"subZone\": \"jf:us-central1-a_7062512536751318190_neg\"\n                      },\n                      \"lbEndpoints\": [\n                        {\n                          \"endpoint\": {\n                            \"address\": {\n                              \"socketAddress\": {\n                                \"address\": \"192.168.120.26\",\n                                \"portValue\": 8080\n                              }\n                            }\n                          },\n                          \"healthStatus\": \"HEALTHY\"\n                        }\n                      ],\n                      \"loadBalancingWeight\": 100\n                    }\n                  ]\n                },\n                \"lastUpdated\": \"2021-03-31T01:20:33.936Z\",\n                \"clientStatus\": \"ACKED\"\n              }\n            ]\n          }\n        }\n      ]\n    }\n  ]\n}\n"
  },
  {
    "path": "internal/testing/testserver/csds_config_dump_multi_scope.json",
    "content": "{\n  \"config\": [\n    {\n      \"node\": {\n        \"id\": \"projects/1040920224690/networks/default/nodes/primary-node\",\n        \"cluster\": \"cluster\",\n        \"userAgentName\": \"gRPC Java\",\n        \"userAgentVersion\": \"1.60.0\"\n      },\n      \"clientScope\": \"primary\",\n      \"xdsConfig\": [\n        {\n          \"listenerConfig\": {\n            \"versionInfo\": \"1617141154495058478\",\n            \"dynamicListeners\": [\n              {\n                \"name\": \"primary-listener:1337\",\n                \"activeState\": {\n                  \"versionInfo\": \"1617141154495058478\",\n                  \"listener\": {\n                    \"@type\": \"type.googleapis.com/envoy.config.listener.v3.Listener\",\n                    \"name\": \"primary-listener:1337\"\n                  },\n                  \"lastUpdated\": \"2021-03-31T01:20:33.144Z\"\n                },\n                \"clientStatus\": \"ACKED\"\n              }\n            ]\n          }\n        },\n        {\n          \"clusterConfig\": {\n            \"versionInfo\": \"1617141154495058478\",\n            \"dynamicActiveClusters\": [\n              {\n                \"versionInfo\": \"1617141154495058478\",\n                \"cluster\": {\n                  \"@type\": \"type.googleapis.com/envoy.config.cluster.v3.Cluster\",\n                  \"name\": \"primary-cluster\",\n                  \"type\": \"EDS\"\n                },\n                \"lastUpdated\": \"2021-03-31T01:20:33.853Z\",\n                \"clientStatus\": \"ACKED\"\n              }\n            ]\n          }\n        }\n      ]\n    },\n    {\n      \"node\": {\n        \"id\": \"projects/1040920224690/networks/default/nodes/fallback-node\",\n        \"cluster\": \"cluster\",\n        \"userAgentName\": \"gRPC Java\",\n        \"userAgentVersion\": \"1.60.0\"\n      },\n      \"clientScope\": \"fallback\",\n      \"xdsConfig\": [\n        {\n          \"listenerConfig\": {\n            \"versionInfo\": \"1617141154495058479\",\n            \"dynamicListeners\": [\n              {\n                \"name\": \"fallback-listener:1338\",\n                \"activeState\": {\n                  \"versionInfo\": \"1617141154495058479\",\n                  \"listener\": {\n                    \"@type\": \"type.googleapis.com/envoy.config.listener.v3.Listener\",\n                    \"name\": \"fallback-listener:1338\"\n                  },\n                  \"lastUpdated\": \"2021-03-31T01:25:33.144Z\"\n                },\n                \"clientStatus\": \"ACKED\"\n              }\n            ]\n          }\n        },\n        {\n          \"clusterConfig\": {\n            \"versionInfo\": \"1617141154495058479\",\n            \"dynamicActiveClusters\": [\n              {\n                \"versionInfo\": \"1617141154495058479\",\n                \"cluster\": {\n                  \"@type\": \"type.googleapis.com/envoy.config.cluster.v3.Cluster\",\n                  \"name\": \"fallback-cluster\",\n                  \"type\": \"EDS\"\n                },\n                \"lastUpdated\": \"2021-03-31T01:25:33.853Z\",\n                \"clientStatus\": \"ACKED\"\n              }\n            ]\n          }\n        }\n      ]\n    }\n  ]\n}\n"
  },
  {
    "path": "internal/testing/testserver/main.go",
    "content": "// Testserver mocking the responses of Channelz/CSDS/Health\npackage main\n\nimport (\n\t\"context\"\n\t\"crypto/tls\"\n\t\"flag\"\n\t\"fmt\"\n\t\"io\"\n\t\"log\"\n\t\"math/rand\"\n\t\"net\"\n\t\"os\"\n\t\"time\"\n\n\t\"google.golang.org/grpc\"\n\t\"google.golang.org/grpc/channelz/service\"\n\t\"google.golang.org/grpc/codes\"\n\t\"google.golang.org/grpc/credentials\"\n\t\"google.golang.org/grpc/health\"\n\t\"google.golang.org/grpc/reflection\"\n\t\"google.golang.org/grpc/status\"\n\t\"google.golang.org/grpc/testdata\"\n\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/fault/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/router/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/http_connection_manager/v3\"\n\tcsdspb \"github.com/envoyproxy/go-control-plane/envoy/service/status/v3\"\n\tpb \"google.golang.org/grpc/examples/helloworld/helloworld\"\n\thealthpb \"google.golang.org/grpc/health/grpc_health_v1\"\n\t\"google.golang.org/protobuf/encoding/protojson\"\n)\n\nvar (\n\tservingPortFlag     = flag.Int(\"serving\", 10001, \"the serving port\")\n\tadminPortFlag       = flag.Int(\"admin\", 50051, \"the admin port\")\n\tsecureAdminPortFlag = flag.Int(\"secure_admin\", 50052, \"the secure admin port\")\n\thealthFlag          = flag.Bool(\"health\", true, \"the health checking status\")\n\tqpsFlag             = flag.Int(\"qps\", 10, \"The size of the generated load against itself\")\n\tabortPercentageFlag = flag.Int(\"abort_percentage\", 10, \"The percentage of failed RPCs\")\n)\n\n// Prepare the CSDS response\nvar csdsResponse csdspb.ClientStatusResponse\n\nfunc init() {\n\tfile, err := os.Open(\"csds_config_dump.json\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tconfigDump, err := io.ReadAll(file)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tif err := protojson.Unmarshal([]byte(configDump), &csdsResponse); err != nil {\n\t\tpanic(err)\n\t}\n}\n\n// Implements the Greeter service\ntype server struct {\n\tpb.UnimplementedGreeterServer\n}\n\nfunc (s *server) SayHello(ctx context.Context, in *pb.HelloRequest) (*pb.HelloReply, error) {\n\tif int(rand.Int31n(100)) <= *abortPercentageFlag {\n\t\treturn nil, status.Errorf(codes.Code(rand.Int31n(15)+1), \"Fault injected\")\n\t}\n\treturn &pb.HelloReply{Message: \"Hello \" + in.Name}, nil\n}\n\n// Implements the CSDS service\ntype mockCsdsServer struct {\n\tcsdspb.UnimplementedClientStatusDiscoveryServiceServer\n}\n\nfunc (*mockCsdsServer) FetchClientStatus(ctx context.Context, req *csdspb.ClientStatusRequest) (*csdspb.ClientStatusResponse, error) {\n\treturn &csdsResponse, nil\n}\n\nfunc setupAdminServer(s *grpc.Server) {\n\treflection.Register(s)\n\tservice.RegisterChannelzServiceToServer(s)\n\tcsdspb.RegisterClientStatusDiscoveryServiceServer(s, &mockCsdsServer{})\n\thealthcheck := health.NewServer()\n\tif *healthFlag {\n\t\thealthcheck.SetServingStatus(\"\", healthpb.HealthCheckResponse_SERVING)\n\t\thealthcheck.SetServingStatus(\"helloworld.Greeter\", healthpb.HealthCheckResponse_SERVING)\n\t} else {\n\t\thealthcheck.SetServingStatus(\"\", healthpb.HealthCheckResponse_NOT_SERVING)\n\t\thealthcheck.SetServingStatus(\"helloworld.Greeter\", healthpb.HealthCheckResponse_NOT_SERVING)\n\t}\n\thealthpb.RegisterHealthServer(s, healthcheck)\n}\n\nfunc main() {\n\t// Parse the flags\n\tflag.Parse()\n\t// Creates the primary server\n\tlis, err := net.Listen(\"tcp\", fmt.Sprintf(\":%d\", *servingPortFlag))\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tdefer lis.Close()\n\tfmt.Printf(\"Serving Business Logic on :%d\\n\", *servingPortFlag)\n\tcert, err := tls.LoadX509KeyPair(testdata.Path(\"server1.pem\"), testdata.Path(\"server1.key\"))\n\tif err != nil {\n\t\tlog.Fatalf(\"failed to load key pair: %s\", err)\n\t}\n\ts := grpc.NewServer(grpc.Creds(credentials.NewServerTLSFromCert(&cert)))\n\tpb.RegisterGreeterServer(s, &server{})\n\tgo s.Serve(lis)\n\tdefer s.Stop()\n\t// Creates the admin server without credentials\n\tinsecureListener, err := net.Listen(\"tcp\", fmt.Sprintf(\":%d\", *adminPortFlag))\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tdefer insecureListener.Close()\n\tinsecureAdminServer := grpc.NewServer()\n\tsetupAdminServer(insecureAdminServer)\n\tgo insecureAdminServer.Serve(insecureListener)\n\tdefer insecureAdminServer.Stop()\n\tfmt.Printf(\"Serving Insecure Admin Services on :%d\\n\", *adminPortFlag)\n\t// Creates the admin server with credentials\n\tsecureListener, err := net.Listen(\"tcp\", fmt.Sprintf(\":%d\", *secureAdminPortFlag))\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tdefer secureListener.Close()\n\tsecureAdminServer := grpc.NewServer(grpc.Creds(credentials.NewServerTLSFromCert(&cert)))\n\tsetupAdminServer(secureAdminServer)\n\tgo secureAdminServer.Serve(secureListener)\n\tdefer secureAdminServer.Stop()\n\tfmt.Printf(\"Serving Secure Admin Services on :%d\\n\", *secureAdminPortFlag)\n\t// Creates a client to hydrate the primary server\n\tcreds, err := credentials.NewClientTLSFromFile(testdata.Path(\"ca.pem\"), \"*.test.youtube.com\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tconn, err := grpc.NewClient(fmt.Sprintf(\"localhost:%d\", *servingPortFlag), grpc.WithTransportCredentials(creds))\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tdefer conn.Close()\n\tgreeterClient := pb.NewGreeterClient(conn)\n\tfor {\n\t\tgreeterClient.SayHello(context.Background(), &pb.HelloRequest{Name: \"world\"})\n\t\ttime.Sleep(time.Second / time.Duration(*qpsFlag))\n\t}\n}\n"
  },
  {
    "path": "main.go",
    "content": "package main\n\nimport (\n\tcmd \"github.com/grpc-ecosystem/grpcdebug/cmd\"\n\n\t// To parse Any protos, ProtoBuf requires the descriptors of the given message\n\t// type to present in its descriptor pool. Otherwise, it will fail. Here we\n\t// preload as much proto descriptors as possible, so the released binaries can\n\t// have better forward compatibility.\n\t_ \"github.com/envoyproxy/go-control-plane/contrib/envoy/extensions/filters/http/dynamo/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/contrib/envoy/extensions/filters/http/squash/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/contrib/envoy/extensions/filters/network/client_ssl_auth/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/contrib/envoy/extensions/filters/network/kafka_broker/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/contrib/envoy/extensions/filters/network/mysql_proxy/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/contrib/envoy/extensions/filters/network/postgres_proxy/v3alpha\"\n\t_ \"github.com/envoyproxy/go-control-plane/contrib/envoy/extensions/filters/network/rocketmq_proxy/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/admin/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/config/accesslog/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/config/bootstrap/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/config/cluster/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/config/common/matcher/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/config/core/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/config/endpoint/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/config/grpc_credential/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/config/listener/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/config/metrics/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/config/overload/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/config/ratelimit/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/config/rbac/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/config/route/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/config/tap/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/config/trace/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/data/accesslog/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/data/cluster/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/data/core/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/data/dns/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/data/tap/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/access_loggers/file/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/access_loggers/grpc/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/access_loggers/wasm/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/clusters/aggregate/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/clusters/dynamic_forward_proxy/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/common/dynamic_forward_proxy/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/common/matching/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/common/ratelimit/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/common/tap/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/compression/brotli/compressor/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/compression/brotli/decompressor/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/compression/gzip/compressor/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/compression/gzip/decompressor/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/common/dependency/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/common/fault/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/common/matcher/action/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/adaptive_concurrency/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/admission_control/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/aws_lambda/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/aws_request_signing/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/buffer/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/cache/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/cdn_loop/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/compressor/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/cors/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/csrf/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/decompressor/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/dynamic_forward_proxy/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/ext_authz/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/ext_proc/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/fault/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/grpc_http1_bridge/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/grpc_http1_reverse_bridge/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/grpc_json_transcoder/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/grpc_stats/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/grpc_web/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/gzip/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/header_to_metadata/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/health_check/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/ip_tagging/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/jwt_authn/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/kill_request/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/local_ratelimit/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/lua/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/oauth2/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/on_demand/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/original_src/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/ratelimit/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/rbac/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/router/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/tap/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/wasm/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/listener/http_inspector/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/listener/original_dst/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/listener/original_src/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/listener/proxy_protocol/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/listener/tls_inspector/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/direct_response/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/dubbo_proxy/router/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/dubbo_proxy/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/echo/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/ext_authz/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/http_connection_manager/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/local_ratelimit/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/mongo_proxy/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/ratelimit/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/rbac/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/redis_proxy/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/sni_cluster/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/sni_dynamic_forward_proxy/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/tcp_proxy/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/thrift_proxy/filters/ratelimit/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/thrift_proxy/router/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/thrift_proxy/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/wasm/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/zookeeper_proxy/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/udp/dns_filter/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/filters/udp/udp_proxy/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/internal_redirect/allow_listed_routes/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/internal_redirect/previous_routes/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/internal_redirect/safe_cross_scheme/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/load_balancing_policies/least_request/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/load_balancing_policies/pick_first/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/load_balancing_policies/ring_hash/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/load_balancing_policies/round_robin/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/load_balancing_policies/wrr_locality/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/network/socket_interface/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/rate_limit_descriptors/expr/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/retry/host/omit_host_metadata/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/retry/host/previous_hosts/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/retry/priority/previous_priorities/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/stat_sinks/wasm/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/transport_sockets/alts/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/transport_sockets/proxy_protocol/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/transport_sockets/quic/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/transport_sockets/raw_buffer/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/transport_sockets/starttls/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/transport_sockets/tap/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/transport_sockets/tls/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/upstreams/http/generic/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/upstreams/http/http/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/upstreams/http/tcp/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/upstreams/http/udp/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/wasm/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/extensions/watchdog/profile_action/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/service/accesslog/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/service/auth/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/service/cluster/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/service/discovery/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/service/endpoint/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/service/event_reporting/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/service/ext_proc/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/service/extension/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/service/health/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/service/listener/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/service/load_stats/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/service/metrics/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/service/ratelimit/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/service/route/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/service/runtime/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/service/secret/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/service/status/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/service/tap/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/type/matcher/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/type/metadata/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/type/tracing/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/type/v3\"\n\t_ \"github.com/envoyproxy/go-control-plane/envoy/watchdog/v3\"\n\n\t// Add the xDS resolver to allow resolving using a \"xds:///\" target.\n\t_ \"google.golang.org/grpc/xds\"\n)\n\nfunc main() {\n\tcmd.Execute()\n}\n"
  }
]