Skip to content

Commit 2531cb8

Browse files
authored
Merge ca773e2 into d0ad473
2 parents d0ad473 + ca773e2 commit 2531cb8

File tree

4 files changed

+144
-5
lines changed

4 files changed

+144
-5
lines changed

src/searchd.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8336,7 +8336,12 @@ static bool HandleSetGlobal ( CSphString & sError, const CSphString & sName, int
83368336
if ( !HttpSetLogVerbosity ( sSetValue ) )
83378337
sError = "Unknown log_level value (http_on, http_off, http_bad_req_on, http_bad_req_off)";
83388338
} else
8339+
{
83398340
sError = "Unknown log_level value (must be one of info, debug, debugv, debugvv, replication)";
8341+
}
8342+
if ( sError.IsEmpty() )
8343+
BuddySetLogLevel ( g_eLogLevel );
8344+
83408345
return true;
83418346
}
83428347

src/searchdbuddy.cpp

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ static BuddyState_e TryToStart ( const char * sArgs, CSphString & sError );
7777
static CSphString GetUrl ( const ListenerDesc_t & tDesc );
7878
static CSphString BuddyGetPath ( const CSphString & sPath, const CSphString & sPluginDir, bool bHasBuddyPath, int iHostPort, const CSphString & sDataDir );
7979
static void BuddyStop ();
80+
static CSphString GetLogLevel();
8081

