Skip to content

Commit

Permalink
Cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
ladatz committed Jan 24, 2024
1 parent be51ac7 commit fc636af
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use tracing::error;
use crate::detection::DetectionLogic;

use examples_common::{
intent_brokering::inspection::{fulfill, Entry},
examples::detection::DetectRequest,
intent_brokering::inspection::{fulfill, Entry},
};

pub struct IntentProvider {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
use anyhow::{anyhow, Error};
use async_stream::try_stream;
use examples_common::{
examples::proto::detection::{DetectRequest, DetectResponse},
intent_brokering::{
api::{IntentBrokering, IntentBrokeringExt as _, GrpcIntentBrokering},
api::{GrpcIntentBrokering, IntentBrokering, IntentBrokeringExt as _},
value::Value,
},
examples::proto::detection::{DetectRequest, DetectResponse},
};
use futures::{stream::BoxStream, TryStreamExt};
use intent_brokering_proto::common::Blob;
Expand Down Expand Up @@ -101,7 +101,10 @@ async fn detect_dog(
}
};

async fn image_contains_dog(intent_broker: &mut impl IntentBrokering, image: Value) -> Result<bool, Error> {
async fn image_contains_dog(
intent_broker: &mut impl IntentBrokering,
image: Value,
) -> Result<bool, Error> {
use prost::Message;

let (media_type, bytes) = image
Expand Down
15 changes: 10 additions & 5 deletions intent_brokering/examples/applications/dog-mode-logic/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::{
use anyhow::{anyhow, Error};
use dog_mode_status::stream_dog_mode_status;
use examples_common::intent_brokering::{
api::{IntentBrokering, IntentBrokeringExt as _, GrpcIntentBrokering},
api::{GrpcIntentBrokering, IntentBrokering, IntentBrokeringExt as _},
value::Value,
};
use tokio::{select, time::sleep_until};
Expand Down Expand Up @@ -165,7 +165,8 @@ pub async fn main() -> Result<(), Error> {
)
.await?;

let mut dog_mode_status_stream = stream_dog_mode_status(intent_broker.clone(), &mut state).await?;
let mut dog_mode_status_stream =
stream_dog_mode_status(intent_broker.clone(), &mut state).await?;

let mut next_timer_wakeup = Instant::now() + TIMEOUT_EVALUATION_INTERVAL;

Expand Down Expand Up @@ -313,15 +314,19 @@ async fn run_dog_mode(
// If the battery level fell below a threshold value, send a warning to the car owner.
if previous_state.battery_level > LOW_BATTERY_LEVEL && state.battery_level <= LOW_BATTERY_LEVEL
{
send_notification(intent_broker, "The battery is low, please return to the car.", state).await?;
set_ui_message(intent_broker, "The battery is low, the animal is in danger.", state).await?;
send_notification(intent_broker, "The battery is low, please return to the car.", state)
.await?;
set_ui_message(intent_broker, "The battery is low, the animal is in danger.", state)
.await?;
}

async fn activate_air_conditioning(
intent_broker: &mut impl IntentBrokering,
value: bool,
) -> Result<(), Error> {
_ = intent_broker.invoke(VDT_NAMESPACE, ACTIVATE_AIR_CONDITIONING_ID, [value.into()]).await?;
_ = intent_broker
.invoke(VDT_NAMESPACE, ACTIVATE_AIR_CONDITIONING_ID, [value.into()])
.await?;
Ok(())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use tracing::error;
use crate::detection::DetectionLogic;

use examples_common::{
intent_brokering::inspection::{fulfill, Entry},
examples::detection::DetectRequest,
intent_brokering::inspection::{fulfill, Entry},
};

pub struct IntentProvider {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use bollard::{container::StatsOptions, Docker};
use examples_common::intent_brokering::{
self,
api::{IntentBrokering, GrpcIntentBrokering},
api::{GrpcIntentBrokering, IntentBrokering},
value::Value,
};
use futures_util::stream::StreamExt;
Expand Down Expand Up @@ -109,7 +109,8 @@ async fn wain() -> Result<(), Error> {

// Only the namespace matters when invoking. The load testing
// provider will not take action based on payload or command.
let sent_value = intent_broker.invoke(LT_PROVIDER_NAMESPACE, "foo", [Value::NULL]).await;
let sent_value =
intent_broker.invoke(LT_PROVIDER_NAMESPACE, "foo", [Value::NULL]).await;

if let Some(request_instant) = now {
let latency = request_instant.elapsed().as_millis() as _;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ async fn connect_intent_brokering_client(
client: &mut Option<IntentBrokeringServiceClient<Channel>>,
intent_brokering_url: String,
) -> Result<(), Error> {
*client = Some(IntentBrokeringServiceClient::connect(intent_brokering_url).await.map_err(|e| {
*client = None; // Set client back to None on error.
Error::from_error("Could not connect to client", Box::new(e))
})?);
*client =
Some(IntentBrokeringServiceClient::connect(intent_brokering_url).await.map_err(|e| {
*client = None; // Set client back to None on error.
Error::from_error("Could not connect to client", Box::new(e))
})?);

Ok(())
}
Expand Down Expand Up @@ -99,7 +100,9 @@ async fn register_and_announce_once(
.expect("No client found")
.register(register_req.clone())
.await
.map_err(|e| Error::from_error("Error registering with IntentBrokering.", Box::new(e)))?;
.map_err(|e| {
Error::from_error("Error registering with IntentBrokering.", Box::new(e))
})?;
}

Ok(())
Expand Down
4 changes: 2 additions & 2 deletions intent_brokering/examples/common/src/intent_brokering/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ pub struct GrpcIntentBrokering {

impl GrpcIntentBrokering {
pub async fn connect() -> Result<Self, Error> {
let intent_brokering_url =
env::var(INTENT_BROKER_URL_KEY).unwrap_or_else(|_| DEFAULT_INTENT_BROKER_URL.to_string());
let intent_brokering_url = env::var(INTENT_BROKER_URL_KEY)
.unwrap_or_else(|_| DEFAULT_INTENT_BROKER_URL.to_string());
let client = IntentBrokeringServiceClient::connect(intent_brokering_url)
.await
.map_err_with("Connecting to IntentBrokering failed.")?;
Expand Down
2 changes: 1 addition & 1 deletion intent_brokering/examples/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
// Licensed under the MIT license.
// SPDX-License-Identifier: MIT

pub mod intent_brokering;
pub mod examples;
pub mod intent_brokering;
pub mod url;
2 changes: 1 addition & 1 deletion intent_brokering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// Licensed under the MIT license.
// SPDX-License-Identifier: MIT

pub mod intent_brokering_grpc;
mod connection_provider;
mod execution;
mod intent_broker;
pub mod intent_brokering_grpc;
pub use intent_broker::IntentBroker;
pub mod registry;
pub mod streaming;
4 changes: 3 additions & 1 deletion intent_brokering/tests/chariott_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ use intent_brokering::registry::{
ExecutionLocality, IntentConfiguration, IntentKind, ServiceConfiguration, ServiceId,
};
use intent_brokering::streaming::StreamingEss;
use intent_brokering::{intent_brokering_grpc::IntentBrokeringServer, registry::Registry, IntentBroker};
use intent_brokering::{
intent_brokering_grpc::IntentBrokeringServer, registry::Registry, IntentBroker,
};
use intent_brokering_common::error::{Error, ResultExt as _};
use intent_brokering_common::shutdown::RouterExt as _;
use intent_brokering_proto::{
Expand Down
5 changes: 3 additions & 2 deletions intent_brokering/tests/registry-e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::time::Duration;

use common::get_uuid;
use examples_common::intent_brokering::{
api::{IntentBrokering, IntentBrokeringExt as _, GrpcIntentBrokering},
api::{GrpcIntentBrokering, IntentBrokering, IntentBrokeringExt as _},
registration::Builder as RegistrationBuilder,
};
use intent_brokering_proto::runtime::{
Expand Down Expand Up @@ -37,7 +37,8 @@ async fn expired_registrations_are_pruned_after_ttl() -> Result<(), anyhow::Erro
builder.register_once(&mut None, true).await?;

let initial_entries = intent_broker.inspect("system.registry", namespace.clone()).await?;
let ttl = Duration::from_secs(env!("INTENT_BROKERING_REGISTRY_TTL_SECS").parse::<u64>().unwrap() + 1);
let ttl =
Duration::from_secs(env!("INTENT_BROKERING_REGISTRY_TTL_SECS").parse::<u64>().unwrap() + 1);
sleep(ttl).await;
let entries = intent_broker.inspect("system.registry", namespace).await?;

Expand Down
2 changes: 1 addition & 1 deletion intent_brokering/tests/store-e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{collections::HashSet, error::Error as _, time::Duration};

use common::get_uuid;
use examples_common::intent_brokering::{
api::{IntentBrokering, IntentBrokeringExt, Event, GrpcIntentBrokering},
api::{Event, GrpcIntentBrokering, IntentBrokering, IntentBrokeringExt},
value::Value,
};
use intent_brokering_common::error::Error;
Expand Down

1 comment on commit fc636af

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ESS Benchmark

Benchmark suite Current: fc636af Previous: 5886244 Ratio
ess/1-subscribers/1000-events 192501 ns/iter (± 8778) 188873 ns/iter (± 6213) 1.02
ess/10-subscribers/1000-events 1356500 ns/iter (± 42346) 1368890 ns/iter (± 32371) 0.99
ess/100-subscribers/1000-events 13112445 ns/iter (± 774203) 13413472 ns/iter (± 574355) 0.98
ess/1-subscribers/10000-events 1780174 ns/iter (± 27603) 1712373 ns/iter (± 59392) 1.04
ess/10-subscribers/10000-events 13375476 ns/iter (± 39713) 13528032 ns/iter (± 51857) 0.99
ess/100-subscribers/10000-events 130129917 ns/iter (± 762198) 131653141 ns/iter (± 461857) 0.99

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.