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

Simplify Service Discovery by decoupling the service registry from intent brokering #141

Merged
merged 13 commits into from
Jun 29, 2023
88 changes: 86 additions & 2 deletions Cargo.lock

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

10 changes: 8 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
# SPDX-License-Identifier: MIT

[workspace]
members = [
"common",
Expand All @@ -15,10 +19,11 @@ members = [
"examples/common",
"keyvalue",
"proto.rs",
"service_discovery/core",
"service_discovery/samples/simple-discovery/consumer",
"service_discovery/samples/simple-discovery/provider"
]

exclude = []

[package]
name = "chariott"
version = "0.1.0"
Expand Down Expand Up @@ -55,6 +60,7 @@ chariott-common = { path = "./common/" }
chariott-proto = { path = "./proto.rs/" }
futures = { version = "0.3" }
lazy_static = "1.4.0"
parking_lot = "0.12.1"
prost = "0.11"
prost-types = "0.11"
regex = "1.7"
Expand Down
21 changes: 21 additions & 0 deletions service_discovery/core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
# SPDX-License-Identifier: MIT

[package]
ladatz marked this conversation as resolved.
Show resolved Hide resolved
name = "service_discovery"
ladatz marked this conversation as resolved.
Show resolved Hide resolved
version = "0.1.0"
edition = "2021"
license = "MIT"

[dependencies]
parking_lot = { workspace = true }
prost = { workspace = true }
ladatz marked this conversation as resolved.
Show resolved Hide resolved
service_discovery_proto = { path = "../proto_build/"}
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
tonic = { workspace = true }
tracing = { version = "0.1" }
tracing-subscriber = { version = "0.3", features = ["env-filter"] }

[build-dependencies]
tonic-build = { workspace = true }
52 changes: 52 additions & 0 deletions service_discovery/core/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
// SPDX-License-Identifier: MIT

//! Project Eclipse Chariott Service Discovery
//!
//! This is the Service Discovery system for Chariott. It includes a service registry,
//! which is a database of services that are currently registered. Other applications
//! can find the metadata for registered services.

// Tells cargo to warn if a doc comment is missing and should be provided.
#![warn(missing_docs)]

use parking_lot::RwLock;
use service_discovery_proto::service_registry::v1::service_registry_server::ServiceRegistryServer;
use std::collections::HashMap;
use std::net::SocketAddr;
use std::sync::Arc;
use tonic::transport::Server;
use tracing::{debug, info};
use tracing_subscriber::util::SubscriberInitExt;
use tracing_subscriber::EnvFilter;

mod service_registry_impl;

/// Endpoint for the service registry
const SERVICE_REGISTRY_ADDR: &str = "0.0.0.0:50000";

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Set up tracing
let collector = tracing_subscriber::fmt()
.with_env_filter(
EnvFilter::builder()
.with_default_directive(tracing::Level::INFO.into())
.from_env_lossy(),
)
.finish();

collector.init();

// Start up registry service
let addr: SocketAddr = SERVICE_REGISTRY_ADDR.parse()?;
let registry_impl =
service_registry_impl::ServiceRegistryImpl::new(Arc::new(RwLock::new(HashMap::new())));
info!("Service Registry listening on {addr}");

Server::builder().add_service(ServiceRegistryServer::new(registry_impl)).serve(addr).await?;

debug!("The Service Registry has completed.");
Ok(())
}
Loading