Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ members = ["crates/*"]
resolver = "2"

[workspace.package]
version = "0.3.9"
version = "0.3.10"
edition = "2021"
publish = false
authors = ["FastEdge Development Team"]
Expand Down
10 changes: 3 additions & 7 deletions crates/http-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ authors.workspace = true

[features]
default = []
metrics = ["prometheus"]
stats = ["clickhouse"]
metrics = ["runtime/metrics"]
stats = ["runtime/stats"]

[dependencies]
anyhow = { workspace = true }
Expand All @@ -30,12 +30,8 @@ reactor = { path = "../reactor" }
runtime = { path = "../runtime" }
http-backend = { path = "../http-backend" }
nanoid = "0.4"
bytesize = "1.2.0"
bytesize = "1.3.0"
futures = "0.3.30"
once_cell = "1.19"
prometheus = { version = "0.13.3", features = ["process"], optional = true }
serde = "1.0"
clickhouse = { version = "0.11.6", optional = true }
chrono = "0.4"
async-trait = "0.1"

Expand Down
10 changes: 1 addition & 9 deletions crates/http-service/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,4 @@ fn to_fastedge_http_method(method: &Method) -> Result<fastedge::http::Method> {
})
}

#[derive(PartialEq, Copy, Clone, Debug)]
pub enum AppResult {
SUCCESS,
#[cfg(feature = "metrics")]
UNKNOWN,
TIMEOUT,
OOM,
OTHER,
}

14 changes: 7 additions & 7 deletions crates/http-service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ use wasmtime_wasi_nn::WasiNnCtx;
use http_backend::Backend;
use runtime::app::Status;
use runtime::service::Service;
use runtime::{App, ContextT, Router, WasmEngine, WasmEngineBuilder};
use runtime::{App, AppResult, ContextT, Router, WasmEngine, WasmEngineBuilder};
#[cfg(feature = "metrics")]
use runtime::util::metrics;

use crate::executor::{AppResult, HttpExecutor};
use crate::executor::{ HttpExecutor};
#[cfg(feature = "stats")]
use crate::stats::StatRow;
use crate::stats::StatsWriter;
use runtime::util::stats::StatRow;
use runtime::util::stats::StatsWriter;

use crate::tls::{load_certs, load_private_key, TlsAcceptor, TlsStream};
pub mod executor;
#[cfg(feature = "metrics")]
pub mod metrics;
pub mod stats;

mod tls;

pub use crate::executor::ExecutorFactory;
Expand Down
103 changes: 0 additions & 103 deletions crates/http-service/src/metrics.rs

This file was deleted.

6 changes: 6 additions & 0 deletions crates/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ authors.workspace = true
[features]
default = ["kafka_log"]
kafka_log = []
metrics = ["prometheus", "lazy_static"]
stats = ["clickhouse"]

[dependencies]
anyhow = { workspace = true }
Expand All @@ -30,6 +32,10 @@ bytes = "1.5"
serde = "1.0"
serde_json = "1.0.108"
chrono = { version = "0.4", features = ["serde"] }
prometheus = { version = "0.13.3", features = ["process"], optional = true }
clickhouse = { version = "0.11.6", optional = true }
lazy_static = { version = "1.4.0", optional = true }


[dev-dependencies]
claims = "0.7"
Expand Down
11 changes: 11 additions & 0 deletions crates/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub mod registry;
pub mod service;
pub mod store;
pub mod stub;
pub mod util;

use crate::logger::Logger;
use anyhow::anyhow;
Expand All @@ -34,6 +35,16 @@ use wasmtime_environ::wasmparser::{Encoding, Parser, Payload};

const PREVIEW1_ADAPTER: &[u8] = include_bytes!("adapters/wasi_snapshot_preview1.reactor.wasm");

#[derive(PartialEq, Copy, Clone, Debug)]
pub enum AppResult {
SUCCESS,
#[cfg(feature = "metrics")]
UNKNOWN,
TIMEOUT,
OOM,
OTHER,
}

pub type InstancePre<T> = Arc<wasmtime::component::InstancePre<Data<T>>>;
pub type ModuleInstancePre<T> = Arc<wasmtime::InstancePre<Data<T>>>;

Expand Down
54 changes: 54 additions & 0 deletions crates/runtime/src/util/metrics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
use lazy_static::lazy_static;
use prometheus::{self, opts, register_int_counter, IntCounter};

use crate::AppResult;

lazy_static! {
static ref TOTAL_COUNT: IntCounter =
register_int_counter!("fastedge_call_count", "Total number of app calls.").unwrap();
}

lazy_static! {
static ref ERROR_COUNT: IntCounter = register_int_counter!(opts!(
"fastedge_error_total_count",
"Number of failed app calls."
))
.unwrap();
}
lazy_static! {
static ref UNKNOWN_COUNT: IntCounter = register_int_counter!(opts!(
"fastedge_error_unknown_count",
"Number of calls for unknown app."
))
.unwrap();
}
lazy_static! {
static ref TIMEOUT_COUNT: IntCounter =
register_int_counter!(opts!("fastedge_error_timeout_count", "Number of timeouts."))
.unwrap();
}
lazy_static! {
static ref OOM_COUNT: IntCounter =
register_int_counter!(opts!("fastedge_error_oom_count", "Number of OOMs.")).unwrap();
}
lazy_static! {
static ref OTHER_ERROR_COUNT: IntCounter = register_int_counter!(opts!(
"fastedge_error_other_count",
"Number of other error."
))
.unwrap();
}

pub fn metrics(result: AppResult) {
TOTAL_COUNT.inc();
if result != AppResult::SUCCESS {
ERROR_COUNT.inc();
}
match result {
AppResult::UNKNOWN => UNKNOWN_COUNT.inc(),
AppResult::TIMEOUT => TIMEOUT_COUNT.inc(),
AppResult::OOM => OOM_COUNT.inc(),
AppResult::OTHER => OTHER_ERROR_COUNT.inc(),
_ => {}
};
}
3 changes: 3 additions & 0 deletions crates/runtime/src/util/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#[cfg(feature = "metrics")]
pub mod metrics;
pub mod stats;
File renamed without changes.
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use clap::{Args, Parser, Subcommand};
use http_backend::{Backend, BackendStrategy};
use http_service::executor::{ExecutorFactory, HttpExecutorImpl};
use http_service::stats::{StatRow, StatsWriter};
use http_service::{ContextHeaders, HttpConfig, HttpService, HttpState};
use hyper::client::HttpConnector;
use hyper_tls::HttpsConnector;
Expand All @@ -19,6 +18,7 @@ use std::path::PathBuf;
use tokio_util::sync::CancellationToken;
use wasmtime::component::Component;
use wasmtime::{Engine, Module};
use runtime::util::stats::{StatRow, StatsWriter};

#[derive(Debug, Parser)]
#[command(name = "cli")]
Expand Down