Open Source alternative to Algolia + Pinecone and an Easier-to-Use alternative to ElasticSearch ⚡ 🔍 ✨ Fast, typo tolerant, in-memory fuzzy Search Engine for building delightful search experiences
C++ algoliadatastoreelasticsearchenterprise-searchfacetingfull-text-searchfuzzy-searchgeosearchin-memoryinstantsearchmerchandisingpineconesearchsearch-enginesemantic-searchsimilarity-searchsite-searchsynonymstypo-tolerancevector-search
Log address in slow request logs.
Kishore Nalland83745a6eb76
diff --git a/include/http_data.h b/include/http_data.hindex 75e91b5e..5a01bdf7 100644--- a/include/http_data.h+++ b/include/http_data.h@@ -195,6 +195,11 @@ struct cached_res_t {}};+struct ip_addr_str_t {+ static const size_t IP_MAX_LEN = 64;+ char ip[IP_MAX_LEN];+};+struct http_req {static constexpr const char* AUTH_HEADER = "x-typesense-api-key";static constexpr const char* AGENT_HEADER = "user-agent";@@ -278,7 +283,8 @@ struct http_req {}}std::string full_url_path = metric_identifier + query_string;- LOG(INFO) << "SLOW REQUEST: " << "(" + std::to_string(ms_since_start) + " ms) " << full_url_path;+ LOG(INFO) << "SLOW REQUEST: " << "(" + std::to_string(ms_since_start) + " ms) "+ << http_req::get_ip_addr(_req).ip << " " << full_url_path;}}}@@ -336,6 +342,18 @@ struct http_req {return content.dump(-1, ' ', false, nlohmann::detail::error_handler_t::ignore);}++ static ip_addr_str_t get_ip_addr(h2o_req_t* h2o_req) {+ ip_addr_str_t ip_addr;+ sockaddr sa;+ if(0 != h2o_req->conn->callbacks->get_peername(h2o_req->conn, &sa)) {+ StringUtils::get_ip_str(&sa, ip_addr.ip, ip_addr.IP_MAX_LEN);+ } else {+ strcpy(ip_addr.ip, "0.0.0.0");+ }++ return ip_addr;+ }};struct route_path {diff --git a/src/http_server.cpp b/src/http_server.cppindex e534f930..7794d016 100644--- a/src/http_server.cpp+++ b/src/http_server.cpp@@ -307,20 +307,10 @@ int HttpServer::catch_all_handler(h2o_handler_t *_h2o_handler, h2o_req_t *req) {AppMetrics::get_instance().increment_count(metric_identifier, 1);if(Config::get_instance().get_enable_access_logging()) {- const size_t IP_MAX_LEN = 64;- char ip_str[IP_MAX_LEN];- sockaddr sa;-- if(0 != req->conn->callbacks->get_peername(req->conn, &sa)) {- StringUtils::get_ip_str(&sa, ip_str, IP_MAX_LEN);- } else {- strncpy(ip_str, "NA", 2);- }-uint64_t now = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch()).count();auto epoch_millis = now / 1000;- AppMetrics::get_instance().write_access_log(epoch_millis, ip_str, metric_identifier);+ AppMetrics::get_instance().write_access_log(epoch_millis, http_req::get_ip_addr(req).ip, metric_identifier);}// Handle CORS