praxis-proxy-protocol 0.7.3

HTTP, TCP, and protocol adapters for Praxis
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
// SPDX-License-Identifier: Apache-2.0
// Copyright (c) 2026 Praxis Contributors

//! Cluster endpoint metadata for admin stats snapshots.

use std::{collections::HashMap, sync::Arc};

use arc_swap::ArcSwap;
use praxis_core::config::{ChainRef, Cluster, Config, FilterEntry};
use serde::Serialize;

// -----------------------------------------------------------------------------
// Constants
// -----------------------------------------------------------------------------

/// Filter types whose config may declare inline `clusters:` lists.
const CLUSTER_BEARING_FILTERS: &[&str] = &["load_balancer", "tcp_load_balancer"];

/// Filter type that nests entries under `steps[].filters`.
const STEP_BEARING_FILTER: &str = "iterative_request_router";

// -----------------------------------------------------------------------------
// ClusterMeta
// -----------------------------------------------------------------------------

/// Upstream endpoint addresses for one cluster (from resolved config).
#[derive(Clone, Debug, Serialize)]
pub struct ClusterMeta {
    /// Cluster name.
    pub name: String,
    /// Upstream socket addresses (`host:port`).
    pub endpoints: Vec<String>,
}

/// Hot-swappable cluster metadata for `/api/stats`.
pub type ClusterMetaStore = Arc<ArcSwap<HashMap<String, ClusterMeta>>>;

/// Wrap a metadata map in an [`ArcSwap`] store.
pub fn new_cluster_meta_store(meta: HashMap<String, ClusterMeta>) -> ClusterMetaStore {
    Arc::new(ArcSwap::from_pointee(meta))
}

/// Build cluster metadata from configuration.
pub fn cluster_meta_from_config(config: &Config) -> HashMap<String, ClusterMeta> {
    let mut meta: HashMap<String, ClusterMeta> = config
        .clusters
        .iter()
        .map(|cluster| (cluster.name.to_string(), cluster_meta_from_cluster(cluster)))
        .collect();

    for chain in &config.filter_chains {
        for entry in &chain.filters {
            collect_clusters_from_entry(entry, &mut meta);
        }
    }

    meta
}

/// Build metadata for one configured cluster.
fn cluster_meta_from_cluster(cluster: &Cluster) -> ClusterMeta {
    ClusterMeta {
        name: cluster.name.to_string(),
        endpoints: cluster.endpoints.iter().map(|ep| ep.address().to_owned()).collect(),
    }
}

// -----------------------------------------------------------------------------
// Metadata Extraction
// -----------------------------------------------------------------------------

/// Merge inline and nested load-balancer clusters into `meta`.
fn collect_clusters_from_entry(entry: &FilterEntry, meta: &mut HashMap<String, ClusterMeta>) {
    if CLUSTER_BEARING_FILTERS.contains(&entry.filter_type.as_str())
        && let Some(clusters) = inline_clusters_from_entry(entry)
    {
        for cluster in clusters {
            meta.entry(cluster.name.to_string())
                .or_insert_with(|| cluster_meta_from_cluster(&cluster));
        }
    }

    for branch in entry.branch_chains.as_deref().unwrap_or_default() {
        for chain_ref in &branch.chains {
            if let ChainRef::Inline { filters, .. } = chain_ref {
                for nested in filters {
                    collect_clusters_from_entry(nested, meta);
                }
            }
        }
    }

    if entry.filter_type == STEP_BEARING_FILTER {
        for nested in step_filters_from_entry(entry) {
            collect_clusters_from_entry(&nested, meta);
        }
    }
}

/// Deserialize inline `clusters:` from a load-balancer filter entry.
fn inline_clusters_from_entry(entry: &FilterEntry) -> Option<Vec<Cluster>> {
    let serde_yaml::Value::Mapping(mapping) = &entry.config else {
        return None;
    };
    let clusters_value = mapping.get("clusters")?;
    serde_yaml::from_value(clusters_value.clone()).ok()
}

/// Deserialize nested filters from an `iterative_request_router` entry.
fn step_filters_from_entry(entry: &FilterEntry) -> Vec<FilterEntry> {
    let serde_yaml::Value::Mapping(mapping) = &entry.config else {
        return Vec::new();
    };
    let Some(serde_yaml::Value::Sequence(steps)) = mapping.get("steps") else {
        return Vec::new();
    };
    let mut filters = Vec::new();
    for step in steps {
        let serde_yaml::Value::Mapping(step_map) = step else {
            continue;
        };
        let Some(step_filters) = step_map.get("filters") else {
            continue;
        };
        if let Ok(parsed) = serde_yaml::from_value::<Vec<FilterEntry>>(step_filters.clone()) {
            filters.extend(parsed);
        }
    }
    filters
}

