Skip to content

Commit 365fdac

Browse files
fix: reuse HTTP client in push_source_data and fix plugin file path
- Share a single reqwest::Client via Axum Extension layer instead of creating a new client on every push_source_data request, avoiding repeated connection pool allocation. - Fix StartupPluginRecord.file_path to use the actual plugin file path instead of the containing directory path. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent d567c2d commit 365fdac

4 files changed

Lines changed: 12 additions & 4 deletions

File tree

src/api/shared/handlers/source_handlers.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ pub async fn stop_source(
453453
/// This handler reads the source's configured host/port and forwards the request.
454454
pub async fn push_source_data(
455455
Extension(core): Extension<Arc<DrasiLib>>,
456+
Extension(http_client): Extension<reqwest::Client>,
456457
Path(id): Path<String>,
457458
Json(body): Json<serde_json::Value>,
458459
) -> Result<Json<ApiResponse<serde_json::Value>>, ErrorResponse> {
@@ -478,8 +479,7 @@ pub async fn push_source_data(
478479
let effective_host = if host == "0.0.0.0" { "127.0.0.1" } else { host };
479480
let url = format!("http://{effective_host}:{port}{base}/sources/{id}/events");
480481

481-
let client = reqwest::Client::new();
482-
match client.post(&url).json(&body).send().await {
482+
match http_client.post(&url).json(&body).send().await {
483483
Ok(resp) if resp.status().is_success() => {
484484
let resp_body: serde_json::Value = resp
485485
.json()

src/api/v1/handlers/source_handlers.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,12 +413,19 @@ pub async fn stop_source(
413413
)]
414414
pub async fn push_source_data(
415415
Extension(registry): Extension<InstanceRegistry>,
416+
Extension(http_client): Extension<reqwest::Client>,
416417
Path(ResourcePath { instance_id, id }): Path<ResourcePath>,
417418
Json(body): Json<serde_json::Value>,
418419
) -> Result<Json<ApiResponse<serde_json::Value>>, ErrorResponse> {
419420
let core = registry
420421
.get(&instance_id)
421422
.await
422423
.ok_or_else(|| ErrorResponse::new(error_codes::INTERNAL_ERROR, "Instance not found"))?;
423-
shared::push_source_data(Extension(core), Path(id), Json(body)).await
424+
shared::push_source_data(
425+
Extension(core),
426+
Extension(http_client),
427+
Path(id),
428+
Json(body),
429+
)
430+
.await
424431
}

src/api/v1/routes.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ pub fn build_v1_router(
6868
.layer(Extension(config_persistence))
6969
.layer(Extension(plugin_registry))
7070
.layer(Extension(solutions_dir))
71+
.layer(Extension(reqwest::Client::new()))
7172
}
7273

7374
/// Build routes for dynamic instance resources.

src/dynamic_loading.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ pub fn load_plugins(
226226

227227
stats.loaded_plugins.push(StartupPluginRecord {
228228
plugin_id: derived_plugin_id,
229-
file_path: dir.to_path_buf(),
229+
file_path: plugin.file_path.clone(),
230230
kinds: plugin_kinds,
231231
generation,
232232
plugin_version,

0 commit comments

Comments
 (0)