Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Zolotarev <alex@maps.me>2015-09-02 00:17:59 +0300
committerAlex Zolotarev <alex@maps.me>2015-09-23 03:03:33 +0300
commit7e9beccb4c5bf3470c5da5063938cb9cafa6ddb6 (patch)
tree9e3359807b87d4c6952a4cf590f6b010a3ddf945 /3party/Alohalytics
parent28c48b05416903a703b0090d03659af7e8020129 (diff)
[alohalytics] Enable/disable statistics collection from user settings screen.
Diffstat (limited to '3party/Alohalytics')
-rw-r--r--3party/Alohalytics/src/alohalytics.h8
-rw-r--r--3party/Alohalytics/src/cpp/alohalytics.cc92
2 files changed, 69 insertions, 31 deletions
diff --git a/3party/Alohalytics/src/alohalytics.h b/3party/Alohalytics/src/alohalytics.h
index 42beba522b..0896bf2ccb 100644
--- a/3party/Alohalytics/src/alohalytics.h
+++ b/3party/Alohalytics/src/alohalytics.h
@@ -38,6 +38,9 @@ namespace alohalytics {
typedef std::map<std::string, std::string> TStringMap;
class Stats final {
+ // Is statistics engine enabled or disabled.
+ // Used if users want to opt-out from events collection.
+ bool enabled_ = true;
std::string upload_url_;
// Unique client id is inserted as a special event in the beginning of every archived file before gzipping it.
// In current implementation it is used to distinguish between different users in the events stream on the server.
@@ -66,6 +69,11 @@ class Stats final {
Stats & SetDebugMode(bool enable);
bool DebugMode() const { return debug_mode_; }
+ // Turn off events collection and sending.
+ void Disable();
+ // Turn back on events collection and sending after Disable();
+ void Enable();
+
// If not set, collected data will never be uploaded.
Stats & SetServerUrl(const std::string & url_to_upload_statistics_to);
diff --git a/3party/Alohalytics/src/cpp/alohalytics.cc b/3party/Alohalytics/src/cpp/alohalytics.cc
index 5b0afa0b1b..61992c5bb5 100644
--- a/3party/Alohalytics/src/cpp/alohalytics.cc
+++ b/3party/Alohalytics/src/cpp/alohalytics.cc
@@ -43,9 +43,13 @@
#include "../cereal/include/types/string.hpp"
#include "../cereal/include/types/map.hpp"
-#define LOG_IF_DEBUG(...) \
- if (debug_mode_) { \
- alohalytics::Logger().Log(__VA_ARGS__); \
+#define LOG_IF_DEBUG(...) \
+ if (debug_mode_) { \
+ if (enabled_) { \
+ alohalytics::Logger().Log(__VA_ARGS__); \
+ } else { \
+ alohalytics::Logger().Log("Disabled:", __VA_ARGS__); \
+ } \
}
namespace alohalytics {
@@ -57,6 +61,16 @@ Stats::Stats()
: messages_queue_(
std::bind(&Stats::GzipAndArchiveFileInTheQueue, this, std::placeholders::_1, std::placeholders::_2)) {}
+void Stats::Disable() {
+ LOG_IF_DEBUG("Statistics collection disabled.");
+ enabled_ = false;
+}
+// Turn back on events collection and sending after Disable();
+void Stats::Enable() {
+ LOG_IF_DEBUG("Statistics collection enabled.");
+ enabled_ = true;
+}
+
void Stats::GzipAndArchiveFileInTheQueue(const std::string & in_file, const std::string & out_archive) {
std::string encoded_unique_client_id;
if (unique_client_id_.empty()) {
@@ -149,51 +163,63 @@ static inline void LogEventImpl(AlohalyticsBaseEvent const & event, THundredKilo
void Stats::LogEvent(std::string const & event_name) {
LOG_IF_DEBUG("LogEvent:", event_name);
- AlohalyticsKeyEvent event;
- event.key = event_name;
- LogEventImpl(event, messages_queue_);
+ if (enabled_) {
+ AlohalyticsKeyEvent event;
+ event.key = event_name;
+ LogEventImpl(event, messages_queue_);
+ }
}
void Stats::LogEvent(std::string const & event_name, Location const & location) {
LOG_IF_DEBUG("LogEvent:", event_name, location.ToDebugString());
- AlohalyticsKeyLocationEvent event;
- event.key = event_name;
- event.location = location;
- LogEventImpl(event, messages_queue_);
+ if (enabled_) {
+ AlohalyticsKeyLocationEvent event;
+ event.key = event_name;
+ event.location = location;
+ LogEventImpl(event, messages_queue_);
+ }
}
void Stats::LogEvent(std::string const & event_name, std::string const & event_value) {
LOG_IF_DEBUG("LogEvent:", event_name, "=", event_value);
- AlohalyticsKeyValueEvent event;
- event.key = event_name;
- event.value = event_value;
- LogEventImpl(event, messages_queue_);
+ if (enabled_) {
+ AlohalyticsKeyValueEvent event;
+ event.key = event_name;
+ event.value = event_value;
+ LogEventImpl(event, messages_queue_);
+ }
}
void Stats::LogEvent(std::string const & event_name, std::string const & event_value, Location const & location) {
LOG_IF_DEBUG("LogEvent:", event_name, "=", event_value, location.ToDebugString());
- AlohalyticsKeyValueLocationEvent event;
- event.key = event_name;
- event.value = event_value;
- event.location = location;
- LogEventImpl(event, messages_queue_);
+ if (enabled_) {
+ AlohalyticsKeyValueLocationEvent event;
+ event.key = event_name;
+ event.value = event_value;
+ event.location = location;
+ LogEventImpl(event, messages_queue_);
+ }
}
void Stats::LogEvent(std::string const & event_name, TStringMap const & value_pairs) {
LOG_IF_DEBUG("LogEvent:", event_name, "=", value_pairs);
- AlohalyticsKeyPairsEvent event;
- event.key = event_name;
- event.pairs = value_pairs;
- LogEventImpl(event, messages_queue_);
+ if (enabled_) {
+ AlohalyticsKeyPairsEvent event;
+ event.key = event_name;
+ event.pairs = value_pairs;
+ LogEventImpl(event, messages_queue_);
+ }
}
void Stats::LogEvent(std::string const & event_name, TStringMap const & value_pairs, Location const & location) {
LOG_IF_DEBUG("LogEvent:", event_name, "=", value_pairs, location.ToDebugString());
- AlohalyticsKeyPairsLocationEvent event;
- event.key = event_name;
- event.pairs = value_pairs;
- event.location = location;
- LogEventImpl(event, messages_queue_);
+ if (enabled_) {
+ AlohalyticsKeyPairsLocationEvent event;
+ event.key = event_name;
+ event.pairs = value_pairs;
+ event.location = location;
+ LogEventImpl(event, messages_queue_);
+ }
}
void Stats::Upload(TFileProcessingFinishedCallback upload_finished_callback) {
@@ -201,9 +227,13 @@ void Stats::Upload(TFileProcessingFinishedCallback upload_finished_callback) {
LOG_IF_DEBUG("Warning: upload server url has not been set, nothing was uploaded.");
return;
}
- LOG_IF_DEBUG("Trying to upload collected statistics to", upload_url_);
- messages_queue_.ProcessArchivedFiles(
- std::bind(&Stats::UploadFileImpl, this, std::placeholders::_1, std::placeholders::_2), upload_finished_callback);
+ if (enabled_) {
+ LOG_IF_DEBUG("Trying to upload collected statistics to", upload_url_);
+ messages_queue_.ProcessArchivedFiles(
+ std::bind(&Stats::UploadFileImpl, this, std::placeholders::_1, std::placeholders::_2), upload_finished_callback);
+ } else {
+ LOG_IF_DEBUG("Statistics is disabled. Nothing was uploaded.");
+ }
}
bool Stats::UploadFileImpl(bool file_name_in_content, const std::string & content) {