Skip to content

Commit

Permalink
HPCC-32874 Code review 3
Browse files Browse the repository at this point in the history
- Changed status codes to success/warning/fail
- Updated All logaccess clients

Signed-off-by: Rodrigo Pastrana <[email protected]>
  • Loading branch information
rpastrana committed Jan 16, 2025
1 parent cb468b2 commit 50ec547
Show file tree
Hide file tree
Showing 4 changed files with 547 additions and 274 deletions.
43 changes: 39 additions & 4 deletions system/jlib/jlog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1721,20 +1721,55 @@ typedef enum

struct LogAccessHealthStatus
{
private:
LogAccessHealthStatusCode code;
StringBuffer message;
StringBuffer messages;
bool hasMessage = false;

public:
LogAccessHealthStatus(LogAccessHealthStatusCode code_)
{
code = code_;
}

void appendMessage(const char * message_)
void appendJSONListMessage(const char * newMessage)
{
message.append(message_);
if (!isEmptyString(newMessage))
{
if (hasMessage)
messages.append(", ");
else
hasMessage = true;

messages.append("\"");
encodeJSON(messages, newMessage);
messages.append("\"");
}
}
};

void toJSONMessageList(StringBuffer & out)
{
out.appendf("\"message\": [ %s ]", messages.str());
}

/*void toJSONMessageList(StringBuffer & out, const char * name)
{
if (!isEmptyString(name))
out.appendf("\"%s\": [ %s ]", message.str());
}*/

bool escalateStatusCode(LogAccessHealthStatusCode newCode)
{
if (newCode <= code) //Takes advantage of enum value assignment
return false; //not escalated
else
code = newCode;

return true; //escalated
}

LogAccessHealthStatusCode getCode() const {return code;}
};

