Skip to content

Commit

Permalink
Build a container for peer (#122)
Browse files Browse the repository at this point in the history
This also include changes to add tracker metrics
  • Loading branch information
muhamadazmy authored Feb 27, 2023
1 parent a121c9d commit ce6a7de
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 13 deletions.
50 changes: 37 additions & 13 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ name: Create Release

env:
REGISTRY: ghcr.io
IMAGE_NAME: threefoldtech/rmb-relay
IMAGE_NAME_RELAY: threefoldtech/rmb-relay
IMAGE_NAME_PEER: threefoldtech/rmb-peer

jobs:
build:
Expand All @@ -33,38 +34,61 @@ jobs:
name: Build release
with:
command: build
args: --release --target=x86_64-unknown-linux-musl
# remove the tracker feature
# later again, this should be
# only in development
args: |
--release
--target=x86_64-unknown-linux-musl
--features tracker
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: |
target/x86_64-unknown-linux-musl/release/rmb-relay
target/x86_64-unknown-linux-musl/release/rmb-peer
- name: Log in to the Container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
- name: Extract metadata (tags, labels) for relay Docker
id: meta_relay
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_RELAY }}

- name: Copy build files for rmb-relay
- name: Extract metadata (tags, labels) for peer Docker
id: meta_peer
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_PEER }}

- name: Copy build files for docker
run: |
mkdir -p /tmp/build
cp ./build/Dockerfile /tmp/build
cp ./target/x86_64-unknown-linux-musl/release/rmb-relay /tmp/build
mkdir -p /tmp/relay /tmp/peer
cp ./build/relay/Dockerfile /tmp/relay
cp ./target/x86_64-unknown-linux-musl/release/rmb-relay /tmp/relay
cp ./build/peer/Dockerfile /tmp/peer
cp ./target/x86_64-unknown-linux-musl/release/rmb-peer /tmp/peer
- name: Build and push Docker image for rmb-relay
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: /tmp/build
context: /tmp/relay
push: true
tags: ${{ steps.meta_relay.outputs.tags }}
labels: ${{ steps.meta_relay.outputs.labels }}

- name: Build and push Docker image for rmb-peer
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: /tmp/peer
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
tags: ${{ steps.meta_peer.outputs.tags }}
labels: ${{ steps.meta_peer.outputs.labels }}
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,6 @@ protobuf-codegen = "3.2.0"

[dev-dependencies]
httpmock = "0.6"

[features]
tracker = []
4 changes: 4 additions & 0 deletions build/peer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM alpine

COPY rmb-peer /usr/sbin
ENTRYPOINT [ "/usr/sbin/rmb-peer" ]
File renamed without changes.
3 changes: 3 additions & 0 deletions src/relay/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,9 @@ impl<M: Metrics> Stream<M> {
let envelope =
Envelope::parse_from_bytes(&msg).context("failed to load input message")?;

#[cfg(feature = "tracker")]
super::switch::MESSAGE_RX_TWIN.with_label_values(&[&format!("{}", envelope.source.twin)]).inc();

if !self.metrics.measure(msg.len()).await {
log::trace!("twin with stream id {} exceeded its request limits, dropping message", self.id);
self.send_error(envelope, "exceeded rate limits, dropping message").await;
Expand Down
13 changes: 13 additions & 0 deletions src/relay/switch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,15 @@ use tokio::time::{sleep, Duration};

use prometheus::{IntCounter, IntGaugeVec, Opts, Registry};

#[cfg(feature = "tracker")]
use prometheus::IntCounterVec;

lazy_static::lazy_static! {
static ref CON_PER_WORKER: IntGaugeVec = IntGaugeVec::new(
Opts::new("relay_worker_connections", "number of connections handled by this worker"),
&["worker"]).unwrap();


static ref MESSAGE_RX: IntCounter = IntCounter::new("relay_message_rx", "number of messages received by relay").unwrap();

static ref MESSAGE_TX: IntCounter = IntCounter::new("relay_message_tx", "number of messages forwarded by relay").unwrap();
Expand All @@ -43,6 +47,13 @@ lazy_static::lazy_static! {
static ref MESSAGE_TX_BYTES: IntCounter = IntCounter::new("relay_message_tx_bytes", "size of messages forwarded by relay in bytes").unwrap();
}

#[cfg(feature = "tracker")]
lazy_static::lazy_static! {
pub static ref MESSAGE_RX_TWIN: IntCounterVec = IntCounterVec::new(
Opts::new("relay_message_rx_twin", "number of messages received by relay per twin"),
&["twin"]).unwrap();

}
pub const DEFAULT_WORKERS: u32 = 100;
pub const DEFAULT_USERS: usize = 100_1000;

Expand Down Expand Up @@ -220,6 +231,8 @@ where
opts.registry.register(Box::new(MESSAGE_TX.clone()))?;
opts.registry.register(Box::new(MESSAGE_RX_BYTES.clone()))?;
opts.registry.register(Box::new(MESSAGE_TX_BYTES.clone()))?;
#[cfg(feature = "tracker")]
opts.registry.register(Box::new(MESSAGE_RX_TWIN.clone()))?;

for id in 0..workers {
// TODO: while workers are mostly ideal may be it's better in the
Expand Down

0 comments on commit ce6a7de

Please sign in to comment.