Skip to content

Commit

Permalink
add readme + remove noisy log
Browse files Browse the repository at this point in the history
  • Loading branch information
johnjmartin committed Jan 6, 2025
1 parent bbc432b commit 5b42cca
Show file tree
Hide file tree
Showing 2 changed files with 173 additions and 2 deletions.
171 changes: 171 additions & 0 deletions crates/sui-edge-proxy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
# Sui Edge Proxy

The Sui Edge Proxy is a simple proxy service that routes read and execution requests to different fullnode endpoints based on configuration. The purpose is to provide a single entrypoint for all RPC requests, and maintain a consistent connection to the read and execution fullnodes, ensuring the fastest possible client experience for RPC requests.

## Deployment

At the time of writing, the Sui Edge Proxy is best run as a Kubernetes Deployment. The following guide will walk you through deploying the `sui-edge-proxy` in k8s.

## Guide to Deploying `sui-edge-proxy` in Kubernetes

This guide will walk you through deploying the `sui-edge-proxy` Rust service on a Kubernetes cluster using a deployment configuration and an accompanying service.

### Prerequisites

- Ensure you have `kubectl` installed and configured to connect to your Kubernetes cluster.
- Have `sui-edge-proxy.yaml`, `benchmark-svc.yaml`, and the ConfigMap `sui-edge-proxy-config` prepared.

### Overview of Components

1. **Deployment**: Defines the `sui-edge-proxy` service deployment in Kubernetes.
2. **Service**: Exposes the `sui-edge-proxy` service to other services within the cluster.
3. **ConfigMap**: Provides configuration details for `sui-edge-proxy`.

### Step 1: Set Up the ConfigMap

The ConfigMap provides runtime configurations for `sui-edge-proxy`.

#### `sui-edge-proxy-config.yaml`

```yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: sui-edge-proxy-config
namespace: benchmark-rpc-testnet
data:
proxy.yaml: |
---
listen-address: "0.0.0.0:8080"
metrics-address: "0.0.0.0:9184"
execution-peer:
# Fullnode address for executing requests, this is created by a ServiceExport resource, available in gke fleet clusters:
# https://cloud.google.com/kubernetes-engine/docs/how-to/multi-cluster-services#registering_a_service_for_export
address: "http://euw2-testnet-benchmark-service.benchmark-rpc-testnet.svc.clusterset.local:9000"
read-peer:
# K8s service address for routing read traffic
address: "http://sui-node-benchmark.benchmark-rpc-testnet.svc.cluster.local:9000"
```
Apply the ConfigMap:
```bash
kubectl apply -f sui-edge-proxy-config.yaml
```

### Step 2: Deploy `sui-edge-proxy` Deployment

The deployment configuration runs a single instance of `sui-edge-proxy` and mounts the configuration from the ConfigMap.

#### `sui-edge-proxy.yaml`

```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: sui-edge-proxy
namespace: benchmark-rpc-testnet
labels:
app: sui-edge-proxy
cluster: sui-fleet-usw1
network: testnet
spec:
replicas: 1
selector:
matchLabels:
app: sui-edge-proxy
template:
metadata:
labels:
app: sui-edge-proxy
annotations:
prometheus.io/path: /metrics
prometheus.io/port: '9184'
prometheus.io/scrape: 'true'
spec:
containers:
- name: sui-edge-proxy
image: mysten/sui-tools:mainnet
imagePullPolicy: IfNotPresent
command:
- /opt/sui/bin/sui-edge-proxy
- --config=/config/proxy.yaml
env:
- name: RUST_LOG
value: debug
ports:
- containerPort: 8080
protocol: TCP
volumeMounts:
- name: config-volume
mountPath: /config
volumes:
- name: config-volume
configMap:
name: sui-edge-proxy-config
```
Apply the deployment:
```bash
kubectl apply -f sui-edge-proxy.yaml
```

### Step 3: Create the Service

The Service routes traffic to the `sui-edge-proxy` deployment. It uses `ClientIP` session affinity to maintain connection consistency for each client.

#### `benchmark-svc.yaml`

```yaml
apiVersion: v1
kind: Service
metadata:
name: sui-node-benchmark
namespace: benchmark-rpc-testnet
annotations:
cloud.google.com/neg: '{"ingress":true}'
spec:
type: ClusterIP
selector:
app: sui-node-benchmark
ports:
- port: 9000
targetPort: 9000
protocol: TCP
sessionAffinity: ClientIP
sessionAffinityConfig:
clientIP:
timeoutSeconds: 10800
```
Apply the service:
```bash
kubectl apply -f benchmark-svc.yaml
```

### Step 4: Verify Deployment and Service

After applying all the configurations, check the deployment and service status:

```bash
kubectl get deployments -n benchmark-rpc-testnet
kubectl get services -n benchmark-rpc-testnet
```

Confirm that the `sui-edge-proxy` pod is running:

```bash
kubectl get pods -n benchmark-rpc-testnet -l app=sui-edge-proxy
```

### Summary

Now that this has been deployed, ingress traffic can be pointed at the edge-proxy pods instead of the fullnode pods directly.

## Troubleshooting / Debugging

If you find any issues with the Sui Edge Proxy or would like to request a feature, please open an issue in the [sui repository](https://github.com/MystenLabs/sui/issues/new).
4 changes: 2 additions & 2 deletions crates/sui-edge-proxy/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use axum::{
};
use bytes::Bytes;
use std::time::Instant;
use tracing::{debug, info, warn};
use tracing::{debug, warn};

#[derive(Debug)]
enum PeerRole {
Expand Down Expand Up @@ -75,7 +75,7 @@ pub async fn proxy_handler(
.and_then(|h| h.to_str().ok())
{
Some("sui_executeTransactionBlock") => {
info!("Using execution peer");
debug!("Using execution peer");
proxy_request(state, parts, body_bytes, PeerRole::Execution).await
}
_ => {
Expand Down

0 comments on commit 5b42cca

Please sign in to comment.