Skip to content

Commit

Permalink
add new telemetry fields chain_id and protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
Trisfald committed Jun 3, 2024
1 parent c10249e commit 61a8c4c
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 2 deletions.
File renamed without changes.
1 change: 1 addition & 0 deletions res/example_telemetry_payload_v2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"agent":{"build":"1.36.1-533-g1098b24d2","name":"near-rs","version":"trunk"},"chain":{"account_id":"test.near","block_production_tracking_delay":0.1,"is_validator":true,"latest_block_hash":"BauFWYx2gMrntNepXF6GN6j1rhQqQEVeLU39WKp2b4C2","latest_block_height":604,"max_block_production_delay":2.0,"max_block_wait_delay":6.0,"min_block_production_delay":0.6,"node_id":"ed25519:6Hat46Wuxrk1czrhENjJrS3GuYUXYDmMgFtGLFyWGWNq","num_peers":0,"status":"NoSync"},"extra_info":"{\"block_production_tracking_delay\":0.1,\"max_block_production_delay\":2.0,\"max_block_wait_delay\":6.0,\"min_block_production_delay\":0.6}","signature":"ed25519:yMax8NT8ptBu3tGa2LWFVSJRxLLRdXmwuVrE6wPnnXdHFqBDbXQvjP4btNGeraFsu75BzkSGvHV7xaJc3vQzUpQ","system":{"bandwidth_download":0,"bandwidth_upload":0,"boot_time_seconds":1715338798,"cpu_usage":0.0,"memory_usage":68648}}
2 changes: 2 additions & 0 deletions src/entities/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ pub struct Model {
pub max_block_production_delay: f64,
#[sea_orm(column_type = "Double")]
pub max_block_wait_delay: f64,
pub chain_id: Option<String>,
pub protocol_version: Option<i32>,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
Expand Down
49 changes: 49 additions & 0 deletions src/migrator/m20240603_000002_add_extra_fields.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use sea_orm_migration::prelude::*;

pub struct Migration;

impl MigrationName for Migration {
fn name(&self) -> &str {
"m_20240603_000002_add_extra_fields"
}
}

#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.alter_table(
Table::alter()
.table(Node::Table)
.add_column(ColumnDef::new(Node::ChainId).string().null())
.to_owned(),
)
.await?;
manager
.alter_table(
Table::alter()
.table(Node::Table)
.add_column(ColumnDef::new(Node::ProtocolVersion).integer().null())
.to_owned(),
)
.await?;
Ok(())
}

async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.alter_table(Table::alter().drop_column(Node::ChainId).to_owned())
.await?;
manager
.alter_table(Table::alter().drop_column(Node::ProtocolVersion).to_owned())
.await?;
Ok(())
}
}

#[derive(Iden)]
pub enum Node {
Table,
ChainId,
ProtocolVersion,
}
6 changes: 5 additions & 1 deletion src/migrator/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
use sea_orm_migration::prelude::*;

mod m20240508_000001_create_tables;
mod m20240603_000002_add_extra_fields;

pub struct Migrator;

#[async_trait::async_trait]
impl MigratorTrait for Migrator {
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
vec![Box::new(m20240508_000001_create_tables::Migration)]
vec![
Box::new(m20240508_000001_create_tables::Migration),
Box::new(m20240603_000002_add_extra_fields::Migration),
]
}
}
2 changes: 2 additions & 0 deletions src/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ async fn parse_and_store_telemetry(db: &DatabaseConnection, body: String) -> Res
min_block_production_delay: ActiveValue::Set(telemetry.chain.min_block_production_delay),
max_block_production_delay: ActiveValue::Set(telemetry.chain.max_block_production_delay),
max_block_wait_delay: ActiveValue::Set(telemetry.chain.max_block_wait_delay),
chain_id: ActiveValue::Set(None),
protocol_version: ActiveValue::Set(None),
};

let on_conflict = OnConflict::column(node::Column::Id)
Expand Down
4 changes: 4 additions & 0 deletions src/telemetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ pub struct TelemetryAgentInfo {
pub name: String,
pub version: String,
pub build: String,
// Added in https://github.com/near/nearcore/pull/11444.
pub protocol_version: Option<u32>,
}

#[derive(serde::Deserialize, Debug)]
Expand All @@ -19,6 +21,8 @@ pub struct TelemetrySystemInfo {

#[derive(serde::Deserialize, Debug)]
pub struct TelemetryChainInfo {
// Added in https://github.com/near/nearcore/pull/11444.
pub chain_id: Option<String>,
pub node_id: String,
// Changed from `Option<AccountId>` to `Option<String>`.
pub account_id: Option<String>,
Expand Down
4 changes: 3 additions & 1 deletion tests/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ async fn entity_insert() {
min_block_production_delay: 0.0,
max_block_production_delay: 0.0,
max_block_wait_delay: 0.0,
chain_id: None,
protocol_version: None,
};
let mock_exec = MockExecResult {
last_insert_id: 1,
Expand All @@ -149,7 +151,7 @@ async fn entity_insert() {
.append_exec_results([mock_exec.clone()])
.into_connection();

let json = fs::read_to_string("example_telemetry_payload").unwrap();
let json = fs::read_to_string("res/example_telemetry_payload_v1").unwrap();
let server = Server::new(MOCK_SOCKET_ADDRESS, db_mainnet, db_testnet).unwrap();

let app = server.app();
Expand Down

0 comments on commit 61a8c4c

Please sign in to comment.