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
use crate::ExportConfig;
#[cfg(feature = "serialize")]
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
#[derive(Debug)]
pub struct GrpcioConfig {
pub credentials: Option<Credentials>,
pub headers: Option<HashMap<String, String>>,
pub compression: Option<Compression>,
pub use_tls: Option<bool>,
pub completion_queue_count: usize,
}
impl Default for GrpcioConfig {
fn default() -> Self {
GrpcioConfig {
credentials: None,
headers: None,
compression: None,
use_tls: None,
completion_queue_count: 2,
}
}
}
#[cfg_attr(feature = "serialize", derive(Deserialize, Serialize))]
#[derive(Clone, Debug)]
pub struct Credentials {
pub cert: String,
pub key: String,
}
#[cfg_attr(feature = "serialize", derive(Deserialize, Serialize))]
#[derive(Clone, Copy, Debug)]
pub enum Compression {
Gzip,
}
impl From<Compression> for grpcio::CompressionAlgorithms {
fn from(compression: Compression) -> Self {
match compression {
Compression::Gzip => grpcio::CompressionAlgorithms::GRPC_COMPRESS_GZIP,
}
}
}
#[derive(Default, Debug)]
pub struct GrpcioExporterBuilder {
pub(crate) exporter_config: ExportConfig,
pub(crate) grpcio_config: GrpcioConfig,
}
impl GrpcioExporterBuilder {
pub fn with_credentials(mut self, credentials: Credentials) -> Self {
self.grpcio_config.credentials = Some(credentials);
self
}
pub fn with_headers(mut self, headers: HashMap<String, String>) -> Self {
self.grpcio_config.headers = Some(headers);
self
}
pub fn with_compression(mut self, compression: Compression) -> Self {
self.grpcio_config.compression = Some(compression);
self
}
pub fn with_tls(mut self, use_tls: bool) -> Self {
self.grpcio_config.use_tls = Some(use_tls);
self
}
pub fn with_completion_queue_count(mut self, count: usize) -> Self {
self.grpcio_config.completion_queue_count = count;
self
}
}