Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use Grafana provisioning for metrics #1625

Merged
merged 3 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions Cargo.lock

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

88 changes: 1 addition & 87 deletions bin/trin/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ use clap::{
arg,
builder::ArgPredicate,
error::{Error, ErrorKind},
Args, Parser, Subcommand,
Parser,
};
use ethportal_api::{
dashboard::grafana::{GrafanaAPI, DASHBOARD_TEMPLATES},
types::{
network::Subnetwork,
portal_wire::{NetworkSpec, MAINNET},
Expand Down Expand Up @@ -206,9 +205,6 @@ pub struct TrinConfig {
default_value_t = DEFAULT_UTP_TRANSFER_LIMIT,
)]
pub utp_transfer_limit: usize,

#[command(subcommand)]
pub command: Option<TrinConfigCommands>,
}

impl Default for TrinConfig {
Expand Down Expand Up @@ -238,7 +234,6 @@ impl Default for TrinConfig {
disable_poke: false,
ws: false,
ws_port: DEFAULT_WEB3_WS_PORT,
command: None,
utp_transfer_limit: DEFAULT_UTP_TRANSFER_LIMIT,
network: MAINNET.clone(),
}
Expand All @@ -257,14 +252,6 @@ impl TrinConfig {
{
let config = Self::try_parse_from(args)?;

if let Some(TrinConfigCommands::CreateDashboard(dashboard_config)) = config.command {
if let Err(err) = create_dashboard(dashboard_config) {
panic!("Creating dashboard failed {err}");
}
// exit program since if the user uses create dashboard this is all we do
std::process::exit(0);
}

match config.web3_transport {
Web3TransportType::HTTP => {
match &config.web3_ipc_path.as_path().display().to_string()[..] {
Expand Down Expand Up @@ -416,52 +403,6 @@ impl fmt::Display for TrinConfig {
}
}

#[derive(Subcommand, Debug, Clone, PartialEq)]
#[allow(clippy::enum_variant_names)]
pub enum TrinConfigCommands {
CreateDashboard(DashboardConfig),
}

#[derive(Args, Debug, Default, Clone, PartialEq)]
#[allow(clippy::enum_variant_names)]
pub struct DashboardConfig {
#[arg(default_value = "http://localhost:3000")]
pub grafana_address: String,

#[arg(default_value = "admin")]
pub grafana_username: String,

#[arg(default_value = "admin")]
pub grafana_password: String,

#[arg(default_value = "http://host.docker.internal:9090")]
pub prometheus_address: String,
}

pub fn create_dashboard(
dashboard_config: DashboardConfig,
) -> Result<(), Box<dyn std::error::Error>> {
let grafana = GrafanaAPI::new(
dashboard_config.grafana_username,
dashboard_config.grafana_password,
dashboard_config.grafana_address,
);

let prometheus_uid = grafana.create_datasource(
"prometheus".to_string(),
"prometheus".to_string(),
dashboard_config.prometheus_address,
)?;

// Create a dashboard from each pre-defined template
for template_path in DASHBOARD_TEMPLATES {
let dashboard_url = grafana.create_dashboard(template_path, &prometheus_uid)?;
println!("Dashboard successfully created: {dashboard_url}");
}

Ok(())
}

impl TrinConfig {
pub fn to_portalnet_config(&self, private_key: B256) -> PortalnetConfig {
PortalnetConfig {
Expand Down Expand Up @@ -715,33 +656,6 @@ mod tests {
.unwrap();
}

#[test_log::test]
fn test_trin_with_create_dashboard() {
let config = TrinConfig::try_parse_from([
"trin",
"create-dashboard",
"http://localhost:8787",
"username",
"password",
"http://docker:9090",
])
.unwrap();
if let Some(TrinConfigCommands::CreateDashboard(dashboard_config)) = config.command {
assert_eq!(
dashboard_config.grafana_address,
"http://localhost:8787".to_string()
);
assert_eq!(dashboard_config.grafana_username, "username".to_string());
assert_eq!(dashboard_config.grafana_password, "password".to_string());
assert_eq!(
dashboard_config.prometheus_address,
"http://docker:9090".to_string()
);
} else {
unreachable!("")
}
}

#[test_log::test]
#[should_panic(expected = "Invalid web3-transport arg. Expected either 'http' or 'ipc'")]
fn test_invalid_web3_transport_argument() {
Expand Down
Loading
Loading