Skip to content

Commit b17d05f

Browse files
authored
Add argument for configuring Prometheus port (#589)
1 parent 35d9a34 commit b17d05f

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,12 @@ Options:
307307
[env: OTLP_SERVICE_NAME=]
308308
[default: text-embeddings-inference.server]
309309
310+
--prometheus-port <PORT>
311+
The Prometheus metrics port to listen on
312+
313+
[env: PROMETHEUS_PORT=]
314+
[default: 9000]
315+
310316
--cors-allow-origin <CORS_ALLOW_ORIGIN>
311317
Unused for gRPC servers
312318

router/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ pub async fn run(
6363
api_key: Option<String>,
6464
otlp_endpoint: Option<String>,
6565
otlp_service_name: String,
66+
prometheus_port: u16,
6667
cors_allow_origin: Option<Vec<String>>,
6768
) -> Result<()> {
6869
let model_id_path = Path::new(&model_id);
@@ -314,7 +315,7 @@ pub async fn run(
314315
}
315316
};
316317

317-
let prom_builder = prometheus::prometheus_builer(info.max_input_length)?;
318+
let prom_builder = prometheus::prometheus_builer(addr, prometheus_port, info.max_input_length)?;
318319

319320
#[cfg(all(feature = "grpc", feature = "http"))]
320321
compile_error!("Features `http` and `grpc` cannot be enabled at the same time.");

router/src/main.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ struct Args {
164164
#[clap(default_value = "text-embeddings-inference.server", long, env)]
165165
otlp_service_name: String,
166166

167+
/// The Prometheus port to listen on.
168+
#[clap(default_value = "9000", long, short, env)]
169+
prometheus_port: u16,
170+
167171
/// Unused for gRPC servers
168172
#[clap(long, env)]
169173
cors_allow_origin: Option<Vec<String>>,
@@ -227,6 +231,7 @@ async fn main() -> Result<()> {
227231
args.api_key,
228232
args.otlp_endpoint,
229233
args.otlp_service_name,
234+
args.prometheus_port,
230235
args.cors_allow_origin,
231236
)
232237
.await?;

router/src/prometheus.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1+
use std::net::SocketAddr;
2+
13
use metrics_exporter_prometheus::{BuildError, Matcher, PrometheusBuilder};
24

3-
pub(crate) fn prometheus_builer(max_input_length: usize) -> Result<PrometheusBuilder, BuildError> {
5+
pub(crate) fn prometheus_builer(
6+
addr: SocketAddr,
7+
port: u16,
8+
max_input_length: usize,
9+
) -> Result<PrometheusBuilder, BuildError> {
10+
let mut addr = addr;
11+
addr.set_port(port);
12+
413
// Duration buckets
514
let duration_matcher = Matcher::Suffix(String::from("duration"));
615
let n_duration_buckets = 35;
@@ -30,6 +39,7 @@ pub(crate) fn prometheus_builer(max_input_length: usize) -> Result<PrometheusBui
3039

3140
// Prometheus handler
3241
PrometheusBuilder::new()
42+
.with_http_listener(addr)
3343
.set_buckets_for_metric(duration_matcher, &duration_buckets)?
3444
.set_buckets_for_metric(input_length_matcher, &input_length_buckets)?
3545
.set_buckets_for_metric(batch_size_matcher, &batch_size_buckets)?

0 commit comments

Comments
 (0)