From 1e607568097bb6dffc682ba3f4b49fc572eb563c Mon Sep 17 00:00:00 2001 From: Stas Klinov Date: Sun, 10 Nov 2024 20:02:35 +0100 Subject: [PATCH] added log of the HTTP request that successfully processed with buddy into the query log; fixed #2235 --- src/searchd.cpp | 9 +++++++-- src/searchdaemon.h | 4 +++- src/searchdbuddy.cpp | 11 ++++++++--- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/searchd.cpp b/src/searchd.cpp index 84d336edf39..968bc072b43 100644 --- a/src/searchd.cpp +++ b/src/searchd.cpp @@ -3442,7 +3442,7 @@ void LogSphinxqlError ( const Str_t & sStmt, const Str_t & sError ) WriteQuery ( tBuf ); } -void LogSphinxqlBuddyQuery ( const Str_t sQuery, const CSphQueryResultMeta & tMeta ) +void LogBuddyQuery ( const Str_t sQuery, const CSphQueryResultMeta & tMeta, BuddyQuery_e tType ) { if ( g_eLogFormat!=LOG_FORMAT_SPHINXQL || g_iQueryLogFile<0 || IsEmpty ( sQuery ) ) return; @@ -3461,8 +3461,13 @@ void LogSphinxqlBuddyQuery ( const Str_t sQuery, const CSphQueryResultMeta & tMe tBuf << " x" << tMeta.m_iMultiplier; tBuf << " found " << tMeta.m_iTotalMatches << " */ "; + if ( tType==BuddyQuery_e::HTTP ) + tBuf << "/* "; tBuf.AppendEscaped ( sQuery.first, EscBld::eFixupSpace, sQuery.second ); - tBuf << '\n'; + if ( tType==BuddyQuery_e::HTTP ) + tBuf << " */"; + + tBuf << ";\n"; WriteQuery ( tBuf ); } diff --git a/src/searchdaemon.h b/src/searchdaemon.h index 29587c0fd20..ad8fa1d22a2 100644 --- a/src/searchdaemon.h +++ b/src/searchdaemon.h @@ -1455,9 +1455,11 @@ namespace session void LogSphinxqlError ( const char * sStmt, const Str_t & sError ); void LogSphinxqlError ( const Str_t & sStmt, const Str_t & sError ); -void LogSphinxqlBuddyQuery ( const Str_t sQuery, const CSphQueryResultMeta & tMeta ); int GetDaemonLogBufSize (); +enum class BuddyQuery_e { SQL, HTTP }; +void LogBuddyQuery ( const Str_t sQuery, const CSphQueryResultMeta & tMeta, BuddyQuery_e tType ); + // that is used from sphinxql command over API void RunSingleSphinxqlCommand ( Str_t sCommand, GenericOutputBuffer_c & tOut ); diff --git a/src/searchdbuddy.cpp b/src/searchdbuddy.cpp index 5544fa8ca58..fc5cca44cbc 100644 --- a/src/searchdbuddy.cpp +++ b/src/searchdbuddy.cpp @@ -662,6 +662,8 @@ static EHTTP_STATUS GetHttpStatusCode ( int iBuddyHttpCode, EHTTP_STATUS eReqHtt return ( iBuddyHttpCode>0 ? HttpGetStatusCodes ( iBuddyHttpCode ) : eReqHttpCode ); } +static void LogBuddyQuery ( const Str_t sSrcQuery, const JsonObj_c & tBudyyReply, BuddyQuery_e tType ); + // we call it ALWAYS, because even with absolutely correct result, we still might reject it for '/cli' endpoint if buddy is not available or prohibited bool ProcessHttpQueryBuddy ( HttpProcessResult_t & tRes, Str_t sSrcQuery, OptionsHash_t & hOptions, CSphVector & dResult, bool bNeedHttpResponse, http_method eRequestType ) { @@ -743,6 +745,9 @@ bool ProcessHttpQueryBuddy ( HttpProcessResult_t & tRes, Str_t sSrcQuery, Option dResult.Resize ( 0 ); ReplyBuf ( FromStr ( sDump ), eHttpStatus, bNeedHttpResponse, dResult ); + + LogBuddyQuery ( sSrcQuery, tReplyParsed.m_tRoot, BuddyQuery_e::HTTP ); + return true; } @@ -791,7 +796,7 @@ bool ConvertValue ( const char * sName, const JsonObj_c & tMeta, T & tVal ) return true; } -static void LogBuddyQuery ( const Str_t sSrcQuery, const JsonObj_c & tBudyyReply ) +void LogBuddyQuery ( const Str_t sSrcQuery, const JsonObj_c & tBudyyReply, BuddyQuery_e tType ) { CSphString sTmpError; CSphQueryResultMeta tLogMeta; @@ -812,7 +817,7 @@ static void LogBuddyQuery ( const Str_t sSrcQuery, const JsonObj_c & tBudyyReply // total_relation => null } - LogSphinxqlBuddyQuery ( sSrcQuery, tLogMeta ); + LogBuddyQuery ( sSrcQuery, tLogMeta, tType ); } void ProcessSqlQueryBuddy ( Str_t sSrcQuery, Str_t tError, std::pair tSavedPos, BYTE & uPacketID, GenericOutputBuffer_c & tOut ) @@ -856,7 +861,7 @@ void ProcessSqlQueryBuddy ( Str_t sSrcQuery, Str_t tError, std::pair std::unique_ptr tBuddyRows ( CreateSqlRowBuffer ( &uPacketID, &tOut ) ); ConvertJsonDataset ( tReplyParsed.m_tMessage, sSrcQuery.first, *tBuddyRows ); - LogBuddyQuery ( sSrcQuery, tReplyParsed.m_tRoot ); + LogBuddyQuery ( sSrcQuery, tReplyParsed.m_tRoot, BuddyQuery_e::SQL ); } #ifdef _WIN32