Skip to content
This repository has been archived by the owner on Jun 10, 2024. It is now read-only.

Commit

Permalink
Adding support for health check requests to streams and logging provi… (
Browse files Browse the repository at this point in the history
#48)

* Adding support for health check requests to streams and logging providers

* Establishing a link for redis streams is now idempotent
  • Loading branch information
autodidaddict authored Mar 10, 2021
1 parent 4a6342a commit 326a7d0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 20 deletions.
3 changes: 2 additions & 1 deletion logging/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "wasmcloud-logging"
version = "0.9.1"
version = "0.9.2"
authors = ["wasmCloud Team"]
edition = "2018"
homepage = "https://wasmcloud.dev"
Expand All @@ -26,3 +26,4 @@ log = "0.4.14"
env_logger = "0.8.2"
wasmcloud-provider-core = "0.1.0"
wasmcloud-actor-logging = "0.1.0"
wasmcloud-actor-core = "0.2.2"
24 changes: 8 additions & 16 deletions logging/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
// Copyright 2015-2020 Capital One Services, LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use log::{debug, error, info, trace, warn};

use std::error::Error;
Expand All @@ -20,9 +6,11 @@ use wasmcloud_actor_logging::{WriteLogArgs, OP_LOG};
use wasmcloud_provider_core::{
capabilities::{CapabilityProvider, Dispatcher, NullDispatcher},
capability_provider,
core::{OP_BIND_ACTOR, OP_REMOVE_ACTOR},
deserialize,
core::{OP_BIND_ACTOR, OP_HEALTH_REQUEST, OP_REMOVE_ACTOR},
deserialize, serialize,
};
extern crate wasmcloud_actor_core as actor;
use actor::HealthCheckResponse;

#[cfg(not(feature = "static_plugin"))]
capability_provider!(LoggingProvider, LoggingProvider::new);
Expand Down Expand Up @@ -102,6 +90,10 @@ impl CapabilityProvider for LoggingProvider {
match op {
OP_BIND_ACTOR if actor == SYSTEM_ACTOR => Ok(vec![]),
OP_REMOVE_ACTOR if actor == SYSTEM_ACTOR => Ok(vec![]),
OP_HEALTH_REQUEST if actor == SYSTEM_ACTOR => Ok(serialize(HealthCheckResponse {
healthy: true,
message: "".to_string(),
})?),
OP_LOG => self.write_log(actor, deserialize(msg)?),
_ => Err(format!("Unknown operation: {}", op).into()),
}
Expand Down
2 changes: 1 addition & 1 deletion redis-streams/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "wasmcloud-streams-redis"
version = "0.4.0"
version = "0.4.1"
authors = ["wasmCloud Team"]
edition = "2018"
homepage = "https://wasmcloud.dev"
Expand Down
12 changes: 10 additions & 2 deletions redis-streams/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ extern crate log;
use ::redis_streams::{
Client, Connection, ErrorKind, RedisError, RedisResult, StreamCommands, Value,
};
use actor::CapabilityConfiguration;
use codec::core::{OP_BIND_ACTOR, OP_REMOVE_ACTOR};
use actor::{CapabilityConfiguration, HealthCheckResponse};
use codec::core::{OP_BIND_ACTOR, OP_HEALTH_REQUEST, OP_REMOVE_ACTOR};
use codec::{
capabilities::{CapabilityProvider, Dispatcher, NullDispatcher},
core::SYSTEM_ACTOR,
Expand Down Expand Up @@ -65,6 +65,10 @@ impl RedisStreamsProvider {
&self,
config: CapabilityConfiguration,
) -> Result<Vec<u8>, Box<dyn Error + Send + Sync>> {
if self.clients.read().unwrap().contains_key(&config.module) {
return Ok(vec![]);
}

let c = initialize_client(config.clone())?;

self.clients.write().unwrap().insert(config.module, c);
Expand Down Expand Up @@ -173,6 +177,10 @@ impl CapabilityProvider for RedisStreamsProvider {
match op {
OP_BIND_ACTOR if actor == SYSTEM_ACTOR => self.configure(deserialize(msg)?),
OP_REMOVE_ACTOR if actor == SYSTEM_ACTOR => self.deconfigure(actor),
OP_HEALTH_REQUEST if actor == SYSTEM_ACTOR => Ok(serialize(HealthCheckResponse {
healthy: true,
message: "".to_string(),
})?),
OP_WRITE_EVENT => self.write_event(actor, deserialize(msg)?),
OP_QUERY_STREAM => self.query_stream(actor, deserialize(msg)?),
_ => Err("bad dispatch".into()),
Expand Down

0 comments on commit 326a7d0

Please sign in to comment.