8182
#if _WIN32
8283
static CSphString g_sBuddyBind = "--bind=0.0.0.0:9999";
@@ -482,12 +483,14 @@ void BuddyStart ( const CSphString & sConfigPath, const CSphString & sPluginDir,
482483
g_dLogBuf.Resize ( 0 );
483484
g_sPath = sPath;
484485

485-
g_sStartArgs.SetSprintf ( "%s --listen=%s %s %s --threads=%d",
486+
CSphString sLogLevel = GetLogLevel();
487+
488+
g_sStartArgs.SetSprintf ( "%s --listen=%s %s %s --threads=%d %s",
486489
g_sPath.cstr(),
487490
g_sListener4Buddy.cstr(),
488491
g_sBuddyBind.scstr(),
489492
( bTelemetry ? "" : "--disable-telemetry" ),
490-
iThreads );
493+
iThreads, sLogLevel.scstr() );
491494

492495
sphLogDebug ( "[BUDDY] start args: %s", g_sStartArgs.cstr() );
493496

@@ -572,6 +575,13 @@ static bool BuddyQueryAddErrorBody ( JsonEscapedBuilder & tBuddyQuery, const Vec
572575
return true;
573576
}
574577

578+
// disable Expect: 100-continue
579+
// as Expect: 100-continue header option added by curl library does not work with the buddy
580+
static void DisableExpectHeader ( StrVec_t & dHeaders )
581+
{
582+
dHeaders.Add ( "Expect:" );
583+
}
584+
575585
static std::pair<bool, CSphString> BuddyQuery ( bool bHttp, Str_t sQueryError, Str_t sPathQuery, Str_t sQuery, http_method eRequestType, const VecTraits_T<BYTE> & dSrcHttpReply )
576586
{
577587
if ( !HasBuddy() )
@@ -604,9 +614,7 @@ static std::pair<bool, CSphString> BuddyQuery ( bool bHttp, Str_t sQueryError, S
604614

605615
StrVec_t dHeaders;
606616
dHeaders.Add ( SphSprintf ( "Request-ID: %d_%u", session::GetConnID(), sphCRC32 ( sQuery.first, sQuery.second, sphRand() ) ) );
607-
// disable Expect: 100-continue
608-
// as Expect: 100-continue header added by curl library do not with the buddy
609-
dHeaders.Add ( "Expect:" );
617+
DisableExpectHeader ( dHeaders );
610618

611619
return PostToHelperUrl ( g_sUrlBuddy, (Str_t)tBuddyQuery, dHeaders );
612620
}
@@ -947,3 +955,46 @@ CSphString BuddyGetPath ( const CSphString & sConfigPath, const CSphString & sPl
947955
return sFullPath;
948956
}
949957
#endif
958+
959+
static const char * GetBuddyLogLevel ( ESphLogLevel eLogLevel )
960+
{
961+
switch ( eLogLevel )
962+
{
963+
case SPH_LOG_DEBUG: return "debug";
964+
case SPH_LOG_RPL_DEBUG: return "debug";
965+
case SPH_LOG_VERBOSE_DEBUG: return "debugv";
966+
case SPH_LOG_VERY_VERBOSE_DEBUG: return "debugvv";
967+
968+
default: return "info";
969+
}
970+
}
971+
972+
CSphString GetLogLevel()
973+
{
974+
CSphString sLogLevel;
975+
if ( g_eLogLevel==SPH_LOG_INFO )
976+
return sLogLevel;
977+
978+
sLogLevel.SetSprintf ( "--log-level=%s", GetBuddyLogLevel ( g_eLogLevel ) );
979+
return sLogLevel;
980+
}
981+
982+
void BuddySetLogLevel ( ESphLogLevel eLogLevel )
983+
{
984+
if ( !HasBuddy() )
985+
return;
986+
987+
JsonEscapedBuilder tBuddyQuery;
988+
{
989+
auto tRoot = tBuddyQuery.Object();
990+
tBuddyQuery.NamedString ( "log_level", GetBuddyLogLevel ( eLogLevel ) );
991+
}
992+
993+
StrVec_t dHeaders;
994+
DisableExpectHeader ( dHeaders );
995+
996+
CSphString sUrl;
997+
sUrl.SetSprintf ( "%s/config", g_sUrlBuddy.cstr() );
998+
999+
PostToHelperUrl ( sUrl, (Str_t)tBuddyQuery, dHeaders );
1000+
}

src/searchdbuddy.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ bool IsBuddyQuery ( const OptionsHash_t & hOptions );
2323

2424
bool ProcessHttpQueryBuddy ( HttpProcessResult_t & tRes, Str_t sSrcQuery, OptionsHash_t& hOptions, CSphVector<BYTE>& dResult, bool bNeedHttpResponse, http_method eRequestType );
2525
void ProcessSqlQueryBuddy ( Str_t sSrcQuery, Str_t sError, std::pair<int, BYTE> tSavedPos, BYTE& uPackedID, GenericOutputBuffer_c& tOut );
26+
void BuddySetLogLevel ( ESphLogLevel eLogLevel );
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
––– block: ../base/start-searchd-with-buddy –––
2+
––– input –––
3+
apt-get install jq -y > /dev/null; echo $?
4+
––– output –––
5+
debconf: delaying package configuration, since apt-utils is not installed
6+
0
7+
––– input –––
8+
BUDDY_PORT=$(grep "started.*at http://127.0.0.1:" /var/log/manticore/searchd.log | tail -1 | sed 's/.*http:\/\/127.0.0.1:\([0-9]*\).*/\1/'); echo "Buddy API port: $BUDDY_PORT"
9+
––– output –––
10+
Buddy API port: %{NUMBER}
11+
––– input –––
12+
sleep 2; curl -s -X GET localhost:$BUDDY_PORT/config; echo
13+
––– output –––
14+
{"log_level":"info"}
15+
––– input –––
16+
curl -s -X GET localhost:$BUDDY_PORT/config | jq -r '.log_level'
17+
––– output –––
18+
info
19+
––– input –––
20+
mysql -h0 -P9306 -e "SET GLOBAL log_level=debug;"
21+
––– output –––
22+
––– input –––
23+
sleep 1; curl -s -X GET localhost:$BUDDY_PORT/config | jq -r '.log_level'
24+
––– output –––
25+
debug
26+
––– input –––
27+
mysql -h0 -P9306 -e "SET GLOBAL log_level=debugv;"
28+
––– output –––
29+
––– input –––
30+
sleep 1; curl -s -X GET localhost:$BUDDY_PORT/config | jq -r '.log_level'
31+
––– output –––
32+
debugv
33+
––– input –––
34+
mysql -h0 -P9306 -e "SET GLOBAL log_level=debugvv;"
35+
––– output –––
36+
––– input –––
37+
sleep 1; curl -s -X GET localhost:$BUDDY_PORT/config | jq -r '.log_level'
38+
––– output –––
39+
debugvv
40+
––– input –––
41+
mysql -h0 -P9306 -e "SET GLOBAL log_level=info;"
42+
––– output –––
43+
––– input –––
44+
sleep 1; curl -s -X GET localhost:$BUDDY_PORT/config | jq -r '.log_level'
45+
––– output –––
46+
info
47+
––– input –––
48+
curl -s -X POST -d '{"log_level":"debug"}' localhost:$BUDDY_PORT/config; echo
49+
––– output –––
50+
{"log_level":"debug"}
51+
––– input –––
52+
mysql -h0 -P9306 -e "SHOW VARIABLES LIKE 'log_level';"
53+
––– output –––
54+
+---------------+-------+
55+
| Variable_name | Value |
56+
+---------------+-------+
57+
| log_level | debug |
58+
+---------------+-------+
59+
––– input –––
60+
curl -s -X POST -d '{"log_level":"debugvv"}' localhost:$BUDDY_PORT/config; echo
61+
––– output –––
62+
{"log_level":"debugvv"}
63+
––– input –––
64+
mysql -h0 -P9306 -e "SHOW VARIABLES LIKE 'log_level';"
65+
––– output –––
66+
+---------------+---------+
67+
| Variable_name | Value |
68+
+---------------+---------+
69+
| log_level | debugvv |
70+
+---------------+---------+
71+
––– input –––
72+
curl -s -X POST -d '{"log_level":"info"}' localhost:$BUDDY_PORT/config; echo
73+
––– output –––
74+
{"log_level":"info"}
75+
––– input –––
76+
mysql -h0 -P9306 -e "SHOW VARIABLES LIKE 'log_level';"
77+
––– output –––
78+
+---------------+-------+
79+
| Variable_name | Value |
80+
+---------------+-------+
81+
| log_level | info |
82+
+---------------+-------+

0 commit comments

Comments
 (0)