-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathLogConfiguration.cpp
More file actions
136 lines (126 loc) · 5.39 KB
/
LogConfiguration.cpp
File metadata and controls
136 lines (126 loc) · 5.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
//
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
//
#include "mat/config.h"
#include "LogConfiguration.hpp"
#ifdef HAVE_MAT_JSONHPP
#include <nlohmann/json.hpp>
using json = nlohmann::json;
#endif
namespace MAT_NS_BEGIN {
static ILogConfiguration currentConfig {
{ CFG_INT_TRACE_LEVEL_MIN, ACTTraceLevel::ACTTraceLevel_Error },
{ CFG_BOOL_ENABLE_TRACE, true },
{ CFG_INT_SDK_MODE, SdkModeTypes::SdkModeTypes_CS },
{ CFG_BOOL_ENABLE_ANALYTICS, false },
{ CFG_INT_CACHE_FILE_SIZE, 3145728 },
{ CFG_INT_RAM_QUEUE_SIZE, 524288 },
{ CFG_BOOL_ENABLE_MULTITENANT, true },
{ CFG_BOOL_ENABLE_DB_DROP_IF_FULL, false },
{ CFG_INT_MAX_TEARDOWN_TIME, 0 },
{ CFG_INT_MAX_PENDING_REQ, 4 },
{ CFG_INT_RAM_QUEUE_BUFFERS, 3 },
{ CFG_INT_TRACE_LEVEL_MASK, 0 },
{ CFG_STR_COLLECTOR_URL, COLLECTOR_URL_PROD },
{ CFG_INT_STORAGE_FULL_PCT, 75 },
{ CFG_INT_STORAGE_FULL_CHECK_TIME, 5000 },
{ CFG_INT_RAMCACHE_FULL_PCT, 75 },
{ CFG_BOOL_ENABLE_NET_DETECT, true },
};
const ILogConfiguration& GetDefaultConfiguration()
{
return currentConfig;
}
//
// v1 to v3 simple LogConfiguration migration helper. This migration helper
// does not support SetProperty nor key-value map parameters previously
// supported by v1. Most of these transient key-value parameters are also
// no longer applicable to v3. Customers who'd like to populate these extra
// props as a map should do this directly on ILogConfiguration object.
ILogConfiguration FromLogConfiguration(MAT_v1::LogConfiguration &src)
{
ILogConfiguration result {
{ CFG_INT_TRACE_LEVEL_MIN, src.minimumTraceLevel },
{ CFG_INT_SDK_MODE, src.sdkmode },
{ CFG_BOOL_ENABLE_ANALYTICS, src.enableLifecycleSession },
{ CFG_INT_CACHE_FILE_SIZE, src.cacheFileSizeLimitInBytes },
{ CFG_INT_RAM_QUEUE_SIZE, src.cacheMemorySizeLimitInBytes },
{ CFG_BOOL_ENABLE_MULTITENANT, src.multiTenantEnabled },
{ CFG_INT_MAX_TEARDOWN_TIME, src.maxTeardownUploadTimeInSec },
{ CFG_INT_MAX_PENDING_REQ, src.maxPendingHTTPRequests },
{ CFG_INT_RAM_QUEUE_BUFFERS, src.maxDBFlushQueues },
{ CFG_INT_TRACE_LEVEL_MASK, src.traceLevelMask },
{ CFG_STR_COLLECTOR_URL, src.eventCollectorUri.c_str() },
{ CFG_INT_STORAGE_FULL_PCT, 75 }, // v1 had these parameters inside STL map.
{ CFG_INT_RAMCACHE_FULL_PCT, 75 }, // Customers transitioning from v1 configuration to v3
// and using these two parameters (e.g. OTEL) should use
// ILogConfiguration class directly. It provides modern
// C++11 initializer list-based config tree.
{ CFG_INT_STORAGE_FULL_CHECK_TIME, 5000 },
};
return result;
}
void MergeFromJSON(ILogConfiguration &config, const char* configuration)
{
#ifdef HAVE_MAT_JSONHPP
auto jsonRoot = json::parse(configuration);
std::function<void(json &node, VariantMap &dst)> parse;
parse = [&parse](json &node, VariantMap &dst)->void {
for (json::iterator it = node.begin(); it != node.end(); ++it) {
auto t = it.value().type();
switch (t)
{
case json::value_t::array:
// TODO
break;
case json::value_t::boolean:
dst[it.key()] = (bool)(it.value());
break;
case json::value_t::discarded:
// TODO
break;
case json::value_t::null:
dst[it.key()] = Variant();
break;
case json::value_t::number_float:
dst[it.key()] = (double)(it.value());
break;
case json::value_t::number_integer:
dst[it.key()] = (int64_t)(it.value());
break;
case json::value_t::number_unsigned:
dst[it.key()] = (uint64_t)(it.value());
break;
case json::value_t::object:
{
VariantMap sub;
parse(it.value(), sub);
dst[it.key()] = sub;
break;
}
case json::value_t::string:
{
std::string val = it.value();
dst[it.key()] = std::move(val);
break;
}
default:
// Ignore unsupported binary type values
break;
}
}
};
parse(jsonRoot, *config);
#else
(void)(configuration);
assert(false /* json.hpp support is not enabled! */);
#endif
}
ILogConfiguration FromJSON(const char* configuration)
{
ILogConfiguration result;
MergeFromJSON(result, configuration);
return result;
}
} MAT_NS_END