Merge remote-tracking branch 'origin/master' into sid-dahiya/AddPrivacyGuard

This commit is contained in:
Sid Dahiya 2020-09-16 14:11:08 -07:00
Родитель 90de50b03e 310083ad34
Коммит 6c4f372189
14 изменённых файлов: 130 добавлений и 50 удалений

Просмотреть файл

@ -27,4 +27,4 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GIT_PULL_TOKEN: ${{ secrets.GIT_PULL_TOKEN }}
run: ./build.sh ${{ matrix.config }} CUSTOM_BUILD_FLAGS="-DHAVE_MAT_EXP -DHAVE_MAT_FIFOSTORAGE" && ./out/tests/functests/FuncTests && ./out/tests/unittests/UnitTests
run: ./build.sh ${{ matrix.config }} CUSTOM_BUILD_FLAGS="-DHAVE_MAT_EXP -DHAVE_MAT_FIFOSTORAGE" && ./out/tests/functests/FuncTests --gtest_filter=-ECS* && ./out/tests/unittests/UnitTests --gtest_filter=-ECS*

Просмотреть файл

@ -42,6 +42,7 @@
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\lib\http\HttpResponseDecoder.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\lib\offline\LogSessionDataProvider.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\lib\offline\MemoryStorage.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\lib\offline\OfflineStorageFactory.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\lib\offline\OfflineStorageHandler.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\lib\offline\OfflineStorage_SQLite.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\lib\offline\StorageObserver.cpp" />
@ -110,7 +111,6 @@
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\lib\include\mat\IDeviceInformation.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\lib\include\mat\IInformationProvider.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\lib\include\mat\INetworkInformation.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\lib\include\mat\IOfflineStorage.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\lib\include\mat\IPropertyChangedCallback.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\lib\include\mat\ISystemInformation.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\lib\include\mat\json.hpp" />
@ -134,6 +134,7 @@
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\lib\include\public\IEventFilterCollection.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\lib\include\public\ILogManager.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\lib\include\public\IDataInspector.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\lib\include\public\IOfflineStorage.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\lib\include\public\IDataViewer.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\lib\include\public\IDataViewerCollection.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\lib\include\public\IHttpClient.hpp" />

Просмотреть файл

@ -96,7 +96,6 @@
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\lib\include\mat\IDeviceInformation.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\lib\include\mat\IInformationProvider.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\lib\include\mat\INetworkInformation.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\lib\include\mat\IOfflineStorage.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\lib\include\mat\IPropertyChangedCallback.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\lib\include\mat\ISystemInformation.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\lib\include\mat\json.hpp" />
@ -122,6 +121,9 @@
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\lib\include\public\IEventFilter.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\lib\include\public\IEventFilterCollection.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\lib\include\public\ILogManager.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\lib\include\public\IOfflineStorage.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\lib\include\public\IDataViewer.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\lib\include\public\IDataViewerCollection.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\lib\include\public\IHttpClient.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\lib\include\public\ILogConfiguration.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\lib\include\public\ILogger.hpp" />
@ -146,6 +148,11 @@
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\lib\offline\KillSwitchManager.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\lib\offline\LogSessionDataProvider.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\lib\offline\MemoryStorage.hpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\lib\offline\OfflineStorageFactory.cpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\lib\offline\OfflineStorageHandler.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\lib\offline\OfflineStorage_SQLite.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\lib\offline\SQLiteWrapper.hpp" />

Просмотреть файл

@ -60,6 +60,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "include", "include", "{5538
..\lib\include\public\ILogger.hpp = ..\lib\include\public\ILogger.hpp
..\lib\include\public\ILogManager.hpp = ..\lib\include\public\ILogManager.hpp
..\lib\include\public\IModule.hpp = ..\lib\include\public\IModule.hpp
..\lib\include\public\IOfflineStorage.hpp = ..\lib\include\public\IOfflineStorage.hpp
..\lib\include\public\ISemanticContext.hpp = ..\lib\include\public\ISemanticContext.hpp
..\lib\include\public\ITaskDispatcher.hpp = ..\lib\include\public\ITaskDispatcher.hpp
..\lib\include\public\LogManager.hpp = ..\lib\include\public\LogManager.hpp