// -----------------------------------------------------------------------------
// Tests
// -----------------------------------------------------------------------------

#[cfg(test)]
#[expect(clippy::allow_attributes, reason = "blanket test suppressions")]
#[allow(
    clippy::unwrap_used,
    clippy::expect_used,
    clippy::needless_raw_strings,
    clippy::uninlined_format_args,
    clippy::needless_raw_string_hashes,
    clippy::too_many_lines,
    reason = "tests"
)]
mod tests {
    use super::*;

    #[test]
    fn cluster_meta_from_config_maps_endpoints() {
        let config = Config::from_yaml(
            r#"
insecure_options:
  allow_private_endpoints: true
listeners:
  - name: web
    address: "127.0.0.1:8080"
    filter_chains: [main]
clusters:
  - name: backend
    endpoints:
      - address: "127.0.0.1:9000"
      - address: "127.0.0.1:9001"
filter_chains:
  - name: main
    filters: [{ filter: static_response, status: 200 }]
"#,
        )
        .expect("config should parse");
        let meta = cluster_meta_from_config(&config);
        let backend = meta.get("backend").expect("backend cluster");
        assert_eq!(
            backend.endpoints,
            vec!["127.0.0.1:9000".to_owned(), "127.0.0.1:9001".to_owned()],
            "endpoint addresses should match config"
        );
    }

    #[test]
    fn cluster_meta_from_config_includes_inline_load_balancer_clusters() {
        let config = Config::from_yaml(
            r#"
insecure_options:
  allow_private_endpoints: true
listeners:
  - name: web
    address: "127.0.0.1:8080"
    filter_chains: [main]
filter_chains:
  - name: main
    filters:
      - filter: load_balancer
        clusters:
          - name: inline-backend
            endpoints:
              - address: "127.0.0.1:9100"
"#,
        )
        .expect("config should parse");
        let meta = cluster_meta_from_config(&config);
        let backend = meta.get("inline-backend").expect("inline cluster");
        assert_eq!(
            backend.endpoints,
            vec!["127.0.0.1:9100".to_owned()],
            "inline load_balancer cluster should appear in stats metadata"
        );
    }

    #[test]
    fn cluster_meta_from_config_includes_tcp_load_balancer_clusters() {
        let config = Config::from_yaml(
            r#"
insecure_options:
  allow_private_endpoints: true
listeners:
  - name: tcp
    address: "127.0.0.1:8080"
    protocol: tcp
    filter_chains: [main]
filter_chains:
  - name: main
    filters:
      - filter: tcp_load_balancer
        clusters:
          - name: tcp-backend
            endpoints:
              - address: "127.0.0.1:9200"
              - address: "127.0.0.1:9201"
"#,
        )
        .expect("config should parse");
        let meta = cluster_meta_from_config(&config);
        let backend = meta.get("tcp-backend").expect("tcp inline cluster");
        assert_eq!(
            backend.endpoints,
            vec!["127.0.0.1:9200".to_owned(), "127.0.0.1:9201".to_owned()],
            "tcp_load_balancer cluster should appear in stats metadata"
        );
    }

    #[test]
    #[ignore]
    fn cluster_meta_from_config_handles_branch_chains() {
        let config = Config::from_yaml(
            r#"
insecure_options:
  allow_private_endpoints: true
listeners:
  - name: web
    address: "127.0.0.1:8080"
    filter_chains: [main]
filter_chains:
  - name: main
    filters:
      - filter: guardrails
        action: flag
        rules: []
        branch_chains:
          - on_result:
              filter: guardrails
              result: passed
            rejoin: next
            chains:
              - name: inline_branch
                filters:
                  - filter: load_balancer
                    clusters:
                      - name: branch-backend
                        endpoints:
                          - address: "127.0.0.1:9300"
"#,
        )
        .expect("config should parse");
        let meta = cluster_meta_from_config(&config);
        let backend = meta.get("branch-backend").expect("branch cluster");
        assert_eq!(
            backend.endpoints,
            vec!["127.0.0.1:9300".to_owned()],
            "clusters in branch chains should be collected"
        );
    }

