From 1430c5d3ed72b18d76be3b56d9b43a091de8bd13 Mon Sep 17 00:00:00 2001 From: Mike Beaumont Date: Mon, 7 Oct 2024 23:48:30 +0200 Subject: [PATCH] feat(metrics-exporter): support IPv6 Pod IPs Signed-off-by: Mike Beaumont --- .../src/bin/io_engine/client/grpc_client.rs | 4 ++-- metrics-exporter/src/bin/io_engine/main.rs | 12 +++++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/metrics-exporter/src/bin/io_engine/client/grpc_client.rs b/metrics-exporter/src/bin/io_engine/client/grpc_client.rs index 0ac661b9e..a030c99b4 100644 --- a/metrics-exporter/src/bin/io_engine/client/grpc_client.rs +++ b/metrics-exporter/src/bin/io_engine/client/grpc_client.rs @@ -7,7 +7,7 @@ use crate::client::{ replica_stat::{ReplicaIoStat, ReplicaIoStats}, }; use actix_web::http::Uri; -use std::time::Duration; +use std::{net::SocketAddr, time::Duration}; use tokio::time::sleep; use tonic::transport::Channel; use tracing::error; @@ -112,7 +112,7 @@ pub(crate) async fn init_client() -> Result { let _ = get_node_name()?; let endpoint = Uri::builder() .scheme("https") - .authority(format!("{pod_ip}:10124")) + .authority(SocketAddr::new(pod_ip, 10124).to_string()) .path_and_query("") .build() .map_err(|error| ExporterError::InvalidURI(error.to_string()))?; diff --git a/metrics-exporter/src/bin/io_engine/main.rs b/metrics-exporter/src/bin/io_engine/main.rs index 13bf2e4f8..c618b8ccf 100644 --- a/metrics-exporter/src/bin/io_engine/main.rs +++ b/metrics-exporter/src/bin/io_engine/main.rs @@ -6,7 +6,10 @@ use crate::{ use actix_web::{middleware, HttpServer}; use clap::Parser; use once_cell::sync::OnceCell; -use std::{env, net::SocketAddr}; +use std::{ + env, + net::{IpAddr, SocketAddr}, +}; use utils::tracing_telemetry::{FmtLayer, FmtStyle}; /// Cache module for exporter. @@ -26,8 +29,11 @@ async fn initialize_cache() { } /// Get pod ip from env. -fn get_pod_ip() -> Result { - env::var("MY_POD_IP").map_err(|_| ExporterError::PodIPError("Unable to get pod ip".to_string())) +fn get_pod_ip() -> Result { + let ip = env::var("MY_POD_IP") + .map_err(|_| ExporterError::PodIPError("Unable to get pod ip".to_string()))?; + ip.parse::() + .map_err(|_| ExporterError::PodIPError("Invalid pod ip".to_string())) } /// Get node name from env.