Skip to content

Configuration

Requirements: Dapr 1.18+ with mTLS enabled. .NET 11.0 SDK.

Virtufin.API supports configuration via environment variables and command-line arguments. Both methods are supported with consistent behavior across all Virtufin projects.

Precedence

Configuration is loaded in the following order:

  1. Environment variables (loaded first)
  2. Command-line arguments (loaded second)

Command-line arguments take precedence over environment variables.

Configuration Keys

Port Configuration

Key Description Default
HttpPort HTTP port (the health checks only) 5001
GrpcPort gRPC port (native gRPC HTTP/2 h2c) 5002
DaprHttpPort Dapr HTTP port 3500
DaprGrpcPort Dapr gRPC port 50001

Environment Variables

Set configuration using environment variables:

export HttpPort=5001
export GrpcPort=5002
export DaprHttpPort=3500
export DaprGrpcPort=50001
export GATEWAY_RETRY_ATTEMPTS=3
export GATEWAY_RETRY_BASE_DELAY_MS=200
export GATEWAY_CIRCUIT_BREAKER_THRESHOLD=5
export GATEWAY_CIRCUIT_BREAKER_DURATION_SECONDS=30

Dapr Resiliency

The GatewayResiliencePipeline wraps every Dapr SDK call the API makes, including the Gateway.Invoke and Gateway.InvokeJson gRPC calls to downstream services (WorkManager). The pipeline uses Polly: retry with exponential backoff, then circuit breaker. The circuit state is exposed at /health (tag dapr).

Key Description Default Range
GATEWAY_RETRY_ATTEMPTS Max retry attempts per Dapr call before the pipeline throws. 3 0–20
GATEWAY_RETRY_BASE_DELAY_MS Base delay between attempts; actual delay is RetryBaseDelayMs * 2^attempt. 200 10–60000
GATEWAY_CIRCUIT_BREAKER_THRESHOLD Minimum throughput before the circuit can trip (Polly MinimumThroughput). 5 1–1000
GATEWAY_CIRCUIT_BREAKER_DURATION_SECONDS How long the circuit stays open before transitioning to half-open. 30 1–3600

The circuit breaker uses Polly's FailureRatio = 0.5 (a 50% failure rate trips the circuit). The above env vars control the other knobs.

Command-Line Arguments

Pass arguments when running the application:

Virtufin.Api --http-port 5001 --grpc-port 5002

Available Arguments

Argument Description Default
--http-port <port> HTTP port (the health checks only) 5001
--grpc-port <port> gRPC port (native gRPC HTTP/2 h2c) 5002
--dapr-http-port <port> Dapr HTTP port 3500
--dapr-grpc-port <port> Dapr gRPC port 50001

Note: The HTTP port serves only the health checks (/health, /healthz, /ready) over HTTP/1.1; any other request there gets 404. The gRPC port serves native gRPC and gRPC-Web over HTTP/2 cleartext (h2c).

Examples

Using Environment Variables

export HttpPort=3000
export GrpcPort=3002
./Virtufin.Api

Using Command-Line Arguments

./Virtufin.Api --http-port 3000 --grpc-port 3002

Combining Both

Environment variables set defaults, command-line arguments override:

export HttpPort=3000
./Virtufin.Api --grpc-port 3002

In this example, HttpPort is 3000 (from environment) and GrpcPort is 3002 (from command line).

CORS Configuration

The API supports CORS configuration via the Cors:AllowedOrigins configuration key:

export Cors:AllowedOrigins__0=https://example.com
export Cors:AllowedOrigins__1=https://app.example.com

Or via appsettings.json:

{
  "Cors": {
    "AllowedOrigins": ["https://example.com", "https://app.example.com"]
  }
}

API Key Authentication

The API supports key-based authentication via the ApiAuth:Keys:<name> configuration key — a map of arbitrary names (typically a username) to secret values. Callers send their key as the x-api-key gRPC metadata entry or HTTP header; it's checked with a constant-time comparison against every configured key.

export ApiAuth__Keys__alice=<secret-value>
export ApiAuth__Keys__bob=<secret-value>

Or via appsettings.json:

{
  "ApiAuth": {
    "Keys": {
      "alice": "<secret-value>",
      "bob": "<secret-value>"
    }
  }
}

Use python scripts/provision_api_key.py <username> to generate a random secret and print the env-var / docker / kubectl snippets for wiring it in — the script only generates the value, it doesn't reach into any running server or deployment. If ApiAuth:Keys is empty or unset, authentication is disabled — this is the default so local development works without configuring anything.

If no origins are configured, CORS is disabled and all cross-origin requests are rejected.

Backend Resources

Resources.ListBackends (Services) reads resources.json, at config/resources.json or the path in ResourcesConfigPath. Without the file the call answers that resources are not configured; a file that is there but wrong stops the start with the problems listed. Helm renders it from resources.*.

{
  "prometheusUrl": "http://prometheus-server.monitoring.svc",
  "rateWindow": "5m",
  "queryTimeoutSeconds": 10,
  "volumeUsedMetric": "node_disk_usage_bytes",
  "growthWindow": "24h",
  "nfsExportDepth": 2,
  "backends": [
    {"name": "api", "roles": ["api"], "namespace": "virtufin", "pods": "api-[a-z0-9]+-[a-z0-9]+"},
    {"name": "redis", "roles": ["pubsub", "state"], "namespace": "redis", "pods": "redis-.*"},
    {"name": "questdb", "roles": ["eventstore"], "namespace": "questdb", "pods": "questdb-.*",
     "dataBytesQuery": "node_disk_usage_bytes{path=~\".*_questdb_questdb-questdb-0\"}"}
  ]
}
Key Default Meaning
prometheusUrl (required) Prometheus' base URL
rateWindow 5m The window CPU use is averaged over (a Prometheus duration)
queryTimeoutSeconds 10 How long one call waits for Prometheus
backends[].pods (required) A regular expression matched against the whole pod name, no backticks
volumeUsedMetric node_disk_usage_bytes The disk-usage collector's metric of a directory's size, labeled path (the upstream disk_usage_exporter's); a volume whose path has no figure is "not measured"
growthWindow 24h The window a volume's growth per day is measured over
nfsExportDepth 2 How many leading segments of an NFS volume's path name its export, the disk it is on (/exports/medusa/… → /exports/medusa)
backends[].dataBytesQuery none PromQL whose sum is the data size in bytes