Skip to content

Commit

Permalink
merge: #3058
Browse files Browse the repository at this point in the history
3058: feat(nats): add connection name to nats connection r=sprutton1 a=sprutton1

This allows giving a connection name to nats. This makes it easier to identify who is connecting to nats. We're considering using a managed nats solution and without this the UI shows all of the connections as `unknown` . Here's a before and after:
![image](https://github.com/systeminit/si/assets/3621657/7a85f47d-1274-4573-8601-52b64338e653)
![image](https://github.com/systeminit/si/assets/3621657/cf2d9aaa-5fbd-4dae-a709-2631b9141e2e)


Co-authored-by: Scott Prutton <[email protected]>
  • Loading branch information
si-bors-ng[bot] and sprutton1 authored Dec 14, 2023
2 parents 966bcf4 + d32a3c9 commit feed3be
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions bin/council/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ impl TryFrom<Args> for Config {
if let Some(creds_file) = args.nats_creds_file {
config_map.set("nats.creds_file", creds_file);
}
config_map.set("nats.connection_name", NAME);
})?
.try_into()
}
Expand Down
2 changes: 1 addition & 1 deletion bin/pinga/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl TryFrom<Args> for Config {
if let Some(instance_id) = args.instance_id {
config_map.set("instance_id", instance_id);
}

config_map.set("nats.connection_name", NAME);
config_map.set("pg.application_name", NAME);
})?
.try_into()
Expand Down
1 change: 1 addition & 0 deletions bin/sdf/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ impl TryFrom<Args> for Config {
config_map.set("module_index_url", module_index_url);
}

config_map.set("nats.connection_name", NAME);
config_map.set("pg.application_name", NAME);
})?
.try_into()
Expand Down
1 change: 1 addition & 0 deletions bin/veritech/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ impl TryFrom<Args> for Config {
if let Some(size) = args.cyclone_pool_size {
config_map.set("cyclone.pool_size", size);
}
config_map.set("nats.connection_name", NAME);
})?
.try_into()
}
Expand Down
13 changes: 9 additions & 4 deletions lib/si-data-nats/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,21 @@ pub type Result<T> = std::result::Result<T, Error>;

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct NatsConfig {
pub url: String,
pub subject_prefix: Option<String>,
pub connection_name: Option<String>,
pub creds: Option<String>,
pub creds_file: Option<String>,
pub subject_prefix: Option<String>,
pub url: String,
}

impl Default for NatsConfig {
fn default() -> Self {
Self {
url: "localhost".to_string(),
subject_prefix: None,
connection_name: None,
creds: None,
creds_file: None,
subject_prefix: None,
url: "localhost".to_string(),
}
}
}
Expand Down Expand Up @@ -106,6 +108,9 @@ impl Client {
if let Some(creds_file) = &config.creds_file {
options = options.credentials_file(creds_file.into()).await?;
}
if let Some(connection_name) = &config.connection_name {
options = options.name(connection_name);
}
Self::connect_with_options(&config.url, config.subject_prefix.clone(), options).await
}

Expand Down

0 comments on commit feed3be

Please sign in to comment.