Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO NOT MERGE] starting slight instrumentation #383

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
112 changes: 112 additions & 0 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ tracing-subscriber = { version = "0.3", features = ["env-filter"] }
reqwest = "0.11"
flate2 = "1"
tar = "0.4"
opentelemetry = { workspace = true }
opentelemetry-jaeger = { workspace = true }

[dev-dependencies]
tempdir = { workspace = true }
Expand Down Expand Up @@ -98,6 +100,8 @@ url = "2.2"
semver = "1"
clap = { version = "4", features = ["derive"] }
rand = "0.8"
opentelemetry = { version = "0.18.0", features = ["rt-tokio"] }
opentelemetry-jaeger = { version = "0.17.0", features = ["rt-tokio" ] }

[workspace]
members = [
Expand Down
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ run-rust:
RUST_LOG=$(LOG_LEVEL) $(SLIGHT) -c './examples/messaging-consumer-demo/nats_slightfile.toml' run ./examples/messaging-consumer-demo/target/wasm32-wasi/release/messaging-consumer-demo.wasm &
RUST_LOG=$(LOG_LEVEL) $(SLIGHT) -c './examples/messaging-producer-demo/nats_slightfile.toml' run ./examples/messaging-producer-demo/target/wasm32-wasi/release/messaging-producer-demo.wasm

.PHONY: quick-telemetry-testrun
quick-telemetry-testrun:
# keyvalue.filesystem
RUST_LOG=$(LOG_LEVEL) $(SLIGHT) -c './examples/keyvalue-demo/keyvalue_filesystem_slightfile.toml' run ./examples/keyvalue-demo/target/wasm32-wasi/release/keyvalue-demo.wasm

.PHONY: clean-rust
clean-rust:
cargo clean --manifest-path ./examples/configs-demo/Cargo.toml & \
Expand Down
2 changes: 2 additions & 0 deletions crates/keyvalue/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ anyhow = { workspace = true }
tracing = { workspace = true }
tokio = { workspace = true }
async-trait = { workspace = true }
opentelemetry = { workspace = true }
opentelemetry-jaeger = { workspace = true }
# kv.azblob deps
azure_storage_blobs = { version = "0.10", optional = true }
azure_storage = { version = "0.10", optional = true }
Expand Down
11 changes: 10 additions & 1 deletion crates/keyvalue/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use anyhow::Result;
use async_trait::async_trait;
use implementors::*;

use opentelemetry::{global, trace::Tracer};
use slight_common::{impl_resource, BasicState};
use slight_file::Resource;

Expand Down Expand Up @@ -148,6 +149,7 @@ impl keyvalue::Keyvalue for Keyvalue {
type Keyvalue = KeyvalueInner;

async fn keyvalue_open(&mut self, name: &str) -> Result<Self::Keyvalue, KeyvalueError> {
let tracer = global::tracer("spiderlightning");
// populate our inner keyvalue object w/ the state received from `slight`
// (i.e., what type of keyvalue implementor we are using), and the assigned
// name of the object.
Expand All @@ -165,7 +167,14 @@ impl keyvalue::Keyvalue for Keyvalue {

tracing::log::info!("Opening implementor {}", &state.implementor);

let inner = Self::Keyvalue::new(state.implementor.clone().into(), &state, name).await;
let inner = tracer
.in_span(
format!("opened implementer {}", &state.implementor),
|_cx| async {
Self::Keyvalue::new(state.implementor.clone().into(), &state, name).await
},
)
.await;

Ok(inner)
}
Expand Down
122 changes: 71 additions & 51 deletions src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ use std::{

use anyhow::{bail, Result};
use as_any::Downcast;
use opentelemetry::{
global,
trace::Tracer,
};
#[cfg(feature = "blob-store")]
use slight_blob_store::{BlobStore, BLOB_STORE_SCHEME_NAME};
use slight_common::{BasicState, Capability, Ctx as _, WasmtimeBuildable};
Expand Down Expand Up @@ -39,48 +43,59 @@ pub struct RunArgs {
}

pub async fn handle_run(args: RunArgs) -> Result<()> {
let toml = read_as_toml_file(args.slightfile.clone())?;
let http_enabled = has_http_cap(&toml);
tracing::info!("Starting slight");

let mut host_builder = build_store_instance(&toml, &args.slightfile, &args.module).await?;
if let Some(io_redirects) = args.io_redirects.clone() {
tracing::info!("slight io redirects were specified");
host_builder = host_builder.set_io(io_redirects);
}
let (mut store, instance) = host_builder.build().await;

// looking for the http capability.
if cfg!(feature = "http-server") && http_enabled {
log::debug!("Http capability enabled");
update_http_states(
toml,
args.slightfile,
args.module,
&mut store,
args.io_redirects,
)
.await?;

// invoke on_server_init
let http_server =
HttpServerInit::new(&mut store, &instance, |ctx| ctx.get_http_server_mut())?;

let res = http_server.on_server_init(&mut store).await?;
match res {
Ok(_) => {}
Err(e) => bail!(e),
}
let tracer = global::tracer("spiderlightning");

tracer
.in_span("command handle_run", |_cx| async {
let toml = read_as_toml_file(args.slightfile.clone())?;
let http_enabled = has_http_cap(&toml);
tracing::info!("Starting slight");

let mut host_builder = tracer
.in_span("handle_run build_store_instance", |_cx| async {
build_store_instance(&toml, &args.slightfile, &args.module).await
})
.await?;

if let Some(io_redirects) = args.io_redirects.clone() {
tracing::info!("slight io redirects were specified");
host_builder = host_builder.set_io(io_redirects);
}
let (mut store, instance) = host_builder.build().await;

// looking for the http capability.
if cfg!(feature = "http-server") && http_enabled {
log::debug!("HTTP capability enabled");
update_http_states(
toml,
args.slightfile,
args.module,
&mut store,
args.io_redirects,
)
.await?;

// invoke on_server_init
let http_server =
HttpServerInit::new(&mut store, &instance, |ctx| ctx.get_http_server_mut())?;

let res = http_server.on_server_init(&mut store).await?;
match res {
Ok(_) => {}
Err(e) => bail!(e),
}

log::info!("waiting for http to finish...");
close_http_server(store).await;
} else {
instance
.get_typed_func::<(), _>(&mut store, "_start")?
.call_async(&mut store, ())
.await?;
}
Ok(())
log::info!("waiting for http to finish...");
close_http_server(store).await;
} else {
instance
.get_typed_func::<(), _>(&mut store, "_start")?
.call_async(&mut store, ())
.await?;
}
Ok(())
})
.await
}

#[cfg(not(feature = "http-server"))]
Expand Down Expand Up @@ -154,6 +169,7 @@ async fn build_store_instance(
toml_file_path: impl AsRef<Path>,
module: impl AsRef<Path>,
) -> Result<Builder> {
let tracer = global::tracer("spiderlightning");
let mut builder = Builder::from_module(module)?;
let mut linked_capabilities: HashSet<String> = HashSet::new();
let mut capability_store: HashMap<String, BasicState> = HashMap::new();
Expand Down Expand Up @@ -196,16 +212,20 @@ async fn build_store_instance(
| Resource::V1KeyvalueFilesystem
| Resource::V1KeyvalueRedis
| Resource::V1KeyvalueAzblob => {
if !linked_capabilities.contains("keyvalue") {
builder.link_capability::<Keyvalue>()?;
linked_capabilities.insert("keyvalue".to_string());
}

let resource = slight_keyvalue::Keyvalue::new(
resource_type.to_string(),
capability_store.clone(),
);
builder.add_to_builder("keyvalue".to_string(), resource);
tracer.in_span("build_store_instance link:keyvalue", |_cx| {
if !linked_capabilities.contains("keyvalue") {
builder.link_capability::<Keyvalue>()?;
linked_capabilities.insert("keyvalue".to_string());
}

let resource = slight_keyvalue::Keyvalue::new(
resource_type.to_string(),
capability_store.clone(),
);
builder.add_to_builder("keyvalue".to_string(), resource);

Ok::<(), anyhow::Error>(())
})?;
}
#[cfg(feature = "distributed-locking")]
Resource::DistributedLockingEtcd | Resource::V1DistributedLockingEtcd => {
Expand Down
Loading