mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 05:01:07 +00:00
Make QueryStat.add never throw; also, avoid where it was throwing, upon a null ActionStack
This commit is contained in:
@ -214,71 +214,78 @@ public class QueryStatManager
|
|||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
public void add(QueryStat queryStat)
|
public void add(QueryStat queryStat)
|
||||||
{
|
{
|
||||||
if(queryStat == null)
|
try
|
||||||
{
|
{
|
||||||
return;
|
if(queryStat == null)
|
||||||
}
|
|
||||||
|
|
||||||
if(active)
|
|
||||||
{
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// set fields that we need to capture now (rather than when the thread to store runs) //
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
if(queryStat.getFirstResultTimestamp() == null)
|
|
||||||
{
|
{
|
||||||
queryStat.setFirstResultTimestamp(Instant.now());
|
|
||||||
}
|
|
||||||
|
|
||||||
if(queryStat.getStartTimestamp() != null && queryStat.getFirstResultTimestamp() != null && queryStat.getFirstResultMillis() == null)
|
|
||||||
{
|
|
||||||
long millis = queryStat.getFirstResultTimestamp().toEpochMilli() - queryStat.getStartTimestamp().toEpochMilli();
|
|
||||||
queryStat.setFirstResultMillis((int) millis);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(queryStat.getFirstResultMillis() != null && queryStat.getFirstResultMillis() < minMillisToStore)
|
|
||||||
{
|
|
||||||
//////////////////////////////////////////////////////////////
|
|
||||||
// discard this record if it's under the min millis setting //
|
|
||||||
//////////////////////////////////////////////////////////////
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(queryStat.getSessionId() == null && QContext.getQSession() != null)
|
if(active)
|
||||||
{
|
{
|
||||||
queryStat.setSessionId(QContext.getQSession().getUuid());
|
////////////////////////////////////////////////////////////////////////////////////////
|
||||||
}
|
// set fields that we need to capture now (rather than when the thread to store runs) //
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////
|
||||||
if(queryStat.getAction() == null)
|
if(queryStat.getFirstResultTimestamp() == null)
|
||||||
{
|
|
||||||
if(!QContext.getActionStack().isEmpty())
|
|
||||||
{
|
{
|
||||||
queryStat.setAction(QContext.getActionStack().peek().getActionIdentity());
|
queryStat.setFirstResultTimestamp(Instant.now());
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
if(queryStat.getStartTimestamp() != null && queryStat.getFirstResultTimestamp() != null && queryStat.getFirstResultMillis() == null)
|
||||||
{
|
{
|
||||||
boolean expected = false;
|
long millis = queryStat.getFirstResultTimestamp().toEpochMilli() - queryStat.getStartTimestamp().toEpochMilli();
|
||||||
Exception e = new Exception("Unexpected empty action stack");
|
queryStat.setFirstResultMillis((int) millis);
|
||||||
for(StackTraceElement stackTraceElement : e.getStackTrace())
|
}
|
||||||
|
|
||||||
|
if(queryStat.getFirstResultMillis() != null && queryStat.getFirstResultMillis() < minMillisToStore)
|
||||||
|
{
|
||||||
|
//////////////////////////////////////////////////////////////
|
||||||
|
// discard this record if it's under the min millis setting //
|
||||||
|
//////////////////////////////////////////////////////////////
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(queryStat.getSessionId() == null && QContext.getQSession() != null)
|
||||||
|
{
|
||||||
|
queryStat.setSessionId(QContext.getQSession().getUuid());
|
||||||
|
}
|
||||||
|
|
||||||
|
if(queryStat.getAction() == null)
|
||||||
|
{
|
||||||
|
if(QContext.getActionStack() != null && !QContext.getActionStack().isEmpty())
|
||||||
{
|
{
|
||||||
String className = stackTraceElement.getClassName();
|
queryStat.setAction(QContext.getActionStack().peek().getActionIdentity());
|
||||||
if(className.contains(QueryStatManagerInsertJob.class.getName()))
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
boolean expected = false;
|
||||||
|
Exception e = new Exception("Unexpected empty action stack");
|
||||||
|
for(StackTraceElement stackTraceElement : e.getStackTrace())
|
||||||
{
|
{
|
||||||
expected = true;
|
String className = stackTraceElement.getClassName();
|
||||||
break;
|
if(className.contains(QueryStatManagerInsertJob.class.getName()))
|
||||||
|
{
|
||||||
|
expected = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!expected)
|
||||||
|
{
|
||||||
|
LOG.debug(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(!expected)
|
synchronized(this)
|
||||||
{
|
{
|
||||||
LOG.debug(e);
|
queryStats.add(queryStat);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
synchronized(this)
|
catch(Exception e)
|
||||||
{
|
{
|
||||||
queryStats.add(queryStat);
|
LOG.debug("Error adding query stat", e);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user