    #[ignore]
    #[test]
    fn cluster_meta_from_config_handles_nested_branches() {
        let config = Config::from_yaml(
            r#"
insecure_options:
  allow_private_endpoints: true
listeners:
  - name: web
    address: "127.0.0.1:8080"
    filter_chains: [main]
filter_chains:
  - name: main
    filters:
      - filter: guardrails
        action: flag
        rules: []
        branch_chains:
          - on_result:
              filter: guardrails
              result: passed
            rejoin: next
            chains:
              - name: outer_branch
                filters:
                  - filter: guardrails
                    action: flag
                    rules: []
                    branch_chains:
                      - on_result:
                          filter: guardrails
                          result: passed
                        rejoin: next
                        chains:
                          - name: inner_branch
                            filters:
                              - filter: load_balancer
                                clusters:
                                  - name: nested-backend
                                    endpoints:
                                      - address: "127.0.0.1:9400"
"#,
        )
        .expect("config should parse");
        let meta = cluster_meta_from_config(&config);
        let backend = meta.get("nested-backend").expect("nested branch cluster");
        assert_eq!(
            backend.endpoints,
            vec!["127.0.0.1:9400".to_owned()],
            "clusters in nested branch chains should be collected recursively"
        );
    }

    #[test]
    fn cluster_meta_from_config_handles_iterative_request_router() {
        let config = Config::from_yaml(
            r#"
insecure_options:
  allow_private_endpoints: true
listeners:
  - name: web
    address: "127.0.0.1:8080"
    filter_chains: [main]
filter_chains:
  - name: main
    filters:
      - filter: iterative_request_router
        steps:
          - filters:
              - filter: load_balancer
                clusters:
                  - name: step1-backend
                    endpoints:
                      - address: "127.0.0.1:9500"
          - filters:
              - filter: load_balancer
                clusters:
                  - name: step2-backend
                    endpoints:
                      - address: "127.0.0.1:9501"
"#,
        )
        .expect("config should parse");
        let meta = cluster_meta_from_config(&config);
        let step1 = meta.get("step1-backend").expect("step 1 cluster");
        assert_eq!(
            step1.endpoints,
            vec!["127.0.0.1:9500".to_owned()],
            "clusters in iterative_request_router steps should be collected"
        );
        let step2 = meta.get("step2-backend").expect("step 2 cluster");
        assert_eq!(
            step2.endpoints,
            vec!["127.0.0.1:9501".to_owned()],
            "all steps should be processed"
        );
    }

    #[test]
    fn cluster_meta_from_config_skips_non_inline_clusters() {
        let config = Config::from_yaml(
            r#"
insecure_options:
  allow_private_endpoints: true
listeners:
  - name: web
    address: "127.0.0.1:8080"
    filter_chains: [main]
clusters:
  - name: top-level
    endpoints:
      - address: "127.0.0.1:9000"
filter_chains:
  - name: main
    filters:
      - filter: load_balancer
        cluster: top-level
"#,
        )
        .expect("config should parse");
        let meta = cluster_meta_from_config(&config);
        let cluster = meta.get("top-level").expect("top-level cluster");
        assert_eq!(
            cluster.endpoints,
            vec!["127.0.0.1:9000".to_owned()],
            "top-level clusters should be collected"
        );
        assert_eq!(meta.len(), 1, "should only collect top-level cluster, not reference");
    }

    #[test]
    fn cluster_meta_from_config_handles_mixed_sources() {
        let config = Config::from_yaml(
            r#"
insecure_options:
  allow_private_endpoints: true
listeners:
  - name: web
    address: "127.0.0.1:8080"
    filter_chains: [main]
clusters:
  - name: top-level
    endpoints:
      - address: "127.0.0.1:9000"
filter_chains:
  - name: main
    filters:
      - filter: load_balancer
        clusters:
          - name: inline-lb
            endpoints:
              - address: "127.0.0.1:9100"
      - filter: tcp_load_balancer
        clusters:
          - name: inline-tcp
            endpoints:
              - address: "127.0.0.1:9200"
"#,
        )
        .expect("config should parse");
        let meta = cluster_meta_from_config(&config);
        assert_eq!(
            meta.len(),
            3,
            "should collect from all sources: top-level, inline HTTP, inline TCP"
        );
        assert!(meta.contains_key("top-level"));
        assert!(meta.contains_key("inline-lb"));
        assert!(meta.contains_key("inline-tcp"));
    }

