Skip to main content

common_meta/kv_backend/
etcd.rs

1// Copyright 2023 Greptime Team
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use std::any::Any;
16use std::fs;
17use std::sync::Arc;
18
19use common_telemetry::{debug, info};
20use etcd_client::{
21    Certificate, Client, DeleteOptions, GetOptions, Identity, PutOptions, TlsOptions, Txn, TxnOp,
22    TxnOpResponse, TxnResponse,
23};
24use snafu::{ResultExt, ensure};
25
26use crate::error::{self, Error, LoadTlsCertificateSnafu, Result};
27use crate::kv_backend::txn::{Txn as KvTxn, TxnResponse as KvTxnResponse};
28use crate::kv_backend::{KvBackend, KvBackendRef, TxnCapability, TxnService};
29use crate::metrics::METRIC_META_TXN_REQUEST;
30use crate::rpc::KeyValue;
31use crate::rpc::store::{
32    BatchDeleteRequest, BatchDeleteResponse, BatchGetRequest, BatchGetResponse, BatchPutRequest,
33    BatchPutResponse, DeleteRangeRequest, DeleteRangeResponse, PutRequest, PutResponse,
34    RangeRequest, RangeResponse,
35};
36
37const DEFAULT_MAX_DECODING_SIZE: usize = 32 * 1024 * 1024; // 32MB
38
39pub struct EtcdStore {
40    client: Client,
41    // Maximum number of operations permitted in a transaction.
42    // The etcd default configuration's `--max-txn-ops` is 128.
43    //
44    // For more detail, see: https://etcd.io/docs/v3.5/op-guide/configuration/
45    max_txn_ops: usize,
46    // Maximum decoding message size in bytes. Default 32MB.
47    max_decoding_size: usize,
48}
49
50impl EtcdStore {
51    pub async fn with_endpoints<E, S>(endpoints: S, max_txn_ops: usize) -> Result<KvBackendRef>
52    where
53        E: AsRef<str>,
54        S: AsRef<[E]>,
55    {
56        let client = Client::connect(endpoints, None)
57            .await
58            .context(error::ConnectEtcdSnafu)?;
59
60        Ok(Self::with_etcd_client(client, max_txn_ops))
61    }
62
63    pub fn with_etcd_client(client: Client, max_txn_ops: usize) -> KvBackendRef {
64        info!("Connected to etcd");
65        Arc::new(Self {
66            client,
67            max_txn_ops,
68            max_decoding_size: DEFAULT_MAX_DECODING_SIZE,
69        })
70    }
71
72    pub fn set_max_decoding_size(&mut self, max_decoding_size: usize) {
73        self.max_decoding_size = max_decoding_size;
74    }
75
76    fn kv_client(&self) -> etcd_client::KvClient {
77        self.client
78            .kv_client()
79            .max_decoding_message_size(self.max_decoding_size)
80    }
81
82    async fn do_multi_txn(&self, txn_ops: Vec<TxnOp>) -> Result<Vec<TxnResponse>> {
83        let max_txn_ops = self.max_txn_ops;
84        if txn_ops.len() < max_txn_ops {
85            // fast path
86            let _timer = METRIC_META_TXN_REQUEST
87                .with_label_values(&["etcd", "txn"])
88                .start_timer();
89            let txn = Txn::new().and_then(txn_ops);
90            let txn_res = self
91                .kv_client()
92                .txn(txn)
93                .await
94                .context(error::EtcdFailedSnafu)?;
95            return Ok(vec![txn_res]);
96        }
97
98        let txns = txn_ops
99            .chunks(max_txn_ops)
100            .map(|part| async move {
101                let _timer = METRIC_META_TXN_REQUEST
102                    .with_label_values(&["etcd", "txn"])
103                    .start_timer();
104                let txn = Txn::new().and_then(part);
105                self.kv_client().txn(txn).await
106            })
107            .collect::<Vec<_>>();
108
109        futures::future::try_join_all(txns)
110            .await
111            .context(error::EtcdFailedSnafu)
112    }
113}
114
115#[async_trait::async_trait]
116impl KvBackend for EtcdStore {
117    fn name(&self) -> &str {
118        "Etcd"
119    }
120
121    fn as_any(&self) -> &dyn Any {
122        self
123    }
124
125    async fn range(&self, req: RangeRequest) -> Result<RangeResponse> {
126        let Get { key, options } = req.try_into()?;
127
128        let mut res = self
129            .kv_client()
130            .get(key, options)
131            .await
132            .context(error::EtcdFailedSnafu)?;
133
134        let kvs = res
135            .take_kvs()
136            .into_iter()
137            .map(KeyValue::from)
138            .collect::<Vec<_>>();
139
140        Ok(RangeResponse {
141            kvs,
142            more: res.more(),
143        })
144    }
145
146    async fn put(&self, req: PutRequest) -> Result<PutResponse> {
147        let Put {
148            key,
149            value,
150            options,
151        } = req.try_into()?;
152
153        let mut res = self
154            .kv_client()
155            .put(key, value, options)
156            .await
157            .context(error::EtcdFailedSnafu)?;
158
159        let prev_kv = res.take_prev_key().map(KeyValue::from);
160        Ok(PutResponse { prev_kv })
161    }
162
163    async fn batch_put(&self, req: BatchPutRequest) -> Result<BatchPutResponse> {
164        let BatchPut { kvs, options } = req.try_into()?;
165
166        let put_ops = kvs
167            .into_iter()
168            .map(|kv| TxnOp::put(kv.key, kv.value, options.clone()))
169            .collect::<Vec<_>>();
170
171        let txn_responses = self.do_multi_txn(put_ops).await?;
172
173        let mut prev_kvs = vec![];
174        for txn_res in txn_responses {
175            for op_res in txn_res.op_responses() {
176                match op_res {
177                    TxnOpResponse::Put(mut put_res) => {
178                        if let Some(prev_kv) = put_res.take_prev_key().map(KeyValue::from) {
179                            prev_kvs.push(prev_kv);
180                        }
181                    }
182                    _ => unreachable!(),
183                }
184            }
185        }
186
187        Ok(BatchPutResponse { prev_kvs })
188    }
189
190    async fn batch_get(&self, req: BatchGetRequest) -> Result<BatchGetResponse> {
191        let BatchGet { keys, options } = req.try_into()?;
192
193        let get_ops: Vec<_> = keys
194            .into_iter()
195            .map(|key| TxnOp::get(key, options.clone()))
196            .collect();
197
198        let txn_responses = self.do_multi_txn(get_ops).await?;
199
200        let mut kvs = vec![];
201        for txn_res in txn_responses {
202            for op_res in txn_res.op_responses() {
203                let mut get_res = match op_res {
204                    TxnOpResponse::Get(get_res) => get_res,
205                    _ => unreachable!(),
206                };
207                kvs.extend(get_res.take_kvs().into_iter().map(KeyValue::from));
208            }
209        }
210
211        Ok(BatchGetResponse { kvs })
212    }
213
214    async fn delete_range(&self, req: DeleteRangeRequest) -> Result<DeleteRangeResponse> {
215        let Delete { key, options } = req.try_into()?;
216
217        let mut res = self
218            .kv_client()
219            .delete(key, options)
220            .await
221            .context(error::EtcdFailedSnafu)?;
222
223        let prev_kvs = res
224            .take_prev_kvs()
225            .into_iter()
226            .map(KeyValue::from)
227            .collect::<Vec<_>>();
228
229        Ok(DeleteRangeResponse {
230            deleted: res.deleted(),
231            prev_kvs,
232        })
233    }
234
235    async fn batch_delete(&self, req: BatchDeleteRequest) -> Result<BatchDeleteResponse> {
236        let BatchDelete { keys, options } = req.try_into()?;
237
238        let mut prev_kvs = Vec::with_capacity(keys.len());
239
240        let delete_ops = keys
241            .into_iter()
242            .map(|key| TxnOp::delete(key, options.clone()))
243            .collect::<Vec<_>>();
244
245        let txn_responses = self.do_multi_txn(delete_ops).await?;
246
247        for txn_res in txn_responses {
248            for op_res in txn_res.op_responses() {
249                match op_res {
250                    TxnOpResponse::Delete(mut delete_res) => {
251                        delete_res
252                            .take_prev_kvs()
253                            .into_iter()
254                            .map(KeyValue::from)
255                            .for_each(|kv| {
256                                prev_kvs.push(kv);
257                            });
258                    }
259                    _ => unreachable!(),
260                }
261            }
262        }
263
264        Ok(BatchDeleteResponse { prev_kvs })
265    }
266}
267
268#[async_trait::async_trait]
269impl TxnService for EtcdStore {
270    type Error = Error;
271
272    async fn txn(&self, txn: KvTxn) -> Result<KvTxnResponse> {
273        let _timer = METRIC_META_TXN_REQUEST
274            .with_label_values(&["etcd", "txn"])
275            .start_timer();
276
277        let max_operations = txn.max_operations();
278
279        let etcd_txn: Txn = txn.into();
280        let txn_res = self
281            .kv_client()
282            .txn(etcd_txn)
283            .await
284            .context(error::EtcdTxnFailedSnafu { max_operations })?;
285        txn_res.try_into()
286    }
287
288    fn txn_capability(&self) -> Option<TxnCapability> {
289        Some(TxnCapability {
290            max_ops: self.max_txn_ops,
291        })
292    }
293}
294
295struct Get {
296    key: Vec<u8>,
297    options: Option<GetOptions>,
298}
299
300impl TryFrom<RangeRequest> for Get {
301    type Error = Error;
302
303    fn try_from(req: RangeRequest) -> Result<Self> {
304        let RangeRequest {
305            key,
306            range_end,
307            limit,
308            keys_only,
309        } = req;
310
311        ensure!(!key.is_empty(), error::EmptyKeySnafu);
312
313        let mut options = GetOptions::default();
314        if !range_end.is_empty() {
315            options = options.with_range(range_end);
316            if limit > 0 {
317                options = options.with_limit(limit);
318            }
319        }
320        if keys_only {
321            options = options.with_keys_only();
322        }
323
324        Ok(Get {
325            key,
326            options: Some(options),
327        })
328    }
329}
330
331struct Put {
332    key: Vec<u8>,
333    value: Vec<u8>,
334    options: Option<PutOptions>,
335}
336
337impl TryFrom<PutRequest> for Put {
338    type Error = Error;
339
340    fn try_from(req: PutRequest) -> Result<Self> {
341        let PutRequest {
342            key,
343            value,
344            prev_kv,
345        } = req;
346
347        let mut options = PutOptions::default();
348        if prev_kv {
349            options = options.with_prev_key();
350        }
351
352        Ok(Put {
353            key,
354            value,
355            options: Some(options),
356        })
357    }
358}
359
360struct BatchGet {
361    keys: Vec<Vec<u8>>,
362    options: Option<GetOptions>,
363}
364
365impl TryFrom<BatchGetRequest> for BatchGet {
366    type Error = Error;
367
368    fn try_from(req: BatchGetRequest) -> Result<Self> {
369        let BatchGetRequest { keys } = req;
370
371        let options = GetOptions::default();
372
373        Ok(BatchGet {
374            keys,
375            options: Some(options),
376        })
377    }
378}
379
380struct BatchPut {
381    kvs: Vec<KeyValue>,
382    options: Option<PutOptions>,
383}
384
385impl TryFrom<BatchPutRequest> for BatchPut {
386    type Error = Error;
387
388    fn try_from(req: BatchPutRequest) -> Result<Self> {
389        let BatchPutRequest { kvs, prev_kv } = req;
390
391        let mut options = PutOptions::default();
392        if prev_kv {
393            options = options.with_prev_key();
394        }
395
396        Ok(BatchPut {
397            kvs,
398            options: Some(options),
399        })
400    }
401}
402
403struct BatchDelete {
404    keys: Vec<Vec<u8>>,
405    options: Option<DeleteOptions>,
406}
407
408impl TryFrom<BatchDeleteRequest> for BatchDelete {
409    type Error = Error;
410
411    fn try_from(req: BatchDeleteRequest) -> Result<Self> {
412        let BatchDeleteRequest { keys, prev_kv } = req;
413
414        let mut options = DeleteOptions::default();
415        if prev_kv {
416            options = options.with_prev_key();
417        }
418
419        Ok(BatchDelete {
420            keys,
421            options: Some(options),
422        })
423    }
424}
425
426struct Delete {
427    key: Vec<u8>,
428    options: Option<DeleteOptions>,
429}
430
431impl TryFrom<DeleteRangeRequest> for Delete {
432    type Error = Error;
433
434    fn try_from(req: DeleteRangeRequest) -> Result<Self> {
435        let DeleteRangeRequest {
436            key,
437            range_end,
438            prev_kv,
439        } = req;
440
441        ensure!(!key.is_empty(), error::EmptyKeySnafu);
442
443        let mut options = DeleteOptions::default();
444        if !range_end.is_empty() {
445            options = options.with_range(range_end);
446        }
447        if prev_kv {
448            options = options.with_prev_key();
449        }
450
451        Ok(Delete {
452            key,
453            options: Some(options),
454        })
455    }
456}
457
458#[derive(Debug, Clone, PartialEq, Eq, Default)]
459pub enum TlsMode {
460    #[default]
461    Disable,
462    Require,
463}
464
465/// TLS configuration for Etcd connections.
466#[derive(Debug, Clone, PartialEq, Eq)]
467pub struct TlsOption {
468    pub mode: TlsMode,
469    pub cert_path: String,
470    pub key_path: String,
471    pub ca_cert_path: String,
472}
473
474/// Creates a Etcd [`TlsOptions`] from a [`TlsOption`].
475///
476/// This function builds the TLS options for etcd client connections based on the provided
477/// [`TlsOption`]. It supports disabling TLS, setting a custom CA certificate, and configuring
478/// client identity for mutual TLS authentication.
479///
480/// Note: All TlsMode variants except [`TlsMode::Disable`] will be treated as enabling TLS.
481pub fn create_etcd_tls_options(tls_config: &TlsOption) -> Result<Option<TlsOptions>> {
482    // If TLS mode is disabled, return None to indicate no TLS configuration.
483    if matches!(tls_config.mode, TlsMode::Disable) {
484        return Ok(None);
485    }
486
487    info!("Creating etcd TLS with mode: {:?}", tls_config.mode);
488    // Start with default TLS options.
489    let mut etcd_tls_opts = TlsOptions::new();
490
491    // If a CA certificate path is provided, load the CA certificate and add it to the options.
492    if !tls_config.ca_cert_path.is_empty() {
493        debug!("Using CA certificate from {}", tls_config.ca_cert_path);
494        let ca_cert_pem = fs::read(&tls_config.ca_cert_path).context(LoadTlsCertificateSnafu {
495            path: &tls_config.ca_cert_path,
496        })?;
497        let ca_cert = Certificate::from_pem(ca_cert_pem);
498        etcd_tls_opts = etcd_tls_opts.ca_certificate(ca_cert);
499    }
500
501    // If both client certificate and key paths are provided, load them and set the client identity.
502    if !tls_config.cert_path.is_empty() && !tls_config.key_path.is_empty() {
503        info!("Loading client certificate for mutual TLS");
504        debug!(
505            "Using client certificate from {} and key from {}",
506            tls_config.cert_path, tls_config.key_path
507        );
508        let cert_pem = fs::read(&tls_config.cert_path).context(LoadTlsCertificateSnafu {
509            path: &tls_config.cert_path,
510        })?;
511        let key_pem = fs::read(&tls_config.key_path).context(LoadTlsCertificateSnafu {
512            path: &tls_config.key_path,
513        })?;
514        let identity = Identity::from_pem(cert_pem, key_pem);
515        etcd_tls_opts = etcd_tls_opts.identity(identity);
516    }
517
518    // Always enable native TLS roots for additional trust anchors.
519    etcd_tls_opts = etcd_tls_opts.with_native_roots();
520
521    Ok(Some(etcd_tls_opts))
522}
523
524#[cfg(test)]
525mod tests {
526    use etcd_client::ConnectOptions;
527
528    use super::*;
529
530    #[test]
531    fn test_parse_get() {
532        let req = RangeRequest {
533            key: b"test_key".to_vec(),
534            range_end: b"test_range_end".to_vec(),
535            limit: 64,
536            keys_only: true,
537        };
538
539        let get: Get = req.try_into().unwrap();
540
541        assert_eq!(b"test_key".to_vec(), get.key);
542        let _ = get.options.unwrap();
543    }
544
545    #[test]
546    fn test_parse_put() {
547        let req = PutRequest {
548            key: b"test_key".to_vec(),
549            value: b"test_value".to_vec(),
550            prev_kv: true,
551        };
552
553        let put: Put = req.try_into().unwrap();
554
555        assert_eq!(b"test_key".to_vec(), put.key);
556        assert_eq!(b"test_value".to_vec(), put.value);
557        let _ = put.options.unwrap();
558    }
559
560    #[test]
561    fn test_parse_batch_get() {
562        let req = BatchGetRequest {
563            keys: vec![b"k1".to_vec(), b"k2".to_vec(), b"k3".to_vec()],
564        };
565
566        let batch_get: BatchGet = req.try_into().unwrap();
567        let keys = batch_get.keys;
568
569        assert_eq!(b"k1".to_vec(), keys.first().unwrap().clone());
570        assert_eq!(b"k2".to_vec(), keys.get(1).unwrap().clone());
571        assert_eq!(b"k3".to_vec(), keys.get(2).unwrap().clone());
572    }
573
574    #[test]
575    fn test_parse_batch_put() {
576        let req = BatchPutRequest {
577            kvs: vec![KeyValue {
578                key: b"test_key".to_vec(),
579                value: b"test_value".to_vec(),
580            }],
581            prev_kv: true,
582        };
583
584        let batch_put: BatchPut = req.try_into().unwrap();
585
586        let kv = batch_put.kvs.first().unwrap();
587        assert_eq!(b"test_key", kv.key());
588        assert_eq!(b"test_value", kv.value());
589        let _ = batch_put.options.unwrap();
590    }
591
592    #[test]
593    fn test_parse_batch_delete() {
594        let req = BatchDeleteRequest {
595            keys: vec![b"k1".to_vec(), b"k2".to_vec(), b"k3".to_vec()],
596            prev_kv: true,
597        };
598
599        let batch_delete: BatchDelete = req.try_into().unwrap();
600
601        assert_eq!(batch_delete.keys.len(), 3);
602        assert_eq!(b"k1".to_vec(), batch_delete.keys.first().unwrap().clone());
603        assert_eq!(b"k2".to_vec(), batch_delete.keys.get(1).unwrap().clone());
604        assert_eq!(b"k3".to_vec(), batch_delete.keys.get(2).unwrap().clone());
605        let _ = batch_delete.options.unwrap();
606    }
607
608    #[test]
609    fn test_parse_delete() {
610        let req = DeleteRangeRequest {
611            key: b"test_key".to_vec(),
612            range_end: b"test_range_end".to_vec(),
613            prev_kv: true,
614        };
615
616        let delete: Delete = req.try_into().unwrap();
617
618        assert_eq!(b"test_key".to_vec(), delete.key);
619        let _ = delete.options.unwrap();
620    }
621
622    use crate::kv_backend::test::{
623        prepare_kv_with_prefix, test_kv_batch_delete_with_prefix, test_kv_batch_get_with_prefix,
624        test_kv_compare_and_put_with_prefix, test_kv_delete_range_with_prefix,
625        test_kv_put_with_prefix, test_kv_range_2_with_prefix, test_kv_range_with_prefix,
626        test_txn_compare_equal, test_txn_compare_greater, test_txn_compare_less,
627        test_txn_compare_not_equal, test_txn_one_compare_op, text_txn_multi_compare_op,
628        unprepare_kv,
629    };
630    use crate::maybe_skip_etcd_tls_integration_test;
631    use crate::test_util::etcd_certs_dir;
632
633    async fn build_kv_backend() -> Option<EtcdStore> {
634        let endpoints = std::env::var("GT_ETCD_ENDPOINTS").unwrap_or_default();
635        if endpoints.is_empty() {
636            return None;
637        }
638
639        let endpoints = endpoints
640            .split(',')
641            .map(|s| s.to_string())
642            .collect::<Vec<String>>();
643
644        let client = Client::connect(endpoints, None)
645            .await
646            .expect("malformed endpoints");
647
648        Some(EtcdStore {
649            client,
650            max_txn_ops: 128,
651            max_decoding_size: DEFAULT_MAX_DECODING_SIZE,
652        })
653    }
654
655    #[tokio::test]
656    async fn test_put() {
657        if let Some(kv_backend) = build_kv_backend().await {
658            let prefix = b"put/";
659            prepare_kv_with_prefix(&kv_backend, prefix.to_vec()).await;
660            test_kv_put_with_prefix(&kv_backend, prefix.to_vec()).await;
661            unprepare_kv(&kv_backend, prefix).await;
662        }
663    }
664
665    #[tokio::test]
666    async fn test_range() {
667        if let Some(kv_backend) = build_kv_backend().await {
668            let prefix = b"range/";
669            prepare_kv_with_prefix(&kv_backend, prefix.to_vec()).await;
670            test_kv_range_with_prefix(&kv_backend, prefix.to_vec()).await;
671            unprepare_kv(&kv_backend, prefix).await;
672        }
673    }
674
675    #[tokio::test]
676    async fn test_range_2() {
677        if let Some(kv_backend) = build_kv_backend().await {
678            test_kv_range_2_with_prefix(&kv_backend, b"range2/".to_vec()).await;
679        }
680    }
681
682    #[tokio::test]
683    async fn test_batch_get() {
684        if let Some(kv_backend) = build_kv_backend().await {
685            let prefix = b"batchGet/";
686            prepare_kv_with_prefix(&kv_backend, prefix.to_vec()).await;
687            test_kv_batch_get_with_prefix(&kv_backend, prefix.to_vec()).await;
688            unprepare_kv(&kv_backend, prefix).await;
689        }
690    }
691
692    #[tokio::test(flavor = "multi_thread")]
693    async fn test_compare_and_put() {
694        if let Some(kv_backend) = build_kv_backend().await {
695            let kv_backend = Arc::new(kv_backend);
696            test_kv_compare_and_put_with_prefix(kv_backend, b"compareAndPut/".to_vec()).await;
697        }
698    }
699
700    #[tokio::test]
701    async fn test_delete_range() {
702        if let Some(kv_backend) = build_kv_backend().await {
703            let prefix = b"deleteRange/";
704            prepare_kv_with_prefix(&kv_backend, prefix.to_vec()).await;
705            test_kv_delete_range_with_prefix(&kv_backend, prefix.to_vec()).await;
706            unprepare_kv(&kv_backend, prefix).await;
707        }
708    }
709
710    #[tokio::test]
711    async fn test_batch_delete() {
712        if let Some(kv_backend) = build_kv_backend().await {
713            let prefix = b"batchDelete/";
714            prepare_kv_with_prefix(&kv_backend, prefix.to_vec()).await;
715            test_kv_batch_delete_with_prefix(&kv_backend, prefix.to_vec()).await;
716            unprepare_kv(&kv_backend, prefix).await;
717        }
718    }
719
720    #[tokio::test]
721    async fn test_etcd_txn() {
722        if let Some(kv_backend) = build_kv_backend().await {
723            test_txn_one_compare_op(&kv_backend).await;
724            text_txn_multi_compare_op(&kv_backend).await;
725            test_txn_compare_equal(&kv_backend).await;
726            test_txn_compare_greater(&kv_backend).await;
727            test_txn_compare_less(&kv_backend).await;
728            test_txn_compare_not_equal(&kv_backend).await;
729        }
730    }
731
732    async fn create_etcd_client_with_tls(endpoints: &[String], tls_config: &TlsOption) -> Client {
733        let endpoints = endpoints
734            .iter()
735            .map(|s| s.trim())
736            .filter(|s| !s.is_empty())
737            .collect::<Vec<_>>();
738        let connect_options =
739            ConnectOptions::new().with_tls(create_etcd_tls_options(tls_config).unwrap().unwrap());
740
741        Client::connect(&endpoints, Some(connect_options))
742            .await
743            .unwrap()
744    }
745
746    #[tokio::test]
747    async fn test_create_etcd_client_with_mtls_and_ca() {
748        maybe_skip_etcd_tls_integration_test!();
749        let endpoints = std::env::var("GT_ETCD_TLS_ENDPOINTS")
750            .unwrap()
751            .split(',')
752            .map(|s| s.to_string())
753            .collect::<Vec<_>>();
754
755        let cert_dir = etcd_certs_dir();
756        let tls_config = TlsOption {
757            mode: TlsMode::Require,
758            ca_cert_path: cert_dir.join("ca.crt").to_string_lossy().to_string(),
759            cert_path: cert_dir.join("client.crt").to_string_lossy().to_string(),
760            key_path: cert_dir
761                .join("client-key.pem")
762                .to_string_lossy()
763                .to_string(),
764        };
765        let mut client = create_etcd_client_with_tls(&endpoints, &tls_config).await;
766        let _ = client.get(b"hello", None).await.unwrap();
767    }
768}