Skip to content

Commit

Permalink
Refactor based on review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Klemm authored and Tim Klemm committed Feb 14, 2025
1 parent 6892834 commit 073ae90
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 38 deletions.
16 changes: 8 additions & 8 deletions esp/services/ws_logaccess/WsLogAccessService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,10 @@ ILogAccessFilter * buildBinaryLogFilter(IConstBinaryLogFilter * binaryfilter)
if (!binaryfilter)
return nullptr;

ILogAccessFilter * leftFilter = nullptr;
Owned<ILogAccessFilter> leftFilter;
if (binaryfilter->getLeftBinaryFilter().ordinality() == 0)
{
leftFilter = buildLogFilter(&binaryfilter->getLeftFilter());
leftFilter.setown(buildLogFilter(&binaryfilter->getLeftFilter()));
}
else
{
Expand All @@ -221,7 +221,7 @@ ILogAccessFilter * buildBinaryLogFilter(IConstBinaryLogFilter * binaryfilter)
if (!isLogFilterEmpty(&binaryfilter->getLeftFilter()))
throw makeStringException(-1, "WsLogAccess: Cannot submit leftFilter and leftBinaryFilter!");

leftFilter = buildBinaryLogFilter(&binaryfilter->getLeftBinaryFilter().item(0));
leftFilter.setown(buildBinaryLogFilter(&binaryfilter->getLeftBinaryFilter().item(0)));
}

if (!leftFilter)
Expand All @@ -233,14 +233,14 @@ ILogAccessFilter * buildBinaryLogFilter(IConstBinaryLogFilter * binaryfilter)
case LogAccessFilterOperator_Undefined: //no operator found
//if (rightFilter != nullptr)
// WARNLOG("right FILTER ENCOUNTERED but no valid operator");
return leftFilter;
return leftFilter.getClear();
case CLogAccessFilterOperator_AND:
case CLogAccessFilterOperator_OR:
{
ILogAccessFilter * rightFilter = nullptr;
Owned<ILogAccessFilter> rightFilter;
if (binaryfilter->getRightBinaryFilter().ordinality() == 0)
{
rightFilter = buildLogFilter(&binaryfilter->getRightFilter());
rightFilter.setown(buildLogFilter(&binaryfilter->getRightFilter()));
}
else
{
Expand All @@ -250,13 +250,13 @@ ILogAccessFilter * buildBinaryLogFilter(IConstBinaryLogFilter * binaryfilter)
if (!isLogFilterEmpty(&binaryfilter->getRightFilter()))
throw makeStringException(-1, "WsLogAccess: Cannot submit rightFilter and rightBinaryFilter!");

rightFilter = buildBinaryLogFilter(&binaryfilter->getRightBinaryFilter().item(0));
rightFilter.setown(buildBinaryLogFilter(&binaryfilter->getRightBinaryFilter().item(0)));
}

if (!rightFilter)
throw makeStringExceptionV(-1, "WsLogAccess: Empty RIGHT filter encountered");

return getBinaryLogAccessFilterOwn(leftFilter, rightFilter, cLogAccessFilterOperator2LogAccessFilterType(binaryfilter->getOperator()));
return getBinaryLogAccessFilter(leftFilter, rightFilter, cLogAccessFilterOperator2LogAccessFilterType(binaryfilter->getOperator()));
}

