From 4f494385f55a1a04e3ccdabdad0d655766cbb265 Mon Sep 17 00:00:00 2001 From: Karim Shamazov Date: Thu, 20 Aug 2026 13:59:44 +0300 Subject: [PATCH] add flushed_http_code tag --- runtime/interface.cpp | 7 ++++--- server/php-worker.cpp | 4 ++-- server/php-worker.h | 2 +- server/server-stats.cpp | 2 +- server/statshouse/statshouse-manager.cpp | 6 +++--- server/statshouse/statshouse-manager.h | 2 +- 6 files changed, 12 insertions(+), 11 deletions(-) diff --git a/runtime/interface.cpp b/runtime/interface.cpp index 7cf80c0400..3a0568ffc8 100644 --- a/runtime/interface.cpp +++ b/runtime/interface.cpp @@ -592,9 +592,9 @@ void f$flush() { } string_buffer const* http_body = compress_http_query_body(&oub[ob_system_level]); string_buffer const* http_headers = nullptr; - if (!php_worker->flushed_http_connection) { + if (!php_worker->flushed_http_code) { http_headers = get_headers(); - php_worker->flushed_http_connection = true; + php_worker->flushed_http_code = http_return_code; } http_send_immediate_response(http_headers ? http_headers->buffer() : nullptr, http_headers ? http_headers->size() : 0, http_body->buffer(), http_body->size()); @@ -612,7 +612,7 @@ void f$fastcgi_finish_request(int64_t exit_code) { headers_sent = true; } int ob_total_buffer = ob_merge_buffers(); - if (php_worker.has_value() && php_worker->flushed_http_connection) { + if (php_worker.has_value() && php_worker->flushed_http_code) { string const raw_response = oub[ob_total_buffer].str(); http_set_result(nullptr, 0, raw_response.c_str(), raw_response.size(), static_cast(exit_code)); php_assert(0); @@ -640,6 +640,7 @@ void f$fastcgi_finish_request(int64_t exit_code) { set_content_length_header(compressed->size()); } const string_buffer* headers = get_headers(); + php_worker->flushed_http_code = http_return_code; http_set_result(headers->buffer(), headers->size(), compressed->buffer(), compressed->size(), static_cast(exit_code)); break; diff --git a/server/php-worker.cpp b/server/php-worker.cpp index a35d4c8363..c042dc39a9 100644 --- a/server/php-worker.cpp +++ b/server/php-worker.cpp @@ -274,7 +274,7 @@ void PhpWorker::state_run() noexcept { if (conn != nullptr) { switch (mode) { case http_worker: - if (!flushed_http_connection) { + if (!flushed_http_code) { http_return(conn, "ERROR", 5); } break; @@ -448,7 +448,7 @@ PhpWorker::PhpWorker(php_worker_mode_t mode_, connection *c, php_query_data_t qu : conn(c) , data(std::move(query_data)) , paused(false) - , flushed_http_connection(false) + , flushed_http_code(0) , terminate_flag(false) , terminate_reason(script_error_t::unclassified_error) , error_message("no error") diff --git a/server/php-worker.h b/server/php-worker.h index 20a8ca44bf..15230106f9 100644 --- a/server/php-worker.h +++ b/server/php-worker.h @@ -40,7 +40,7 @@ class PhpWorker { php_query_data_t data; bool paused; - bool flushed_http_connection; + int flushed_http_code; bool terminate_flag; script_error_t terminate_reason; const char *error_message; diff --git a/server/server-stats.cpp b/server/server-stats.cpp index 4025d31f32..a81f155ba9 100644 --- a/server/server-stats.cpp +++ b/server/server-stats.cpp @@ -656,7 +656,7 @@ void ServerStats::add_request_stats(double script_time_sec, double net_time_sec, stats.add_request_stats(queries_stat, error, script_memory_stats, curl_total_allocated); shared_stats_->workers.add_worker_stats(queries_stat, worker_process_id_); - StatsHouseManager::get().add_request_stats(script_time.count(), net_time.count(), script_max_running_interval.count(), error, script_memory_stats, builtin_stats, script_queries, long_script_queries, + StatsHouseManager::get().add_request_stats(script_time.count(), net_time.count(), script_max_running_interval.count(), php_worker->flushed_http_code, error, script_memory_stats, builtin_stats, script_queries, long_script_queries, script_user_time.count(), script_system_time.count(), script_init_time.count(), http_connection_process_time.count(), script_rusage.voluntary_context_switches, script_rusage.involuntary_context_switches); diff --git a/server/statshouse/statshouse-manager.cpp b/server/statshouse/statshouse-manager.cpp index 30ea442d36..bfa009008b 100644 --- a/server/statshouse/statshouse-manager.cpp +++ b/server/statshouse/statshouse-manager.cpp @@ -110,7 +110,7 @@ void StatsHouseManager::generic_cron_check_if_tag_host_needed() { } } -void StatsHouseManager::add_request_stats(uint64_t script_time_ns, uint64_t net_time_ns, uint64_t script_max_running_interval_ns, script_error_t error, +void StatsHouseManager::add_request_stats(uint64_t script_time_ns, uint64_t net_time_ns, uint64_t script_max_running_interval_ns, int flushed_http_code, script_error_t error, const memory_resource::MemoryStats &script_memory_stats, const std::optional &builtin_stats, uint64_t script_queries, uint64_t long_script_queries, uint64_t script_user_time_ns, uint64_t script_system_time_ns, @@ -126,7 +126,7 @@ void StatsHouseManager::add_request_stats(uint64_t script_time_ns, uint64_t net_ client.metric("kphp_request_cpu_time").tag("system").tag(worker_type).tag(status).write_value(script_system_time_ns); client.metric("kphp_request_init_time").tag(worker_type).tag(status).write_value(script_init_time); if (process_type == ProcessType::http_worker) { - client.metric("kphp_http_connection_process_time").tag(status).write_value(http_connection_process_time); + client.metric("kphp_http_connection_process_time").tag("flushed_http_code", std::to_string(flushed_http_code)).tag(status).write_value(http_connection_process_time); } client.metric("kphp_by_host_request_time", true).tag("script").tag(worker_type).write_value(script_time_ns); @@ -135,7 +135,7 @@ void StatsHouseManager::add_request_stats(uint64_t script_time_ns, uint64_t net_ client.metric("kphp_by_host_request_cpu_time", true).tag("system").tag(worker_type).tag(status).write_value(script_system_time_ns); client.metric("kphp_by_host_request_init_time", true).tag(worker_type).tag(status).write_value(script_init_time); if (process_type == ProcessType::http_worker) { - client.metric("kphp_by_host_http_connection_process_time", true).tag(status).write_value(http_connection_process_time); + client.metric("kphp_by_host_http_connection_process_time", true).tag("flushed_http_code", std::to_string(flushed_http_code)).tag(status).write_value(http_connection_process_time); } if (error != script_error_t::no_error) { diff --git a/server/statshouse/statshouse-manager.h b/server/statshouse/statshouse-manager.h index bd3cbd4f77..e022f14c2d 100644 --- a/server/statshouse/statshouse-manager.h +++ b/server/statshouse/statshouse-manager.h @@ -58,7 +58,7 @@ class StatsHouseManager : vk::not_copyable { return this->instance_cache_key_normalization_function != nullptr; } - void add_request_stats(uint64_t script_time_ns, uint64_t net_time_ns, uint64_t script_max_running_interval_ns, script_error_t error, + void add_request_stats(uint64_t script_time_ns, uint64_t net_time_ns, uint64_t script_max_running_interval_ns, int flushed_http_code, script_error_t error, const memory_resource::MemoryStats &script_memory_stats, const std::optional &builtin_stats, uint64_t script_queries, uint64_t long_script_queries, uint64_t script_user_time_ns, uint64_t script_system_time_ns,