Add getStateSummary method for diagnostics
Summary: Adds a more structured representation of state updates than a multiline string. Also changes the string form to omit [started] records. Reviewed By: danielbuechele Differential Revision: D9315503 fbshipit-source-id: 55b8f9572091fd42fe852c8d26a8f2a53f76c82a
This commit is contained in:
committed by
Facebook Github Bot
parent
e51b8c0742
commit
660da3f80e
@@ -12,6 +12,7 @@
|
||||
#include "SonarState.h"
|
||||
#include "SonarStep.h"
|
||||
#include "SonarWebSocketImpl.h"
|
||||
#include <vector>
|
||||
|
||||
#ifdef __ANDROID__
|
||||
#include <android/log.h>
|
||||
@@ -110,10 +111,8 @@ void SonarClient::refreshPlugins() {
|
||||
void SonarClient::onConnected() {
|
||||
SONAR_LOG("SonarClient::onConnected");
|
||||
|
||||
auto step = sonarState_->start("Connect");
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
connected_ = true;
|
||||
step->complete();
|
||||
}
|
||||
|
||||
void SonarClient::onDisconnected() {
|
||||
@@ -216,6 +215,10 @@ std::string SonarClient::getState() {
|
||||
return sonarState_->getState();
|
||||
}
|
||||
|
||||
std::vector<StateElement> SonarClient::getStateElements() {
|
||||
return sonarState_->getStateElements();
|
||||
}
|
||||
|
||||
} // namespace sonar
|
||||
} // namespace facebook
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include "SonarStep.h"
|
||||
#include <vector>
|
||||
|
||||
namespace facebook {
|
||||
namespace sonar {
|
||||
@@ -77,6 +78,8 @@ class SonarClient : public SonarWebSocket::Callbacks {
|
||||
|
||||
std::string getState();
|
||||
|
||||
std::vector<StateElement> getStateElements();
|
||||
|
||||
template <typename P>
|
||||
std::shared_ptr<P> getPlugin(const std::string& identifier) {
|
||||
return std::static_pointer_cast<P>(getPlugin(identifier));
|
||||
|
||||
@@ -8,34 +8,41 @@
|
||||
#include "SonarState.h"
|
||||
#include "SonarStateUpdateListener.h"
|
||||
#include "SonarStep.h"
|
||||
#include <vector>
|
||||
|
||||
using namespace facebook::sonar;
|
||||
|
||||
/* Class responsible for collecting state updates and combining them into a
|
||||
* view of the current state of the sonar client. */
|
||||
|
||||
SonarState::SonarState() {
|
||||
stateUpdates = "";
|
||||
}
|
||||
|
||||
SonarState::SonarState(): log("") {}
|
||||
void SonarState::setUpdateListener(
|
||||
std::shared_ptr<SonarStateUpdateListener> listener) {
|
||||
mListener = listener;
|
||||
}
|
||||
|
||||
void SonarState::started(std::string step) {
|
||||
stateUpdates = stateUpdates + "[Started] " + step + "\n";
|
||||
if (stateMap.find(step) == stateMap.end()) {
|
||||
insertOrder.push_back(step);
|
||||
}
|
||||
stateMap[step] = State::in_progress;
|
||||
if (mListener) {
|
||||
mListener->onUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
void SonarState::success(std::string step) {
|
||||
stateUpdates = stateUpdates + "[Success] " + step + "\n";
|
||||
log = log + "[Success] " + step + "\n";
|
||||
stateMap[step] = State::success;
|
||||
if (mListener) {
|
||||
mListener->onUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
void SonarState::failed(std::string step, std::string errorMessage) {
|
||||
stateUpdates = stateUpdates + "[Failed] " + step + "\n";
|
||||
log = log + "[Failed] " + step + "\n";
|
||||
stateMap[step] = State::failed;
|
||||
if (mListener) {
|
||||
mListener->onUpdate();
|
||||
}
|
||||
@@ -45,7 +52,15 @@ void SonarState::failed(std::string step, std::string errorMessage) {
|
||||
// representation of the current state so the UI can show it in a more intuitive
|
||||
// way
|
||||
std::string SonarState::getState() {
|
||||
return stateUpdates;
|
||||
return log;
|
||||
}
|
||||
|
||||
std::vector<StateElement> SonarState::getStateElements() {
|
||||
std::vector<StateElement> v;
|
||||
for (auto stepName : insertOrder) {
|
||||
v.push_back(StateElement(stepName, stateMap[stepName]));
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
std::shared_ptr<SonarStep> SonarState::start(std::string step_name) {
|
||||
|
||||
@@ -10,11 +10,27 @@
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <Sonar/SonarStep.h>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
class SonarStep;
|
||||
class SonarStateUpdateListener;
|
||||
|
||||
namespace facebook {
|
||||
namespace sonar {
|
||||
|
||||
enum State { success, in_progress, failed };
|
||||
|
||||
class StateElement {
|
||||
public:
|
||||
StateElement(std::string name, State state): name_(name), state_(state) {};
|
||||
std::string name_;
|
||||
State state_;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
class SonarState {
|
||||
friend SonarStep;
|
||||
|
||||
@@ -22,6 +38,7 @@ class SonarState {
|
||||
SonarState();
|
||||
void setUpdateListener(std::shared_ptr<SonarStateUpdateListener>);
|
||||
std::string getState();
|
||||
std::vector<facebook::sonar::StateElement> getStateElements();
|
||||
|
||||
/* To record a state update, call start() with the name of the step to get a
|
||||
SonarStep object. Call complete on this to register it successful,
|
||||
@@ -33,6 +50,9 @@ class SonarState {
|
||||
void success(std::string);
|
||||
void failed(std::string, std::string);
|
||||
void started(std::string);
|
||||
|
||||
std::shared_ptr<SonarStateUpdateListener> mListener = nullptr;
|
||||
std::string stateUpdates;
|
||||
std::string log;
|
||||
std::vector<std::string> insertOrder;
|
||||
std::map<std::string, facebook::sonar::State> stateMap;
|
||||
};
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
*/
|
||||
|
||||
#include "SonarWebSocketImpl.h"
|
||||
#include "SonarStep.h"
|
||||
#include <folly/String.h>
|
||||
#include <folly/futures/Future.h>
|
||||
#include <folly/io/async/SSLContext.h>
|
||||
@@ -224,11 +225,12 @@ void SonarWebSocketImpl::sendMessage(const folly::dynamic& message) {
|
||||
}
|
||||
|
||||
bool SonarWebSocketImpl::isCertificateExchangeNeeded() {
|
||||
auto step = sonarState_->start("Check required certificates are present");
|
||||
|
||||
if (failedConnectionAttempts_ >= 2) {
|
||||
return true;
|
||||
}
|
||||
|
||||
auto step = sonarState_->start("Check required certificates are present");
|
||||
std::string caCert = loadStringFromFile(absoluteFilePath(SONAR_CA_FILE_NAME));
|
||||
std::string clientCert =
|
||||
loadStringFromFile(absoluteFilePath(CLIENT_CERT_FILE_NAME));
|
||||
|
||||
Reference in New Issue
Block a user