Skip to content

Commit c708041

Browse files
authored
chore: envvars for http paths and live health endpoint (#1846)
Signed-off-by: Greg Clark <grclark@nvidia.com>
1 parent 6cdda03 commit c708041

File tree

2 files changed

+62
-10
lines changed

2 files changed

+62
-10
lines changed

lib/llm/src/http/service/health.rs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,44 @@ pub fn health_check_router(
3737
state: Arc<service_v2::State>,
3838
path: Option<String>,
3939
) -> (Vec<RouteDoc>, Router) {
40-
let path = path.unwrap_or_else(|| "/health".to_string());
40+
let health_path = path.unwrap_or_else(|| "/health".to_string());
4141

42-
let docs: Vec<RouteDoc> = vec![RouteDoc::new(Method::GET, &path)];
42+
let docs: Vec<RouteDoc> = vec![RouteDoc::new(Method::GET, &health_path)];
4343

4444
let router = Router::new()
45-
.route(&path, get(health_handler))
45+
.route(&health_path, get(health_handler))
4646
.with_state(state);
4747

4848
(docs, router)
4949
}
5050

51+
pub fn live_check_router(
52+
state: Arc<service_v2::State>,
53+
path: Option<String>,
54+
) -> (Vec<RouteDoc>, Router) {
55+
let live_path = path.unwrap_or_else(|| "/live".to_string());
56+
57+
let docs: Vec<RouteDoc> = vec![RouteDoc::new(Method::GET, &live_path)];
58+
59+
let router = Router::new()
60+
.route(&live_path, get(live_handler))
61+
.with_state(state);
62+
63+
(docs, router)
64+
}
65+
66+
async fn live_handler(
67+
axum::extract::State(_state): axum::extract::State<Arc<service_v2::State>>,
68+
) -> impl IntoResponse {
69+
(
70+
StatusCode::OK,
71+
Json(json!({
72+
"status": "live",
73+
"message": "Service is live"
74+
})),
75+
)
76+
}
77+
5178
async fn health_handler(
5279
axum::extract::State(state): axum::extract::State<Arc<service_v2::State>>,
5380
) -> impl IntoResponse {

lib/llm/src/http/service/service_v2.rs

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4+
use std::env::var;
45
use std::sync::Arc;
56
use std::time::Duration;
67

@@ -132,6 +133,23 @@ impl HttpService {
132133
}
133134
}
134135

136+
/// Environment variable to set the metrics endpoint path (default: `/metrics`)
137+
static HTTP_SVC_METRICS_PATH_ENV: &str = "DYN_HTTP_SVC_METRICS_PATH";
138+
/// Environment variable to set the models endpoint path (default: `/v1/models`)
139+
static HTTP_SVC_MODELS_PATH_ENV: &str = "DYN_HTTP_SVC_MODELS_PATH";
140+
/// Environment variable to set the health endpoint path (default: `/health`)
141+
static HTTP_SVC_HEALTH_PATH_ENV: &str = "DYN_HTTP_SVC_HEALTH_PATH";
142+
/// Environment variable to set the live endpoint path (default: `/live`)
143+
static HTTP_SVC_LIVE_PATH_ENV: &str = "DYN_HTTP_SVC_LIVE_PATH";
144+
/// Environment variable to set the chat completions endpoint path (default: `/v1/chat/completions`)
145+
static HTTP_SVC_CHAT_PATH_ENV: &str = "DYN_HTTP_SVC_CHAT_PATH";
146+
/// Environment variable to set the completions endpoint path (default: `/v1/completions`)
147+
static HTTP_SVC_CMP_PATH_ENV: &str = "DYN_HTTP_SVC_CMP_PATH";
148+
/// Environment variable to set the embeddings endpoint path (default: `/v1/embeddings`)
149+
static HTTP_SVC_EMB_PATH_ENV: &str = "DYN_HTTP_SVC_EMB_PATH";
150+
/// Environment variable to set the responses endpoint path (default: `/v1/responses`)
151+
static HTTP_SVC_RESPONSES_PATH_ENV: &str = "DYN_HTTP_SVC_RESPONSES_PATH";
152+
135153
impl HttpServiceConfigBuilder {
136154
pub fn build(self) -> Result<HttpService, anyhow::Error> {
137155
let config: HttpServiceConfig = self.build_internal()?;
@@ -148,32 +166,39 @@ impl HttpServiceConfigBuilder {
148166
let mut all_docs = Vec::new();
149167

150168
let mut routes = vec![
151-
metrics::router(registry, None),
152-
super::openai::list_models_router(state.clone(), None),
153-
super::health::health_check_router(state.clone(), None),
169+
metrics::router(registry, var(HTTP_SVC_METRICS_PATH_ENV).ok()),
170+
super::openai::list_models_router(state.clone(), var(HTTP_SVC_MODELS_PATH_ENV).ok()),
171+
super::health::health_check_router(state.clone(), var(HTTP_SVC_HEALTH_PATH_ENV).ok()),
172+
super::health::live_check_router(state.clone(), var(HTTP_SVC_LIVE_PATH_ENV).ok()),
154173
];
155174

156175
if config.enable_chat_endpoints {
157176
routes.push(super::openai::chat_completions_router(
158177
state.clone(),
159178
config.request_template.clone(), // TODO clone()? reference?
160-
None,
179+
var(HTTP_SVC_CHAT_PATH_ENV).ok(),
161180
));
162181
}
163182

164183
if config.enable_cmpl_endpoints {
165-
routes.push(super::openai::completions_router(state.clone(), None));
184+
routes.push(super::openai::completions_router(
185+
state.clone(),
186+
var(HTTP_SVC_CMP_PATH_ENV).ok(),
187+
));
166188
}
167189

168190
if config.enable_embeddings_endpoints {
169-
routes.push(super::openai::embeddings_router(state.clone(), None));
191+
routes.push(super::openai::embeddings_router(
192+
state.clone(),
193+
var(HTTP_SVC_EMB_PATH_ENV).ok(),
194+
));
170195
}
171196

172197
if config.enable_responses_endpoints {
173198
routes.push(super::openai::responses_router(
174199
state.clone(),
175200
config.request_template,
176-
None,
201+
var(HTTP_SVC_RESPONSES_PATH_ENV).ok(),
177202
));
178203
}
179204

0 commit comments

Comments
 (0)