Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HPCC-32874 Add WsLogAcces Health Report Method #19307

Open
wants to merge 2 commits into
base: candidate-9.8.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 50 additions & 1 deletion esp/scm/ws_logaccess.ecm
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,59 @@ ESPResponse GetLogsResponse
[min_ver("1.02")] unsigned int TotalLogLinesAvailable;
};

ESPservice [auth_feature("WsLogAccess:READ"), version("1.06"), default_client_version("1.06"), exceptions_inline("xslt/exceptions.xslt")] ws_logaccess
ESPRequest GetHealthReportRequest
{
bool IncludeConfiguration(false);
bool IncludeDebugReport(false);
bool IncludeSampleQuery(false);
};

ESPenum LogAccessStatusCode : int
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeclrsg this service can either provide a green/yellow/red type status, or more specific status codes as in the enum below. Let me know what you'd prefer.

{
Unknown(0, "Unknown"),
Green(1, "Green"),
Yellow(2, "Yellow"),
Red(3, "Red")
};

/*
ESPenum LogAccessStatusCode : int
{
NotConfigured(0, "NotConfigured"),
Misconfigured(1, "Misconfigured"),
FailedToConnect(2, "FailedToConnect"),
FailedToAuth(3, "FailedToAuth"),
FailedToQuery(4, "FailedToQuery"),
EmptyQueryResult(5, "EmptyQueryResult"),
Warned(6, "Warned"),
Failed(7, "Failed")
};*/

ESPStruct LogAccessStatus
{
LogAccessStatusCode Code;
LogAccessStatusCode Messages;
};

ESPStruct LogAccessDebugReport
{
string SampleQueryReport;
string PluginDebugReport;
string ServerDebugReport;
};

ESPResponse [exceptions_inline] GetHealthReportResponse
{
ESPStruct LogAccessStatus Status;
ESPStruct LogAccessDebugReport DebugReport;
string Configuration;
};

ESPservice [auth_feature("WsLogAccess:READ"), version("1.07"), default_client_version("1.07"), exceptions_inline("xslt/exceptions.xslt")] ws_logaccess
{
ESPmethod GetLogAccessInfo(GetLogAccessInfoRequest, GetLogAccessInfoResponse);
ESPmethod GetLogs(GetLogsRequest, GetLogsResponse);
ESPmethod [min_ver("1.07")] GetHealthReport(GetHealthReportRequest, GetHealthReportResponse);
};

SCMexportdef(ws_logaccess);
Expand Down
49 changes: 49 additions & 0 deletions esp/services/ws_logaccess/WsLogAccessService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,3 +385,52 @@ bool Cws_logaccessEx::onGetLogs(IEspContext &context, IEspGetLogsRequest &req, I

return true;
}

bool Cws_logaccessEx::onGetHealthReport(IEspContext &context, IEspGetHealthReportRequest &req, IEspGetHealthReportResponse &resp)
{
IEspLogAccessStatus * status = createLogAccessStatus("","");

StringBuffer report;
LogAccessHealthReportDetails reportDetails;
LogAccessHealthReportOptions options;
options.IncludeConfiguration = req.getIncludeConfiguration();
options.IncludeDebugReport = req.getIncludeDebugReport();
options.IncludeSampleQuery = req.getIncludeSampleQuery();

if (!queryRemoteLogAccessor())
{
status->setCode("Red");
status->setMessages("Configuration Error - LogAccess plugin not available, review logAccess configuration!");
}
else
{
IEspLogAccessDebugReport * debugReport = createLogAccessDebugReport();
queryRemoteLogAccessor()->healthReport(options, reportDetails);
status->setCode(LogAccessHealthStatusToString(reportDetails.status.code));
VStringBuffer encapsulatedMessages("{%s}", reportDetails.status.message.str());
status->setMessages(encapsulatedMessages.str());

if (options.IncludeConfiguration)
{
resp.setConfiguration(reportDetails.Configuration.str());
DBGLOG("WsLogAccessHealth: configuration: %s", reportDetails.Configuration.str());
}

if (options.IncludeSampleQuery)
{
debugReport->setSampleQueryReport(reportDetails.DebugReport.SampleQueryReport.str());
}

if (options.IncludeDebugReport)
{
debugReport->setPluginDebugReport(reportDetails.DebugReport.PluginDebugReport.str());
debugReport->setServerDebugReport(reportDetails.DebugReport.ServerDebugReport.str());
}

resp.setDebugReport(*debugReport);
}

resp.setStatus(*status);

return true;
}
1 change: 1 addition & 0 deletions esp/services/ws_logaccess/WsLogAccessService.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Cws_logaccessEx : public Cws_logaccess
virtual ~Cws_logaccessEx();
virtual bool onGetLogAccessInfo(IEspContext &context, IEspGetLogAccessInfoRequest &req, IEspGetLogAccessInfoResponse &resp);
virtual bool onGetLogs(IEspContext &context, IEspGetLogsRequest &req, IEspGetLogsResponse & resp);
virtual bool onGetHealthReport(IEspContext &context, IEspGetHealthReportRequest &req, IEspGetHealthReportResponse &resp);
};

#endif
100 changes: 99 additions & 1 deletion system/jlib/jlog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1500,9 +1500,44 @@ enum LogAccessMappedField
LOGACCESS_MAPPEDFIELD_host,
LOGACCESS_MAPPEDFIELD_traceid,
LOGACCESS_MAPPEDFIELD_spanid,
LOGACCESS_MAPPEDFIELD_global,
LOGACCESS_MAPPEDFIELD_container,
LOGACCESS_MAPPEDFIELD_message,
LOGACCESS_MAPPEDFIELD_unmapped
};

