Skip to content
Snippets Groups Projects
Commit d94a31db authored by Matthew Andrew's avatar Matthew Andrew
Browse files

Re #21709 Added uptime and renamed to errorreporter

parent 3541dc60
No related branches found
No related tags found
No related merge requests found
......@@ -15,7 +15,6 @@ set ( SRC_FILES
src/ConfigService.cpp
src/ConfigObserver.cpp
src/ConfigPropertyObserver.cpp
src/CrashService.cpp
src/DateAndTime.cpp
src/DataItem.cpp
src/DateAndTimeHelpers.cpp
......@@ -30,6 +29,7 @@ set ( SRC_FILES
src/EnabledWhenProperty.cpp
src/EnvironmentHistory.cpp
src/EqualBinsChecker.cpp
src/ErrorReporter.cpp
src/Exception.cpp
src/FacilityInfo.cpp
src/FileDescriptor.cpp
......@@ -167,7 +167,6 @@ set ( INC_FILES
inc/MantidKernel/ConfigService.h
inc/MantidKernel/ConfigObserver.h
inc/MantidKernel/ConfigPropertyObserver.h
inc/MantidKernel/CrashService.h
inc/MantidKernel/DateAndTime.h
inc/MantidKernel/DataItem.h
inc/MantidKernel/DataService.h
......@@ -186,6 +185,7 @@ set ( INC_FILES
inc/MantidKernel/EmptyValues.h
inc/MantidKernel/EnabledWhenProperty.h
inc/MantidKernel/EnvironmentHistory.h
inc/MantidKernel/ErrorReporter.h
inc/MantidKernel/EqualBinsChecker.h
inc/MantidKernel/Exception.h
inc/MantidKernel/FacilityInfo.h
......@@ -342,7 +342,6 @@ set ( TEST_FILES
ConfigServiceTest.h
ConfigObserverTest.h
ConfigPropertyObserverTest.h
CrashServiceTest.h
CowPtrTest.h
DataServiceTest.h
DateAndTimeHelpersTest.h
......@@ -358,6 +357,7 @@ set ( TEST_FILES
EigenConversionHelpersTest.h
EnabledWhenPropertyTest.h
EnvironmentHistoryTest.h
ErrorReporterTest.h
EqualBinsCheckerTest.h
FacilitiesTest.h
FileDescriptorTest.h
......
#ifndef MANTID_KERNEL_CRASHSERVICE_H_
#define MANTID_KERNEL_CRASHSERVICE_H_
#ifndef MANTID_KERNEL_ERRORSERVICE_H_
#define MANTID_KERNEL_ERRORSERVICE_H_
#ifndef Q_MOC_RUN
#include <boost/date_time/posix_time/posix_time.hpp>
#endif
#include <string>
#include <Poco/ActiveMethod.h>
#include "MantidKernel/DateAndTime.h"
#include "MantidKernel/DllConfig.h"
namespace Mantid {
namespace Kernel {
/** CrashReporter : The Crash reporter is responsible for sending crash reports
/** ErrorReporter : The error reporter is responsible for sending error reports
Copyright &copy; 2015 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge
National Laboratory & European Spallation Source
......@@ -33,26 +37,26 @@ namespace Kernel {
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class MANTID_KERNEL_DLL CrashServiceImpl {
class MANTID_KERNEL_DLL ErrorReporter {
public:
CrashServiceImpl(std::string application);
CrashServiceImpl(std::string application, std::string startTime);
void sendCrashReport();
ErrorReporter(std::string application);
ErrorReporter(std::string application, Types::Core::time_duration startTime);
void sendErrorReport();
protected:
virtual std::string generateCrashMessage();
virtual std::string generateErrorMessage();
virtual int sendReport(const std::string &message,
const std::string &url);
private:
int sendCrashAsyncImpl(const std::string &message);
int sendErrorAsyncImpl(const std::string &message);
const std::string m_application;
const std::string m_startTime;
Types::Core::time_duration m_upTime;
/// Async method for sending startup notifications
Poco::ActiveMethod<int, std::string, CrashServiceImpl> m_crashActiveMethod;
Poco::ActiveMethod<int, std::string, ErrorReporter> m_errorActiveMethod;
};
} // namespace Kernel
} // namespace Mantid
#endif /* MANTID_KERNEL_CRASHSERVICE_H_ */
\ No newline at end of file
#endif /* MANTID_KERNEL_ERRORSERVICE_H_ */
\ No newline at end of file
#ifndef MANTID_KERNEL_USAGESERVICE_H_
#define MANTID_KERNEL_USAGESERVICE_H_
#include "MantidKernel/DateAndTime.h"
#include "MantidKernel/DllConfig.h"
#include "MantidKernel/SingletonHolder.h"
#ifndef Q_MOC_RUN
#include <boost/date_time/posix_time/posix_time.hpp>
#endif
#include <json/value.h>
#include <Poco/ActiveMethod.h>
......@@ -85,7 +89,7 @@ public:
void flush();
void shutdown();
/// gets the uptime of this mantid instance
std::string getStartTime();
Types::Core::time_duration getUpTime();
protected:
/// Constructor
......@@ -133,7 +137,7 @@ private:
bool m_isEnabled;
mutable std::mutex m_mutex;
std::string m_application;
std::string m_startTime;
Types::Core::DateAndTime m_startTime;
/// Async method for sending startup notifications
Poco::ActiveMethod<int, std::string, UsageServiceImpl> m_startupActiveMethod;
......
#include "MantidKernel/CrashService.h"
#include "MantidKernel/ErrorReporter.h"
#include "MantidKernel/ChecksumHelper.h"
#include "MantidKernel/ConfigService.h"
#include "MantidKernel/DateAndTime.h"
......@@ -18,33 +18,36 @@ namespace Kernel {
namespace {
/// static logger
Logger g_log("CrashServiceImpl");
Logger g_log("ErrorReporter");
}
const std::string CRASH_URL("http://crashreports.mantidproject.org/api/crash");
const std::string ERROR_URL("http://errorreports.mantidproject.org/api/error");
// const std::string STARTUP_URL(
// "http://posttestserver.com/post.php?dir=Mantid"); // dev location
// http://posttestserver.com/data/
//----------------------------------------------------------------------------------------------
// Constructor for CrashServiceImpl
CrashServiceImpl::CrashServiceImpl(std::string application)
: m_application(application), m_startTime(""), m_crashActiveMethod(this, &CrashServiceImpl::sendCrashAsyncImpl) {}
// Constructor for ErrorReporter
ErrorReporter::ErrorReporter(std::string application)
: m_application(application), m_errorActiveMethod(this, &ErrorReporter::sendErrorAsyncImpl) {
Types::Core::time_duration upTime(0,0,0,0);
m_upTime = upTime;
}
CrashServiceImpl::CrashServiceImpl(std::string application, std::string startTime)
: m_application(application), m_startTime(startTime), m_crashActiveMethod(this, &CrashServiceImpl::sendCrashAsyncImpl) {}
ErrorReporter::ErrorReporter(std::string application, Types::Core::time_duration startTime)
: m_application(application), m_upTime(startTime), m_errorActiveMethod(this, &ErrorReporter::sendErrorAsyncImpl) {}
void CrashServiceImpl::sendCrashReport() {
void ErrorReporter::sendErrorReport() {
try {
std::string message = this->generateCrashMessage();
std::string message = this->generateErrorMessage();
// send the report
Poco::ActiveResult<int> result = m_crashActiveMethod(message);
Poco::ActiveResult<int> result = m_errorActiveMethod(message);
} catch (std::exception &ex) {
g_log.debug() << "Send crash report failure. " << ex.what() << '\n';
g_log.debug() << "Send error report failure. " << ex.what() << '\n';
}
}
std::string CrashServiceImpl::generateCrashMessage() {
std::string ErrorReporter::generateErrorMessage() {
::Json::Value message;
// username
......@@ -74,7 +77,7 @@ std::string CrashServiceImpl::generateCrashMessage() {
message["dateTime"] =
Types::Core::DateAndTime::getCurrentTime().toISO8601String();
message["startTime"] = m_startTime;
message["upTime"] = to_iso_string(m_upTime);
message["application"] = m_application;
......@@ -84,11 +87,11 @@ std::string CrashServiceImpl::generateCrashMessage() {
return writer.write(message);
}
int CrashServiceImpl::sendCrashAsyncImpl(const std::string &message) {
return this->sendReport(message, CRASH_URL);
int ErrorReporter::sendErrorAsyncImpl(const std::string &message) {
return this->sendReport(message, ERROR_URL);
}
int CrashServiceImpl::sendReport(const std::string &message,
int ErrorReporter::sendReport(const std::string &message,
const std::string &url) {
int status = -1;
try {
......
......@@ -131,8 +131,8 @@ void UsageServiceImpl::flush() {
}
}
std::string UsageServiceImpl::getStartTime() {
return m_startTime;
Types::Core::time_duration UsageServiceImpl::getUpTime() {
return Types::Core::DateAndTime::getCurrentTime() - m_startTime;
}
void UsageServiceImpl::shutdown() {
......@@ -149,7 +149,7 @@ void UsageServiceImpl::shutdown() {
void UsageServiceImpl::sendStartupReport() {
try {
m_startTime = Types::Core::DateAndTime::getCurrentTime().toISO8601String();
m_startTime = Types::Core::DateAndTime::getCurrentTime();
std::string message = this->generateStartupMessage();
// send the report
Poco::ActiveResult<int> result = m_startupActiveMethod(message);
......@@ -231,7 +231,7 @@ std::string UsageServiceImpl::generateStartupMessage() {
message["mantidSha1"] = MantidVersion::revisionFull();
// mantid version and sha1
message["dateTime"] = m_startTime;
message["dateTime"] = m_startTime.toISO8601String();
message["application"] = m_application;
......
#ifndef MANTID_API_CRASHSERVICETEST_H_
#define MANTID_API_CRASHSERVICETEST_H_
#ifndef MANTID_API_ERRORSERVICETEST_H_
#define MANTID_API_ERRORSERVICETEST_H_
#include <cxxtest/TestSuite.h>
#include "MantidKernel/CrashService.h"
#include "MantidKernel/ErrorReporter.h"
#include <algorithm>
#include <json/json.h>
using Mantid::Kernel::CrashServiceImpl;
using Mantid::Kernel::ErrorReporter;
class TestableCrashService : public CrashServiceImpl {
class TestableErrorReporter : public ErrorReporter {
public:
//TestableCrashService() : CrashServiceImpl() {}
using CrashServiceImpl::CrashServiceImpl;
using ErrorReporter::ErrorReporter;
/// generates the message body for a crash message
std::string generateCrashMessage() override {
return CrashServiceImpl::generateCrashMessage();
/// generates the message body for a error message
std::string generateErrorMessage() override {
return ErrorReporter::generateErrorMessage();
}
protected:
......@@ -29,17 +28,18 @@ protected:
}
};
class CrashServiceTest : public CxxTest::TestSuite {
class ErrorReporterTest : public CxxTest::TestSuite {
public:
// This pair of boilerplate methods prevent the suite being created statically
// This means the constructor isn't called when running other tests
static CrashServiceTest *createSuite() { return new CrashServiceTest(); }
static void destroySuite(CrashServiceTest *suite) { delete suite; }
static ErrorReporterTest *createSuite() { return new ErrorReporterTest(); }
static void destroySuite(ErrorReporterTest *suite) { delete suite; }
void test_crashMessage() {
void test_errorMessage() {
std::string name = "My testing application name";
TestableCrashService crashService(name);
std::string message = crashService.generateCrashMessage();
Mantid::Types::Core::time_duration upTime(5,0,7,0);
TestableErrorReporter errorService(name, upTime);
std::string message = errorService.generateErrorMessage();
::Json::Reader reader;
::Json::Value root;
......@@ -47,7 +47,7 @@ public:
auto members = root.getMemberNames();
std::vector<std::string> expectedMembers{
"ParaView", "application", "host", "mantidSha1", "mantidVersion",
"osArch", "osName", "osReadable", "osVersion", "uid", "facility"};
"osArch", "osName", "osReadable", "osVersion", "uid", "facility", "upTime"};
for (auto expectedMember : expectedMembers) {
TSM_ASSERT(expectedMember + " not found",
std::find(members.begin(), members.end(), expectedMember) !=
......@@ -55,6 +55,7 @@ public:
}
TS_ASSERT_EQUALS(root["application"].asString(), name);
TS_ASSERT_EQUALS(root["upTime"].asString(), to_iso_string(upTime));
}
};
......
......@@ -5,7 +5,7 @@
#include "MantidQtWidgets/Common/MantidDialog.h"
#include "MantidKernel/ConfigService.h"
#include "MantidKernel/CrashService.h"
#include "MantidKernel/ErrorReporter.h"
#include "MantidKernel/Logger.h"
#include "MantidKernel/UsageService.h"
......@@ -42,8 +42,8 @@ bool MantidApplication::notify(QObject *receiver, QEvent *event) {
int reportingEnabled = 0;
int retVal = Mantid::Kernel::ConfigService::Instance().getValue("usagereports.enabled", reportingEnabled);
if (reportingEnabled && retVal == 1){
Mantid::Kernel::CrashServiceImpl crashService("mantidplot", Mantid::Kernel::UsageService::Instance().getStartTime());
crashService.sendCrashReport();
Mantid::Kernel::ErrorReporter errorReporter("mantidplot", Mantid::Kernel::UsageService::Instance().getUpTime());
errorReporter.sendErrorReport();
}
if (MantidQt::API::MantidDialog::handle(receiver, e))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment