Skip to content

Commit f589c11

Browse files
authored
Merge pull request #155 from firstbatchxyz/erhant/task-monitor
feat: task monitor
2 parents 014c5c8 + ecea7f3 commit f589c11

File tree

24 files changed

+474
-122
lines changed

24 files changed

+474
-122
lines changed

.env.example

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ GEMINI_API_KEY=
3232
OPENROUTER_API_KEY=
3333

3434
## Ollama (if used, optional) ##
35-
# do not change this, it is used by Docker
36-
OLLAMA_HOST=http://host.docker.internal
35+
OLLAMA_HOST=http://localhost
3736
# you can change the port if you would like
3837
OLLAMA_PORT=11434
3938
# if "true", automatically pull models from Ollama

Cargo.lock

Lines changed: 24 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
[workspace]
22
resolver = "2"
3-
members = ["compute", "p2p", "workflows", "utils"]
4-
# compute node is the default member, until Oracle comes in
5-
# then, a Launcher will be the default member
6-
default-members = ["compute"]
3+
members = ["compute", "p2p", "workflows", "utils", "monitor"]
74

85
[workspace.package]
96
edition = "2021"
10-
version = "0.2.25"
7+
version = "0.2.26"
118
license = "Apache-2.0"
129
readme = "README.md"
1310

Makefile

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,37 @@ endif
77
###############################################################################
88
.PHONY: launch # | Run with INFO logs in release mode
99
launch:
10-
RUST_LOG=none,dkn_compute=info,dkn_workflows=info,dkn_p2p=info cargo run --release
10+
cargo run --release --bin dkn-compute
1111

1212
.PHONY: run # | Run with INFO logs
1313
run:
14-
cargo run
14+
cargo run --bin dkn-compute
15+
16+
.PHONY: monitor # | Run monitor node with INFO logs
17+
monitor:
18+
cargo run --bin dkn-monitor
1519

1620
.PHONY: debug # | Run with DEBUG logs with INFO log-level workflows
1721
debug:
18-
RUST_LOG=warn,dkn_compute=debug,dkn_workflows=debug,dkn_p2p=debug,ollama_workflows=info cargo run
22+
RUST_LOG=warn,dkn_compute=debug,dkn_workflows=debug,dkn_p2p=debug,ollama_workflows=info \
23+
cargo run --bin dkn-compute
1924

2025
.PHONY: trace # | Run with TRACE logs
2126
trace:
22-
RUST_LOG=warn,dkn_compute=trace,libp2p=debug cargo run
27+
RUST_LOG=warn,dkn_compute=trace,libp2p=debug \
28+
cargo run --bin dkn-compute
2329

2430
.PHONY: build # | Build
2531
build:
2632
cargo build --workspace
2733

2834
.PHONY: profile-cpu # | Profile CPU usage with flamegraph
2935
profile-cpu:
30-
DKN_EXIT_TIMEOUT=120 cargo flamegraph --root --profile=profiling
36+
DKN_EXIT_TIMEOUT=120 cargo flamegraph --root --profile=profiling --bin dkn-compute
3137

3238
.PHONY: profile-mem # | Profile memory usage with instruments
3339
profile-mem:
34-
DKN_EXIT_TIMEOUT=120 cargo instruments --profile=profiling -t Allocations
40+
DKN_EXIT_TIMEOUT=120 cargo instruments --profile=profiling -t Allocations --bin dkn-compute
3541

3642
.PHONY: ollama-versions
3743
ollama-versions:

compute/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ base64 = "0.22.0"
2828
hex = "0.4.3"
2929
hex-literal = "0.4.1"
3030
uuid = { version = "1.8.0", features = ["v4"] }
31+
rand.workspace = true
3132

3233
# logging & errors
33-
rand.workspace = true
3434
env_logger.workspace = true
3535
log.workspace = true
3636
eyre.workspace = true

