global: snapshot

This commit is contained in:
nym21
2026-01-11 17:19:00 +01:00
parent 6f45ec13f3
commit ea70c381de
419 changed files with 38059 additions and 7653 deletions
+56
View File
@@ -0,0 +1,56 @@
//! Basic example of using the BRK client.
use brk_client::{BrkClient, BrkClientOptions};
fn main() -> brk_client::Result<()> {
// Create client with default options
let client = BrkClient::new("http://localhost:3110");
// Or with custom options
let _client_with_options = BrkClient::with_options(BrkClientOptions {
base_url: "http://localhost:3110".to_string(),
timeout_secs: 60,
});
// Fetch price data using the typed tree API
let price_close = client
.tree()
.price
.usd
.split
.close
.by
.dateindex()
.range(None, Some(-3))?;
println!("Last 3 price close values: {:?}", price_close);
// Fetch block data
let block_count = client
.tree()
.blocks
.count
.block_count
.sum
.by
.height()
.range(None, Some(-3))?;
println!("Last 3 block count values: {:?}", block_count);
// Fetch supply data
let circulating = client
.tree()
.supply
.circulating
.bitcoin
.by
.dateindex()
.range(None, Some(-3))?;
println!("Last 3 circulating supply values: {:?}", circulating);
// Using generic metric fetching
let metricdata =
client.get_metric_by_index("dateindex", "price_close", None, None, None, None)?;
println!("Generic fetch result count: {}", metricdata.data.len());
Ok(())
}
+76
View File
@@ -0,0 +1,76 @@
//! Comprehensive test that fetches all endpoints in the tree.
//!
//! This example demonstrates how to iterate over all metrics and fetch data
//! from each endpoint. Run with: cargo run --example test_all_endpoints
use brk_client::{BrkClient, Index};
fn main() -> brk_client::Result<()> {
let client = BrkClient::new("http://localhost:3110");
// Get all metrics from the tree
let metrics = client.all_metrics();
println!("\nFound {} metrics", metrics.len());
let mut success = 0;
let mut failed = 0;
let mut errors: Vec<String> = Vec::new();
for metric in &metrics {
let name = metric.name();
let indexes = metric.indexes();
for index in indexes {
let path = format!("/api/metric/{}/{}", name, index.serialize_long());
match client.get::<serde_json::Value>(&format!("{}?to=-3", path)) {
Ok(data) => {
let count = data
.get("data")
.and_then(|d| d.as_array())
.map(|a| a.len())
.unwrap_or(0);
if count != 3 {
failed += 1;
let error_msg = format!(
"FAIL: {}.{} -> expected 3, got {}",
name,
index.serialize_long(),
count
);
errors.push(error_msg.clone());
println!("{}", error_msg);
} else {
success += 1;
println!("OK: {}.{} -> {} items", name, index.serialize_long(), count);
}
}
Err(e) => {
failed += 1;
let error_msg = format!("FAIL: {}.{} -> {}", name, index.serialize_long(), e);
errors.push(error_msg.clone());
println!("{}", error_msg);
}
}
}
}
println!("\n=== Results ===");
println!("Success: {}", success);
println!("Failed: {}", failed);
if !errors.is_empty() {
println!("\nErrors:");
for err in errors.iter().take(10) {
println!(" {}", err);
}
if errors.len() > 10 {
println!(" ... and {} more", errors.len() - 10);
}
}
if failed > 0 {
std::process::exit(1);
}
Ok(())
}