    #[test]
    fn cluster_meta_from_config_deduplicates_cluster_names() {
        let config = Config::from_yaml(
            r#"
insecure_options:
  allow_private_endpoints: true
listeners:
  - name: web
    address: "127.0.0.1:8080"
    filter_chains: [main]
clusters:
  - name: shared
    endpoints:
      - address: "127.0.0.1:9000"
filter_chains:
  - name: main
    filters:
      - filter: load_balancer
        clusters:
          - name: shared
            endpoints:
              - address: "127.0.0.1:9100"
"#,
        )
        .expect("config should parse");
        let meta = cluster_meta_from_config(&config);
        assert_eq!(
            meta.len(),
            1,
            "duplicate cluster names should not create multiple entries"
        );
        let shared = meta.get("shared").expect("shared cluster");
        assert_eq!(
            shared.endpoints,
            vec!["127.0.0.1:9000".to_owned()],
            "top-level cluster should win (not be overwritten by inline)"
        );
    }

    #[test]
    fn cluster_meta_from_cluster_preserves_all_endpoints() {
        let config = Config::from_yaml(
            r#"
insecure_options:
  allow_private_endpoints: true
listeners:
  - name: web
    address: "127.0.0.1:8080"
    filter_chains: [main]
clusters:
  - name: multi
    endpoints:
      - address: "127.0.0.1:9000"
      - address: "127.0.0.1:9001"
      - address: "127.0.0.1:9002"
filter_chains:
  - name: main
    filters: [{ filter: static_response, status: 200 }]
"#,
        )
        .expect("config should parse");
        let cluster = config.clusters.first().expect("should have cluster");
        let meta = cluster_meta_from_cluster(cluster);
        assert_eq!(meta.name, "multi");
        assert_eq!(
            meta.endpoints,
            vec![
                "127.0.0.1:9000".to_owned(),
                "127.0.0.1:9001".to_owned(),
                "127.0.0.1:9002".to_owned(),
            ],
            "all endpoints should be preserved in metadata"
        );
    }

    #[test]
    fn new_cluster_meta_store_wraps_in_arcswap() {
        let mut map = HashMap::new();
        map.insert(
            "test".to_owned(),
            ClusterMeta {
                name: "test".to_owned(),
                endpoints: vec!["127.0.0.1:9000".to_owned()],
            },
        );
        let store = new_cluster_meta_store(map);
        let loaded = store.load();
        assert_eq!(loaded.len(), 1);
        let cluster = loaded.get("test").expect("should have test cluster");
        assert_eq!(cluster.name, "test");
        assert_eq!(cluster.endpoints, vec!["127.0.0.1:9000".to_owned()]);
    }

    #[test]
    fn cluster_meta_store_supports_updates() {
        let initial = HashMap::new();
        let store = new_cluster_meta_store(initial);
        assert_eq!(store.load().len(), 0, "should start empty");

        let mut updated = HashMap::new();
        updated.insert(
            "new".to_owned(),
            ClusterMeta {
                name: "new".to_owned(),
                endpoints: vec!["127.0.0.1:9999".to_owned()],
            },
        );
        store.store(Arc::new(updated));

        let loaded = store.load();
        assert_eq!(loaded.len(), 1, "should have updated cluster");
        let cluster = loaded.get("new").expect("should have new cluster");
        assert_eq!(cluster.name, "new");
    }

    #[test]
    fn inline_clusters_from_entry_handles_non_mapping_config() {
        let entry = FilterEntry {
            filter_type: "load_balancer".to_owned(),
            config: serde_yaml::Value::String("not-a-mapping".to_owned()),
            branch_chains: None,
            conditions: Vec::new(),
            name: None,
            response_conditions: Vec::new(),
            failure_mode: praxis_core::config::FailureMode::Closed,
        };
        let result = inline_clusters_from_entry(&entry);
        assert!(result.is_none(), "should return None for non-mapping config");
    }

    #[test]
    fn inline_clusters_from_entry_handles_missing_clusters_key() {
        let entry = FilterEntry {
            filter_type: "load_balancer".to_owned(),
            config: serde_yaml::from_str("other_field: value").expect("should parse"),
            branch_chains: None,
            conditions: Vec::new(),
            name: None,
            response_conditions: Vec::new(),
            failure_mode: praxis_core::config::FailureMode::Closed,
        };
        let result = inline_clusters_from_entry(&entry);
        assert!(result.is_none(), "should return None when clusters key is missing");
    }

    #[test]
    fn inline_clusters_from_entry_handles_malformed_clusters() {
        let entry = FilterEntry {
            filter_type: "load_balancer".to_owned(),
            config: serde_yaml::from_str("clusters: not-a-list").expect("should parse"),
            branch_chains: None,
            conditions: Vec::new(),
            name: None,
            response_conditions: Vec::new(),
            failure_mode: praxis_core::config::FailureMode::Closed,
        };
        let result = inline_clusters_from_entry(&entry);
        assert!(result.is_none(), "should return None for malformed clusters value");
    }

