Permalink
Browse files

Merge branch 'idxn' into github

  • Loading branch information...
2 parents 7dcf5e1 + 4a8183c commit 2edb39c1f461a31730b840b40feaf5cbabb36075 @nniclausse nniclausse committed Feb 4, 2013
View
@@ -3229,7 +3229,7 @@ <H4 CLASS="subsubsection"><!--SEC ANCHOR --><A NAME="htoc69">6.7.4</A>  Checki
</TABLE><P>You can use a regexp instead of a simple string.</P><P>The list of available actions to do is:
</P><UL CLASS="itemize"><LI CLASS="li-itemize">
continue: do nothing, continue (only update match or nomatch counters)
-</LI><LI CLASS="li-itemize">log: log the request id, userid, sessionid in a file (in <TT>match.log</TT>)
+</LI><LI CLASS="li-itemize">log: log the request id, userid, sessionid, name in a file (in <TT>match.log</TT>)
</LI><LI CLASS="li-itemize">abort : abort the session
</LI><LI CLASS="li-itemize">restart: restart the session. The maximum number of
restarts is 3 by default.
@@ -3296,7 +3296,29 @@ <H4 CLASS="subsubsection"><!--SEC ANCHOR --><A NAME="htoc69">6.7.4</A>  Checki
</TD></TR>
</TABLE></TD></TR>
</TABLE></TD></TR>
-</TABLE><!--TOC subsubsection Loops, If, Foreach-->
+</TABLE>
+
+<P><B>Since 1.5.0</B>, it's now possible to add <TT>name</TT> attribute in <TT>match</TT> tag to name a record printed in match.log as follow:
+</P><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0><TR><TD><TABLE BORDER=0 CELLPADDING=0
+CELLSPACING=0><TR><TD BGCOLOR=black COLSPAN="3"><TABLE CELLSPACING="1" CELLPADDING=0 BORDER=0><TR><TD>
+</TD></TR>
+</TABLE></TD></TR>
+<TR><TD BGCOLOR=black COLSPAN="1"><TABLE CELLSPACING="1" CELLPADDING=0 BORDER=0><TR><TD>
+</TD></TR>
+
+</TABLE></TD><TD><TABLE BORDER=0 CELLPADDING="1" CELLSPACING=0><TR><TD><PRE CLASS="verbatim">&lt;match do='log' when='match' name='http_match_200ok'&gt;200OK&lt;/match&gt;
+&lt;http url="/" method="GET"/&gt;
+</PRE></TD></TR>
+</TABLE></TD><TD BGCOLOR=black COLSPAN="1"><TABLE CELLSPACING="1" CELLPADDING=0 BORDER=0><TR><TD>
+</TD></TR>
+</TABLE></TD></TR>
+<TR><TD BGCOLOR=black COLSPAN="3"><TABLE CELLSPACING="1" CELLPADDING=0 BORDER=0><TR><TD>
+</TD></TR>
+</TABLE></TD></TR>
+</TABLE></TD></TR>
+</TABLE>
+
+<!--TOC subsubsection Loops, If, Foreach-->
<H4 CLASS="subsubsection"><!--SEC ANCHOR --><A NAME="htoc70">6.7.5</A>  Loops, If, Foreach</H4><!--SEC END --><P><B>Since 1.3.0</B>, it’s now possible to add conditional/unconditional loops in a session.</P><P><B>Since 1.4.0</B>, it is possible to loop through a list of dynamic variables thanks to foreach.</P><!--TOC paragraph &lt;for&gt;-->
<H5 CLASS="paragraph"><!--SEC ANCHOR -->&lt;for&gt;</H5><!--SEC END --><P>Repeat the enclosing actions a fixed number of times. A dynamic
variable is used as counter, so the current iteration could be used in
View
@@ -2493,7 +2493,7 @@ \subsubsection{Checking the server's response}
The list of available actions to do is:
\begin{itemize}
\item continue: do nothing, continue (only update match or nomatch counters)
-\item log: log the request id, userid, sessionid in a file (in \file{match.log})
+\item log: log the request id, userid, sessionid, name in a file (in \file{match.log})
\item abort : abort the session
\item restart: restart the session. The maximum number of
restarts is 3 by default.
@@ -2532,6 +2532,12 @@ \subsubsection{Checking the server's response}
<http url="/" method="GET"/>
\end{Verbatim}
+\strong{Since 1.5.0}, it's now possible to add 'name' attribute in 'match' tag to name a record printed in match.log as follow:
+\begin{Verbatim}
+<match do='log' when='match' name='http_match_200ok'>200OK</match>
+<http url="/" method="GET" version="1.1"/>
+\end{Verbatim}
+
\subsubsection{Loops, If, Foreach}
\strong{Since 1.3.0}, it's now possible to add conditional/unconditional loops in a session.
View
@@ -28,6 +28,7 @@
{ regexp,
subst = false,
'when' = false,
+ name,
do = continue, %(continue | loop | abort | log )
sleep_loop, % in seconds
apply_to_content,
@@ -77,8 +77,8 @@ add(Data) ->
%% @spec add_match(Data::list(),{UserId::integer(),SessionId::integer(),RequestId::integer(),
%% TimeStamp::tuple(), Transactions::list()}) -> ok
-add_match(Data,{UserId,SessionId,RequestId,TimeStamp,Bin,Tr}) ->
- gen_server:cast(?MODULE, {add_match, Data, {UserId,SessionId,RequestId,TimeStamp,Bin,Tr}}).
+add_match(Data,{UserId,SessionId,RequestId,TimeStamp,Bin,Tr,Name}) ->
+ gen_server:cast(?MODULE, {add_match, Data, {UserId,SessionId,RequestId,TimeStamp,Bin,Tr,Name}}).
%%====================================================================
%% Server functions
@@ -124,9 +124,9 @@ handle_cast({add, Data}, State) when is_list(Data) ->
{noreply, LastState };
handle_cast({add, Data}, State) when is_tuple(Data) ->
{noreply,update_stats(Data, State)};
-handle_cast({add_match, Data=[First|_Tail],{UserId,SessionId,RequestId,TimeStamp,Bin,Tr}},
+handle_cast({add_match, Data=[First|_Tail],{UserId,SessionId,RequestId,TimeStamp,Bin,Tr,Name}},
State=#state{stats=List, match=MatchList})->
- NewMatchList=lists:append([{UserId,SessionId,RequestId,TimeStamp,First, Bin, Tr}], MatchList),
+ NewMatchList=lists:append([{UserId,SessionId,RequestId,TimeStamp,First, Bin, Tr,Name}], MatchList),
{noreply, State#state{stats = lists:append(Data, List), match = NewMatchList}};
handle_cast(_Msg, State) ->
View
@@ -194,15 +194,15 @@ match([Match=#match{regexp=RawRegExp,subst=Subst, do=Action, 'when'=When}
setcount(#match{do=continue}, {Count, _MaxC, _SessionId, _UserId}, Stats,_,_)->
ts_mon:add(Stats),
Count;
-setcount(#match{do=log}, {Count, MaxC, SessionId, UserId}, Stats,_,Tr)->
- ts_mon:add_match(Stats,{UserId,SessionId,MaxC-Count,Tr}),
+setcount(#match{do=log, name=Name}, {Count, MaxC, SessionId, UserId}, Stats,_,Tr)->
+ ts_mon:add_match(Stats,{UserId,SessionId,MaxC-Count,Tr, Name}),
Count;
-setcount(#match{do=dump}, {Count, MaxC, SessionId, UserId}, Stats, Data, Tr)->
- ts_mon:add_match(Stats,{UserId,SessionId,MaxC-Count, Data, Tr}),
+setcount(#match{do=dump, name=Name}, {Count, MaxC, SessionId, UserId}, Stats, Data, Tr)->
+ ts_mon:add_match(Stats,{UserId,SessionId,MaxC-Count, Data, Tr, Name}),
Count;
-setcount(#match{do=restart, max_restart=MaxRestart}, {Count, MaxC,SessionId,UserId}, Stats,_, Tr)->
+setcount(#match{do=restart, max_restart=MaxRestart, name=Name}, {Count, MaxC,SessionId,UserId}, Stats,_, Tr)->
CurRestart = get(restart_count),
- Ids={UserId,SessionId,MaxC-Count,Tr},
+ Ids={UserId,SessionId,MaxC-Count,Tr,Name},
?LOGF("Restart on (no)match ~p~n",[CurRestart], ?INFO),
case CurRestart of
undefined ->
@@ -236,8 +236,8 @@ setcount(#match{do=loop,loop_back=Back,max_loop=MaxLoop,sleep_loop=Sleep},{Count
timer:sleep(Sleep),
Count + 1 + Back
end;
-setcount(#match{do=abort}, {Count,MaxC,SessionId,UserId}, Stats,_, Tr) ->
- ts_mon:add_match([{count, match_stop} | Stats],{UserId,SessionId,MaxC-Count,Tr}),
+setcount(#match{do=abort,name=Name}, {Count,MaxC,SessionId,UserId}, Stats,_, Tr) ->
+ ts_mon:add_match([{count, match_stop} | Stats],{UserId,SessionId,MaxC-Count,Tr, Name}),
0.
%%----------------------------------------------------------------------
@@ -616,6 +616,7 @@ parse(Element=#xmlElement{name=match,attributes=Attrs},
Conf=#config{match=Match})->
Do = getAttr(atom, Attrs, do, continue),
When = getAttr(atom, Attrs, 'when', match),
+ Name = getAttr(string, Attrs, name, "-"),
Subst = getAttr(atom, Attrs, subst, false),
MaxLoop = getAttr(integer, Attrs, max_loop, 20),
LoopBack = getAttr(integer, Attrs, loop_back, 0),
@@ -630,7 +631,7 @@ parse(Element=#xmlElement{name=match,attributes=Attrs},
{Mod, Fun} = ts_utils:split2(Data,$:),
{list_to_atom(Mod), list_to_atom(Fun)}
end,
- NewMatch = #match{regexp=RegExp,subst=Subst, do=Do,'when'=When,
+ NewMatch = #match{regexp=RegExp,subst=Subst, do=Do,'when'=When, name=Name,
sleep_loop=SleepLoop * 1000, skip_headers=SkipHeaders,
loop_back=LoopBack, max_restart=MaxRestart, max_loop=MaxLoop, apply_to_content=ApplyTo},
@@ -96,7 +96,7 @@ init([LogDir]) ->
case file:open(Filename,[write, {delayed_write, ?DELAYED_WRITE_SIZE, ?DELAYED_WRITE_DELAY}]) of
{ok, Fd} ->
?LOG("starting match logger~n",?INFO),
- io:format(Fd,"# timestamp userid sessionid requestid event transaction~n",[]),
+ io:format(Fd,"# timestamp userid sessionid requestid event transaction name~n",[]),
{ok, #state{ fd = Fd,
filename = Filename,
logdir = LogDir
@@ -172,12 +172,12 @@ code_change(_OldVsn, StateData, _Extra) ->
%%% Internal functions
%%%----------------------------------------------------------------------
-log({UserId,SessionId,RequestId,TimeStamp,{count, Val},[], Tr},State=#state{fd=File}) ->
+log({UserId,SessionId,RequestId,TimeStamp,{count, Val},[], Tr,Name},State=#state{fd=File}) ->
TS=ts_utils:time2sec_hires(TimeStamp),
- io:format(File,"~f ~B ~B ~B ~p ~s~n",[TS,UserId,SessionId,RequestId,Val,log_transaction(Tr)]),
+ io:format(File,"~f ~B ~B ~B ~p ~s ~s~n",[TS,UserId,SessionId,RequestId,Val,log_transaction(Tr),Name]),
State;
-log({UserId,SessionId,RequestId,TimeStamp,{count, Val},Bin, Tr}, State=#state{logdir=LogDir, dumpid=Id}) ->
- log({UserId,SessionId,RequestId,TimeStamp,{count, Val},[],Tr}, State),
+log({UserId,SessionId,RequestId,TimeStamp,{count, Val},Bin, Tr,MatchName}, State=#state{logdir=LogDir, dumpid=Id}) ->
+ log({UserId,SessionId,RequestId,TimeStamp,{count, Val},[],Tr, MatchName}, State),
Name=ts_utils:join("-",lists:map(fun integer_to_list/1,[UserId,SessionId,RequestId,Id])),
Filename=filename:join(LogDir, "match-"++ Name ++".dump"),
file:write_file(Filename,Bin),
@@ -105,12 +105,12 @@ add(nocache,Data) ->
add(Data) ->
ts_mon_cache:add(Data).
-add_match(Data,{UserId,SessionId,RequestId,Tr}) ->
- add_match(Data,{UserId,SessionId,RequestId,[],Tr});
-add_match(Data=[Head|_],{UserId,SessionId,RequestId,Bin,Tr}) ->
+add_match(Data,{UserId,SessionId,RequestId,Tr,Name}) ->
+ add_match(Data,{UserId,SessionId,RequestId,[],Tr,Name});
+add_match(Data=[Head|_],{UserId,SessionId,RequestId,Bin,Tr,Name}) ->
TimeStamp=?NOW,
put(last_match,Head),
- ts_mon_cache:add_match(Data,{UserId,SessionId,RequestId,TimeStamp, Bin,Tr}).
+ ts_mon_cache:add_match(Data,{UserId,SessionId,RequestId,TimeStamp, Bin,Tr,Name}).
status() ->
gen_server:call({global, ?MODULE}, {status}).
View
@@ -149,6 +149,7 @@ repeat | if | change_type | foreach | set_option | interaction )*>
when (match|nomatch) "match"
subst (true|false) "false"
loop_back NMTOKEN "0"
+ name NMTOKEN "-"
max_loop NMTOKEN "20"
max_restart NMTOKEN "3"
sleep_loop NMTOKEN "5"

0 comments on commit 2edb39c

Please sign in to comment.