|
|
|
@ -16,10 +16,6 @@ |
|
|
|
|
|
|
|
|
|
#include <memory> |
|
|
|
|
|
|
|
|
|
#include "absl/container/flat_hash_map.h" |
|
|
|
|
#include "absl/strings/match.h" |
|
|
|
|
#include "absl/strings/str_cat.h" |
|
|
|
|
#include "absl/strings/str_join.h" |
|
|
|
|
#include "gmock/gmock.h" |
|
|
|
|
#include "gtest/gtest.h" |
|
|
|
|
|
|
|
|
@ -40,15 +36,15 @@ class MetricsTest : public ::testing::Test { |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
TEST_F(MetricsTest, UInt64Counter) { |
|
|
|
|
const absl::string_view kLabelKeys[] = {"label_key_1", "label_key_2"}; |
|
|
|
|
const absl::string_view kOptionalLabelKeys[] = {"optional_label_key_1", |
|
|
|
|
"optional_label_key_2"}; |
|
|
|
|
auto uint64_counter_handle = GlobalInstrumentsRegistry::RegisterUInt64Counter( |
|
|
|
|
"uint64_counter", "A simple uint64 counter.", "unit", kLabelKeys, |
|
|
|
|
kOptionalLabelKeys, true); |
|
|
|
|
constexpr absl::string_view kLabelValues[] = {"label_value_1", |
|
|
|
|
"label_value_2"}; |
|
|
|
|
constexpr absl::string_view kOptionalLabelValues[] = { |
|
|
|
|
auto uint64_counter_handle = |
|
|
|
|
GlobalInstrumentsRegistry::RegisterUInt64Counter( |
|
|
|
|
"uint64_counter", "A simple uint64 counter.", "unit", true) |
|
|
|
|
.Labels("label_key_1", "label_key_2") |
|
|
|
|
.OptionalLabels("optional_label_key_1", "optional_label_key_2") |
|
|
|
|
.Build(); |
|
|
|
|
std::array<absl::string_view, 2> kLabelValues = {"label_value_1", |
|
|
|
|
"label_value_2"}; |
|
|
|
|
std::array<absl::string_view, 2> kOptionalLabelValues = { |
|
|
|
|
"optional_label_value_1", "optional_label_value_2"}; |
|
|
|
|
constexpr absl::string_view kDomain1To4 = "domain1.domain2.domain3.domain4"; |
|
|
|
|
constexpr absl::string_view kDomain2To4 = "domain2.domain3.domain4"; |
|
|
|
@ -58,34 +54,37 @@ TEST_F(MetricsTest, UInt64Counter) { |
|
|
|
|
auto plugin3 = MakeStatsPluginForTarget(kDomain3To4); |
|
|
|
|
GlobalStatsPluginRegistry::GetStatsPluginsForChannel( |
|
|
|
|
StatsPluginChannelScope(kDomain1To4, "")) |
|
|
|
|
.AddCounter(uint64_counter_handle, 1, kLabelValues, kOptionalLabelValues); |
|
|
|
|
.AddCounter(uint64_counter_handle, uint64_t(1), kLabelValues, |
|
|
|
|
kOptionalLabelValues); |
|
|
|
|
GlobalStatsPluginRegistry::GetStatsPluginsForChannel( |
|
|
|
|
StatsPluginChannelScope(kDomain2To4, "")) |
|
|
|
|
.AddCounter(uint64_counter_handle, 2, kLabelValues, kOptionalLabelValues); |
|
|
|
|
.AddCounter(uint64_counter_handle, uint64_t(2), kLabelValues, |
|
|
|
|
kOptionalLabelValues); |
|
|
|
|
GlobalStatsPluginRegistry::GetStatsPluginsForChannel( |
|
|
|
|
StatsPluginChannelScope(kDomain3To4, "")) |
|
|
|
|
.AddCounter(uint64_counter_handle, 3, kLabelValues, kOptionalLabelValues); |
|
|
|
|
EXPECT_THAT(plugin1->GetCounterValue(uint64_counter_handle, kLabelValues, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
.AddCounter(uint64_counter_handle, uint64_t(3), kLabelValues, |
|
|
|
|
kOptionalLabelValues); |
|
|
|
|
EXPECT_THAT(plugin1->GetUInt64CounterValue( |
|
|
|
|
uint64_counter_handle, kLabelValues, kOptionalLabelValues), |
|
|
|
|
::testing::Optional(1)); |
|
|
|
|
EXPECT_THAT(plugin2->GetCounterValue(uint64_counter_handle, kLabelValues, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_THAT(plugin2->GetUInt64CounterValue( |
|
|
|
|
uint64_counter_handle, kLabelValues, kOptionalLabelValues), |
|
|
|
|
::testing::Optional(3)); |
|
|
|
|
EXPECT_THAT(plugin3->GetCounterValue(uint64_counter_handle, kLabelValues, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_THAT(plugin3->GetUInt64CounterValue( |
|
|
|
|
uint64_counter_handle, kLabelValues, kOptionalLabelValues), |
|
|
|
|
::testing::Optional(6)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(MetricsTest, DoubleCounter) { |
|
|
|
|
const absl::string_view kLabelKeys[] = {"label_key_1", "label_key_2"}; |
|
|
|
|
const absl::string_view kOptionalLabelKeys[] = {"optional_label_key_1", |
|
|
|
|
"optional_label_key_2"}; |
|
|
|
|
auto double_counter_handle = GlobalInstrumentsRegistry::RegisterDoubleCounter( |
|
|
|
|
"double_counter", "A simple double counter.", "unit", kLabelKeys, |
|
|
|
|
kOptionalLabelKeys, true); |
|
|
|
|
constexpr absl::string_view kLabelValues[] = {"label_value_1", |
|
|
|
|
"label_value_2"}; |
|
|
|
|
constexpr absl::string_view kOptionalLabelValues[] = { |
|
|
|
|
auto double_counter_handle = |
|
|
|
|
GlobalInstrumentsRegistry::RegisterDoubleCounter( |
|
|
|
|
"double_counter", "A simple double counter.", "unit", true) |
|
|
|
|
.Labels("label_key_1", "label_key_2") |
|
|
|
|
.OptionalLabels("optional_label_key_1", "optional_label_key_2") |
|
|
|
|
.Build(); |
|
|
|
|
std::array<absl::string_view, 2> kLabelValues = {"label_value_1", |
|
|
|
|
"label_value_2"}; |
|
|
|
|
std::array<absl::string_view, 2> kOptionalLabelValues = { |
|
|
|
|
"optional_label_value_1", "optional_label_value_2"}; |
|
|
|
|
constexpr absl::string_view kDomain1To4 = "domain1.domain2.domain3.domain4"; |
|
|
|
|
constexpr absl::string_view kDomain2To4 = "domain2.domain3.domain4"; |
|
|
|
@ -105,28 +104,27 @@ TEST_F(MetricsTest, DoubleCounter) { |
|
|
|
|
StatsPluginChannelScope(kDomain3To4, "")) |
|
|
|
|
.AddCounter(double_counter_handle, 3.45, kLabelValues, |
|
|
|
|
kOptionalLabelValues); |
|
|
|
|
EXPECT_THAT(plugin1->GetCounterValue(double_counter_handle, kLabelValues, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_THAT(plugin1->GetDoubleCounterValue( |
|
|
|
|
double_counter_handle, kLabelValues, kOptionalLabelValues), |
|
|
|
|
::testing::Optional(1.23)); |
|
|
|
|
EXPECT_THAT(plugin2->GetCounterValue(double_counter_handle, kLabelValues, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_THAT(plugin2->GetDoubleCounterValue( |
|
|
|
|
double_counter_handle, kLabelValues, kOptionalLabelValues), |
|
|
|
|
::testing::Optional(3.57)); |
|
|
|
|
EXPECT_THAT(plugin3->GetCounterValue(double_counter_handle, kLabelValues, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_THAT(plugin3->GetDoubleCounterValue( |
|
|
|
|
double_counter_handle, kLabelValues, kOptionalLabelValues), |
|
|
|
|
::testing::Optional(7.02)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(MetricsTest, UInt64Histogram) { |
|
|
|
|
const absl::string_view kLabelKeys[] = {"label_key_1", "label_key_2"}; |
|
|
|
|
const absl::string_view kOptionalLabelKeys[] = {"optional_label_key_1", |
|
|
|
|
"optional_label_key_2"}; |
|
|
|
|
auto uint64_histogram_handle = |
|
|
|
|
GlobalInstrumentsRegistry::RegisterUInt64Histogram( |
|
|
|
|
"uint64_histogram", "A simple uint64 histogram.", "unit", kLabelKeys, |
|
|
|
|
kOptionalLabelKeys, true); |
|
|
|
|
constexpr absl::string_view kLabelValues[] = {"label_value_1", |
|
|
|
|
"label_value_2"}; |
|
|
|
|
constexpr absl::string_view kOptionalLabelValues[] = { |
|
|
|
|
"uint64_histogram", "A simple uint64 histogram.", "unit", true) |
|
|
|
|
.Labels("label_key_1", "label_key_2") |
|
|
|
|
.OptionalLabels("optional_label_key_1", "optional_label_key_2") |
|
|
|
|
.Build(); |
|
|
|
|
std::array<absl::string_view, 2> kLabelValues = {"label_value_1", |
|
|
|
|
"label_value_2"}; |
|
|
|
|
std::array<absl::string_view, 2> kOptionalLabelValues = { |
|
|
|
|
"optional_label_value_1", "optional_label_value_2"}; |
|
|
|
|
constexpr absl::string_view kDomain1To4 = "domain1.domain2.domain3.domain4"; |
|
|
|
|
constexpr absl::string_view kDomain2To4 = "domain2.domain3.domain4"; |
|
|
|
@ -136,38 +134,37 @@ TEST_F(MetricsTest, UInt64Histogram) { |
|
|
|
|
auto plugin3 = MakeStatsPluginForTarget(kDomain3To4); |
|
|
|
|
GlobalStatsPluginRegistry::GetStatsPluginsForChannel( |
|
|
|
|
StatsPluginChannelScope(kDomain1To4, "")) |
|
|
|
|
.RecordHistogram(uint64_histogram_handle, 1, kLabelValues, |
|
|
|
|
.RecordHistogram(uint64_histogram_handle, uint64_t(1), kLabelValues, |
|
|
|
|
kOptionalLabelValues); |
|
|
|
|
GlobalStatsPluginRegistry::GetStatsPluginsForChannel( |
|
|
|
|
StatsPluginChannelScope(kDomain2To4, "")) |
|
|
|
|
.RecordHistogram(uint64_histogram_handle, 2, kLabelValues, |
|
|
|
|
.RecordHistogram(uint64_histogram_handle, uint64_t(2), kLabelValues, |
|
|
|
|
kOptionalLabelValues); |
|
|
|
|
GlobalStatsPluginRegistry::GetStatsPluginsForChannel( |
|
|
|
|
StatsPluginChannelScope(kDomain3To4, "")) |
|
|
|
|
.RecordHistogram(uint64_histogram_handle, 3, kLabelValues, |
|
|
|
|
.RecordHistogram(uint64_histogram_handle, uint64_t(3), kLabelValues, |
|
|
|
|
kOptionalLabelValues); |
|
|
|
|
EXPECT_THAT(plugin1->GetHistogramValue(uint64_histogram_handle, kLabelValues, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_THAT(plugin1->GetUInt64HistogramValue( |
|
|
|
|
uint64_histogram_handle, kLabelValues, kOptionalLabelValues), |
|
|
|
|
::testing::Optional(::testing::UnorderedElementsAre(1))); |
|
|
|
|
EXPECT_THAT(plugin2->GetHistogramValue(uint64_histogram_handle, kLabelValues, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_THAT(plugin2->GetUInt64HistogramValue( |
|
|
|
|
uint64_histogram_handle, kLabelValues, kOptionalLabelValues), |
|
|
|
|
::testing::Optional(::testing::UnorderedElementsAre(1, 2))); |
|
|
|
|
EXPECT_THAT(plugin3->GetHistogramValue(uint64_histogram_handle, kLabelValues, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_THAT(plugin3->GetUInt64HistogramValue( |
|
|
|
|
uint64_histogram_handle, kLabelValues, kOptionalLabelValues), |
|
|
|
|
::testing::Optional(::testing::UnorderedElementsAre(1, 2, 3))); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(MetricsTest, DoubleHistogram) { |
|
|
|
|
const absl::string_view kLabelKeys[] = {"label_key_1", "label_key_2"}; |
|
|
|
|
const absl::string_view kOptionalLabelKeys[] = {"optional_label_key_1", |
|
|
|
|
"optional_label_key_2"}; |
|
|
|
|
auto double_histogram_handle = |
|
|
|
|
GlobalInstrumentsRegistry::RegisterDoubleHistogram( |
|
|
|
|
"double_histogram", "A simple double histogram.", "unit", kLabelKeys, |
|
|
|
|
kOptionalLabelKeys, true); |
|
|
|
|
constexpr absl::string_view kLabelValues[] = {"label_value_1", |
|
|
|
|
"label_value_2"}; |
|
|
|
|
constexpr absl::string_view kOptionalLabelValues[] = { |
|
|
|
|
"double_histogram", "A simple double histogram.", "unit", true) |
|
|
|
|
.Labels("label_key_1", "label_key_2") |
|
|
|
|
.OptionalLabels("optional_label_key_1", "optional_label_key_2") |
|
|
|
|
.Build(); |
|
|
|
|
std::array<absl::string_view, 2> kLabelValues = {"label_value_1", |
|
|
|
|
"label_value_2"}; |
|
|
|
|
std::array<absl::string_view, 2> kOptionalLabelValues = { |
|
|
|
|
"optional_label_value_1", "optional_label_value_2"}; |
|
|
|
|
constexpr absl::string_view kDomain1To4 = "domain1.domain2.domain3.domain4"; |
|
|
|
|
constexpr absl::string_view kDomain2To4 = "domain2.domain3.domain4"; |
|
|
|
@ -187,31 +184,30 @@ TEST_F(MetricsTest, DoubleHistogram) { |
|
|
|
|
StatsPluginChannelScope(kDomain3To4, "")) |
|
|
|
|
.RecordHistogram(double_histogram_handle, 3.45, kLabelValues, |
|
|
|
|
kOptionalLabelValues); |
|
|
|
|
EXPECT_THAT(plugin1->GetHistogramValue(double_histogram_handle, kLabelValues, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_THAT(plugin1->GetDoubleHistogramValue( |
|
|
|
|
double_histogram_handle, kLabelValues, kOptionalLabelValues), |
|
|
|
|
::testing::Optional(::testing::UnorderedElementsAre(1.23))); |
|
|
|
|
EXPECT_THAT(plugin2->GetHistogramValue(double_histogram_handle, kLabelValues, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_THAT(plugin2->GetDoubleHistogramValue( |
|
|
|
|
double_histogram_handle, kLabelValues, kOptionalLabelValues), |
|
|
|
|
::testing::Optional(::testing::UnorderedElementsAre(1.23, 2.34))); |
|
|
|
|
EXPECT_THAT( |
|
|
|
|
plugin3->GetHistogramValue(double_histogram_handle, kLabelValues, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
plugin3->GetDoubleHistogramValue(double_histogram_handle, kLabelValues, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
::testing::Optional(::testing::UnorderedElementsAre(1.23, 2.34, 3.45))); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(MetricsTest, Int64CallbackGauge) { |
|
|
|
|
const absl::string_view kLabelKeys[] = {"label_key_1", "label_key_2"}; |
|
|
|
|
const absl::string_view kOptionalLabelKeys[] = {"optional_label_key_1", |
|
|
|
|
"optional_label_key_2"}; |
|
|
|
|
auto int64_gauge_handle = |
|
|
|
|
GlobalInstrumentsRegistry::RegisterCallbackInt64Gauge( |
|
|
|
|
"int64_gauge", "A simple int64 gauge.", "unit", kLabelKeys, |
|
|
|
|
kOptionalLabelKeys, true); |
|
|
|
|
constexpr absl::string_view kLabelValues[] = {"label_value_1", |
|
|
|
|
"label_value_2"}; |
|
|
|
|
constexpr absl::string_view kLabelValues2[] = {"label_value_3", |
|
|
|
|
"label_value_2"}; |
|
|
|
|
constexpr absl::string_view kOptionalLabelValues[] = { |
|
|
|
|
"int64_gauge", "A simple int64 gauge.", "unit", true) |
|
|
|
|
.Labels("label_key_1", "label_key_2") |
|
|
|
|
.OptionalLabels("optional_label_key_1", "optional_label_key_2") |
|
|
|
|
.Build(); |
|
|
|
|
std::array<absl::string_view, 2> kLabelValues = {"label_value_1", |
|
|
|
|
"label_value_2"}; |
|
|
|
|
std::array<absl::string_view, 2> kLabelValues2 = {"label_value_3", |
|
|
|
|
"label_value_2"}; |
|
|
|
|
std::array<absl::string_view, 2> kOptionalLabelValues = { |
|
|
|
|
"optional_label_value_1", "optional_label_value_2"}; |
|
|
|
|
constexpr absl::string_view kDomain1To4 = "domain1.domain2.domain3.domain4"; |
|
|
|
|
constexpr absl::string_view kDomain2To4 = "domain2.domain3.domain4"; |
|
|
|
@ -226,57 +222,57 @@ TEST_F(MetricsTest, Int64CallbackGauge) { |
|
|
|
|
StatsPluginChannelScope(kDomain3To4, "")); |
|
|
|
|
auto callback1 = group1.RegisterCallback( |
|
|
|
|
[&](CallbackMetricReporter& reporter) { |
|
|
|
|
reporter.Report(int64_gauge_handle, 1, kLabelValues, |
|
|
|
|
reporter.Report(int64_gauge_handle, int64_t(1), kLabelValues, |
|
|
|
|
kOptionalLabelValues); |
|
|
|
|
}, |
|
|
|
|
{int64_gauge_handle}); |
|
|
|
|
Duration::Seconds(5), int64_gauge_handle); |
|
|
|
|
auto callback2 = group1.RegisterCallback( |
|
|
|
|
[&](CallbackMetricReporter& reporter) { |
|
|
|
|
reporter.Report(int64_gauge_handle, 2, kLabelValues2, |
|
|
|
|
reporter.Report(int64_gauge_handle, int64_t(2), kLabelValues2, |
|
|
|
|
kOptionalLabelValues); |
|
|
|
|
}, |
|
|
|
|
{int64_gauge_handle}); |
|
|
|
|
Duration::Seconds(5), int64_gauge_handle); |
|
|
|
|
// No plugins have data yet.
|
|
|
|
|
EXPECT_EQ(plugin1->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_EQ(plugin1->GetInt64CallbackGaugeValue( |
|
|
|
|
int64_gauge_handle, kLabelValues, kOptionalLabelValues), |
|
|
|
|
absl::nullopt); |
|
|
|
|
EXPECT_EQ(plugin1->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues2, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_EQ(plugin1->GetInt64CallbackGaugeValue( |
|
|
|
|
int64_gauge_handle, kLabelValues2, kOptionalLabelValues), |
|
|
|
|
absl::nullopt); |
|
|
|
|
EXPECT_EQ(plugin2->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_EQ(plugin2->GetInt64CallbackGaugeValue( |
|
|
|
|
int64_gauge_handle, kLabelValues, kOptionalLabelValues), |
|
|
|
|
absl::nullopt); |
|
|
|
|
EXPECT_EQ(plugin2->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues2, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_EQ(plugin2->GetInt64CallbackGaugeValue( |
|
|
|
|
int64_gauge_handle, kLabelValues2, kOptionalLabelValues), |
|
|
|
|
absl::nullopt); |
|
|
|
|
EXPECT_EQ(plugin3->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_EQ(plugin3->GetInt64CallbackGaugeValue( |
|
|
|
|
int64_gauge_handle, kLabelValues, kOptionalLabelValues), |
|
|
|
|
absl::nullopt); |
|
|
|
|
EXPECT_EQ(plugin3->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues2, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_EQ(plugin3->GetInt64CallbackGaugeValue( |
|
|
|
|
int64_gauge_handle, kLabelValues2, kOptionalLabelValues), |
|
|
|
|
absl::nullopt); |
|
|
|
|
// Now invoke the callbacks.
|
|
|
|
|
plugin1->TriggerCallbacks(); |
|
|
|
|
plugin2->TriggerCallbacks(); |
|
|
|
|
plugin3->TriggerCallbacks(); |
|
|
|
|
// Now plugin1 should have data, but the others should not.
|
|
|
|
|
EXPECT_THAT(plugin1->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_THAT(plugin1->GetInt64CallbackGaugeValue( |
|
|
|
|
int64_gauge_handle, kLabelValues, kOptionalLabelValues), |
|
|
|
|
::testing::Optional(1)); |
|
|
|
|
EXPECT_THAT(plugin1->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues2, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_THAT(plugin1->GetInt64CallbackGaugeValue( |
|
|
|
|
int64_gauge_handle, kLabelValues2, kOptionalLabelValues), |
|
|
|
|
::testing::Optional(2)); |
|
|
|
|
EXPECT_EQ(plugin2->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_EQ(plugin2->GetInt64CallbackGaugeValue( |
|
|
|
|
int64_gauge_handle, kLabelValues, kOptionalLabelValues), |
|
|
|
|
absl::nullopt); |
|
|
|
|
EXPECT_EQ(plugin2->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues2, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_EQ(plugin2->GetInt64CallbackGaugeValue( |
|
|
|
|
int64_gauge_handle, kLabelValues2, kOptionalLabelValues), |
|
|
|
|
absl::nullopt); |
|
|
|
|
EXPECT_EQ(plugin3->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_EQ(plugin3->GetInt64CallbackGaugeValue( |
|
|
|
|
int64_gauge_handle, kLabelValues, kOptionalLabelValues), |
|
|
|
|
absl::nullopt); |
|
|
|
|
EXPECT_EQ(plugin3->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues2, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_EQ(plugin3->GetInt64CallbackGaugeValue( |
|
|
|
|
int64_gauge_handle, kLabelValues2, kOptionalLabelValues), |
|
|
|
|
absl::nullopt); |
|
|
|
|
// De-register the callbacks.
|
|
|
|
|
callback1.reset(); |
|
|
|
@ -287,57 +283,57 @@ TEST_F(MetricsTest, Int64CallbackGauge) { |
|
|
|
|
StatsPluginChannelScope(kDomain2To4, "")); |
|
|
|
|
callback1 = group2.RegisterCallback( |
|
|
|
|
[&](CallbackMetricReporter& reporter) { |
|
|
|
|
reporter.Report(int64_gauge_handle, 3, kLabelValues, |
|
|
|
|
reporter.Report(int64_gauge_handle, int64_t(3), kLabelValues, |
|
|
|
|
kOptionalLabelValues); |
|
|
|
|
}, |
|
|
|
|
{int64_gauge_handle}); |
|
|
|
|
Duration::Seconds(5), int64_gauge_handle); |
|
|
|
|
callback2 = group2.RegisterCallback( |
|
|
|
|
[&](CallbackMetricReporter& reporter) { |
|
|
|
|
reporter.Report(int64_gauge_handle, 4, kLabelValues2, |
|
|
|
|
reporter.Report(int64_gauge_handle, int64_t(4), kLabelValues2, |
|
|
|
|
kOptionalLabelValues); |
|
|
|
|
}, |
|
|
|
|
{int64_gauge_handle}); |
|
|
|
|
Duration::Seconds(5), int64_gauge_handle); |
|
|
|
|
// Plugin1 still has data from before, but the others have none.
|
|
|
|
|
EXPECT_THAT(plugin1->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_THAT(plugin1->GetInt64CallbackGaugeValue( |
|
|
|
|
int64_gauge_handle, kLabelValues, kOptionalLabelValues), |
|
|
|
|
::testing::Optional(1)); |
|
|
|
|
EXPECT_THAT(plugin1->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues2, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_THAT(plugin1->GetInt64CallbackGaugeValue( |
|
|
|
|
int64_gauge_handle, kLabelValues2, kOptionalLabelValues), |
|
|
|
|
::testing::Optional(2)); |
|
|
|
|
EXPECT_EQ(plugin2->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_EQ(plugin2->GetInt64CallbackGaugeValue( |
|
|
|
|
int64_gauge_handle, kLabelValues, kOptionalLabelValues), |
|
|
|
|
absl::nullopt); |
|
|
|
|
EXPECT_EQ(plugin2->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues2, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_EQ(plugin2->GetInt64CallbackGaugeValue( |
|
|
|
|
int64_gauge_handle, kLabelValues2, kOptionalLabelValues), |
|
|
|
|
absl::nullopt); |
|
|
|
|
EXPECT_EQ(plugin3->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_EQ(plugin3->GetInt64CallbackGaugeValue( |
|
|
|
|
int64_gauge_handle, kLabelValues, kOptionalLabelValues), |
|
|
|
|
absl::nullopt); |
|
|
|
|
EXPECT_EQ(plugin3->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues2, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_EQ(plugin3->GetInt64CallbackGaugeValue( |
|
|
|
|
int64_gauge_handle, kLabelValues2, kOptionalLabelValues), |
|
|
|
|
absl::nullopt); |
|
|
|
|
// Now invoke the callbacks.
|
|
|
|
|
plugin1->TriggerCallbacks(); |
|
|
|
|
plugin2->TriggerCallbacks(); |
|
|
|
|
plugin3->TriggerCallbacks(); |
|
|
|
|
// Now plugin1 and plugin2 should have data, but plugin3 should not.
|
|
|
|
|
EXPECT_THAT(plugin1->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_THAT(plugin1->GetInt64CallbackGaugeValue( |
|
|
|
|
int64_gauge_handle, kLabelValues, kOptionalLabelValues), |
|
|
|
|
::testing::Optional(3)); |
|
|
|
|
EXPECT_THAT(plugin1->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues2, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_THAT(plugin1->GetInt64CallbackGaugeValue( |
|
|
|
|
int64_gauge_handle, kLabelValues2, kOptionalLabelValues), |
|
|
|
|
::testing::Optional(4)); |
|
|
|
|
EXPECT_THAT(plugin2->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_THAT(plugin2->GetInt64CallbackGaugeValue( |
|
|
|
|
int64_gauge_handle, kLabelValues, kOptionalLabelValues), |
|
|
|
|
::testing::Optional(3)); |
|
|
|
|
EXPECT_THAT(plugin2->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues2, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_THAT(plugin2->GetInt64CallbackGaugeValue( |
|
|
|
|
int64_gauge_handle, kLabelValues2, kOptionalLabelValues), |
|
|
|
|
::testing::Optional(4)); |
|
|
|
|
EXPECT_EQ(plugin3->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_EQ(plugin3->GetInt64CallbackGaugeValue( |
|
|
|
|
int64_gauge_handle, kLabelValues, kOptionalLabelValues), |
|
|
|
|
absl::nullopt); |
|
|
|
|
EXPECT_EQ(plugin3->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues2, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_EQ(plugin3->GetInt64CallbackGaugeValue( |
|
|
|
|
int64_gauge_handle, kLabelValues2, kOptionalLabelValues), |
|
|
|
|
absl::nullopt); |
|
|
|
|
// De-register the callbacks.
|
|
|
|
|
callback1.reset(); |
|
|
|
@ -348,57 +344,57 @@ TEST_F(MetricsTest, Int64CallbackGauge) { |
|
|
|
|
StatsPluginChannelScope(kDomain1To4, "")); |
|
|
|
|
callback1 = group3.RegisterCallback( |
|
|
|
|
[&](CallbackMetricReporter& reporter) { |
|
|
|
|
reporter.Report(int64_gauge_handle, 5, kLabelValues, |
|
|
|
|
reporter.Report(int64_gauge_handle, int64_t(5), kLabelValues, |
|
|
|
|
kOptionalLabelValues); |
|
|
|
|
}, |
|
|
|
|
{int64_gauge_handle}); |
|
|
|
|
Duration::Seconds(5), int64_gauge_handle); |
|
|
|
|
callback2 = group3.RegisterCallback( |
|
|
|
|
[&](CallbackMetricReporter& reporter) { |
|
|
|
|
reporter.Report(int64_gauge_handle, 6, kLabelValues2, |
|
|
|
|
reporter.Report(int64_gauge_handle, int64_t(6), kLabelValues2, |
|
|
|
|
kOptionalLabelValues); |
|
|
|
|
}, |
|
|
|
|
{int64_gauge_handle}); |
|
|
|
|
Duration::Seconds(5), int64_gauge_handle); |
|
|
|
|
// Plugin1 and plugin2 still has data from before, but plugin3 has none.
|
|
|
|
|
EXPECT_THAT(plugin1->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_THAT(plugin1->GetInt64CallbackGaugeValue( |
|
|
|
|
int64_gauge_handle, kLabelValues, kOptionalLabelValues), |
|
|
|
|
::testing::Optional(3)); |
|
|
|
|
EXPECT_THAT(plugin1->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues2, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_THAT(plugin1->GetInt64CallbackGaugeValue( |
|
|
|
|
int64_gauge_handle, kLabelValues2, kOptionalLabelValues), |
|
|
|
|
::testing::Optional(4)); |
|
|
|
|
EXPECT_THAT(plugin2->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_THAT(plugin2->GetInt64CallbackGaugeValue( |
|
|
|
|
int64_gauge_handle, kLabelValues, kOptionalLabelValues), |
|
|
|
|
::testing::Optional(3)); |
|
|
|
|
EXPECT_THAT(plugin2->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues2, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_THAT(plugin2->GetInt64CallbackGaugeValue( |
|
|
|
|
int64_gauge_handle, kLabelValues2, kOptionalLabelValues), |
|
|
|
|
::testing::Optional(4)); |
|
|
|
|
EXPECT_EQ(plugin3->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_EQ(plugin3->GetInt64CallbackGaugeValue( |
|
|
|
|
int64_gauge_handle, kLabelValues, kOptionalLabelValues), |
|
|
|
|
absl::nullopt); |
|
|
|
|
EXPECT_EQ(plugin3->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues2, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_EQ(plugin3->GetInt64CallbackGaugeValue( |
|
|
|
|
int64_gauge_handle, kLabelValues2, kOptionalLabelValues), |
|
|
|
|
absl::nullopt); |
|
|
|
|
// Now invoke the callbacks.
|
|
|
|
|
plugin1->TriggerCallbacks(); |
|
|
|
|
plugin2->TriggerCallbacks(); |
|
|
|
|
plugin3->TriggerCallbacks(); |
|
|
|
|
// Now plugin1 and plugin2 should have data, but plugin3 should not.
|
|
|
|
|
EXPECT_THAT(plugin1->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_THAT(plugin1->GetInt64CallbackGaugeValue( |
|
|
|
|
int64_gauge_handle, kLabelValues, kOptionalLabelValues), |
|
|
|
|
::testing::Optional(5)); |
|
|
|
|
EXPECT_THAT(plugin1->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues2, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_THAT(plugin1->GetInt64CallbackGaugeValue( |
|
|
|
|
int64_gauge_handle, kLabelValues2, kOptionalLabelValues), |
|
|
|
|
::testing::Optional(6)); |
|
|
|
|
EXPECT_THAT(plugin2->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_THAT(plugin2->GetInt64CallbackGaugeValue( |
|
|
|
|
int64_gauge_handle, kLabelValues, kOptionalLabelValues), |
|
|
|
|
::testing::Optional(5)); |
|
|
|
|
EXPECT_THAT(plugin2->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues2, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_THAT(plugin2->GetInt64CallbackGaugeValue( |
|
|
|
|
int64_gauge_handle, kLabelValues2, kOptionalLabelValues), |
|
|
|
|
::testing::Optional(6)); |
|
|
|
|
EXPECT_THAT(plugin3->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_THAT(plugin3->GetInt64CallbackGaugeValue( |
|
|
|
|
int64_gauge_handle, kLabelValues, kOptionalLabelValues), |
|
|
|
|
::testing::Optional(5)); |
|
|
|
|
EXPECT_THAT(plugin3->GetCallbackGaugeValue(int64_gauge_handle, kLabelValues2, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_THAT(plugin3->GetInt64CallbackGaugeValue( |
|
|
|
|
int64_gauge_handle, kLabelValues2, kOptionalLabelValues), |
|
|
|
|
::testing::Optional(6)); |
|
|
|
|
// Need to destroy callbacks before the plugin group that created them.
|
|
|
|
|
callback1.reset(); |
|
|
|
@ -406,18 +402,17 @@ TEST_F(MetricsTest, Int64CallbackGauge) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(MetricsTest, DoubleCallbackGauge) { |
|
|
|
|
const absl::string_view kLabelKeys[] = {"label_key_1", "label_key_2"}; |
|
|
|
|
const absl::string_view kOptionalLabelKeys[] = {"optional_label_key_1", |
|
|
|
|
"optional_label_key_2"}; |
|
|
|
|
auto double_gauge_handle = |
|
|
|
|
GlobalInstrumentsRegistry::RegisterCallbackDoubleGauge( |
|
|
|
|
"double_gauge", "A simple double gauge.", "unit", kLabelKeys, |
|
|
|
|
kOptionalLabelKeys, true); |
|
|
|
|
constexpr absl::string_view kLabelValues[] = {"label_value_1", |
|
|
|
|
"label_value_2"}; |
|
|
|
|
constexpr absl::string_view kLabelValues2[] = {"label_value_3", |
|
|
|
|
"label_value_2"}; |
|
|
|
|
constexpr absl::string_view kOptionalLabelValues[] = { |
|
|
|
|
"double_gauge", "A simple double gauge.", "unit", true) |
|
|
|
|
.Labels("label_key_1", "label_key_2") |
|
|
|
|
.OptionalLabels("optional_label_key_1", "optional_label_key_2") |
|
|
|
|
.Build(); |
|
|
|
|
std::array<absl::string_view, 2> kLabelValues = {"label_value_1", |
|
|
|
|
"label_value_2"}; |
|
|
|
|
std::array<absl::string_view, 2> kLabelValues2 = {"label_value_3", |
|
|
|
|
"label_value_2"}; |
|
|
|
|
std::array<absl::string_view, 2> kOptionalLabelValues = { |
|
|
|
|
"optional_label_value_1", "optional_label_value_2"}; |
|
|
|
|
constexpr absl::string_view kDomain1To4 = "domain1.domain2.domain3.domain4"; |
|
|
|
|
constexpr absl::string_view kDomain2To4 = "domain2.domain3.domain4"; |
|
|
|
@ -435,54 +430,54 @@ TEST_F(MetricsTest, DoubleCallbackGauge) { |
|
|
|
|
reporter.Report(double_gauge_handle, 1.23, kLabelValues, |
|
|
|
|
kOptionalLabelValues); |
|
|
|
|
}, |
|
|
|
|
{double_gauge_handle}); |
|
|
|
|
Duration::Seconds(5), double_gauge_handle); |
|
|
|
|
auto callback2 = group1.RegisterCallback( |
|
|
|
|
[&](CallbackMetricReporter& reporter) { |
|
|
|
|
reporter.Report(double_gauge_handle, 2.34, kLabelValues2, |
|
|
|
|
kOptionalLabelValues); |
|
|
|
|
}, |
|
|
|
|
{double_gauge_handle}); |
|
|
|
|
Duration::Seconds(5), double_gauge_handle); |
|
|
|
|
// No plugins have data yet.
|
|
|
|
|
EXPECT_EQ(plugin1->GetCallbackGaugeValue(double_gauge_handle, kLabelValues, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_EQ(plugin1->GetDoubleCallbackGaugeValue( |
|
|
|
|
double_gauge_handle, kLabelValues, kOptionalLabelValues), |
|
|
|
|
absl::nullopt); |
|
|
|
|
EXPECT_EQ(plugin1->GetCallbackGaugeValue(double_gauge_handle, kLabelValues2, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_EQ(plugin1->GetDoubleCallbackGaugeValue( |
|
|
|
|
double_gauge_handle, kLabelValues2, kOptionalLabelValues), |
|
|
|
|
absl::nullopt); |
|
|
|
|
EXPECT_EQ(plugin2->GetCallbackGaugeValue(double_gauge_handle, kLabelValues, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_EQ(plugin2->GetDoubleCallbackGaugeValue( |
|
|
|
|
double_gauge_handle, kLabelValues, kOptionalLabelValues), |
|
|
|
|
absl::nullopt); |
|
|
|
|
EXPECT_EQ(plugin2->GetCallbackGaugeValue(double_gauge_handle, kLabelValues2, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_EQ(plugin2->GetDoubleCallbackGaugeValue( |
|
|
|
|
double_gauge_handle, kLabelValues2, kOptionalLabelValues), |
|
|
|
|
absl::nullopt); |
|
|
|
|
EXPECT_EQ(plugin3->GetCallbackGaugeValue(double_gauge_handle, kLabelValues, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_EQ(plugin3->GetDoubleCallbackGaugeValue( |
|
|
|
|
double_gauge_handle, kLabelValues, kOptionalLabelValues), |
|
|
|
|
absl::nullopt); |
|
|
|
|
EXPECT_EQ(plugin3->GetCallbackGaugeValue(double_gauge_handle, kLabelValues2, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_EQ(plugin3->GetDoubleCallbackGaugeValue( |
|
|
|
|
double_gauge_handle, kLabelValues2, kOptionalLabelValues), |
|
|
|
|
absl::nullopt); |
|
|
|
|
// Now invoke the callbacks.
|
|
|
|
|
plugin1->TriggerCallbacks(); |
|
|
|
|
plugin2->TriggerCallbacks(); |
|
|
|
|
plugin3->TriggerCallbacks(); |
|
|
|
|
// Now plugin1 should have data, but the others should not.
|
|
|
|
|
EXPECT_THAT(plugin1->GetCallbackGaugeValue(double_gauge_handle, kLabelValues, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_THAT(plugin1->GetDoubleCallbackGaugeValue( |
|
|
|
|
double_gauge_handle, kLabelValues, kOptionalLabelValues), |
|
|
|
|
::testing::Optional(1.23)); |
|
|
|
|
EXPECT_THAT(plugin1->GetCallbackGaugeValue(double_gauge_handle, kLabelValues2, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_THAT(plugin1->GetDoubleCallbackGaugeValue( |
|
|
|
|
double_gauge_handle, kLabelValues2, kOptionalLabelValues), |
|
|
|
|
::testing::Optional(2.34)); |
|
|
|
|
EXPECT_EQ(plugin2->GetCallbackGaugeValue(double_gauge_handle, kLabelValues, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_EQ(plugin2->GetDoubleCallbackGaugeValue( |
|
|
|
|
double_gauge_handle, kLabelValues, kOptionalLabelValues), |
|
|
|
|
absl::nullopt); |
|
|
|
|
EXPECT_EQ(plugin2->GetCallbackGaugeValue(double_gauge_handle, kLabelValues2, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_EQ(plugin2->GetDoubleCallbackGaugeValue( |
|
|
|
|
double_gauge_handle, kLabelValues2, kOptionalLabelValues), |
|
|
|
|
absl::nullopt); |
|
|
|
|
EXPECT_EQ(plugin3->GetCallbackGaugeValue(double_gauge_handle, kLabelValues, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_EQ(plugin3->GetDoubleCallbackGaugeValue( |
|
|
|
|
double_gauge_handle, kLabelValues, kOptionalLabelValues), |
|
|
|
|
absl::nullopt); |
|
|
|
|
EXPECT_EQ(plugin3->GetCallbackGaugeValue(double_gauge_handle, kLabelValues2, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_EQ(plugin3->GetDoubleCallbackGaugeValue( |
|
|
|
|
double_gauge_handle, kLabelValues2, kOptionalLabelValues), |
|
|
|
|
absl::nullopt); |
|
|
|
|
// De-register the callbacks.
|
|
|
|
|
callback1.reset(); |
|
|
|
@ -496,54 +491,54 @@ TEST_F(MetricsTest, DoubleCallbackGauge) { |
|
|
|
|
reporter.Report(double_gauge_handle, 3.45, kLabelValues, |
|
|
|
|
kOptionalLabelValues); |
|
|
|
|
}, |
|
|
|
|
{double_gauge_handle}); |
|
|
|
|
Duration::Seconds(5), double_gauge_handle); |
|
|
|
|
callback2 = group2.RegisterCallback( |
|
|
|
|
[&](CallbackMetricReporter& reporter) { |
|
|
|
|
reporter.Report(double_gauge_handle, 4.56, kLabelValues2, |
|
|
|
|
kOptionalLabelValues); |
|
|
|
|
}, |
|
|
|
|
{double_gauge_handle}); |
|
|
|
|
Duration::Seconds(5), double_gauge_handle); |
|
|
|
|
// Plugin1 still has data from before, but the others have none.
|
|
|
|
|
EXPECT_THAT(plugin1->GetCallbackGaugeValue(double_gauge_handle, kLabelValues, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_THAT(plugin1->GetDoubleCallbackGaugeValue( |
|
|
|
|
double_gauge_handle, kLabelValues, kOptionalLabelValues), |
|
|
|
|
::testing::Optional(1.23)); |
|
|
|
|
EXPECT_THAT(plugin1->GetCallbackGaugeValue(double_gauge_handle, kLabelValues2, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_THAT(plugin1->GetDoubleCallbackGaugeValue( |
|
|
|
|
double_gauge_handle, kLabelValues2, kOptionalLabelValues), |
|
|
|
|
::testing::Optional(2.34)); |
|
|
|
|
EXPECT_EQ(plugin2->GetCallbackGaugeValue(double_gauge_handle, kLabelValues, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_EQ(plugin2->GetDoubleCallbackGaugeValue( |
|
|
|
|
double_gauge_handle, kLabelValues, kOptionalLabelValues), |
|
|
|
|
absl::nullopt); |
|
|
|
|
EXPECT_EQ(plugin2->GetCallbackGaugeValue(double_gauge_handle, kLabelValues2, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_EQ(plugin2->GetDoubleCallbackGaugeValue( |
|
|
|
|
double_gauge_handle, kLabelValues2, kOptionalLabelValues), |
|
|
|
|
absl::nullopt); |
|
|
|
|
EXPECT_EQ(plugin3->GetCallbackGaugeValue(double_gauge_handle, kLabelValues, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_EQ(plugin3->GetDoubleCallbackGaugeValue( |
|
|
|
|
double_gauge_handle, kLabelValues, kOptionalLabelValues), |
|
|
|
|
absl::nullopt); |
|
|
|
|
EXPECT_EQ(plugin3->GetCallbackGaugeValue(double_gauge_handle, kLabelValues2, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_EQ(plugin3->GetDoubleCallbackGaugeValue( |
|
|
|
|
double_gauge_handle, kLabelValues2, kOptionalLabelValues), |
|
|
|
|
absl::nullopt); |
|
|
|
|
// Now invoke the callbacks.
|
|
|
|
|
plugin1->TriggerCallbacks(); |
|
|
|
|
plugin2->TriggerCallbacks(); |
|
|
|
|
plugin3->TriggerCallbacks(); |
|
|
|
|
// Now plugin1 and plugin2 should have data, but plugin3 should not.
|
|
|
|
|
EXPECT_THAT(plugin1->GetCallbackGaugeValue(double_gauge_handle, kLabelValues, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_THAT(plugin1->GetDoubleCallbackGaugeValue( |
|
|
|
|
double_gauge_handle, kLabelValues, kOptionalLabelValues), |
|
|
|
|
::testing::Optional(3.45)); |
|
|
|
|
EXPECT_THAT(plugin1->GetCallbackGaugeValue(double_gauge_handle, kLabelValues2, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_THAT(plugin1->GetDoubleCallbackGaugeValue( |
|
|
|
|
double_gauge_handle, kLabelValues2, kOptionalLabelValues), |
|
|
|
|
::testing::Optional(4.56)); |
|
|
|
|
EXPECT_THAT(plugin2->GetCallbackGaugeValue(double_gauge_handle, kLabelValues, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_THAT(plugin2->GetDoubleCallbackGaugeValue( |
|
|
|
|
double_gauge_handle, kLabelValues, kOptionalLabelValues), |
|
|
|
|
::testing::Optional(3.45)); |
|
|
|
|
EXPECT_THAT(plugin2->GetCallbackGaugeValue(double_gauge_handle, kLabelValues2, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_THAT(plugin2->GetDoubleCallbackGaugeValue( |
|
|
|
|
double_gauge_handle, kLabelValues2, kOptionalLabelValues), |
|
|
|
|
::testing::Optional(4.56)); |
|
|
|
|
EXPECT_EQ(plugin3->GetCallbackGaugeValue(double_gauge_handle, kLabelValues, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_EQ(plugin3->GetDoubleCallbackGaugeValue( |
|
|
|
|
double_gauge_handle, kLabelValues, kOptionalLabelValues), |
|
|
|
|
absl::nullopt); |
|
|
|
|
EXPECT_EQ(plugin3->GetCallbackGaugeValue(double_gauge_handle, kLabelValues2, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_EQ(plugin3->GetDoubleCallbackGaugeValue( |
|
|
|
|
double_gauge_handle, kLabelValues2, kOptionalLabelValues), |
|
|
|
|
absl::nullopt); |
|
|
|
|
// De-register the callbacks.
|
|
|
|
|
callback1.reset(); |
|
|
|
@ -557,54 +552,54 @@ TEST_F(MetricsTest, DoubleCallbackGauge) { |
|
|
|
|
reporter.Report(double_gauge_handle, 5.67, kLabelValues, |
|
|
|
|
kOptionalLabelValues); |
|
|
|
|
}, |
|
|
|
|
{double_gauge_handle}); |
|
|
|
|
Duration::Seconds(5), double_gauge_handle); |
|
|
|
|
callback2 = group3.RegisterCallback( |
|
|
|
|
[&](CallbackMetricReporter& reporter) { |
|
|
|
|
reporter.Report(double_gauge_handle, 6.78, kLabelValues2, |
|
|
|
|
kOptionalLabelValues); |
|
|
|
|
}, |
|
|
|
|
{double_gauge_handle}); |
|
|
|
|
Duration::Seconds(5), double_gauge_handle); |
|
|
|
|
// Plugin1 and plugin2 still has data from before, but plugin3 has none.
|
|
|
|
|
EXPECT_THAT(plugin1->GetCallbackGaugeValue(double_gauge_handle, kLabelValues, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_THAT(plugin1->GetDoubleCallbackGaugeValue( |
|
|
|
|
double_gauge_handle, kLabelValues, kOptionalLabelValues), |
|
|
|
|
::testing::Optional(3.45)); |
|
|
|
|
EXPECT_THAT(plugin1->GetCallbackGaugeValue(double_gauge_handle, kLabelValues2, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_THAT(plugin1->GetDoubleCallbackGaugeValue( |
|
|
|
|
double_gauge_handle, kLabelValues2, kOptionalLabelValues), |
|
|
|
|
::testing::Optional(4.56)); |
|
|
|
|
EXPECT_THAT(plugin2->GetCallbackGaugeValue(double_gauge_handle, kLabelValues, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_THAT(plugin2->GetDoubleCallbackGaugeValue( |
|
|
|
|
double_gauge_handle, kLabelValues, kOptionalLabelValues), |
|
|
|
|
::testing::Optional(3.45)); |
|
|
|
|
EXPECT_THAT(plugin2->GetCallbackGaugeValue(double_gauge_handle, kLabelValues2, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_THAT(plugin2->GetDoubleCallbackGaugeValue( |
|
|
|
|
double_gauge_handle, kLabelValues2, kOptionalLabelValues), |
|
|
|
|
::testing::Optional(4.56)); |
|
|
|
|
EXPECT_EQ(plugin3->GetCallbackGaugeValue(double_gauge_handle, kLabelValues, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_EQ(plugin3->GetDoubleCallbackGaugeValue( |
|
|
|
|
double_gauge_handle, kLabelValues, kOptionalLabelValues), |
|
|
|
|
absl::nullopt); |
|
|
|
|
EXPECT_EQ(plugin3->GetCallbackGaugeValue(double_gauge_handle, kLabelValues2, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_EQ(plugin3->GetDoubleCallbackGaugeValue( |
|
|
|
|
double_gauge_handle, kLabelValues2, kOptionalLabelValues), |
|
|
|
|
absl::nullopt); |
|
|
|
|
// Now invoke the callbacks.
|
|
|
|
|
plugin1->TriggerCallbacks(); |
|
|
|
|
plugin2->TriggerCallbacks(); |
|
|
|
|
plugin3->TriggerCallbacks(); |
|
|
|
|
// Now plugin1 and plugin2 should have data, but plugin3 should not.
|
|
|
|
|
EXPECT_THAT(plugin1->GetCallbackGaugeValue(double_gauge_handle, kLabelValues, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_THAT(plugin1->GetDoubleCallbackGaugeValue( |
|
|
|
|
double_gauge_handle, kLabelValues, kOptionalLabelValues), |
|
|
|
|
::testing::Optional(5.67)); |
|
|
|
|
EXPECT_THAT(plugin1->GetCallbackGaugeValue(double_gauge_handle, kLabelValues2, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_THAT(plugin1->GetDoubleCallbackGaugeValue( |
|
|
|
|
double_gauge_handle, kLabelValues2, kOptionalLabelValues), |
|
|
|
|
::testing::Optional(6.78)); |
|
|
|
|
EXPECT_THAT(plugin2->GetCallbackGaugeValue(double_gauge_handle, kLabelValues, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_THAT(plugin2->GetDoubleCallbackGaugeValue( |
|
|
|
|
double_gauge_handle, kLabelValues, kOptionalLabelValues), |
|
|
|
|
::testing::Optional(5.67)); |
|
|
|
|
EXPECT_THAT(plugin2->GetCallbackGaugeValue(double_gauge_handle, kLabelValues2, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_THAT(plugin2->GetDoubleCallbackGaugeValue( |
|
|
|
|
double_gauge_handle, kLabelValues2, kOptionalLabelValues), |
|
|
|
|
::testing::Optional(6.78)); |
|
|
|
|
EXPECT_THAT(plugin3->GetCallbackGaugeValue(double_gauge_handle, kLabelValues, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_THAT(plugin3->GetDoubleCallbackGaugeValue( |
|
|
|
|
double_gauge_handle, kLabelValues, kOptionalLabelValues), |
|
|
|
|
::testing::Optional(5.67)); |
|
|
|
|
EXPECT_THAT(plugin3->GetCallbackGaugeValue(double_gauge_handle, kLabelValues2, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_THAT(plugin3->GetDoubleCallbackGaugeValue( |
|
|
|
|
double_gauge_handle, kLabelValues2, kOptionalLabelValues), |
|
|
|
|
::testing::Optional(6.78)); |
|
|
|
|
// Need to destroy callbacks before the plugin group that created them.
|
|
|
|
|
callback1.reset(); |
|
|
|
@ -612,16 +607,15 @@ TEST_F(MetricsTest, DoubleCallbackGauge) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(MetricsTest, DisableByDefaultMetricIsNotRecordedByFakeStatsPlugin) { |
|
|
|
|
const absl::string_view kLabelKeys[] = {"label_key_1", "label_key_2"}; |
|
|
|
|
const absl::string_view kOptionalLabelKeys[] = {"optional_label_key_1", |
|
|
|
|
"optional_label_key_2"}; |
|
|
|
|
auto double_histogram_handle = |
|
|
|
|
GlobalInstrumentsRegistry::RegisterDoubleHistogram( |
|
|
|
|
"double_histogram", "A simple double histogram.", "unit", kLabelKeys, |
|
|
|
|
kOptionalLabelKeys, /*enable_by_default=*/false); |
|
|
|
|
constexpr absl::string_view kLabelValues[] = {"label_value_1", |
|
|
|
|
"label_value_2"}; |
|
|
|
|
constexpr absl::string_view kOptionalLabelValues[] = { |
|
|
|
|
"double_histogram", "A simple double histogram.", "unit", false) |
|
|
|
|
.Labels("label_key_1", "label_key_2") |
|
|
|
|
.OptionalLabels("optional_label_key_1", "optional_label_key_2") |
|
|
|
|
.Build(); |
|
|
|
|
std::array<absl::string_view, 2> kLabelValues = {"label_value_1", |
|
|
|
|
"label_value_2"}; |
|
|
|
|
std::array<absl::string_view, 2> kOptionalLabelValues = { |
|
|
|
|
"optional_label_value_1", "optional_label_value_2"}; |
|
|
|
|
constexpr absl::string_view kDomain1To4 = "domain1.domain2.domain3.domain4"; |
|
|
|
|
auto plugin = MakeStatsPluginForTarget(kDomain1To4); |
|
|
|
@ -629,24 +623,26 @@ TEST_F(MetricsTest, DisableByDefaultMetricIsNotRecordedByFakeStatsPlugin) { |
|
|
|
|
StatsPluginChannelScope(kDomain1To4, "")) |
|
|
|
|
.RecordHistogram(double_histogram_handle, 1.23, kLabelValues, |
|
|
|
|
kOptionalLabelValues); |
|
|
|
|
EXPECT_EQ(plugin->GetHistogramValue(double_histogram_handle, kLabelValues, |
|
|
|
|
kOptionalLabelValues), |
|
|
|
|
EXPECT_EQ(plugin->GetDoubleHistogramValue(double_histogram_handle, |
|
|
|
|
kLabelValues, kOptionalLabelValues), |
|
|
|
|
absl::nullopt); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
using MetricsDeathTest = MetricsTest; |
|
|
|
|
|
|
|
|
|
TEST_F(MetricsDeathTest, RegisterTheSameMetricNameWouldCrash) { |
|
|
|
|
const absl::string_view kLabelKeys[] = {"label_key_1", "label_key_2"}; |
|
|
|
|
const absl::string_view kOptionalLabelKeys[] = {"optional_label_key_1", |
|
|
|
|
"optional_label_key_2"}; |
|
|
|
|
(void)GlobalInstrumentsRegistry::RegisterDoubleHistogram( |
|
|
|
|
"double_histogram", "A simple double histogram.", "unit", kLabelKeys, |
|
|
|
|
kOptionalLabelKeys, true); |
|
|
|
|
EXPECT_DEATH(GlobalInstrumentsRegistry::RegisterDoubleHistogram( |
|
|
|
|
"double_histogram", "A simple double histogram.", "unit", |
|
|
|
|
kLabelKeys, kOptionalLabelKeys, true), |
|
|
|
|
"Metric name double_histogram has already been registered."); |
|
|
|
|
"double_histogram", "A simple double histogram.", "unit", true) |
|
|
|
|
.Labels("label_key_1", "label_key_2") |
|
|
|
|
.OptionalLabels("optional_label_key_1", "optional_label_key_2") |
|
|
|
|
.Build(); |
|
|
|
|
EXPECT_DEATH( |
|
|
|
|
GlobalInstrumentsRegistry::RegisterDoubleHistogram( |
|
|
|
|
"double_histogram", "A simple double histogram.", "unit", true) |
|
|
|
|
.Labels("label_key_1", "label_key_2") |
|
|
|
|
.OptionalLabels("optional_label_key_1", "optional_label_key_2") |
|
|
|
|
.Build(), |
|
|
|
|
"Metric name double_histogram has already been registered."); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|