Skip to content

Commit

Permalink
added log of the HTTP request that successfully processed with buddy …
Browse files Browse the repository at this point in the history
…into the query log; fixed #2235
  • Loading branch information
tomatolog authored and donhardman committed Nov 14, 2024
1 parent d331a27 commit 1e60756
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
9 changes: 7 additions & 2 deletions src/searchd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 );
}
Expand Down
4 changes: 3 additions & 1 deletion src/searchdaemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down
11 changes: 8 additions & 3 deletions src/searchdbuddy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<BYTE> & dResult, bool bNeedHttpResponse, http_method eRequestType )
{
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand All @@ -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<int, BYTE> tSavedPos, BYTE & uPacketID, GenericOutputBuffer_c & tOut )
Expand Down Expand Up @@ -856,7 +861,7 @@ void ProcessSqlQueryBuddy ( Str_t sSrcQuery, Str_t tError, std::pair<int, BYTE>
std::unique_ptr<RowBuffer_i> 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
Expand Down

0 comments on commit 1e60756

Please sign in to comment.