Skip to content

Commit

Permalink
chore(prover-service): setup metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
oyyblin committed Nov 23, 2024
1 parent 65cfc8e commit fee0d3f
Show file tree
Hide file tree
Showing 7 changed files with 319 additions and 62 deletions.
5 changes: 5 additions & 0 deletions charts/prover-service/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ spec:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- containerPort: 9090
name: grpc
- containerPort: 4014
name: http-prometheus
envFrom:
- secretRef:
name: {{ if .Values.useExistingSecrets }}{{ .Values.existingSecretName }}{{ else }}{{ include "service.fullname" . }}{{ end }}
Expand Down
17 changes: 17 additions & 0 deletions charts/prover-service/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: v1
kind: Service
metadata:
name: {{include "service.fullname" .}}
labels: {{- include "service.labels" . | nindent 4}}
spec:
type: ClusterIP
ports:
- port: 9090
targetPort: grpc
protocol: TCP
name: grpc
- port: 4014
targetPort: http-prometheus
protocol: TCP
name: http-prometheus
selector: {{- include "service.selectorLabels" . | nindent 4}}
171 changes: 171 additions & 0 deletions prover-service/Cargo.lock

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

3 changes: 3 additions & 0 deletions prover-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ clap = { version = "4.5", features = ["derive"] }
hex = "0.4.3"
log = "0.4.22"
env_logger = "0.11"
prometheus = "0.13"
lazy_static = "1.4"
warp = "0.3"

[build-dependencies]
tonic-build = "0.10"
2 changes: 1 addition & 1 deletion prover-service/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ RUN apt-get update && apt-get install -y libssl3 ca-certificates
COPY --from=builder /usr/src/app/target/release/server /usr/local/bin/server
COPY --from=builder /usr/src/app/elf/riscv32im-succinct-zkvm-elf /usr/local/bin/elf/

EXPOSE 9090
EXPOSE 9090 4014

CMD ["server", "--elf-path", "/usr/local/bin/elf/riscv32im-succinct-zkvm-elf"]
23 changes: 23 additions & 0 deletions prover-service/src/bin/server.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use clap::Parser;
use prover_service::proto::prover::prover_service_server::ProverServiceServer;
use prover_service::service::ProverServiceImpl;
use std::net::SocketAddr;
use tonic::transport::Server;
use tonic_health::server::health_reporter;
use warp::Filter;

#[derive(Parser)]
#[command(
Expand Down Expand Up @@ -32,6 +34,10 @@ struct Args {
/// Timeout for waiting for the proof in seconds
#[arg(long, default_value = "300", env = "TIMEOUT_SECS")]
timeout_secs: u64,

/// Port number for Prometheus metrics
#[arg(long, default_value = "4014", env = "METRICS_PORT")]
metrics_port: u16,
}

#[tokio::main]
Expand All @@ -53,6 +59,23 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.set_serving::<ProverServiceServer<ProverServiceImpl>>()
.await;

// Start Prometheus metrics endpoint
let metrics_addr = format!("0.0.0.0:{}", args.metrics_port);
let metrics_route = warp::path!("metrics").and_then(|| async {
use prometheus::Encoder;
let encoder = prometheus::TextEncoder::new();
let mut buffer = Vec::new();
encoder.encode(&prometheus::gather(), &mut buffer).unwrap();
Ok::<_, warp::Rejection>(String::from_utf8(buffer).unwrap())
});

tokio::spawn(async move {
log::info!("Prometheus metrics server listening on {}", metrics_addr);
warp::serve(metrics_route)
.run(metrics_addr.parse::<SocketAddr>().unwrap())
.await;
});

// Serve requests
log::info!("Health Server and GRPC Prover Server listening on {}", addr);
Server::builder()
Expand Down
Loading

0 comments on commit fee0d3f

Please sign in to comment.