Skip to content

Commit

Permalink
Add conditional compilation of kafka_egress in edgeless_node
Browse files Browse the repository at this point in the history
  • Loading branch information
ccicconetti committed Oct 14, 2024
1 parent 8c186e7 commit 85e1f87
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 22 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ below.
| `file-log` | Save log lines to a node-local file | file_log_provider | filename, add-timestamp | [click](examples/file_log/README.md) |
| `http-egress` | Execute HTTP commands on external web servers | http_egress_provider | | [click](examples/http_egress/README.md) |
| `http-ingress` | Ingest HTTP commands from external web clients | http_ingress_provider, http_ingress_url | host, methods | [click](examples/http_ingress/README.md) |
| `kafka-egress` | Send a message to an external [Apache Kafka](https://kafka.apache.org/) server | kafka_egress_provider | brokers, topic | [click](examples/kafka_egress/README.md) |
| `kafka-egress` | Send a message to an external [Apache Kafka](https://kafka.apache.org/) server | kafka_egress_provider (requires `rdkafka` feature) | brokers, topic | [click](examples/kafka_egress/README.md) |
| `ollama` | Interact via an LLM ChatBot deployed on an external [ollama](https://ollama.com/) server | host, port, messages_number_limit, provider (separate section) | model | [click](examples/ollama/README.md) |
| `redis` | Update a value on an external [Redis](https://redis.io/) server | redis_provider | url, key | [click](examples/redis/README.md) |

Expand Down
2 changes: 1 addition & 1 deletion edgeless_node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ base64 = "0.22.1"
rs-docker = "0.0.58"
chrono = "0.4.38"
ollama-rs = { version = "0.2.0", features = ["chat-history"] }
rdkafka = "0.36.2"
rdkafka = { version = "0.36.2", optional = true }
dda = { path = "../dda" }

[build-dependencies]
Expand Down
45 changes: 25 additions & 20 deletions edgeless_node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,26 +425,31 @@ async fn fill_resources(

if let Some(provider_id) = &settings.kafka_egress_provider {
if !provider_id.is_empty() {
log::info!("Creating resource '{}'", provider_id);
let class_type = "kafka-egress".to_string();
ret.insert(
provider_id.clone(),
agent::ResourceDesc {
class_type: class_type.clone(),
client: Box::new(
resources::kafka_egress::KafkaEgressResourceProvider::new(
data_plane.clone(),
edgeless_api::function_instance::InstanceId::new(node_id),
)
.await,
),
},
);
provider_specifications.push(edgeless_api::node_registration::ResourceProviderSpecification {
provider_id: provider_id.clone(),
class_type,
outputs: vec![],
});
#[cfg(feature = "rdkafka")]
{
log::info!("Creating resource '{}'", provider_id);
let class_type = "kafka-egress".to_string();
ret.insert(
provider_id.clone(),
agent::ResourceDesc {
class_type: class_type.clone(),
client: Box::new(
resources::kafka_egress::KafkaEgressResourceProvider::new(
data_plane.clone(),
edgeless_api::function_instance::InstanceId::new(node_id),
)
.await,
),
},
);
provider_specifications.push(edgeless_api::node_registration::ResourceProviderSpecification {
provider_id: provider_id.clone(),
class_type,
outputs: vec![],
});
}
#[cfg(not(feature = "rdkafka"))]
log::error!("Could not create resource '{}' because rdkafka was disabled at compile time", provider_id);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions edgeless_node/src/resources/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub mod dda;
pub mod file_log;
pub mod http_egress;
pub mod http_ingress;
#[cfg(feature = "rdkafka")]
pub mod kafka_egress;
pub mod metrics_collector;
pub mod ollama;
Expand Down
11 changes: 11 additions & 0 deletions examples/kafka_egress/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
### Kafka-egress example

#### Requirements

Deploying a node with a `kafka_egress` resource provider requires
the `rdkafka` feature at compile time, e.g.:

```shell
cargo build --features rdkafka
```

#### Example

The example creates a function that periodically updates a counter on the
topic `test` of an [Apache Kafka server](https://kafka.apache.org/).

Expand Down

0 comments on commit 85e1f87

Please sign in to comment.