Skip to content

Commit

Permalink
bot: Don't require a token for influxdb performance db queries
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-at-planetariummusic committed Jun 6, 2023
1 parent 9fdf52a commit 2811d3d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
6 changes: 2 additions & 4 deletions bot/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1604,12 +1604,10 @@ fn classify(
validators_app_client.get_all_commision_changes_since(five_days_ago)?;

let performance_metrics_for_this_epoch: Option<HashMap<Pubkey, (bool, String)>> =
if let (Some(performance_db_url), Some(performance_db_token)) =
(&config.performance_db_url, &config.performance_db_token)
{
if let Some(performance_db_url) = &config.performance_db_url {
let reported_performance_metrics = get_reported_performance_metrics(
performance_db_url,
performance_db_token,
&config.performance_db_token,
&config.cluster,
rpc_client,
&(epoch - 1),
Expand Down
20 changes: 11 additions & 9 deletions bot/src/performance_db_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub fn get_mainnet_pk_from_participant(participant: &Participant) -> Pubkey {
/// Returns a map of validator keys -> (passsed, reason)
pub fn get_reported_performance_metrics(
performance_db_url: &String,
performance_db_token: &String,
performance_db_token: &Option<String>,
cluster: &Cluster,
rpc_client: &RpcClient,
epoch: &Epoch,
Expand Down Expand Up @@ -126,7 +126,7 @@ pub fn get_reported_performance_metrics(
/// Get a list of validators who reported during the specified epoch
fn find_reporters_for_epoch(
performance_db_url: &String,
performance_db_token: &String,
performance_db_token: &Option<String>,
cluster: &Cluster,
epoch: &Epoch,
rpc_client: &RpcClient,
Expand Down Expand Up @@ -194,7 +194,7 @@ fn find_reporters_for_epoch(
/// from a validator in a minute, we can assume they are under-reporting.
fn fetch_data(
performance_db_url: &String,
performance_db_token: &String,
performance_db_token: &Option<String>,
cluster: &Cluster,
date_time: DateTime<Utc>,
) -> Result<HashMap<Pubkey, i32>, Box<dyn std::error::Error>> {
Expand All @@ -217,14 +217,16 @@ fn fetch_data(

let client = reqwest::blocking::Client::new();

let body = client
let mut request_builder = client
.post(performance_db_url)
.header("Authorization", format!("Token {}", performance_db_token))
.header("Accept", "application/csv")
.header("Content-type", "application/vnd.flux")
.body(query)
.send()?
.text()?;
.header("Content-type", "application/vnd.flux");

if let Some(token) = performance_db_token {
request_builder = request_builder.header("Authorization", format!("Token {}", token));
}

let body = request_builder.body(query).send()?.text()?;

let mut reader = csv::ReaderBuilder::new().from_reader(body.as_bytes());

Expand Down

0 comments on commit 2811d3d

Please sign in to comment.