Skip to content

Commit 2481fb1

Browse files
committed
fix: cleanup after open telemetry feature from code0 flow
1 parent fe49003 commit 2481fb1

5 files changed

Lines changed: 40 additions & 74 deletions

File tree

src/configuration/config.rs

Lines changed: 19 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::{fmt, path::Path};
22

3+
use code0_flow::flow_telemetry::OpenTelemetry;
34
use config::{Config as ConfigLoader, ConfigError, File};
45
use serde::{Deserialize, Serialize};
56

@@ -15,6 +16,7 @@ pub struct Config {
1516
pub mode: Mode,
1617
pub log_level: String,
1718
#[serde(alias = "telemetry")]
19+
#[serde(default = "default_opentelemetry")]
1820
pub opentelemetry: OpenTelemetry,
1921
pub nats: Nats,
2022
pub static_config: StaticConfig,
@@ -30,16 +32,6 @@ pub struct Nats {
3032
pub bucket: String,
3133
}
3234

33-
#[derive(Clone, Debug, Deserialize, Serialize)]
34-
#[serde(default)]
35-
pub struct OpenTelemetry {
36-
pub enabled: bool,
37-
pub service_name: String,
38-
pub logs_endpoint: Option<String>,
39-
pub metrics_endpoint: Option<String>,
40-
pub traces_endpoint: Option<String>,
41-
}
42-
4335
#[derive(Clone, Debug, Deserialize, Serialize)]
4436
#[serde(default)]
4537
pub struct StaticConfig {
@@ -90,7 +82,7 @@ impl Default for Config {
9082
environment: Environment::Development,
9183
mode: Mode::Static,
9284
log_level: "debug".into(),
93-
opentelemetry: OpenTelemetry::default(),
85+
opentelemetry: default_opentelemetry(),
9486
nats: Nats::default(),
9587
static_config: StaticConfig::default(),
9688
dynamic_config: DynamicConfig::default(),
@@ -100,42 +92,13 @@ impl Default for Config {
10092
}
10193
}
10294

103-
impl Default for OpenTelemetry {
104-
fn default() -> Self {
105-
Self {
106-
enabled: false,
107-
service_name: env!("CARGO_PKG_NAME").into(),
108-
logs_endpoint: None,
109-
metrics_endpoint: None,
110-
traces_endpoint: None,
111-
}
112-
}
113-
}
114-
115-
impl OpenTelemetry {
116-
pub fn logs_endpoint(&self) -> Option<&str> {
117-
non_empty_url(&self.logs_endpoint)
118-
}
119-
120-
pub fn metrics_endpoint(&self) -> Option<&str> {
121-
non_empty_url(&self.metrics_endpoint)
122-
}
123-
124-
pub fn traces_endpoint(&self) -> Option<&str> {
125-
non_empty_url(&self.traces_endpoint)
126-
}
127-
128-
pub fn has_enabled_exporter(&self) -> bool {
129-
self.logs_endpoint().is_some()
130-
|| self.metrics_endpoint().is_some()
131-
|| self.traces_endpoint().is_some()
95+
fn default_opentelemetry() -> OpenTelemetry {
96+
OpenTelemetry {
97+
service_name: env!("CARGO_PKG_NAME").into(),
98+
..OpenTelemetry::default()
13299
}
133100
}
134101

135-
fn non_empty_url(url: &Option<String>) -> Option<&str> {
136-
url.as_deref().filter(|value| !value.trim().is_empty())
137-
}
138-
139102
impl Default for Nats {
140103
fn default() -> Self {
141104
Self {
@@ -294,7 +257,9 @@ impl fmt::Display for Config {
294257
}
295258

296259
fn display_optional_url(url: &Option<String>) -> &str {
297-
non_empty_url(url).unwrap_or("<disabled>")
260+
url.as_deref()
261+
.filter(|value| !value.trim().is_empty())
262+
.unwrap_or("<disabled>")
298263
}
299264

300265
#[cfg(test)]
@@ -303,7 +268,9 @@ mod tests {
303268

304269
use config::Config as ConfigLoader;
305270

306-
use super::{Config, OpenTelemetry};
271+
use code0_flow::flow_telemetry::OpenTelemetry;
272+
273+
use super::{Config, default_opentelemetry};
307274

308275
static ENV_LOCK: Mutex<()> = Mutex::new(());
309276

@@ -357,7 +324,7 @@ mod tests {
357324
fn opentelemetry_endpoints_are_enabled_by_presence() {
358325
let config: OpenTelemetry = ConfigLoader::builder()
359326
.add_source(
360-
ConfigLoader::try_from(&OpenTelemetry::default())
327+
ConfigLoader::try_from(&default_opentelemetry())
361328
.expect("default telemetry config should serialize"),
362329
)
363330
.set_override("enabled", true)
@@ -382,4 +349,9 @@ mod tests {
382349
assert_eq!(config.traces_endpoint(), Some("http://localhost:4317"));
383350
assert!(config.has_enabled_exporter());
384351
}
352+
353+
#[test]
354+
fn opentelemetry_default_service_name_is_aquila() {
355+
assert_eq!(Config::default().opentelemetry.service_name, "aquila");
356+
}
385357
}

src/configuration/service.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,17 +116,17 @@ impl ServiceConfiguration {
116116
None => return false,
117117
};
118118

119-
self
120-
.runtimes
119+
self.runtimes
121120
.iter()
122-
.find(|x| &x.token == token && x.identifier == name).is_some()
121+
.find(|x| &x.token == token && x.identifier == name)
122+
.is_some()
123123
}
124124

125125
pub fn has_action(&self, token: &String, action_name: &String) -> bool {
126-
self
127-
.actions
126+
self.actions
128127
.iter()
129-
.find(|x| &x.token == token && &x.service_name == action_name).is_some()
128+
.find(|x| &x.token == token && &x.service_name == action_name)
129+
.is_some()
130130
}
131131

132132
pub fn get_action_configuration(

src/main.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,6 @@ async fn main() {
3535
.as_ref()
3636
.map(|config| config.environment.to_string())
3737
.unwrap_or_else(|_| "unknown".into());
38-
let telemetry_config = telemetry::OpenTelemetry {
39-
enabled: telemetry_config.enabled,
40-
service_name: telemetry_config.service_name,
41-
logs_endpoint: telemetry_config.logs_endpoint,
42-
metrics_endpoint: telemetry_config.metrics_endpoint,
43-
traces_endpoint: telemetry_config.traces_endpoint,
44-
};
4538
let telemetry = telemetry::Telemetry::initialize(
4639
&telemetry_config,
4740
telemetry::TelemetrySettings {

src/server/action_transfer_service_server_impl.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,11 @@ fn pending_reply_keys(
220220
}
221221

222222
if let Some(subject_execution_id) = subject_execution_id
223-
&& !subject_execution_id.is_empty() && !keys.iter().any(|key| key == subject_execution_id) {
224-
keys.push(subject_execution_id.to_string());
225-
}
223+
&& !subject_execution_id.is_empty()
224+
&& !keys.iter().any(|key| key == subject_execution_id)
225+
{
226+
keys.push(subject_execution_id.to_string());
227+
}
226228

227229
keys
228230
}
@@ -789,14 +791,15 @@ async fn forward_nats_to_action(
789791

790792
let subject_execution_id = subject_execution_identifier(&msg.subject);
791793
if execution.execution_identifier.is_empty()
792-
&& let Some(subject_execution_id) = subject_execution_id.as_ref() {
793-
log::warn!(
794-
"Filled missing action execution identifier from NATS subject subject={} execution_id={}",
795-
msg.subject,
796-
subject_execution_id
797-
);
798-
execution.execution_identifier = subject_execution_id.clone();
799-
}
794+
&& let Some(subject_execution_id) = subject_execution_id.as_ref()
795+
{
796+
log::warn!(
797+
"Filled missing action execution identifier from NATS subject subject={} execution_id={}",
798+
msg.subject,
799+
subject_execution_id
800+
);
801+
execution.execution_identifier = subject_execution_id.clone();
802+
}
800803

801804
let execution_id = execution.execution_identifier.clone();
802805

src/server/dynamic_server.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,7 @@ impl AquilaDynamicServer {
118118
runtime_status_service.clone(),
119119
self.service_configuration.clone(),
120120
Duration::from_secs(self.runtime_status_not_responding_after_secs),
121-
Duration::from_secs(
122-
self.runtime_status_stopped_after_not_responding_secs,
123-
),
121+
Duration::from_secs(self.runtime_status_stopped_after_not_responding_secs),
124122
Duration::from_secs(self.runtime_status_monitor_interval_secs),
125123
);
126124

0 commit comments

Comments
 (0)