Skip to content

Commit

Permalink
Runtime metrics renamed to counters. Yagna update.
Browse files Browse the repository at this point in the history
  • Loading branch information
pwalski committed Mar 31, 2024
1 parent 08a6e6c commit 0ed2ab7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 32 deletions.
23 changes: 13 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 7 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ members = [
]

[dependencies]
ya-core-model = { git = "https://github.com/golemfactory/yagna.git", rev = "b3f1e8238f26b224729c578eae6c29098d8800d7", features = ["activity", "appkey"] }
ya-runtime-api = { git = "https://github.com/golemfactory/yagna.git", rev = "b3f1e8238f26b224729c578eae6c29098d8800d7" }
ya-core-model = { git = "https://github.com/golemfactory/yagna.git", rev = "0e22f60cc8fe5d032cea7db6d5230320e8b2947f", features = ["activity", "appkey"] }
ya-runtime-api = { git = "https://github.com/golemfactory/yagna.git", rev = "0e22f60cc8fe5d032cea7db6d5230320e8b2947f" }
ya-service-bus = "0.7.1"
ya-client-model = "0.6.0"
ya-agreement-utils = "0.5"
ya-transfer = { git = "https://github.com/golemfactory/yagna.git", rev = "b3f1e8238f26b224729c578eae6c29098d8800d7" }
ya-counters = { path = "../yagna/exe-unit/components/counters" }
ya-transfer = { git = "https://github.com/golemfactory/yagna.git", rev = "0e22f60cc8fe5d032cea7db6d5230320e8b2947f" }
ya-counters = { git = "https://github.com/golemfactory/yagna.git", rev = "0e22f60cc8fe5d032cea7db6d5230320e8b2947f" }

actix = "0.13"
actix-rt = "2"
Expand All @@ -30,16 +30,15 @@ dotenv = "0.15"
anyhow = "1.0"
env_logger = "0.11"
yansi = "1.0"
chrono = "0.4"
chrono = "0.4.34"
tokio = { version = "1.32", features = ["macros", "signal"] }
tokio-stream = { version = "0.1.14", features = ["io-util"] }
futures = "0.3"
flexi_logger = { version = "0.28", features = ["colors"] }
regex = "1"
reqwest = { version = "0.11", features = ["blocking", "json"] }
async-stream = "0.3.5"
# ya-gsb-http-proxy = { git = "https://github.com/golemfactory/yagna.git", rev = "b3f1e8238f26b224729c578eae6c29098d8800d7" }
ya-gsb-http-proxy = { path = "../yagna/exe-unit/components/gsb-http-proxy" }
ya-gsb-http-proxy = { git = "https://github.com/golemfactory/yagna.git", rev = "0e22f60cc8fe5d032cea7db6d5230320e8b2947f" }
http = "1.1.0"
bytes = "1.5.0"
humantime = "2.1"
Expand All @@ -54,4 +53,4 @@ assert_cmd = "2.0"
predicates = "3.1"

[patch.crates-io]
ya-core-model = { git = "https://github.com/golemfactory/yagna.git", rev = "b3f1e8238f26b224729c578eae6c29098d8800d7" }
ya-core-model = { git = "https://github.com/golemfactory/yagna.git", rev = "0e22f60cc8fe5d032cea7db6d5230320e8b2947f" }
29 changes: 15 additions & 14 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ use futures::prelude::*;
use process::Runtime;
use tokio::select;
use tokio::sync::{mpsc, mpsc::Receiver, mpsc::Sender};

use ya_client_model::activity::activity_state::*;
use ya_client_model::activity::ExeScriptCommand;
use ya_client_model::activity::{ActivityUsage, CommandResult, ExeScriptCommandResult};
use ya_core_model::activity;
use ya_core_model::activity::RpcMessageError;
use ya_counters::counters::TimeMetric;
use ya_counters::error::MetricError;
use ya_counters::message::GetMetrics;
use ya_counters::service::{MetricsService, MetricsServiceBuilder};
use ya_counters::error::CounterError;
use ya_counters::message::GetCounters;
use ya_counters::service::{CountersService, CountersServiceBuilder};
use ya_counters::TimeCounter;
use ya_gsb_http_proxy::gsb_to_http::GsbToHttpProxy;
use ya_gsb_http_proxy::message::GsbHttpCallMessage;
use ya_service_bus::typed as gsb;
Expand Down Expand Up @@ -60,13 +61,13 @@ async fn activity_loop<T: process::Runtime + Clone + Unpin + 'static>(
report_url: &str,
activity_id: &str,
process: ProcessController<T>,
metrics: Addr<MetricsService>,
counters: Addr<CountersService>,
) -> anyhow::Result<()> {
let report_service = gsb::service(report_url);

while let Some(()) = process.report() {
// make it a function
match metrics.send(GetMetrics).await {
match counters.send(GetCounters).await {
Ok(resp) => match resp {
Ok(current_usage) => {
let timestamp = Utc::now().timestamp();
Expand All @@ -89,11 +90,11 @@ async fn activity_loop<T: process::Runtime + Clone + Unpin + 'static>(
}
}
Err(err) => match err {
MetricError::UsageLimitExceeded(info) => {
CounterError::UsageLimitExceeded(info) => {
log::warn!("Usage limit exceeded: {}", info);
// TODO State::Terminated
}
error => log::warn!("Unable to retrieve metrics: {:?}", error),
error => log::warn!("Unable to retrieve counters: {:?}", error),
},
},
Err(e) => log::warn!("Unable to report activity usage: {:?}", e),
Expand Down Expand Up @@ -223,18 +224,18 @@ async fn run<RUNTIME: process::Runtime + Clone + Unpin + 'static>(

let mut gsb_proxy = GsbToHttpProxy::new("http://localhost:7861/".into());

let mut counters = MetricsServiceBuilder::new(agreement.counters.clone(), Some(10000));
let mut counters = CountersServiceBuilder::new(agreement.counters.clone(), Some(10000));
counters
.with_metric(TimeMetric::ID, Box::<TimeMetric>::default())
.with_metric(
.with_counter(TimeCounter::ID, Box::<TimeCounter>::default())
.with_counter(
"ai-runtime.requests",
Box::new(gsb_proxy.requests_counter()),
)
.with_metric(
.with_counter(
"golem.usage.gpu-sec",
Box::new(gsb_proxy.requests_duration_counter()),
);
let metrics = counters.build().start();
let counters = counters.build().start();

let ctx = ExeUnitContext {
activity_id: activity_id.clone(),
Expand All @@ -255,7 +256,7 @@ async fn run<RUNTIME: process::Runtime + Clone + Unpin + 'static>(
report_url,
activity_id,
ctx.process_controller.clone(),
metrics.clone(),
counters.clone(),
);

#[cfg(target_os = "windows")]
Expand Down

0 comments on commit 0ed2ab7

Please sign in to comment.