Skip to content

Commit

Permalink
Add --client-alias CLI and client-alias config parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
aterentic-ethernal committed Jul 22, 2024
1 parent 69db6e9 commit 303a136
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion client/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.11.1

- Release changes are enumerated in [`core` CHANGELOG](../core/CHANGELOG.md) under the version 1.11.1

## [1.11.0](https://github.com/availproject/avail-light/releases/tag/avail-light-client-v1.11.0) - 2024-07-18

- Release changes are enumerated in [`core` CHANGELOG](core/CHANGELOG.md) under the version 1.11.0
- Release changes are enumerated in [`core` CHANGELOG](../core/CHANGELOG.md) under the version 1.11.0
2 changes: 1 addition & 1 deletion client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "avail-light-client"
version = "1.11.0"
version = "1.11.1"
edition = "2021"
description = "Avail network p2p Light Client"

Expand Down
3 changes: 3 additions & 0 deletions client/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,7 @@ pub struct CliOpts {
/// Set logs format to JSON
#[arg(long)]
pub logs_json: bool,
/// Set client alias for use in logs and metrics
#[arg(long)]
pub client_alias: Option<String>,
}
8 changes: 7 additions & 1 deletion client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ async fn run(
multiaddress: "".to_string(),
client_id: client_id.to_string(),
execution_id: execution_id.to_string(),
client_alias: cfg.client_alias.clone().unwrap_or("".to_string()),
};

let cfg_otel: OtelConfig = (&cfg).into();
Expand Down Expand Up @@ -560,6 +561,10 @@ pub fn load_runtime_config(opts: &CliOpts) -> Result<RuntimeConfig> {
cfg.block_matrix_partition = Some(*partition)
}

if let Some(client_alias) = &opts.client_alias {
cfg.client_alias = Some(client_alias.clone())
}

Ok(cfg)
}

Expand Down Expand Up @@ -610,7 +615,8 @@ pub async fn main() -> Result<()> {
Level::INFO,
"run",
client_id = client_id.to_string(),
execution_id = execution_id.to_string()
execution_id = execution_id.to_string(),
client_alias = cfg.client_alias.clone().unwrap_or("".to_string())
);
// Do not enter span if logs format is not JSON
let _enter = if logs_json { Some(span.enter()) } else { None };
Expand Down
4 changes: 4 additions & 0 deletions core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.11.1

- Add `--client-alias` CLI parameter and `client-alias` config parameter for setting human readable alias of the client

## [1.11.0](https://github.com/availproject/avail-light/releases/tag/avail-light-client-v1.11.0) - 2024-07-18

- Return empty data on `v2/blocks/{block_number}/data` endpoint in case of `incomplete` blocks
Expand Down
4 changes: 3 additions & 1 deletion core/src/telemetry/otlp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use opentelemetry_otlp::{ExportConfig, Protocol, WithExportConfig};
use std::{collections::HashMap, sync::Arc, time::Duration};
use tokio::sync::{Mutex, RwLock};

const ATTRIBUTE_NUMBER: usize = 11;
const ATTRIBUTE_NUMBER: usize = 12;

// NOTE: Buffers are less space efficient, as opposed to the solution with in place compute.
// That can be optimized by using dedicated data structure with proper bounds.
Expand All @@ -41,6 +41,7 @@ pub struct MetricAttributes {
pub multiaddress: String,
pub client_id: String,
pub execution_id: String,
pub client_alias: String,
}

impl Metrics {
Expand All @@ -58,6 +59,7 @@ impl Metrics {
KeyValue::new("multiaddress", attributes.multiaddress.clone()),
KeyValue::new("client_id", attributes.client_id.clone()),
KeyValue::new("execution_id", attributes.execution_id.clone()),
KeyValue::new("client_alias", attributes.client_alias.clone()),
]
}

Expand Down
3 changes: 3 additions & 0 deletions core/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,8 @@ pub struct RuntimeConfig {
#[cfg(feature = "crawl")]
#[serde(flatten)]
pub crawl: crate::crawl_client::CrawlConfig,
/// Client alias for use in logs and metrics
pub client_alias: Option<String>,
}

impl RuntimeConfig {
Expand Down Expand Up @@ -910,6 +912,7 @@ impl Default for RuntimeConfig {
retries: 6,
}),
automatic_server_mode: true,
client_alias: None,
}
}
}
Expand Down

0 comments on commit 303a136

Please sign in to comment.