inline const char * MappedFieldTypeToString(LogAccessMappedField mappedField)
{
if (mappedField == LOGACCESS_MAPPEDFIELD_timestamp)
return "timestamp";
else if (mappedField == LOGACCESS_MAPPEDFIELD_jobid)
return "jobid";
else if (mappedField == LOGACCESS_MAPPEDFIELD_component)
return "component";
else if (mappedField == LOGACCESS_MAPPEDFIELD_class)
return "class";
else if (mappedField == LOGACCESS_MAPPEDFIELD_audience)
return "audience";
else if (mappedField == LOGACCESS_MAPPEDFIELD_instance)
return "instance";
else if (mappedField == LOGACCESS_MAPPEDFIELD_pod)
return "pod";
else if (mappedField == LOGACCESS_MAPPEDFIELD_host)
return "host";
else if (mappedField == LOGACCESS_MAPPEDFIELD_traceid)
return "traceID";
else if (mappedField == LOGACCESS_MAPPEDFIELD_spanid)
return "spanID";
else if (mappedField == LOGACCESS_MAPPEDFIELD_global)
return "global";
else if (mappedField == LOGACCESS_MAPPEDFIELD_container)
return "container";
else if (mappedField == LOGACCESS_MAPPEDFIELD_message)
return "message";
else
return "UNKNOWNFIELDTYPE";
}

enum SortByDirection
{
SORTBY_DIRECTION_none,
Expand Down Expand Up @@ -1676,6 +1711,68 @@ struct LogQueryResultDetails
unsigned int totalAvailable;
};


typedef enum
{
LOGACCESS_STATUS_unknown = 0,
LOGACCESS_STATUS_green = 1,
LOGACCESS_STATUS_yellow = 2,
LOGACCESS_STATUS_red = 3
} LogAccessHealthStatusCode;

struct LogAccessHealthStatus
{
LogAccessHealthStatusCode code;
StringBuffer message;

LogAccessHealthStatus(LogAccessHealthStatusCode code_)
{
code = code_;
}

void appendMessage(const char * message_)
{
message.append(message_);
}
};


inline const char * LogAccessHealthStatusToString(LogAccessHealthStatusCode statusCode)
{
switch(statusCode)
{
case LOGACCESS_STATUS_green:
return "Green";
case LOGACCESS_STATUS_yellow:
return "Yellow";
case LOGACCESS_STATUS_red:
return "Red";
default:
return "Unknown";
}
};

struct LogAccessDebugReport
{
StringBuffer SampleQueryReport;
StringBuffer PluginDebugReport;
StringBuffer ServerDebugReport;
};

struct LogAccessHealthReportDetails
{
LogAccessHealthStatus status = LOGACCESS_STATUS_unknown;
LogAccessDebugReport DebugReport;
StringAttr Configuration;
};

struct LogAccessHealthReportOptions
{
bool IncludeConfiguration = true;
bool IncludeDebugReport = true;
bool IncludeSampleQuery = true;
};

// Log Access Interface - Provides filtered access to persistent logging - independent of the log storage mechanism
// -- Declares method to retrieve log entries based on options set
// -- Declares method to retrieve remote log access type (eg elasticstack, etc)
Expand All @@ -1690,6 +1787,7 @@ interface IRemoteLogAccess : extends IInterface
virtual IPropertyTree * queryLogMap() const = 0;
virtual const char * fetchConnectionStr() const = 0;
virtual bool supportsResultPaging() const = 0;
virtual void healthReport(LogAccessHealthReportOptions options, LogAccessHealthReportDetails & report) = 0;
};

// Helper functions to construct log access filters
Expand All @@ -1714,7 +1812,7 @@ extern jlib_decl bool fetchLog(LogQueryResultDetails & resultDetails, StringBuff
extern jlib_decl bool fetchJobIDLog(LogQueryResultDetails & resultDetails, StringBuffer & returnbuf, IRemoteLogAccess & logAccess, const char *jobid, LogAccessTimeRange timeRange, StringArray & cols, LogAccessLogFormat format);
extern jlib_decl bool fetchComponentLog(LogQueryResultDetails & resultDetails, StringBuffer & returnbuf, IRemoteLogAccess & logAccess, const char * component, LogAccessTimeRange timeRange, StringArray & cols, LogAccessLogFormat format);
extern jlib_decl bool fetchLogByAudience(LogQueryResultDetails & resultDetails, StringBuffer & returnbuf, IRemoteLogAccess & logAccess, MessageAudience audience, LogAccessTimeRange timeRange, StringArray & cols, LogAccessLogFormat format);
extern jlib_decl bool fetchLogByClass(LogQueryResultDetails & resultDetails, StringBuffer & returnbuf, IRemoteLogAccess & logAccess, LogMsgClass logclass, LogAccessTimeRange timeRange, StringArray & cols, LogAccessLogFormat format);
extern jlib_decl bool fetchLogByClass(LogQueryResultDetails & resultDetails, StringBuffer & returnbuf, IRemoteLogAccess & logAccess, LogMsgClass logclass, LogAccessTimeRange timeRange, StringArray & cols, LogAccessLogFormat format);
extern jlib_decl IRemoteLogAccess * queryRemoteLogAccessor();

#endif
Loading
Loading