|
| 1 | +# Orion XDS Examples – Full Usage Guide |
| 2 | + |
| 3 | +## Directory: `orion-xds/examples/` |
| 4 | + |
| 5 | +This folder contains several examples that demonstrate how to use the Orion XDS library for service discovery and configuration. These are structured around a basic **XDS client-server model**, using **gRPC and async Rust**. |
| 6 | + |
| 7 | +--- |
| 8 | + |
| 9 | +## Prerequisites |
| 10 | + |
| 11 | +Before running any example, ensure your environment meets the following: |
| 12 | + |
| 13 | +### Rust Environment |
| 14 | + |
| 15 | +- Install Rust: https://rustup.rs |
| 16 | +- Minimum Rust version: `1.70+` (recommended) |
| 17 | + |
| 18 | +### Dependencies |
| 19 | + |
| 20 | +Run this in the root of the Orion repo to make sure all dependencies are available: |
| 21 | + |
| 22 | +```bash |
| 23 | +cargo build |
| 24 | +``` |
| 25 | + |
| 26 | +### Enable Logging (Optional but Useful) |
| 27 | + |
| 28 | +Set the `RUST_LOG` environment variable to see debug/info logs: |
| 29 | + |
| 30 | +```bash |
| 31 | +export RUST_LOG=info,orion_xds=debug |
| 32 | +``` |
| 33 | + |
| 34 | +--- |
| 35 | + |
| 36 | +## How to Run the Examples |
| 37 | + |
| 38 | +These examples follow a basic flow: |
| 39 | + |
| 40 | +- Start the **XDS server** (one of the server variants) |
| 41 | +- In another terminal, start the **XDS client** |
| 42 | +- Observe real-time communication: resource updates (clusters, listeners, secrets) flow from server to client |
| 43 | + |
| 44 | +--- |
| 45 | + |
| 46 | +## Running Client and Server Example |
| 47 | + |
| 48 | +### 1. Open **Terminal A** – Run the Server |
| 49 | + |
| 50 | +```bash |
| 51 | +cd orion-xds |
| 52 | +cargo run --example server |
| 53 | +``` |
| 54 | + |
| 55 | +What it does: |
| 56 | + |
| 57 | +- Starts a gRPC server on `127.0.0.1:50051` |
| 58 | +- Periodically creates and pushes **Cluster** and **Listener** resources |
| 59 | +- Also shows how to **remove** those resources dynamically |
| 60 | + |
| 61 | +You’ll see logs like: |
| 62 | + |
| 63 | +```sh |
| 64 | +2025-08-07T09:03:29.314549Z INFO server: Server started |
| 65 | +2025-08-07T09:03:29.314589Z INFO orion_xds::xds::server: Server started 127.0.0.1:50051 |
| 66 | +2025-08-07T09:03:39.316111Z INFO server: Adding cluster Cluster-9d0e506a-b3b9-4429-b266-83ae3cdbf4b7 |
| 67 | +2025-08-07T09:03:44.318214Z INFO server: Adding listener Resource { name: "Listener-9d0e506a-b3b9-4429-b266-83ae3cdbf4b7", resource_name: None, aliases: [], version: "", resource: Some(Any { type_url: "type.googleapis.com/envoy.config.listener.v3.Listener", value: [10, 45, 76, 105, 115, 116, 101, 110, 101, 114, 45, 57, 100, 48, 101, 53, 48, 54, 97, 45, 98, 51, 98, 57, 45, 52, 52, 50, 57, 45, 98, 50, 54, 54, 45, 56, 51, 97, 101, 51, 99, 100, 98, 102, 52, 98, 55, 18, 19, 10, 17, 18, 12, 49, 57, 50, 46, 49, 54, 56, 46, 49, 46, 49, 48, 24, 192, 62, 26, 252, 3, 26, 199, 3, 10, 101, 116, 121, 112, 101, 46, 103, 111, 111, 103, 108, 101, 97, 112, 105, 115, 46, 99, 111, 109, 47, 101, 110, 118, 111, 121, 46, 101, 120, 116, 101, 110, 115, 105, 111, 110, 115, 46, 102, 105, 108, 116, 101, 114, 115, 46, 110, 101, 116, 119, 111, 114, 107, 46, 104, 116, 116, 112, 95, 99, 111, 110, 110, 101, 99, 116, 105, 111, 110, 95, 109, 97, 110, 97, 103, 101, 114, 46, 118, 51, 46, 72, 116, 116, 112, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 77, 97, 110, 97, 103, 101, 114, 34, 221, 2, 10, 101, 116, 121, 112, 101, 46, 103, 111, 111, 103, 108, 101, 97, 112, 105, 115, 46, 99, 111, 109, 47, 101, 110, 118, 111, 121, 46, 101, 120, 116, 101, 110, 115, 105, 111, 110, 115, 46, 102, 105, 108, 116, 101, 114, 115, 46, 110, 101, 116, 119, 111, 114, 107, 46, 104, 116, 116, 112, 95, 99, 111, 110, 110, 101, 99, 116, 105, 111, 110, 95, 109, 97, 110, 97, 103, 101, 114, 46, 118, 51, 46, 72, 116, 116, 112, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 77, 97, 110, 97, 103, 101, 114, 18, 243, 1, 8, 1, 34, 238, 1, 10, 56, 76, 105, 115, 116, 101, 110, 101, 114, 45, 57, 100, 48, 101, 53, 48, 54, 97, 45, 98, 51, 98, 57, 45, 52, 52, 50, 57, 45, 98, 50, 54, 54, 45, 56, 51, 97, 101, 51, 99, 100, 98, 102, 52, 98, 55, 45, 114, 111, 117, 116, 101, 45, 99, 111, 110, 102, 18, 177, 1, 10, 48, 76, 105, 115, 116, 101, 110, 101, 114, 45, 57, 100, 48, 101, 53, 48, 54, 97, 45, 98, 51, 98, 57, 45, 52, 52, 50, 57, 45, 98, 50, 54, 54, 45, 56, 51, 97, 101, 51, 99, 100, 98, 102, 52, 98, 55, 45, 118, 99, 18, 1, 42, 18, 11, 101, 120, 97, 109, 112, 108, 101, 46, 99, 111, 109, 26, 109, 10, 3, 18, 1, 47, 18, 46, 10, 44, 67, 108, 117, 115, 116, 101, 114, 45, 57, 100, 48, 101, 53, 48, 54, 97, 45, 98, 51, 98, 57, 45, 52, 52, 50, 57, 45, 98, 50, 54, 54, 45, 56, 51, 97, 101, 51, 99, 100, 98, 102, 52, 98, 55, 114, 54, 76, 105, 115, 116, 101, 110, 101, 114, 45, 57, 100, 48, 101, 53, 48, 54, 97, 45, 98, 51, 98, 57, 45, 52, 52, 50, 57, 45, 98, 50, 54, 54, 45, 56, 51, 97, 101, 51, 99, 100, 98, 102, 52, 98, 55, 45, 118, 99, 45, 114, 111, 117, 116, 101, 58, 48, 76, 105, 115, 116, 101, 110, 101, 114, 45, 57, 100, 48, 101, 53, 48, 54, 97, 45, 98, 51, 98, 57, 45, 52, 52, 50, 57, 45, 98, 50, 54, 54, 45, 56, 51, 97, 101, 51, 99, 100, 98, 102, 52, 98, 55, 45, 102, 99] }), ttl: None, cache_control: None, metadata: None } |
| 68 | +2025-08-07T09:03:59.319701Z INFO server: Removing cluster Cluster-9d0e506a-b3b9-4429-b266-83ae3cdbf4b7 |
| 69 | +2025-08-07T09:04:04.320811Z INFO server: Removing listener Resource { name: "Listener-9d0e506a-b3b9-4429-b266-83ae3cdbf4b7", resource_name: None, aliases: [], version: "", resource: Some(Any { type_url: "type.googleapis.com/envoy.config.listener.v3.Listener", value: [10, 45, 76, 105, 115, 116, 101, 110, 101, 114, 45, 57, 100, 48, 101, 53, 48, 54, 97, 45, 98, 51, 98, 57, 45, 52, 52, 50, 57, 45, 98, 50, 54, 54, 45, 56, 51, 97, 101, 51, 99, 100, 98, 102, 52, 98, 55, 18, 19, 10, 17, 18, 12, 49, 57, 50, 46, 49, 54, 56, 46, 49, 46, 49, 48, 24, 192, 62, 26, 252, 3, 26, 199, 3, 10, 101, 116, 121, 112, 101, 46, 103, 111, 111, 103, 108, 101, 97, 112, 105, 115, 46, 99, 111, 109, 47, 101, 110, 118, 111, 121, 46, 101, 120, 116, 101, 110, 115, 105, 111, 110, 115, 46, 102, 105, 108, 116, 101, 114, 115, 46, 110, 101, 116, 119, 111, 114, 107, 46, 104, 116, 116, 112, 95, 99, 111, 110, 110, 101, 99, 116, 105, 111, 110, 95, 109, 97, 110, 97, 103, 101, 114, 46, 118, 51, 46, 72, 116, 116, 112, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 77, 97, 110, 97, 103, 101, 114, 34, 221, 2, 10, 101, 116, 121, 112, 101, 46, 103, 111, 111, 103, 108, 101, 97, 112, 105, 115, 46, 99, 111, 109, 47, 101, 110, 118, 111, 121, 46, 101, 120, 116, 101, 110, 115, 105, 111, 110, 115, 46, 102, 105, 108, 116, 101, 114, 115, 46, 110, 101, 116, 119, 111, 114, 107, 46, 104, 116, 116, 112, 95, 99, 111, 110, 110, 101, 99, 116, 105, 111, 110, 95, 109, 97, 110, 97, 103, 101, 114, 46, 118, 51, 46, 72, 116, 116, 112, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 77, 97, 110, 97, 103, 101, 114, 18, 243, 1, 8, 1, 34, 238, 1, 10, 56, 76, 105, 115, 116, 101, 110, 101, 114, 45, 57, 100, 48, 101, 53, 48, 54, 97, 45, 98, 51, 98, 57, 45, 52, 52, 50, 57, 45, 98, 50, 54, 54, 45, 56, 51, 97, 101, 51, 99, 100, 98, 102, 52, 98, 55, 45, 114, 111, 117, 116, 101, 45, 99, 111, 110, 102, 18, 177, 1, 10, 48, 76, 105, 115, 116, 101, 110, 101, 114, 45, 57, 100, 48, 101, 53, 48, 54, 97, 45, 98, 51, 98, 57, 45, 52, 52, 50, 57, 45, 98, 50, 54, 54, 45, 56, 51, 97, 101, 51, 99, 100, 98, 102, 52, 98, 55, 45, 118, 99, 18, 1, 42, 18, 11, 101, 120, 97, 109, 112, 108, 101, 46, 99, 111, 109, 26, 109, 10, 3, 18, 1, 47, 18, 46, 10, 44, 67, 108, 117, 115, 116, 101, 114, 45, 57, 100, 48, 101, 53, 48, 54, 97, 45, 98, 51, 98, 57, 45, 52, 52, 50, 57, 45, 98, 50, 54, 54, 45, 56, 51, 97, 101, 51, 99, 100, 98, 102, 52, 98, 55, 114, 54, 76, 105, 115, 116, 101, 110, 101, 114, 45, 57, 100, 48, 101, 53, 48, 54, 97, 45, 98, 51, 98, 57, 45, 52, 52, 50, 57, 45, 98, 50, 54, 54, 45, 56, 51, 97, 101, 51, 99, 100, 98, 102, 52, 98, 55, 45, 118, 99, 45, 114, 111, 117, 116, 101, 58, 48, 76, 105, 115, 116, 101, 110, 101, 114, 45, 57, 100, 48, 101, 53, 48, 54, 97, 45, 98, 51, 98, 57, 45, 52, 52, 50, 57, 45, 98, 50, 54, 54, 45, 56, 51, 97, 101, 51, 99, 100, 98, 102, 52, 98, 55, 45, 102, 99] }), ttl: None, cache_control: None, metadata: None } |
| 70 | +``` |
| 71 | + |
| 72 | + |
| 73 | +### 2. Open **Terminal B** – Run the Client |
| 74 | + |
| 75 | +```bash |
| 76 | +cd orion-xds |
| 77 | +cargo run --example client |
| 78 | +``` |
| 79 | + |
| 80 | +What it does: |
| 81 | + |
| 82 | +- Connects to the XDS server at `127.0.0.1:50051` |
| 83 | +- Subscribes to Aggregated Discovery Service (ADS) |
| 84 | +- Sends DeltaDiscoveryRequests for various resource types (Listeners, Clusters) |
| 85 | +- Prints updates received for supported resource types (e.g., Clusters) |
| 86 | + |
| 87 | +However, note: |
| 88 | + |
| 89 | +> **Current Limitation:** The client fails to decode Listener configurations due to an unsupported field (`name`) inside the route configuration. You will see warnings about this in the logs. |
| 90 | +
|
| 91 | +Sample logs: |
| 92 | +``` |
| 93 | +INFO client: Got update for cluster Cluster-1c6d9ce7-a843-4d91-842c-b4b9dd64cc83 |
| 94 | +WARN orion_xds::xds::client: problem decoding config update for Listener-1c6d9ce7-a843-4d91-842c-b4b9dd64cc83 : error Some(ConversionError(TracedError([... / routes [0], UnsupportedField("name")))) |
| 95 | +``` |
| 96 | + |
| 97 | +**What this means:** |
| 98 | +- Cluster resources are successfully received and parsed. |
| 99 | +- ❌ Listener resources are received but fail during decoding due to an unsupported `"name"` field in the route. |
| 100 | +- The client will continue retrying and resubscribing as expected, but it won't process listener configs correctly until the field is removed. |
| 101 | + |
| 102 | +--- |
| 103 | + |
| 104 | +## Running Other Examples |
| 105 | + |
| 106 | +Each file demonstrates a specialized XDS capability. |
| 107 | + |
| 108 | +### `server_routes_and_loads.rs` |
| 109 | + |
| 110 | +```bash |
| 111 | +cargo run --example server_routes_and_loads |
| 112 | +``` |
| 113 | +Sample Logs: |
| 114 | +```sh |
| 115 | +2025-08-07T09:13:53.411123Z INFO server_routes_and_loads: Server started |
| 116 | +2025-08-07T09:13:53.411184Z INFO orion_xds::xds::server: Server started 127.0.0.1:50051 |
| 117 | +2025-08-07T09:14:03.412738Z INFO server_routes_and_loads: Adding Cluster Load Assignment for cluster cluster_http |
| 118 | +2025-08-07T09:14:08.414280Z INFO server_routes_and_loads: Adding Route configuration rds_route |
| 119 | +2025-08-07T09:14:23.415020Z INFO server_routes_and_loads: Removing cluster load assignment cluster_http |
| 120 | +2025-08-07T09:14:28.416480Z INFO server_routes_and_loads: Removing route configuration rds_route |
| 121 | +``` |
| 122 | + |
| 123 | +**Purpose**: |
| 124 | +Shows how to: |
| 125 | + |
| 126 | +- Dynamically add and remove XDS resources at runtime |
| 127 | +- Configure RouteConfiguration objects that map URL paths to upstream clusters |
| 128 | +- Push ClusterLoadAssignments that specify endpoint details for a cluster |
| 129 | + |
| 130 | +**Use case**: |
| 131 | +Testing Dynamic Config Updates, Simulating Traffic Shaping and Routing Logic, Endpoint Failover and Service Discovery |
| 132 | + |
| 133 | +**Client**: |
| 134 | +For running the client you can rerun the previous example of the client. |
0 commit comments