default:
Expand Down
6 changes: 3 additions & 3 deletions esp/services/ws_workunits/ws_workunitsHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4270,9 +4270,9 @@ void CWsWuFileHelper::readWULogToFiles(IConstWorkUnit *cwu, WsWuInfo &winfo, con
ForEach(*iter)
{
const char *processName = iter->query().queryProp("@podName");
Owned<ILogAccessFilter> processLogFetchFilter(logFetchFilter.getLink()); // retain original for next iteration
compoundOwnedFilter(processLogFetchFilter, getPodLogAccessFilter(processName), LOGACCESS_FILTER_and);
zapLogFilterOptions.logFilter.logFetchOptions.setFilter(processLogFetchFilter.getClear());
Owned<ILogAccessFilter> podFilter(getPodLogAccessFilter(processName));
Owned<ILogAccessFilter> compoundFilter(getCompoundLogAccessFilter(logFetchFilter, podFilter, LOGACCESS_FILTER_and));
zapLogFilterOptions.logFilter.logFetchOptions.setFilter(compoundFilter.getClear());

VStringBuffer processLog("%s%c%s-%s-log.%s", path, PATHSEPCHAR, wuid, processName, logfileextension.str());
readWULogToFile(processLog, winfo, zapLogFilterOptions);
Expand Down
28 changes: 22 additions & 6 deletions esp/services/ws_workunits/ws_workunitsHelpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,18 +255,25 @@ struct WUComponentLogOptions
{
StringArray componentsFilter;
componentsFilter.appendList(componentsFilterList.str(), ",");
compoundOwnedFilter(logFetchFilter, getOredComponentsLogFilter(componentsFilter), LOGACCESS_FILTER_and);
Owned<ILogAccessFilter> filterClause = getOredComponentsLogFilter(componentsFilter);
logFetchFilter.setown(getCompoundLogAccessFilter(logFetchFilter, filterClause, LOGACCESS_FILTER_and));
}

StringBuffer logType; //"DIS","ERR","WRN","INF","PRO","MET","EVT","ALL"
zapHttpRequest->getParameter("LogFilter_LogEventType", logType);
if (!logType.isEmpty() && strcmp(logType.str(), "ALL") != 0)
compoundOwnedFilter(logFetchFilter, getClassLogAccessFilter(LogMsgClassFromAbbrev(logType.str())), LOGACCESS_FILTER_and);
{
Owned<ILogAccessFilter> filterClause(getClassLogAccessFilter(LogMsgClassFromAbbrev(logType.str())));
logFetchFilter.setown(getCompoundLogAccessFilter(logFetchFilter, filterClause, LOGACCESS_FILTER_and));
}

StringBuffer wildCharFilter;
zapHttpRequest->getParameter("LogFilter_WildcardFilter", wildCharFilter);
if (!wildCharFilter.isEmpty())
compoundOwnedFilter(logFetchFilter, getWildCardLogAccessFilter(wildCharFilter), LOGACCESS_FILTER_or);
{
Owned<ILogAccessFilter> filterClause(getWildCardLogAccessFilter(wildCharFilter.str()));
logFetchFilter.setown(getCompoundLogAccessFilter(logFetchFilter, filterClause, LOGACCESS_FILTER_or));
}

logFetchOptions.setFilter(logFetchFilter.getClear());

Expand Down Expand Up @@ -326,15 +333,24 @@ struct WUComponentLogOptions
logFetchOptions.setStartFrom(logFilterReq.getLineStartFrom());

if (logFilterReq.getComponentsFilter().length() > 0)
compoundOwnedFilter(logFetchFilter, getOredComponentsLogFilter(logFilterReq.getComponentsFilter()), LOGACCESS_FILTER_and);
{
Owned<ILogAccessFilter> filterClause = getOredComponentsLogFilter(logFilterReq.getComponentsFilter());
logFetchFilter.setown(getCompoundLogAccessFilter(logFetchFilter, filterClause, LOGACCESS_FILTER_and));
}

const char * logType = logFilterReq.getLogEventTypeAsString();
if (!isEmptyString(logType) && strcmp(logType,"ALL") != 0)
compoundOwnedFilter(logFetchFilter, getClassLogAccessFilter(LogMsgClassFromAbbrev(logType)), LOGACCESS_FILTER_and);
{
Owned<ILogAccessFilter> filterClause(getClassLogAccessFilter(LogMsgClassFromAbbrev(logType)));
logFetchFilter.setown(getCompoundLogAccessFilter(logFetchFilter, filterClause, LOGACCESS_FILTER_and));
}

const char * wildCharFilter = logFilterReq.getWildcardFilter();
if (!isEmptyString(wildCharFilter))
compoundOwnedFilter(logFetchFilter, getWildCardLogAccessFilter(wildCharFilter), LOGACCESS_FILTER_or);
{
Owned<ILogAccessFilter> filterClause(getWildCardLogAccessFilter(wildCharFilter));
logFetchFilter.setown(getCompoundLogAccessFilter(logFetchFilter, filterClause, LOGACCESS_FILTER_or));
}

logFetchOptions.setFilter(logFetchFilter.getClear());
CSortDirection espSortDirection = logFilterReq.getSortByTimeDirection();
Expand Down
11 changes: 6 additions & 5 deletions system/jlib/jlog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3158,12 +3158,13 @@ ILogAccessFilter * getBinaryLogAccessFilterOwn(ILogAccessFilter * arg1, ILogAcce
return ret;
}

void compoundOwnedFilter(Owned<ILogAccessFilter>& compoundFilter, ILogAccessFilter* extension, LogAccessFilterType operation)
ILogAccessFilter* getCompoundLogAccessFilter(ILogAccessFilter* arg1, ILogAccessFilter* arg2, LogAccessFilterType type)
{
if (!compoundFilter)
compoundFilter.setown(extension);
else if (extension)
compoundFilter.setown(getBinaryLogAccessFilterOwn(compoundFilter.getLink(), extension, operation));
if (!arg1)
return LINK(arg2);
if (!arg2)
return LINK(arg1);
return getBinaryLogAccessFilter(arg1, arg2, type);
}


Expand Down
17 changes: 1 addition & 16 deletions system/jlib/jlog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1705,26 +1705,11 @@ extern jlib_decl ILogAccessFilter * getAudienceLogAccessFilter(MessageAudience a
extern jlib_decl ILogAccessFilter * getClassLogAccessFilter(LogMsgClass logclass);
extern jlib_decl ILogAccessFilter * getBinaryLogAccessFilter(ILogAccessFilter * arg1, ILogAccessFilter * arg2, LogAccessFilterType type);
extern jlib_decl ILogAccessFilter * getBinaryLogAccessFilterOwn(ILogAccessFilter * arg1, ILogAccessFilter * arg2, LogAccessFilterType type);
extern jlib_decl ILogAccessFilter * getCompoundLogAccessFilter(ILogAccessFilter * arg1, ILogAccessFilter * arg2, LogAccessFilterType type);
extern jlib_decl ILogAccessFilter * getWildCardLogAccessFilter();
extern jlib_decl ILogAccessFilter * getWildCardLogAccessFilter(const char * wildcardfilter);
extern jlib_decl ILogAccessFilter * getColumnLogAccessFilter(const char * columnName, const char * value);

/**
* @brief Logically combine a new filter with an existing compound filter.
*
* Given an existing filter, an extension filter is logically combined with it based on a
* requested logical operation. The existing filter is replaced by the combined filter.
*
* If the existing filter is NULL, it is assigned to the extension. If the extension is NULL,
* the existing filter is unchanged.
*
* @param compoundFilter The existing filter to be logically combined with the extension.
* @param extension The new filter to be logically combined with the existing filter.
* Ownership of the given reference is transferred to the function.
* @param operation The logical operation to be performed on the existing and new filters.
*/
extern jlib_decl void compoundOwnedFilter(Owned<ILogAccessFilter> & compoundFilter, ILogAccessFilter * extension, LogAccessFilterType operation);

// Helper functions to actuate log access query
extern jlib_decl bool fetchLog(LogQueryResultDetails & resultDetails, StringBuffer & returnbuf, IRemoteLogAccess & logAccess, ILogAccessFilter * filter, LogAccessTimeRange timeRange, const StringArray & cols, LogAccessLogFormat format, unsigned int & totalReceived, unsigned int & totalAvailable);
extern jlib_decl bool fetchJobIDLog(LogQueryResultDetails & resultDetails, StringBuffer & returnbuf, IRemoteLogAccess & logAccess, const char *jobid, LogAccessTimeRange timeRange, StringArray & cols, LogAccessLogFormat format);
Expand Down

0 comments on commit 073ae90

Please sign in to comment.