    #[test]
    fn step_filters_from_entry_handles_non_mapping_config() {
        let entry = FilterEntry {
            filter_type: "iterative_request_router".to_owned(),
            config: serde_yaml::Value::Null,
            branch_chains: None,
            conditions: Vec::new(),
            name: None,
            response_conditions: Vec::new(),
            failure_mode: praxis_core::config::FailureMode::Closed,
        };
        let result = step_filters_from_entry(&entry);
        assert!(result.is_empty(), "should return empty vec for non-mapping config");
    }

    #[test]
    fn step_filters_from_entry_handles_missing_steps() {
        let entry = FilterEntry {
            filter_type: "iterative_request_router".to_owned(),
            config: serde_yaml::from_str("other_field: value").expect("should parse"),
            branch_chains: None,
            conditions: Vec::new(),
            name: None,
            response_conditions: Vec::new(),
            failure_mode: praxis_core::config::FailureMode::Closed,
        };
        let result = step_filters_from_entry(&entry);
        assert!(result.is_empty(), "should return empty vec when steps key is missing");
    }

    #[test]
    fn step_filters_from_entry_handles_non_sequence_steps() {
        let entry = FilterEntry {
            filter_type: "iterative_request_router".to_owned(),
            config: serde_yaml::from_str("steps: not-a-sequence").expect("should parse"),
            branch_chains: None,
            conditions: Vec::new(),
            name: None,
            response_conditions: Vec::new(),
            failure_mode: praxis_core::config::FailureMode::Closed,
        };
        let result = step_filters_from_entry(&entry);
        assert!(
            result.is_empty(),
            "should return empty vec when steps is not a sequence"
        );
    }

    #[test]
    fn step_filters_from_entry_skips_non_mapping_steps() {
        let entry = FilterEntry {
            filter_type: "iterative_request_router".to_owned(),
            config: serde_yaml::from_str(
                r#"
steps:
  - "not-a-mapping"
  - filters: []
"#,
            )
            .expect("should parse"),
            branch_chains: None,
            conditions: Vec::new(),
            name: None,
            response_conditions: Vec::new(),
            failure_mode: praxis_core::config::FailureMode::Closed,
        };
        let result = step_filters_from_entry(&entry);
        assert_eq!(result.len(), 0, "should skip non-mapping steps and process valid ones");
    }

    #[test]
    fn step_filters_from_entry_skips_steps_without_filters() {
        let entry = FilterEntry {
            filter_type: "iterative_request_router".to_owned(),
            config: serde_yaml::from_str(
                r#"
steps:
  - other_field: value
  - filters:
      - filter: static_response
        status: 200
"#,
            )
            .expect("should parse"),
            branch_chains: None,
            conditions: Vec::new(),
            name: None,
            response_conditions: Vec::new(),
            failure_mode: praxis_core::config::FailureMode::Closed,
        };
        let result = step_filters_from_entry(&entry);
        assert_eq!(
            result.len(),
            1,
            "should skip steps without filters key and process valid ones"
        );
    }

    #[test]
    fn step_filters_from_entry_handles_malformed_filters() {
        let entry = FilterEntry {
            filter_type: "iterative_request_router".to_owned(),
            config: serde_yaml::from_str(
                r#"
steps:
  - filters: "not-valid-filter-list"
"#,
            )
            .expect("should parse"),
            branch_chains: None,
            conditions: Vec::new(),
            name: None,
            response_conditions: Vec::new(),
            failure_mode: praxis_core::config::FailureMode::Closed,
        };
        let result = step_filters_from_entry(&entry);
        assert_eq!(result.len(), 0, "should skip steps with malformed filters");
    }

    #[test]
    fn cluster_meta_clone() {
        let original = ClusterMeta {
            name: "test".to_owned(),
            endpoints: vec!["127.0.0.1:9000".to_owned()],
        };
        let cloned = original.clone();
        assert_eq!(original.name, cloned.name);
        assert_eq!(original.endpoints, cloned.endpoints);
    }

    #[test]
    fn cluster_meta_debug() {
        let meta = ClusterMeta {
            name: "debug-test".to_owned(),
            endpoints: vec!["127.0.0.1:9000".to_owned()],
        };
        let debug_str = format!("{:?}", meta);
        assert!(debug_str.contains("ClusterMeta"));
        assert!(debug_str.contains("debug-test"));
        assert!(debug_str.contains("127.0.0.1:9000"));
    }
}