Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
ThetaSinner committed Mar 8, 2024
1 parent dfd9c25 commit c9e9abc
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 20 deletions.
2 changes: 1 addition & 1 deletion framework/instruments/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mod report;

pub mod prelude {
pub use crate::report::{ReportCollector, ReportMetric};
pub use crate::{ReportConfig, Reporter, OperationRecord, report_operation};
pub use crate::{report_operation, OperationRecord, ReportConfig, Reporter};
}

#[derive(Default)]
Expand Down
4 changes: 2 additions & 2 deletions framework/instruments/src/report.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
mod metrics_report;
mod summary_report;

use std::ops::Deref;
use influxive_core::{Metric, StringType};
use crate::OperationRecord;
use influxive_core::{Metric, StringType};
use std::ops::Deref;

pub use metrics_report::MetricsReportCollector;
pub use summary_report::SummaryReportCollector;
Expand Down
8 changes: 5 additions & 3 deletions framework/instruments/src/report/metrics_report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use crate::report::{ReportCollector, ReportMetric};
use crate::OperationRecord;
use anyhow::Context;
use influxdb::{Client, InfluxDbWriteable, Timestamp, WriteQuery};
use influxive_core::DataType;
use std::sync::atomic::AtomicBool;
use std::sync::Arc;
use std::time::SystemTime;
use influxive_core::DataType;
use tokio::runtime::Runtime;
use tokio::select;
use tokio::sync::mpsc::UnboundedSender;
Expand Down Expand Up @@ -91,11 +91,13 @@ impl ReportCollector for MetricsReportCollector {
let metric = metric.into_inner();

let mut query = Timestamp::Nanoseconds(
metric.timestamp
metric
.timestamp
.duration_since(SystemTime::UNIX_EPOCH)
.unwrap()
.as_nanos(),
).into_query(metric.name.into_string());
)
.into_query(metric.name.into_string());

for (k, v) in metric.fields {
query = query.add_field(k.into_string(), v.into_type());
Expand Down
37 changes: 29 additions & 8 deletions scenarios/dht_sync_lag/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::collections::HashSet;
use anyhow::anyhow;
use holochain_types::prelude::{ActionHash, Record, Timestamp};
use holochain_wind_tunnel_runner::prelude::*;
use holochain_wind_tunnel_runner::scenario_happ_path;
use std::collections::HashSet;
use std::path::Path;
use std::time::SystemTime;
use anyhow::anyhow;
use timed_integrity::TimedEntry;

#[derive(Debug, Default)]
Expand Down Expand Up @@ -54,20 +54,41 @@ fn agent_behaviour_record_lag(
) -> HookResult {
let found: Vec<Record> = call_zome(ctx, "timed", "get_timed_entries_local", ())?;

let found = found.into_iter().filter(|r| !ctx.get().scenario_values.seen_actions.contains(r.action_address())).collect::<Vec<_>>();
let found = found
.into_iter()
.filter(|r| {
!ctx.get()
.scenario_values
.seen_actions
.contains(r.action_address())
})
.collect::<Vec<_>>();

let reporter_handle = ctx.runner_context().reporter().clone();
for new_record in &found {
let timed_entry: TimedEntry = new_record.entry().to_app_option().map_err(|e| anyhow!("Failed to deserialize TimedEntry: {}", e))?.unwrap();
let timed_entry: TimedEntry = new_record
.entry()
.to_app_option()
.map_err(|e| anyhow!("Failed to deserialize TimedEntry: {}", e))?
.unwrap();

let metric = ReportMetric::new("dht_sync_lag");
let lag_ms = (metric.timestamp.clone().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_micros() - timed_entry.created_at.as_micros() as u128) as f64 / 1000.0;
let metric = metric
.with_field("value", lag_ms);
let lag_ms = (metric
.timestamp
.clone()
.duration_since(SystemTime::UNIX_EPOCH)
.unwrap()
.as_micros()
- timed_entry.created_at.as_micros() as u128) as f64
/ 1000.0;
let metric = metric.with_field("value", lag_ms);

reporter_handle.add_custom(metric);

ctx.get_mut().scenario_values.seen_actions.insert(new_record.action_address().clone());
ctx.get_mut()
.scenario_values
.seen_actions
.insert(new_record.action_address().clone());
}

let metric = ReportMetric::new("dht_sync_recv_count")
Expand Down
1 change: 0 additions & 1 deletion zomes/crud/coordinator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ name = "crud"
version = "0.1.0"
edition = "2021"
description = "A Holochain coordinator zome for CRUD"
build = "../../wasm_build.rs"

[lib]
name = "crud_coordinator"
Expand Down
1 change: 0 additions & 1 deletion zomes/crud/integrity/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ name = "crud_integrity"
version = "0.1.0"
edition = "2021"
description = "A Holochain integrity zome for CRUD"
build = "../../wasm_build.rs"

[lib]
name = "crud_integrity"
Expand Down
1 change: 0 additions & 1 deletion zomes/return_single_value/coordinator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ name = "return_single_value"
version = "0.1.0"
edition = "2021"
description = "A Holochain zome with a single zome function 'get_value' that returns 5"
build = "../../wasm_build.rs"

[lib]
name = "return_single_value_coordinator"
Expand Down
14 changes: 11 additions & 3 deletions zomes/timed/coordinator/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
use hdk::prelude::*;
use hdk::prelude::holo_hash::blake2b_256;
use hdk::prelude::holo_hash::hash_type::AnyLinkable;
use hdk::prelude::*;
use timed_integrity::{EntryTypes, LinkTypes, TimedEntry};

#[hdk_extern]
fn created_timed_entry(timed: TimedEntry) -> ExternResult<ActionHash> {
let action_hash = create_entry(EntryTypes::TimedEntry(timed))?;

create_link(fixed_base(), action_hash.clone(), LinkTypes::FixedToTimedEntry, ())?;
create_link(
fixed_base(),
action_hash.clone(),
LinkTypes::FixedToTimedEntry,
(),
)?;

Ok(action_hash)
}
Expand All @@ -19,7 +24,10 @@ fn get_timed_entries_local(_: ()) -> ExternResult<Vec<Record>> {

let mut records = Vec::new();
for link in links {
let action_hash: ActionHash = link.target.try_into().map_err(|_| wasm_error!(WasmErrorInner::Guest("Not an action hash".to_string())))?;
let action_hash: ActionHash = link
.target
.try_into()
.map_err(|_| wasm_error!(WasmErrorInner::Guest("Not an action hash".to_string())))?;
// Try to stay local
let record = get(action_hash, GetOptions::content())?;
if let Some(record) = record {
Expand Down

0 comments on commit c9e9abc

Please sign in to comment.