Skip to content

Commit b942d50

Browse files
committed
Use plugin versions
1 parent a8fe749 commit b942d50

File tree

7 files changed

+15
-20
lines changed

7 files changed

+15
-20
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub const PLUGIN_VERSION: &str = env!("CARGO_PKG_VERSION");

packages/libraries/router/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
pub mod consts;
12
pub mod persisted_documents;
23
pub mod registry;
34
pub mod registry_logger;

packages/libraries/router/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Specify the modules our binary should include -- https://twitter.com/YassinEldeeb7/status/1468680104243077128
2+
mod consts;
23
mod persisted_documents;
34
mod registry;
45
mod registry_logger;

packages/libraries/router/src/registry.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::consts::PLUGIN_VERSION;
12
use crate::registry_logger::Logger;
23
use anyhow::{anyhow, Result};
34
use hive_console_sdk::supergraph_fetcher::SupergraphFetcher;
@@ -124,7 +125,7 @@ impl HiveRegistry {
124125
fetcher: SupergraphFetcher::try_new(
125126
endpoint,
126127
key,
127-
"hive-apollo-router".to_string(),
128+
format!("hive-apollo-router/{}", PLUGIN_VERSION),
128129
5,
129130
60,
130131
accept_invalid_certs,

packages/libraries/router/src/usage.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::consts::PLUGIN_VERSION;
12
use apollo_router::layers::ServiceBuilderExt;
23
use apollo_router::plugin::Plugin;
34
use apollo_router::plugin::PluginInit;
@@ -253,7 +254,7 @@ impl Plugin for UsagePlugin {
253254
request_timeout,
254255
accept_invalid_certs,
255256
flush_interval,
256-
"hive-apollo-router".to_string(),
257+
format!("hive-apollo-router/{}", PLUGIN_VERSION),
257258
));
258259
start_flush_interval(agent.clone());
259260
Some(agent)

packages/libraries/sdk-rs/src/agent.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ use std::{
1111
use thiserror::Error;
1212
use tokio_util::sync::CancellationToken;
1313

14-
static COMMIT: Option<&'static str> = option_env!("GITHUB_SHA");
15-
1614
#[derive(Serialize, Debug)]
1715
pub struct Report {
1816
size: usize,
@@ -115,7 +113,7 @@ pub struct UsageAgent {
115113
processor: Arc<OperationProcessor>,
116114
client: ClientWithMiddleware,
117115
flush_interval: Duration,
118-
user_agent_prefix: String,
116+
user_agent: String,
119117
}
120118

121119
fn non_empty_string(value: Option<String>) -> Option<String> {
@@ -147,7 +145,7 @@ impl UsageAgent {
147145
request_timeout: u64,
148146
accept_invalid_certs: bool,
149147
flush_interval: Duration,
150-
user_agent_prefix: String,
148+
user_agent: String,
151149
) -> Self {
152150
let processor = Arc::new(OperationProcessor::new());
153151

@@ -181,7 +179,7 @@ impl UsageAgent {
181179
buffer_size,
182180
client,
183181
flush_interval,
184-
user_agent_prefix,
182+
user_agent,
185183
}
186184
}
187185

@@ -278,10 +276,7 @@ impl UsageAgent {
278276
reqwest::header::AUTHORIZATION,
279277
format!("Bearer {}", self.token),
280278
)
281-
.header(
282-
reqwest::header::USER_AGENT,
283-
format!("{}/{}", self.user_agent_prefix, COMMIT.unwrap_or("local")),
284-
)
279+
.header(reqwest::header::USER_AGENT, self.user_agent.to_string())
285280
.header(reqwest::header::CONTENT_TYPE, "application/json")
286281
.header(reqwest::header::CONTENT_LENGTH, report_body.len())
287282
.body(report_body)

packages/libraries/sdk-rs/src/supergraph_fetcher.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,15 @@ pub struct SupergraphFetcher {
55
client: reqwest::blocking::Client,
66
endpoint: String,
77
key: String,
8-
user_agent_prefix: String,
8+
user_agent: String,
99
etag: Option<String>,
1010
}
1111

12-
static COMMIT: Option<&'static str> = option_env!("GITHUB_SHA");
13-
1412
impl SupergraphFetcher {
1513
pub fn try_new(
1614
endpoint: String,
1715
key: String,
18-
user_agent_prefix: String,
16+
user_agent: String,
1917
connect_timeout: u64,
2018
request_timeout: u64,
2119
accept_invalid_certs: bool,
@@ -40,7 +38,7 @@ impl SupergraphFetcher {
4038
client,
4139
endpoint,
4240
key,
43-
user_agent_prefix,
41+
user_agent,
4442
etag: None,
4543
})
4644
}
@@ -50,10 +48,7 @@ impl SupergraphFetcher {
5048

5149
headers.insert(
5250
reqwest::header::USER_AGENT,
53-
reqwest::header::HeaderValue::from_str(
54-
format!("{}/{}", self.user_agent_prefix, COMMIT.unwrap_or("local")).as_str(),
55-
)
56-
.unwrap(),
51+
reqwest::header::HeaderValue::from_str(&self.user_agent).unwrap(),
5752
);
5853
headers.insert("X-Hive-CDN-Key", self.key.parse().unwrap());
5954

0 commit comments

Comments
 (0)