Skip to content

Commit a81a67a

Browse files
authored
feat: support HTTPS protocol for otel (#1206)
Signed-off-by: Gaius <gaius.qi@gmail.com>
1 parent b317323 commit a81a67a

File tree

10 files changed

+68
-24
lines changed

10 files changed

+68
-24
lines changed

Cargo.lock

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ members = [
1212
]
1313

1414
[workspace.package]
15-
version = "0.2.39"
15+
version = "0.2.40"
1616
authors = ["The Dragonfly Developers"]
1717
homepage = "https://d7y.io/"
1818
repository = "https://github.com/dragonflyoss/client.git"
@@ -22,13 +22,13 @@ readme = "README.md"
2222
edition = "2021"
2323

2424
[workspace.dependencies]
25-
dragonfly-client = { path = "dragonfly-client", version = "0.2.39" }
26-
dragonfly-client-core = { path = "dragonfly-client-core", version = "0.2.39" }
27-
dragonfly-client-config = { path = "dragonfly-client-config", version = "0.2.39" }
28-
dragonfly-client-storage = { path = "dragonfly-client-storage", version = "0.2.39" }
29-
dragonfly-client-backend = { path = "dragonfly-client-backend", version = "0.2.39" }
30-
dragonfly-client-util = { path = "dragonfly-client-util", version = "0.2.39" }
31-
dragonfly-client-init = { path = "dragonfly-client-init", version = "0.2.39" }
25+
dragonfly-client = { path = "dragonfly-client", version = "0.2.40" }
26+
dragonfly-client-core = { path = "dragonfly-client-core", version = "0.2.40" }
27+
dragonfly-client-config = { path = "dragonfly-client-config", version = "0.2.40" }
28+
dragonfly-client-storage = { path = "dragonfly-client-storage", version = "0.2.40" }
29+
dragonfly-client-backend = { path = "dragonfly-client-backend", version = "0.2.40" }
30+
dragonfly-client-util = { path = "dragonfly-client-util", version = "0.2.40" }
31+
dragonfly-client-init = { path = "dragonfly-client-init", version = "0.2.40" }
3232
dragonfly-api = "=2.1.39"
3333
thiserror = "2.0"
3434
futures = "0.3.31"

dragonfly-client-config/src/dfdaemon.rs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,12 @@ fn default_download_max_schedule_count() -> u32 {
164164
5
165165
}
166166

167+
/// default_tracing_path is the default tracing path for dfdaemon.
168+
#[inline]
169+
fn default_tracing_path() -> Option<PathBuf> {
170+
Some(PathBuf::from("/v1/traces"))
171+
}
172+
167173
/// default_scheduler_announce_interval is the default interval to announce peer to the scheduler.
168174
#[inline]
169175
fn default_scheduler_announce_interval() -> Duration {
@@ -1460,7 +1466,7 @@ pub struct Stats {
14601466
}
14611467

14621468
/// Tracing is the tracing configuration for dfdaemon.
1463-
#[derive(Debug, Clone, Default, Validate, Deserialize)]
1469+
#[derive(Debug, Clone, Validate, Deserialize)]
14641470
#[serde(default, rename_all = "camelCase")]
14651471
pub struct Tracing {
14661472
/// Protocol specifies the communication protocol for the tracing server.
@@ -1471,11 +1477,28 @@ pub struct Tracing {
14711477
/// endpoint is the endpoint to report tracing log, example: "localhost:4317".
14721478
pub endpoint: Option<String>,
14731479

1480+
/// path is the path to report tracing log, example: "/v1/traces" if the protocol is "http" or
1481+
/// "https".
1482+
#[serde(default = "default_tracing_path")]
1483+
pub path: Option<PathBuf>,
1484+
14741485
/// headers is the headers to report tracing log.
14751486
#[serde(with = "http_serde::header_map")]
14761487
pub headers: reqwest::header::HeaderMap,
14771488
}
14781489

1490+
/// Tracing implements Default.
1491+
impl Default for Tracing {
1492+
fn default() -> Self {
1493+
Self {
1494+
protocol: None,
1495+
endpoint: None,
1496+
path: default_tracing_path(),
1497+
headers: reqwest::header::HeaderMap::new(),
1498+
}
1499+
}
1500+
}
1501+
14791502
/// Config is the configuration for dfdaemon.
14801503
#[derive(Debug, Clone, Default, Validate, Deserialize)]
14811504
#[serde(default, rename_all = "camelCase")]
@@ -2189,12 +2212,18 @@ key: /etc/ssl/private/client.pem
21892212
let json_data = r#"
21902213
{
21912214
"protocol": "http",
2192-
"endpoint": "tracing.example.com"
2215+
"endpoint": "tracing.example.com",
2216+
"path": "/v1/traces",
2217+
"headers": {
2218+
"X-Custom-Header": "value"
2219+
}
21932220
}"#;
21942221

21952222
let tracing: Tracing = serde_json::from_str(json_data).unwrap();
21962223
assert_eq!(tracing.protocol, Some("http".to_string()));
21972224
assert_eq!(tracing.endpoint, Some("tracing.example.com".to_string()));
2225+
assert_eq!(tracing.path, Some(PathBuf::from("/v1/traces")));
2226+
assert!(tracing.headers.contains_key("X-Custom-Header"));
21982227
}
21992228

22002229
#[test]

dragonfly-client-init/src/bin/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ async fn main() -> Result<(), anyhow::Error> {
9393
None,
9494
None,
9595
None,
96+
None,
9697
false,
9798
args.console,
9899
);

dragonfly-client/src/bin/dfcache/export.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ impl ExportCommand {
136136
None,
137137
None,
138138
None,
139+
None,
139140
false,
140141
self.console,
141142
);

dragonfly-client/src/bin/dfcache/import.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ impl ImportCommand {
142142
None,
143143
None,
144144
None,
145+
None,
145146
false,
146147
self.console,
147148
);

dragonfly-client/src/bin/dfcache/stat.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ impl StatCommand {
8888
None,
8989
None,
9090
None,
91+
None,
9192
false,
9293
self.console,
9394
);

dragonfly-client/src/bin/dfdaemon/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ async fn main() -> Result<(), anyhow::Error> {
147147
args.log_max_files,
148148
config.tracing.protocol.clone(),
149149
config.tracing.endpoint.clone(),
150+
config.tracing.path.clone(),
150151
Some(config.tracing.headers.clone()),
151152
Some(config.host.clone()),
152153
config.seed_peer.enable,

dragonfly-client/src/bin/dfget/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ async fn main() -> anyhow::Result<()> {
307307
None,
308308
None,
309309
None,
310+
None,
310311
false,
311312
args.console,
312313
);

dragonfly-client/src/tracing/mod.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ pub fn init_tracing(
4646
log_max_files: usize,
4747
otel_protocol: Option<String>,
4848
otel_endpoint: Option<String>,
49+
otel_path: Option<PathBuf>,
4950
otel_headers: Option<reqwest::header::HeaderMap>,
5051
host: Option<Host>,
5152
is_seed_peer: bool,
@@ -122,23 +123,31 @@ pub fn init_tracing(
122123
}
123124
}
124125

125-
let addr = format!("http://{}", endpoint);
126+
let endpoint_url = url::Url::parse(&format!("http://{}", endpoint))
127+
.expect("failed to parse OTLP endpoint URL");
128+
126129
opentelemetry_otlp::SpanExporter::builder()
127130
.with_tonic()
128-
.with_endpoint(addr)
131+
.with_endpoint(endpoint_url)
129132
.with_timeout(SPAN_EXPORTER_TIMEOUT)
130133
.with_metadata(metadata)
131134
.build()
132135
.expect("failed to create OTLP exporter")
133136
}
134137
"http" | "https" => {
135-
let endpoint_url = url::Url::parse(&format!("{}://{}", protocol, endpoint))
136-
.expect("failed to parse OTLP endpoint URL")
137-
.join("v1/traces")
138-
.expect("failed to construct OTLP endpoint URL");
138+
let mut endpoint_url = url::Url::parse(&format!("http://{}", endpoint))
139+
.expect("failed to parse OTLP endpoint URL");
140+
141+
if let Some(path) = otel_path {
142+
endpoint_url = endpoint_url
143+
.join(path.to_str().unwrap())
144+
.expect("failed to join OTLP endpoint path");
145+
}
146+
139147
opentelemetry_otlp::SpanExporter::builder()
140148
.with_http()
141149
.with_endpoint(endpoint_url.as_str())
150+
.with_protocol(opentelemetry_otlp::Protocol::HttpJson)
142151
.with_timeout(SPAN_EXPORTER_TIMEOUT)
143152
.build()
144153
.expect("failed to create OTLP exporter")

0 commit comments

Comments
 (0)