compute/src/config.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub(crate) const DEFAULT_P2P_LISTEN_ADDR: &str = "/ip4/0.0.0.0/tcp/4001";
3333
#[allow(clippy::new_without_default)]
3434
impl DriaComputeNodeConfig {
3535
/// Creates new config from environment variables.
36-
pub fn new() -> Self {
36+
pub fn new(workflows: DriaWorkflowsConfig) -> Self {
3737
let secret_key = match env::var("DKN_WALLET_SECRET_KEY") {
3838
Ok(secret_env) => {
3939
let secret_dec = hex::decode(secret_env.trim_start_matches("0x"))
@@ -91,15 +91,7 @@ impl DriaComputeNodeConfig {
9191
hex::encode(admin_public_key.serialize_compressed())
9292
);
9393

94-
let workflows =
95-
DriaWorkflowsConfig::new_from_csv(&env::var("DKN_MODELS").unwrap_or_default());
96-
#[cfg(not(test))]
97-
if workflows.models.is_empty() {
98-
log::error!("No models were provided, make sure to restart with at least one model provided within DKN_MODELS.");
99-
panic!("No models provided.");
100-
}
101-
log::info!("Configured models: {:?}", workflows.models);
102-
94+
// parse listen address
10395
let p2p_listen_addr_str = env::var("DKN_P2P_LISTEN_ADDR")
10496
.map(|addr| addr.trim_matches('"').to_string())
10597
.unwrap_or(DEFAULT_P2P_LISTEN_ADDR.to_string());
@@ -152,7 +144,7 @@ impl Default for DriaComputeNodeConfig {
152144
);
153145
env::set_var("DKN_MODELS", "gpt-3.5-turbo");
154146

155-
Self::new()
147+
Self::new(Default::default())
156148
}
157149
}
158150

compute/src/handlers/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
mod pingpong;
2-
pub use pingpong::PingpongHandler;
2+
pub use pingpong::*;
33

44
mod workflow;
5-
pub use workflow::WorkflowHandler;
5+
pub use workflow::*;

compute/src/handlers/pingpong.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ use serde::{Deserialize, Serialize};
88
pub struct PingpongHandler;
99

1010
#[derive(Serialize, Deserialize, Debug, Clone)]
11-
struct PingpongPayload {
11+
pub struct PingpongPayload {
1212
/// UUID of the ping request, prevents replay attacks.
1313
uuid: String,
1414
/// Deadline for the ping request.
1515
deadline: u128,
1616
}
1717

1818
#[derive(Serialize, Deserialize, Debug, Clone)]
19-
struct PingpongResponse {
19+
pub struct PingpongResponse {
2020
/// UUID as given in the ping payload.
2121
pub(crate) uuid: String,
2222
/// Models available in the node.
@@ -26,8 +26,8 @@ struct PingpongResponse {
2626
}
2727

2828
impl PingpongHandler {
29-
pub(crate) const LISTEN_TOPIC: &'static str = "ping";
30-
pub(crate) const RESPONSE_TOPIC: &'static str = "pong";
29+
pub const LISTEN_TOPIC: &'static str = "ping";
30+
pub const RESPONSE_TOPIC: &'static str = "pong";
3131

3232
/// Handles the ping message and responds with a pong message.
3333
///

compute/src/handlers/workflow.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ use libsecp256k1::PublicKey;
66
use serde::Deserialize;
77
use tokio_util::either::Either;
88

9-
use crate::payloads::{TaskErrorPayload, TaskRequestPayload, TaskResponsePayload, TaskStats};
9+
use crate::payloads::*;
1010
use crate::utils::DriaMessage;
1111
use crate::workers::workflow::*;
1212
use crate::DriaComputeNode;
1313

1414
pub struct WorkflowHandler;
1515

1616
#[derive(Debug, Deserialize)]
17-
struct WorkflowPayload {
17+
pub struct WorkflowPayload {
1818
/// [Workflow](https://github.com/andthattoo/ollama-workflows/blob/main/src/program/workflow.rs) object to be parsed.
1919
pub(crate) workflow: Workflow,
2020
/// A lıst of model (that can be parsed into `Model`) or model provider names.
@@ -27,8 +27,8 @@ struct WorkflowPayload {
2727
}
2828

2929
impl WorkflowHandler {
30-
pub(crate) const LISTEN_TOPIC: &'static str = "task";
31-
pub(crate) const RESPONSE_TOPIC: &'static str = "results";
30+
pub const LISTEN_TOPIC: &'static str = "task";
31+
pub const RESPONSE_TOPIC: &'static str = "results";
3232

3333
pub(crate) async fn handle_compute(
3434
node: &mut DriaComputeNode,

compute/src/lib.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
pub(crate) mod config;
2-
pub(crate) mod handlers;
3-
pub(crate) mod node;
4-
pub(crate) mod payloads;
5-
pub(crate) mod utils;
6-
pub(crate) mod workers;
1+
pub mod config;
2+
pub mod handlers;
3+
pub mod node;
4+
pub mod payloads;
5+
pub mod utils;
6+
pub mod workers;
77

88
/// Crate version of the compute node.
99
/// This value is attached within the published messages.
1010
pub const DRIA_COMPUTE_NODE_VERSION: &str = env!("CARGO_PKG_VERSION");
1111

12+
pub use utils::refresh_dria_nodes;
13+
1214
pub use config::DriaComputeNodeConfig;
1315
pub use node::DriaComputeNode;

0 commit comments

Comments
 (0)