Просмотреть файл

@ -39,6 +39,7 @@ set(SRCS decorators/BaseDecorator.cpp
stats/Statistics.cpp
stats/MetaStats.cpp
offline/StorageObserver.cpp
offline/OfflineStorageFactory.cpp
offline/MemoryStorage.cpp
offline/OfflineStorage_SQLite.cpp
offline/OfflineStorageHandler.cpp

Просмотреть файл

@ -57,6 +57,7 @@ set(SRCS
${SDK_ROOT}/lib/jni/Utils_jni.cpp
${SDK_ROOT}/lib/offline/MemoryStorage.cpp
${SDK_ROOT}/lib/offline/LogSessionDataProvider.cpp
${SDK_ROOT}/lib/offline/OfflineStorageFactory.cpp
${SDK_ROOT}/lib/offline/OfflineStorageHandler.cpp
${SDK_ROOT}/lib/offline/StorageObserver.cpp
${SDK_ROOT}/lib/packager/BondSplicer.cpp

Просмотреть файл

@ -268,6 +268,11 @@ namespace MAT_NS_BEGIN
/// </summary>
static constexpr const char* const CFG_MODULE_PRIVACY_GUARD = "privacy_guard";
/// <summary>
/// IDecorator override module
/// </summary>
static constexpr const char* const CFG_MODULE_OFFLINE_STORAGE = "offlineStorage";
/// <summary>
/// Pointer to the Android app's JavaVM
/// </summary>

Просмотреть файл

@ -1,11 +1,25 @@
// Copyright (c) Microsoft. All rights reserved.
///////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2020 Microsoft Corporation. All rights reserved.
//
// This code is licensed under the MIT License (MIT).
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef IOFFLINESTORAGE_HPP
#define IOFFLINESTORAGE_HPP
#include "pal/PAL.hpp"
#include "Enums.hpp"
#include "IHttpClient.hpp"
#include "ctmacros.hpp"
#include "ILogManager.hpp"
#include <functional>
#include <string>
@ -118,8 +132,11 @@ namespace MAT_NS_BEGIN {
virtual void OnStorageRecordsSaved(size_t numRecords) = 0;
};
class IOfflineStorage {
class IOfflineStorage
{
public:
IOfflineStorage() noexcept = default;
virtual ~IOfflineStorage() noexcept = default;
/// <summary>
@ -318,6 +335,11 @@ namespace MAT_NS_BEGIN {
};
// IOfflineStorage as Module. External offline storage implementations need to inherit from it.
class IOfflineStorageModule : public IOfflineStorage, public IModule
{
};
} MAT_NS_END
#endif

Просмотреть файл

@ -0,0 +1,34 @@
// Copyright (c) Microsoft. All rights reserved.
#include "mat/config.h"
#include "OfflineStorageFactory.hpp"
#ifdef USE_ROOM
#include "offline/OfflineStorage_Room.hpp"
#else
#include "offline/OfflineStorage_SQLite.hpp"
#endif
namespace MAT_NS_BEGIN
{
std::shared_ptr<IOfflineStorage> OfflineStorageFactory::Create(ILogManager& logManager, IRuntimeConfig& runtimeConfig)
{
#ifdef HAVE_MAT_STORAGE
std::shared_ptr<IModule> module = logManager.GetLogConfiguration().GetModule(CFG_MODULE_OFFLINE_STORAGE);
if ( nullptr != module ) {
LOG_TRACE("Creating OfflineStorage from module");
return std::static_pointer_cast<IOfflineStorage>(std::static_pointer_cast<IOfflineStorageModule>(module));
}
#ifdef USE_ROOM
LOG_TRACE("Creating OfflineStorage_Room");
return std::make_shared<OfflineStorage_Room>(logManager, runtimeConfig);
#else
LOG_TRACE("Creating OfflineStorage_SQLite");
return std::make_shared<OfflineStorage_SQLite>(logManager, runtimeConfig);
#endif //USE_ROOM
#else
LOG_TRACE("MAT storage disabled");
return nullptr;
#endif //HAVE_MAT_STORAGE
}
}
MAT_NS_END

Просмотреть файл

@ -0,0 +1,21 @@
// Copyright (c) Microsoft. All rights reserved.
#ifndef OFFLINESTORAGEFACTORY_HPP
#define OFFLINESTORAGEFACTORY_HPP
#ifdef HAVE_MAT_STORAGE
#include "IOfflineStorage.hpp"
#include "api/IRuntimeConfig.hpp"
namespace MAT_NS_BEGIN
{
class OfflineStorageFactory
{
public:
static std::shared_ptr<IOfflineStorage> Create(ILogManager& logManager, IRuntimeConfig& runtimeConfig);
};
}
MAT_NS_END
#endif // HAVE_MAT_STORAGE
#endif // HTTPCLIENTFACTORY_HPP

Просмотреть файл

@ -1,14 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.
#include "OfflineStorageHandler.hpp"
#ifdef HAVE_MAT_STORAGE
#ifdef USE_ROOM
#include "offline/OfflineStorage_Room.hpp"
#else
#include "offline/OfflineStorage_SQLite.hpp"
#endif
#endif
#include "OfflineStorageFactory.hpp"
#include "offline/MemoryStorage.hpp"
@ -22,8 +15,8 @@ namespace MAT_NS_BEGIN {
MATSDK_LOG_INST_COMPONENT_CLASS(OfflineStorageHandler, "EventsSDK.StorageHandler", "Events telemetry client - OfflineStorageHandler class");
OfflineStorageHandler::OfflineStorageHandler(ILogManager& logManager, IRuntimeConfig& runtimeConfig, ITaskDispatcher& taskDispatcher)
: m_logManager(logManager),
OfflineStorageHandler::OfflineStorageHandler(ILogManager& logManager, IRuntimeConfig& runtimeConfig, ITaskDispatcher& taskDispatcher) :
m_logManager(logManager),
m_config(runtimeConfig),
m_taskDispatcher(taskDispatcher),
m_killSwitchManager(),
@ -46,7 +39,8 @@ namespace MAT_NS_BEGIN {
m_memoryDbSizeNotificationLimit = (percentage * cacheMemorySizeLimitInBytes) / 100;
}
else
{// incase user has specified bad percentage, we stck to 75%
{
// In case if user has specified bad percentage, we stick to 75%
m_memoryDbSizeNotificationLimit = (DB_FULL_NOTIFICATION_DEFAULT_PERCENTAGE * cacheMemorySizeLimitInBytes) / 100;
}
}
@ -87,17 +81,8 @@ namespace MAT_NS_BEGIN {
m_observer = &observer;
uint32_t cacheMemorySizeLimitInBytes = m_config[CFG_INT_RAM_QUEUE_SIZE];
#ifndef HAVE_MAT_STORAGE
/* No storage configured */
m_offlineStorageDisk.reset(nullptr);
#else
#ifdef USE_ROOM
m_offlineStorageDisk.reset(new OfflineStorage_Room(m_logManager, m_config));
#else
m_offlineStorageDisk.reset(new OfflineStorage_SQLite(m_logManager, m_config));
#endif
m_offlineStorageDisk = OfflineStorageFactory::Create(m_logManager, m_config);
m_offlineStorageDisk->Initialize(*this);
#endif
// TODO: [MG] - consider passing m_offlineStorageDisk to m_offlineStorageMemory,
// so that the Flush() op on memory storage leads to saving unflushed events to
@ -277,10 +262,13 @@ namespace MAT_NS_BEGIN {
return true;
}
size_t OfflineStorageHandler::StoreRecords(std::vector<StorageRecord> & records) {
size_t OfflineStorageHandler::StoreRecords(std::vector<StorageRecord>& records)
{
size_t stored = 0;
for (auto & i : records) {
if (StoreRecord(i)) {
for (auto& i : records)
{
if (StoreRecord(i))
{
++stored;
}
}
@ -344,10 +332,9 @@ namespace MAT_NS_BEGIN {
}
}
if (m_config.IsClockSkewEnabled()
&& !m_clockSkewManager.GetResumeTransmissionAfterClockSkew()
if (m_config.IsClockSkewEnabled() && !m_clockSkewManager.GetResumeTransmissionAfterClockSkew()
/* && !consumedIds.empty() */
)
)
{
m_clockSkewManager.GetDelta();
}
@ -372,29 +359,29 @@ namespace MAT_NS_BEGIN {
* invoked by HTTP callback thread. The scrubbing is done
* async in context where the HTTP callback is running.
*/
void OfflineStorageHandler::DeleteRecordsByKeys(const std::list<std::string> & keys)
void OfflineStorageHandler::DeleteRecordsByKeys(const std::list<std::string>& keys)
{
for (const auto & key : keys)
for (const auto& key : keys)
{
/* DELETE * FROM events WHERE tenant_token=${key} */
DeleteRecords({ { "tenant_token", key } });
DeleteRecords({{"tenant_token", key}});
}
}
/**
* Perform scrub of both memory queue and offline storage.
*/
/// <summary>
/// Perform scrub of underlying storage systems using 'where' clause
/// </summary>
/// <param name="whereFilter">The where filter.</param>
/// <remarks>
/// whereFilter contains the key-value pairs for the
/// WHERE [key0==value0 .. keyN==valueN] clause.
/// </remarks>
void OfflineStorageHandler::DeleteRecords(const std::map<std::string, std::string> & whereFilter)
/// <summary>
/// Perform scrub of underlying storage systems using 'where' clause
/// </summary>
/// <param name="whereFilter">The where filter.</param>
/// <remarks>
/// whereFilter contains the key-value pairs for the
/// WHERE [key0==value0 .. keyN==valueN] clause.
/// </remarks>
void OfflineStorageHandler::DeleteRecords(const std::map<std::string, std::string>& whereFilter)
{
for (const auto storagePtr : { m_offlineStorageMemory.get() , m_offlineStorageDisk.get() })
for (const auto storagePtr : {m_offlineStorageMemory.get(), m_offlineStorageDisk.get()})
{
if (storagePtr != nullptr)
{
@ -430,7 +417,7 @@ namespace MAT_NS_BEGIN {
}
LOG_TRACE(" OfflineStorageHandler Deleting %u sent event(s) {%s%s}...",
static_cast<unsigned>(ids.size()), ids.front().c_str(), (ids.size() > 1) ? ", ..." : "");
static_cast<unsigned>(ids.size()), ids.front().c_str(), (ids.size() > 1) ? ", ..." : "");
if (fromMemory && nullptr != m_offlineStorageMemory)
{
m_offlineStorageMemory->DeleteRecords(ids, headers, fromMemory);

Просмотреть файл

@ -76,7 +76,7 @@ namespace MAT_NS_BEGIN {
PAL::Event m_flushComplete;
std::unique_ptr<IOfflineStorage> m_offlineStorageMemory;
std::unique_ptr<IOfflineStorage> m_offlineStorageDisk;
std::shared_ptr<IOfflineStorage> m_offlineStorageDisk;
bool m_readFromMemory;
unsigned m_lastReadCount;

Просмотреть файл

@ -23,7 +23,7 @@ namespace MAT_NS_BEGIN {
class OfflineStorage_SQLite : public IOfflineStorage
{
public:
OfflineStorage_SQLite(ILogManager& logManager, IRuntimeConfig& runtimeConfig, bool inMemory = false);
OfflineStorage_SQLite(ILogManager& logManager, IRuntimeConfig& runtimeConfig, bool inMemory=false);
virtual ~OfflineStorage_SQLite() override;
virtual void Initialize(IOfflineStorageObserver& observer) override;

Просмотреть файл

@ -610,4 +610,4 @@ namespace MAT_NS_BEGIN {
} MAT_NS_END
#endif
#endif