Skip to content

Commit

Permalink
HPCC-32874 Code review 1
Browse files Browse the repository at this point in the history
- Adds ESP respons structure
- Introduces top level gree/yellow/red status concept
- Introduces jlog structs to help status reporting
- Utilizes JSON appending/encoding functionality
- Various other minor changes

Signed-off-by: Rodrigo Pastrana <[email protected]>
  • Loading branch information
rpastrana committed Dec 20, 2024
1 parent f77d122 commit ffa9cca
Show file tree
Hide file tree
Showing 10 changed files with 303 additions and 202 deletions.
46 changes: 41 additions & 5 deletions esp/scm/ws_logaccess.ecm
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,50 @@ ESPResponse GetLogsResponse

ESPRequest GetHealthReportRequest
{
bool IncludeServerInternals(true);
bool IncludePluginInternals(true);
bool IncludeSampleQuery(true);
bool IncludeConfiguration(false);
bool IncludeDebugReport(false);
bool IncludeSampleQuery(false);
};

ESPResponse GetHealthReportResponse
ESPenum LogAccessStatusCode : int
{
string Report;
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
Expand Down
48 changes: 35 additions & 13 deletions esp/services/ws_logaccess/WsLogAccessService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,27 +388,49 @@ bool Cws_logaccessEx::onGetLogs(IEspContext &context, IEspGetLogsRequest &req, I

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

StringBuffer report;
//LogAccessHealthReportDetails reportDetails;
LogAccessHealthReportDetails reportDetails;
LogAccessHealthReportOptions options;
options.IncludeServerInternals = req.getIncludeServerInternals();
options.IncludePluginInternals = req.getIncludePluginInternals();
options.IncludeConfiguration = req.getIncludeConfiguration();
options.IncludeDebugReport = req.getIncludeDebugReport();
options.IncludeSampleQuery = req.getIncludeSampleQuery();

report.set("{ ");
bool success = true;
if (!queryRemoteLogAccessor())
{
report.append("\"Error\": \"LogAccess plugin not available, review logAccess configuration!\"");
success = false;
status->setCode("Red");
status->setMessages("Configuration Error - LogAccess plugin not available, review logAccess configuration!");
}
else
{
//queryRemoteLogAccessor()->healthReport(report, reportDetails);
queryRemoteLogAccessor()->healthReport(report, options);
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);
}
report.append(" }");
resp.setReport(report.str());

return success;
}
resp.setStatus(*status);

return true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ global:
id: "1"
name: "Loki"
namespace:
name: "default"
name: "hpcc"
logFormat:
type: "json"
logMaps:
Expand Down
115 changes: 38 additions & 77 deletions system/jlib/jlog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1710,104 +1710,66 @@ struct LogQueryResultDetails
unsigned int totalReceived;
unsigned int totalAvailable;
};
/*


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

struct LogAccessConnectionDetails
struct LogAccessHealthStatus
{
StringAttr connectionString;
StringAttr connectionInfo;
StringAttr connectionStatus;
StringAttr sampleQueryStatus;
void toJSON(StringBuffer & out)
{
}
};
LogAccessHealthStatusCode code;
StringBuffer message;

struct LogAccessConfigLogMap
{
LogAccessMappedField logFieldType;
StringAttr fieldName;
StringAttr sourceName;
LogAccessConfigLogMap(LogAccessMappedField type, const char * name, const char * source)
LogAccessHealthStatus(LogAccessHealthStatusCode code_)
{
logFieldType = type;
fieldName.set(name);
sourceName.set(source);
code = code_;
}

void toJSON(StringBuffer & out)
void appendMessage(const char * message_)
{
out.appendf("\"%s\": { \"ColName\": \"%s\", \"Source\": \"%s\" }", MappedFieldTypeToString(logFieldType), fieldName.str(), sourceName.str());
message.append(message_);
}
};

struct LogAccessConfigDetails
{
StringAttr connectionInfo;
StringArray logMaps;
//IArrayOf<LogAccessConfigLogMap> logMaps;

void appendLogMap(LogAccessConfigLogMap logMap)
inline const char * LogAccessHealthStatusToString(LogAccessHealthStatusCode statusCode)
{
switch(statusCode)
{
StringBuffer logMapJson;
logMap.toJSON(logMapJson);
logMaps.append(logMapJson.str());
//logMaps.append(logMap);
case LOGACCESS_STATUS_green:
return "Green";
case LOGACCESS_STATUS_yellow:
return "Yellow";
case LOGACCESS_STATUS_red:
return "Red";
default:
return "Unknown";
}
};

void toJSON(StringBuffer & out)
{
out.appendf("\"ConfigInfo\": { \"LogMaps\": {");
ForEachItemIn(i, logMaps)
//logMaps.item(i).toJSON(out);
out.append(logMaps.item(i));
//close out the logmaps
out.append(" }");
//close out the ConfigInfo
out.append(" }");
}
struct LogAccessDebugReport
{
StringBuffer SampleQueryReport;
StringBuffer PluginDebugReport;
StringBuffer ServerDebugReport;
};

struct LogAccessHealthReportDetails
{
LogAccessConnectionDetails connectionInfo;
LogAccessConfigDetails configInfo;
StringBuffer JsonMessages;
void appendLogMap(LogAccessConfigLogMap logMap)
{
configInfo.appendLogMap(logMap);
}
void toJSON(StringBuffer & out)
{
StringBuffer scratch;
out.append("{ \"Connection\": ");
connectionInfo.toJSON(scratch);
out.append(scratch.str());
out.append(", \"ConfigInfo\": ");
configInfo.toJSON(scratch.clear());
out.append(scratch.str());
out.appendf(", \"Messages\": \"%s\"", JsonMessages.str());
}
LogAccessHealthStatus status = LOGACCESS_STATUS_unknown;
LogAccessDebugReport DebugReport;
StringAttr Configuration;
};
*/

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

Expand All @@ -1825,8 +1787,7 @@ interface IRemoteLogAccess : extends IInterface
virtual IPropertyTree * queryLogMap() const = 0;
virtual const char * fetchConnectionStr() const = 0;
virtual bool supportsResultPaging() const = 0;
//virtual bool healthReport(StringBuffer & messages, LogAccessHealthReportDetails & report) = 0;
virtual bool healthReport(StringBuffer & report, LogAccessHealthReportOptions options) = 0;
virtual void healthReport(LogAccessHealthReportOptions options, LogAccessHealthReportDetails & report) = 0;
};

// Helper functions to construct log access filters
Expand Down
Loading

0 comments on commit ffa9cca

Please sign in to comment.