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
136
|
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#include <aws/core/utils/memory/AWSMemory.h>
#include <aws/core/monitoring/MonitoringInterface.h>
#include <aws/core/monitoring/MonitoringFactory.h>
#include <aws/core/monitoring/MonitoringManager.h>
#include <aws/core/monitoring/DefaultMonitoring.h>
#include <aws/core/Core_EXPORTS.h>
#ifdef _MSC_VER
#pragma warning(disable : 4592)
#endif
namespace Aws
{
namespace Monitoring
{
typedef Aws::Vector<Aws::UniquePtr<MonitoringInterface>> Monitors;
const char MonitoringTag[] = "MonitoringAllocTag";
/**
* Global factory to create global metrics instance.
*/
static Monitors* s_monitors(nullptr);
Aws::Vector<void*> OnRequestStarted(const Aws::String& serviceName, const Aws::String& requestName, const std::shared_ptr<const Aws::Http::HttpRequest>& request)
{
Aws::Vector<void*> contexts;
if (s_monitors)
{
contexts.reserve(s_monitors->size());
for (const auto& interface: *s_monitors)
{
contexts.emplace_back(interface->OnRequestStarted(serviceName, requestName, request));
}
}
return contexts;
}
void OnRequestSucceeded(const Aws::String& serviceName, const Aws::String& requestName, const std::shared_ptr<const Aws::Http::HttpRequest>& request,
const Aws::Client::HttpResponseOutcome& outcome, const CoreMetricsCollection& metricsFromCore, const Aws::Vector<void*>& contexts)
{
if (s_monitors)
{
assert(contexts.size() == s_monitors->size());
size_t index = 0;
for (const auto& interface: *s_monitors)
{
interface->OnRequestSucceeded(serviceName, requestName, request, outcome, metricsFromCore, contexts[index++]);
}
}
}
void OnRequestFailed(const Aws::String& serviceName, const Aws::String& requestName, const std::shared_ptr<const Aws::Http::HttpRequest>& request,
const Aws::Client::HttpResponseOutcome& outcome, const CoreMetricsCollection& metricsFromCore, const Aws::Vector<void*>& contexts)
{
if (s_monitors)
{
assert(contexts.size() == s_monitors->size());
size_t index = 0;
for (const auto& interface: *s_monitors)
{
interface->OnRequestFailed(serviceName, requestName, request, outcome, metricsFromCore, contexts[index++]);
}
}
}
void OnRequestRetry(const Aws::String& serviceName, const Aws::String& requestName,
const std::shared_ptr<const Aws::Http::HttpRequest>& request, const Aws::Vector<void*>& contexts)
{
if (s_monitors)
{
assert(contexts.size() == s_monitors->size());
size_t index = 0;
for (const auto& interface: *s_monitors)
{
interface->OnRequestRetry(serviceName, requestName, request, contexts[index++]);
}
}
}
void OnFinish(const Aws::String& serviceName, const Aws::String& requestName,
const std::shared_ptr<const Aws::Http::HttpRequest>& request, const Aws::Vector<void*>& contexts)
{
if (s_monitors)
{
assert(contexts.size() == s_monitors->size());
size_t index = 0;
for (const auto& interface: *s_monitors)
{
interface->OnFinish(serviceName, requestName, request, contexts[index++]);
}
}
}
void InitMonitoring(const std::vector<MonitoringFactoryCreateFunction>& monitoringFactoryCreateFunctions)
{
if (s_monitors)
{
return;
}
assert(Aws::get_aws_allocator() != nullptr);
s_monitors = Aws::New<Monitors>(MonitoringTag);
for (const auto& function: monitoringFactoryCreateFunctions)
{
auto factory = function();
if (factory)
{
auto instance = factory->CreateMonitoringInstance();
if (instance)
{
s_monitors->emplace_back(std::move(instance));
}
}
}
auto defaultMonitoringFactory = Aws::MakeShared<DefaultMonitoringFactory>(MonitoringTag);
auto instance = defaultMonitoringFactory->CreateMonitoringInstance();
if (instance)
{
s_monitors->emplace_back(std::move(instance));
}
}
void CleanupMonitoring()
{
Aws::Delete(s_monitors);
s_monitors = nullptr;
}
} // namespace Monitoring
} // namespace Aws
|