inline const char * LogAccessHealthStatusToString(LogAccessHealthStatusCode statusCode)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1096,28 +1096,69 @@ void AzureLogAnalyticsCurlClient::healthReport(LogAccessHealthReportOptions opti
LogAccessHealthStatus status = LOGACCESS_STATUS_unknown;
try
{
if (options.IncludeConfiguration)
{
StringBuffer configuration;
configuration.set("{");
StringBuffer configuration;
configuration.set("{");

if (m_pluginCfg)
if (m_pluginCfg)
{
if (options.IncludeConfiguration)
{
StringBuffer configJSON;
toJSON(m_pluginCfg, configJSON, 0, JSON_Format);
appendJSONStringValue(configuration, "ConfigurationTree", configJSON.str(), false);
}
else
{
status = LOGACCESS_STATUS_fail;
appendJSONStringValue(status.message, "Message", "ALA Pluging Configuration tree is empty!!!", false);
}
}
else
{
status.escalateStatusCode(LOGACCESS_STATUS_fail);
status.appendJSONListMessage("ALA Pluging Configuration tree is empty!!!");
}

configuration.append(" }"); // close config info
report.Configuration.set(configuration.str()); //empty if !(options.IncludeConfiguration)

if (m_logAnalyticsWorkspaceID.length() == 0)
{
status.appendJSONListMessage("Target Azure Log Analytics workspace ID is empty!");
status.escalateStatusCode(LOGACCESS_STATUS_fail);
}

configuration.append(" }"); // close config info
report.Configuration.set(configuration.str());
if (m_aadTenantID.length() == 0)
{
status.appendJSONListMessage("Target Azure Tenant ID is empty!");
status.escalateStatusCode(LOGACCESS_STATUS_fail);
}

if (m_aadClientID.length() == 0)
{
status.appendJSONListMessage("Target Azure Log Analytics Client Application ID is empty!");
status.escalateStatusCode(LOGACCESS_STATUS_fail);
}

if (m_aadClientSecret.length()==0)
{
status.appendJSONListMessage("Target Azure Log Analytics Client Secret is empty!");
status.escalateStatusCode(LOGACCESS_STATUS_fail);
}

if (!m_disableComponentNameJoins)
{
status.appendJSONListMessage("Costly query joins used to fetch component names are enabled!");
status.escalateStatusCode(LOGACCESS_STATUS_warning);
}

if (!m_blobMode)
{
status.appendJSONListMessage("Blob mode not enabled, slow server response is likely");
status.escalateStatusCode(LOGACCESS_STATUS_warning);
}

if (!targetIsContainerLogV2)
{
status.appendJSONListMessage("Azure Log Analytics container schema V1 enabled, V2 is recommended");
status.escalateStatusCode(LOGACCESS_STATUS_warning);
}

if (options.IncludeDebugReport)
{
StringBuffer debugReport;
debugReport.set("{");
Expand Down Expand Up @@ -1180,13 +1221,13 @@ void AzureLogAnalyticsCurlClient::healthReport(LogAccessHealthReportOptions opti
debugReport.append(" }"); //close logmaps

debugReport.append(" }"); //close debugreport
report.DebugReport.PluginDebugReport.set(debugReport);
report.DebugReport.ServerDebugReport.set("{}");

appendJSONStringValue(status.message, "Message", "ALA Debug report succeeded", false);
if (options.IncludeDebugReport)
{
report.DebugReport.PluginDebugReport.set(debugReport);
report.DebugReport.ServerDebugReport.set("{}");
}
}

if (options.IncludeSampleQuery)
{
StringBuffer sampleQueryReport;
sampleQueryReport.append("{ \"SampleTokenRequest\": { ");
Expand All @@ -1199,15 +1240,15 @@ void AzureLogAnalyticsCurlClient::healthReport(LogAccessHealthReportOptions opti
}
catch(IException * e)
{
StringBuffer description;
VStringBuffer description("Exception while requesting sample token (%d) - ", e->errorCode());
e->errorMessage(description);
status = LOGACCESS_STATUS_fail;
appendJSONStringValue(status.message, "Result", "Exception while requesting sample token (%d) - %s", e->errorCode(), description.str());
status.appendJSONListMessage(description.str());
e->Release();
}
catch(...)
{
appendJSONStringValue(status.message, "Message", "Unknown exception while requesting sample token", false);
status.appendJSONListMessage("Unknown exception while requesting sample token");
status = LOGACCESS_STATUS_fail;
}
sampleQueryReport.append(" }"); //close sample token request
Expand Down Expand Up @@ -1255,33 +1296,34 @@ void AzureLogAnalyticsCurlClient::healthReport(LogAccessHealthReportOptions opti
if (resultDetails.totalReceived==0)
{
status = LOGACCESS_STATUS_warning;
appendJSONStringValue(status.message, "Message", "Query succeeded but returned 0 log entries", false);
status.appendJSONListMessage("Query succeeded but returned 0 log entries");
}

appendJSONStringValue(sampleQueryReport, "Results", logs.str(), true);
}
catch(IException * e)
{
StringBuffer description;
VStringBuffer description("Exception while executing sample ALA query (%d) - ", e->errorCode());
e->errorMessage(description);
status = LOGACCESS_STATUS_fail;
status.message.appendf("%s{\"Message\": \"Exception while executing sample ALA query (%d) - %s\"", status.message.length() == 0 ? "" : ", ", e->errorCode(), description.str());
status.appendJSONListMessage(description.str());
e->Release();
}
catch(...)
{
appendJSONStringValue(status.message, "Message", "Unknown exception while executing sample ALA query", false);
status.appendJSONListMessage("Unknown exception while executing sample ALA query");
status = LOGACCESS_STATUS_fail;
}
sampleQueryReport.append(" }"); //close sample query

report.DebugReport.SampleQueryReport.set(sampleQueryReport);
if (options.IncludeSampleQuery)
report.DebugReport.SampleQueryReport.set(sampleQueryReport);
}
}
catch(...)
{
status = LOGACCESS_STATUS_fail;
appendJSONStringValue(status.message, "Message", "Encountered unexpected exception during health report", false);
status.appendJSONListMessage("Encountered unexpected exception during health report");
}

report.status = status;
Expand Down
Loading

0 comments on commit 50ec547

Please sign in to comment.