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

feat: add env vars for proxy configurations #1120

Open
wants to merge 17 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Renamed the protobuf file of the transaction prover to `tx_prover.proto` (#1110).
- [BREAKING] Renamed `AccountData` to `AccountFile` (#1116).
- Implement transaction batch prover in Rust (#1112).
- Refactored config file for `miden-proving-service` to be based on environment variables (#1120).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I think this might have to be [BREAKING]


## 0.7.2 (2025-01-28) - `miden-objects` crate only

Expand Down
82 changes: 0 additions & 82 deletions Cargo.lock

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

13 changes: 13 additions & 0 deletions bin/proving-service/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
MPS_HOST="0.0.0.0"
MPS_PORT="8082"
MPS_WORKERS_UPDATE_PORT="8083"
MPS_TIMEOUT_SECS="100"
MPS_CONNECTION_TIMEOUT_SECS="10"
MPS_MAX_QUEUE_ITEMS="10"
MPS_MAX_RETRIES_PER_REQUEST="1"
MPS_MAX_REQ_PER_SEC="5"
MPS_AVAILABLE_WORKERS_POLLING_TIME_MS="20"
MPS_HEALTH_CHECK_INTERVAL_SECS="1"
MPS_PROMETHEUS_HOST="127.0.0.1"
MPS_PROMETHEUS_PORT="6192"
RUST_LOG="info"
4 changes: 1 addition & 3 deletions bin/proving-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ concurrent = ["miden-tx/concurrent"]
async-trait = "0.1"
axum = { version = "0.7" }
bytes = "1.0"
clap = { version = "4.5", features = ["derive"] }
figment = { version = "0.10", features = ["toml", "env"] }
clap = { version = "4.5", features = ["derive", "env"] }
miden-lib = { workspace = true, default-features = false }
miden-objects = { workspace = true, default-features = false, features = ["std"] }
miden-tx = { workspace = true, default-features = false, features = ["std"] }
Expand All @@ -43,7 +42,6 @@ serde = { version = "1.0", features = ["derive"] }
serde_qs = { version = "0.13" }
tokio = { version = "1.38", features = ["full"] }
tokio-stream = { version = "0.1", features = [ "net" ]}
toml = { version = "0.8" }
thiserror = { workspace = true }
tonic = { version = "0.12", default-features = false, features = ["codegen", "prost", "transport"] }
tonic-health = { version = "0.12" }
Expand Down
43 changes: 10 additions & 33 deletions bin/proving-service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,48 +28,25 @@ This will spawn a worker using the hosts and ports defined in the command option

## Proxy

First, you need to create a configuration file for the proxy with:
To start the proxy service, you will need to run:

```bash
miden-proving-service init
```

This will create the `miden-proving-service.toml` file in your current directory. This file will hold the configuration for the proxy. You can modify the configuration by changing the host and ports of the services, the maximum size of the queue, among other options. An example configuration is:

```toml
# Host of the proxy server
host = "0.0.0.0"
# Port of the proxy server
port = 8082
# Timeout for a new request to be completed
timeout_secs = 100
# Timeout for establishing a connection to the worker
connection_timeout_secs = 10
# Maximum amount of items that a queue can handle
max_queue_items = 10
# Maximum amount of retries that a request can take
max_retries_per_request = 1
# Maximum amount of requests that a given IP address can make per second
max_req_per_sec = 5
# Time to wait before checking the availability of workers
available_workers_polling_time_ms = 20
# Interval to check the health of the workers
health_check_interval_secs = 1
# Host of the metrics server
prometheus_host = "127.0.0.1"
# Port of the metrics server
prometheus_port = 6192
miden-proving-service start-proxy [worker1] [worker2] ... [workerN]
```

Then, to start the proxy service, you will need to run:
For example:

```bash
miden-proving-service start-proxy [worker1] [worker2] ... [workerN]
miden-proving-service start-proxy 0.0.0.0:8084 0.0.0.0:8085
```

This command will start the proxy using the workers passed as arguments. The workers should be in the format `host:port`. If no workers are passed, the proxy will start without any workers and will not be able to handle any requests until one is added through the `miden-proving-service add-worker` command.

At the moment, when a worker added to the proxy stops working and can not connect to it for a request, the connection is marked as retriable meaning that the proxy will try reaching another worker. The number of retries is configurable via the `max_retries_per_request` value in the configuration file.
You can customize the proxy service by setting environment variables. Possible customizations can be found by running `miden-proving-service start-proxy --help`.

An example `.env` file is provided in the crate's root directory. To use the variables from a file, in any `Unix-like` operating systems, you can run `source <your-file>`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: missing period at the end of the paragraph.

Also, I would probably remove backticks from around "Unix-like". The last sentence could read: "To use the variables from a file in any Unix-like operating system, you can run source <your-file>.


At the moment, when a worker added to the proxy stops working and can not connect to it for a request, the connection is marked as retriable meaning that the proxy will try reaching another worker. The number of retries is configurable via the `MPS_MAX_RETRIES_PER_REQUEST` environmental variable.

## Updating workers on a running proxy

Expand Down Expand Up @@ -120,7 +97,7 @@ If Docker is not an option, Jaeger can also be set up directly on your machine o

## Metrics

The proxy includes a service that exposes metrics to be consumed by [Prometheus](https://prometheus.io/docs/introduction/overview/). This service is always enabled and uses the host and port defined in the `miden-proving-service.toml` file.
The proxy includes a service that exposes metrics to be consumed by [Prometheus](https://prometheus.io/docs/introduction/overview/). This service is always enabled and uses the host and port defined in the `.env` file through the `MPS_PROMETHEUS_HOST` and `MPS_PROMETHEUS_PORT` variables.

The metrics architecture works by having the proxy expose metrics at an endpoint (`/metrics`) in a format Prometheus can read. Prometheus periodically scrapes this endpoint, adds timestamps to the metrics, and stores them in its time-series database. Then, we can use tools like Grafana to query Prometheus and visualize these metrics in configurable dashboards.

Expand Down
48 changes: 0 additions & 48 deletions bin/proving-service/src/commands/init.rs

This file was deleted.

Loading
Loading