Skip to content

Commit

Permalink
Log topology generation failures with content aware severity
Browse files Browse the repository at this point in the history
  • Loading branch information
rbx committed Apr 9, 2024
1 parent 7e7962f commit ced929f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
20 changes: 18 additions & 2 deletions odc/Controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <boost/process.hpp>

#include <algorithm>
#include <cctype> // std::tolower
#include <filesystem>

using namespace odc;
Expand Down Expand Up @@ -1314,12 +1315,26 @@ void Controller::fillAndLogFatalError(const CommonParams& common, Error& error,
OLOG(fatal, common) << error.mDetails;
}

void Controller::logLineWarningOrDetectedSev(const CommonParams& common, const string& line)
{
string lowerCaseLine = line;
std::transform(lowerCaseLine.begin(), lowerCaseLine.end(), lowerCaseLine.begin(), [](unsigned char c){ return std::tolower(c); });

if (lowerCaseLine.find("fatal") != string::npos) {
OLOG(fatal, common) << line;
} else if (lowerCaseLine.find("error") != string::npos) {
OLOG(error, common) << line;
} else {
OLOG(warning, common) << line;
}
}

void Controller::logFatalLineByLine(const CommonParams& common, const string& msg)
{
stringstream ss(msg);
string line;
while (getline(ss, line, '\n')) {
OLOG(fatal, common) << line;
logLineWarningOrDetectedSev(common, line);
}
}

Expand Down Expand Up @@ -1494,7 +1509,8 @@ string Controller::topoFilepath(const CommonParams& common, const string& topolo
}

if (exitCode != EXIT_SUCCESS) {
logFatalLineByLine(common, toString("Topology generation script failed with exit code: ", exitCode, ", stderr:\n", quoted(err), ",\nstdout:\n", quoted(shortOut), shortSuffix));
OLOG(fatal, common) << "Topology generation script failed with exit code: " << exitCode;
logFatalLineByLine(common, toString(", stderr:\n", quoted(err), ",\nstdout:\n", quoted(shortOut), shortSuffix));
throw runtime_error(toString("Topology generation script failed with exit code: ", exitCode, ", stderr: ", quoted(err)));
}

Expand Down
1 change: 1 addition & 0 deletions odc/Controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ class Controller
void fillAndLogFatalError( const CommonParams& common, Error& error, ErrorCode errorCode, const std::string& msg);
void fillAndLogFatalErrorLineByLine(const CommonParams& common, Error& error, ErrorCode errorCode, const std::string& msg);
void logFatalLineByLine( const CommonParams& common, const std::string& msg);
void logLineWarningOrDetectedSev( const CommonParams& common, const std::string& line);

RequestResult createRequestResult(const CommonParams& common, const Session& session, const Error& error, const std::string& msg, TopologyState&& topologyState, const std::unordered_set<std::string>& hosts);
RequestResult createRequestResult(const CommonParams& common, const std::string& sessionId, const Error& error, const std::string& msg, TopologyState&& topologyState, const std::unordered_set<std::string>& hosts);
Expand Down

0 comments on commit ced929f

Please sign in to comment.