aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common/Metric/Metric.cpp10
-rw-r--r--src/common/Metric/Metric.h23
2 files changed, 25 insertions, 8 deletions
diff --git a/src/common/Metric/Metric.cpp b/src/common/Metric/Metric.cpp
index 455bdce039a..c924c233e02 100644
--- a/src/common/Metric/Metric.cpp
+++ b/src/common/Metric/Metric.cpp
@@ -152,8 +152,14 @@ void Metric::SendBatch()
if (!_realmName.empty())
batchedData << ",realm=" << _realmName;
- for (MetricTag const& tag : data->Tags)
- batchedData << "," << tag.first << "=" << FormatInfluxDBTagValue(tag.second);
+ if (data->Tags)
+ {
+ auto begin = std::visit([](auto&& value) { return value.data(); }, *data->Tags);
+ auto end = std::visit([](auto&& value) { return value.data() + value.size(); }, *data->Tags);
+ for (auto itr = begin; itr != end; ++itr)
+ if (!itr->first.empty())
+ batchedData << "," << itr->first << "=" << FormatInfluxDBTagValue(itr->second);
+ }
batchedData << " ";
diff --git a/src/common/Metric/Metric.h b/src/common/Metric/Metric.h
index d5dfcc0374e..6d1bb07d8be 100644
--- a/src/common/Metric/Metric.h
+++ b/src/common/Metric/Metric.h
@@ -22,13 +22,13 @@
#include "Duration.h"
#include "MPSCQueue.h"
#include "Optional.h"
-#include <boost/container/small_vector.hpp>
#include <functional>
#include <iosfwd>
#include <memory>
#include <string>
#include <unordered_map>
#include <utility>
+#include <variant>
namespace Trinity
{
@@ -46,7 +46,6 @@ enum MetricDataType
};
using MetricTag = std::pair<std::string, std::string>;
-using MetricTagsVector = boost::container::small_vector<MetricTag, 2>;
struct MetricData
{
@@ -55,7 +54,7 @@ struct MetricData
MetricDataType Type;
// LogValue-specific fields
- MetricTagsVector Tags;
+ Optional<std::variant<std::array<MetricTag, 2>, std::vector<MetricTag>>> Tags;
// LogEvent-specific fields
std::string Title;
@@ -113,8 +112,8 @@ public:
void Update();
bool ShouldLog(std::string const& category, int64 value) const;
- template<class T, class... Tags>
- void LogValue(std::string category, T value, Tags&&... tags)
+ template<class T, class... TagsList>
+ void LogValue(std::string category, T value, TagsList&&... tags)
{
using namespace std::chrono;
@@ -124,7 +123,19 @@ public:
data->Type = METRIC_DATA_VALUE;
data->ValueOrEventText = FormatInfluxDBValue(value);
if constexpr (sizeof...(tags) > 0)
- (data->Tags.emplace_back(std::move(tags)), ...);
+ {
+ data->Tags.emplace();
+ if constexpr (sizeof...(tags) > 2)
+ {
+ decltype(auto) tagsVector = data->Tags->emplace<1>();
+ (tagsVector.emplace_back(std::move(tags)), ...);
+ }
+ else
+ {
+ decltype(auto) tagsArray = data->Tags->emplace<0>();
+ tagsArray = { std::move(tags)... };
+ }
+ }
_queuedData.Enqueue(data);
}