Skip to content

Commit

Permalink
Merge pull request #78 from eclipse-ibeji/wilyle/tokio-console
Browse files Browse the repository at this point in the history
`tokio_console` feature, `--log-level` argument, and markdown workflow updates
  • Loading branch information
wilyle authored Nov 27, 2023
2 parents 40a3468 + 6c752f9 commit 79efe56
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 7 deletions.
4 changes: 4 additions & 0 deletions .accepted_words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ CHARIOTT
Chariott
Chariott's
chariott
cfg
com
config
containerized
Expand Down Expand Up @@ -67,6 +68,7 @@ ps
repo
Repo
rm
RUSTFLAGS
rustup
sdk
sdl
Expand All @@ -76,6 +78,8 @@ snapd
standalone
sudo
timothee
tokio
Tokio
toml
Tonic
toolchain
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/markdown-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ on:
- 'docs/**'
- '**.md'
- '**.markdown'
- '.markdownlint.jsonc'
- '.markdownlinkcheck.json'

jobs:
lint-markdown:
Expand All @@ -26,4 +28,4 @@ jobs:
- uses: actions/checkout@v2
- run: |
npm install markdown-link-check
find . -type d \( -name node_modules -o -name .github \) -prune -o -type f -name '*.md' -print0 | xargs -0 -n1 node_modules/.bin/markdown-link-check --config .markdownlinkcheck.jsonc --quiet
find . -type d \( -name node_modules -o -name .github \) -prune -o -type f -name '*.md' -print0 | xargs -0 -n1 node_modules/.bin/markdown-link-check --config .markdownlinkcheck.json --quiet
4 changes: 4 additions & 0 deletions .markdownlinkcheck.jsonc → .markdownlinkcheck.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
"ignorePatterns": [
{
"pattern": "^http://localhost"
},
{
"_patternComment": "Checking aka.ms links is unstable and frequently fails on valid links",
"pattern": "^https://aka.ms"
}
],
"aliveStatusCodes": [
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ serde_json = "^1.0"
strum = "0.25"
strum_macros = "0.25.1"
tokio = "1.29.1"
tokio-console-subscriber = { version = "0.2.0", package = "console-subscriber" }
tokio-stream = "0.1.14"
tonic = "0.10.0"
tonic-build = "0.10.0"
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- [Install MQTT Broker](#install-mqtt-broker)
- [Cloning the Repo](#cloning-the-repo)
- [Building](#building)
- [Tokio Console Support](#tokio-console-support)
- [Running the Tests](#running-the-tests)
- [Running the Samples](#running-the-samples)
- [Property Sample](#property-sample)
Expand Down Expand Up @@ -107,6 +108,16 @@ Once you have installed the prerequisites, go to your enlistment's root director

This should build all of the libraries and executables.

### Tokio Console Support

Ibeji has support for using the [tokio console](https://github.com/tokio-rs/console) for advanced debugging. To enable this support, you need to build with the `tokio_console` feature enabled and with the `tokio_unstable` config flag for the rust compiler:

```bash
RUSTFLAGS="--cfg tokio_unstable" cargo build --features tokio_console
```

Note that the tokio console will intercept trace-level logs, so these will not be visible when debugging with the tokio console.

## <a name="running-the-tests">Running the Tests</a>

After successfully building Ibeji, you can run all of the unit tests. To do this go to the enlistment's root directory and run:
Expand Down
4 changes: 2 additions & 2 deletions core/common/src/grpc_interceptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,13 @@ where
Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send + 'static>>;

/// Implementation of tower's Service trait's poll_ready method.
/// See https://docs.rs/tower/latest/tower/trait.Service.html
/// See <https://docs.rs/tower/latest/tower/trait.Service.html>
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
self.service.poll_ready(cx)
}

/// Implementation of tower's Service trait's call method.
/// See https://docs.rs/tower/latest/tower/trait.Service.html
/// See <https://docs.rs/tower/latest/tower/trait.Service.html>
fn call(
&mut self,
mut request: http::request::Request<tonic::transport::Body>,
Expand Down
4 changes: 3 additions & 1 deletion core/invehicle-digital-twin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ serde_derive = { workspace = true }
serde_json = { workspace = true }
strum = { workspace = true }
strum_macros = { workspace = true }
tokio = { workspace = true , features = ["macros", "rt-multi-thread"] }
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
tokio-console-subscriber = { workspace = true, optional = true }
tonic = { workspace = true }
tower = { workspace = true }
url = { workspace = true }
Expand All @@ -39,3 +40,4 @@ tonic-build = { workspace = true }
[features]
managed_subscribe = ["dep:managed_subscribe"]
containerize = ["common/containerize"]
tokio_console = ["dep:tokio-console-subscriber", "tokio/tracing"]
38 changes: 36 additions & 2 deletions core/invehicle-digital-twin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ use parking_lot::RwLock;
use std::boxed::Box;
use std::collections::HashMap;
use std::convert::Infallible;
use std::env;
use std::net::SocketAddr;
use std::str::FromStr;
use std::sync::Arc;
use tonic::body::BoxBody;
use tonic::transport::{Body, NamedService};
Expand All @@ -37,6 +39,7 @@ use tower::Service;
mod invehicle_digital_twin_config;
mod invehicle_digital_twin_impl;

const DEFAULT_LOG_LEVEL: &str = "info";
const INVEHICLE_DIGITAL_TWIN_SERVICE_NAMESPACE: &str = "sdv.ibeji";
const INVEHICLE_DIGITAL_TWIN_SERVICE_NAME: &str = "invehicle_digital_twin";
const INVEHICLE_DIGITAL_TWIN_SERVICE_VERSION: &str = "1.0";
Expand Down Expand Up @@ -136,8 +139,39 @@ where

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Setup logging.
Builder::new().filter(None, LevelFilter::Info).target(Target::Stdout).init();
let args: HashMap<String, Option<String>> = env::args()
.skip(1)
.map(|arg| {
let mut split = arg.split('=');
let key = split.next().expect("Couldn't parse argument key").to_owned();
let val = split.next().map(|v| v.to_owned());

if split.next().is_some() {
panic!("Too many pieces in argument");
}

(key, val)
})
.collect();

debug!("args: {args:?}");

// Setup logging
let log_level_arg = args
.get("--log-level")
.cloned()
.unwrap_or(Some(DEFAULT_LOG_LEVEL.to_owned()))
.expect("No log-level value provided");
let log_level =
LevelFilter::from_str(log_level_arg.as_str()).expect("Could not parse log level");
Builder::new().filter(None, log_level).target(Target::Stdout).init();

#[cfg(feature = "tokio_console")]
{
// enable tracing for tokio console
info!("Tokio console tracing is enabled");
tokio_console_subscriber::init();
}

info!("The In-Vehicle Digital Twin Service has started.");

Expand Down
2 changes: 1 addition & 1 deletion samples/common/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub mod chariott {
}

/// Media/MIME types.
/// Common MIME types can be found here: https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
/// Common MIME types can be found here: <https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types>
pub mod mime_type {
pub const JPEG_IMAGES: &str = "image/jpeg";
}
Expand Down

0 comments on commit 79efe56

Please sign in to comment.