Move "cell_reader_test.cc" to xla/tsl/lib/monitoring.

PiperOrigin-RevId: 823067036
This commit is contained in:
A. Unique TensorFlower 2025-10-23 09:15:05 -07:00 committed by TensorFlower Gardener
parent b7b3893296
commit d98db379d1
4 changed files with 116 additions and 108 deletions

View File

@ -1936,21 +1936,15 @@ tf_cc_tests(
)
tf_cc_tests(
name = "cell_reader_test",
name = "test_utils_test",
size = "small",
srcs = [
"//tensorflow/core/lib/monitoring:cell_reader_test.cc",
"//tensorflow/core/lib/monitoring:test_utils_test.cc",
],
deps = [
":protos_all_cc",
":test",
":test_main",
"//tensorflow/core/lib/monitoring:cell_reader",
"//tensorflow/core/lib/monitoring:counter",
"//tensorflow/core/lib/monitoring:gauge",
"//tensorflow/core/lib/monitoring:percentile_sampler",
"//tensorflow/core/lib/monitoring:sampler",
"//tensorflow/core/lib/monitoring:test_utils",
"//tensorflow/core/lib/monitoring:types",
"//tensorflow/core/platform:errors",

View File

@ -263,7 +263,6 @@ filegroup(
# "/tensorflow/test/sampler_without_labels").
exports_files(
[
"cell_reader_test.cc",
"collection_registry_test.cc",
"counter_test.cc",
"gauge_test.cc",

View File

@ -1,5 +1,9 @@
load("//xla/tsl:tsl.bzl", "internal_visibility")
load("//xla/tsl:tsl.default.bzl", "filegroup")
load(
"//xla/tsl/platform:build_config.bzl",
"tsl_cc_test",
)
load(
"//xla/tsl/platform:rules_cc.bzl",
"cc_library",
@ -180,6 +184,22 @@ cc_library(
],
)
tsl_cc_test(
name = "cell_reader_test",
size = "small",
srcs = ["cell_reader_test.cc"],
deps = [
":cell_reader",
":counter",
":gauge",
":percentile_sampler",
":sampler",
":test_utils",
":types",
"@com_google_googletest//:gtest_main",
],
)
cc_library(
name = "percentile_sampler",
srcs = ["percentile_sampler.cc"],

View File

@ -12,21 +12,22 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#include "tensorflow/core/lib/monitoring/cell_reader.h"
#include "xla/tsl/lib/monitoring/cell_reader.h"
#include <cstdint>
#include <string>
#include <vector>
#include "tensorflow/core/lib/monitoring/counter.h"
#include "tensorflow/core/lib/monitoring/gauge.h"
#include "tensorflow/core/lib/monitoring/percentile_sampler.h"
#include "tensorflow/core/lib/monitoring/sampler.h"
#include "tensorflow/core/lib/monitoring/test_utils.h"
#include "tensorflow/core/lib/monitoring/types.h"
#include "tensorflow/core/platform/test.h"
#include <gtest/gtest.h>
#include "xla/tsl/lib/monitoring/counter.h"
#include "xla/tsl/lib/monitoring/gauge.h"
#include "xla/tsl/lib/monitoring/percentile_sampler.h"
#include "xla/tsl/lib/monitoring/sampler.h"
#include "xla/tsl/lib/monitoring/test_utils.h"
#include "xla/tsl/lib/monitoring/types.h"
namespace tensorflow {
namespace tsl {
namespace monitoring {
namespace testing {
namespace {
@ -35,64 +36,65 @@ std::vector<double> GetDefaultPercentiles() {
return {25.0, 50.0, 80.0, 90.0, 95.0, 99.0};
}
auto* test_counter = monitoring::Counter<0>::New(
"/tensorflow/monitoring/test/counter", "Test counter.");
auto* test_counter = tsl::monitoring::Counter<0>::New(
"/tsl/monitoring/test/counter", "Test counter.");
auto* test_counter_with_labels = monitoring::Counter<2>::New(
"/tensorflow/monitoring/test/counter_with_labels",
"Test counter with two labels.", "label1", "label2");
auto* test_counter_with_labels = tsl::monitoring::Counter<2>::New(
"/tsl/monitoring/test/counter_with_labels", "Test counter with two labels.",
"label1", "label2");
auto* test_sampler = monitoring::Sampler<0>::New(
{"/tensorflow/monitoring/test/sampler", "Test sampler."},
/*buckets=*/monitoring::Buckets::Explicit(
auto* test_sampler = tsl::monitoring::Sampler<0>::New(
{"/tsl/monitoring/test/sampler", "Test sampler."},
/*buckets=*/tsl::monitoring::Buckets::Explicit(
{0.0, 0.2, 0.4, 0.6, 0.8, 1.0, 1.2, 1.4, 1.6, 1.8, 2.0}));
auto* test_sampler_with_labels = monitoring::Sampler<2>::New(
{"/tensorflow/monitoring/test/sampler_with_labels", "Test sampler.",
"label1", "label2"},
/*buckets=*/monitoring::Buckets::Exponential(
auto* test_sampler_with_labels = tsl::monitoring::Sampler<2>::New(
{"/tsl/monitoring/test/sampler_with_labels", "Test sampler.", "label1",
"label2"},
/*buckets=*/tsl::monitoring::Buckets::Exponential(
/*scale=*/1, /*growth_factor=*/10, /*bucket_count=*/5));
auto* test_int_gauge = monitoring::Gauge<int64_t, 0>::New(
"/tensorflow/monitoring/test/int_gauge", "Test gauge.");
auto* test_int_gauge = tsl::monitoring::Gauge<int64_t, 0>::New(
"/tsl/monitoring/test/int_gauge", "Test gauge.");
auto* test_int_gauge_with_labels = monitoring::Gauge<int64_t, 2>::New(
"/tensorflow/monitoring/test/int_gauge_with_labels", "Test gauge.",
"label1", "label2");
auto* test_int_gauge_with_labels = tsl::monitoring::Gauge<int64_t, 2>::New(
"/tsl/monitoring/test/int_gauge_with_labels", "Test gauge.", "label1",
"label2");
auto* test_string_gauge = monitoring::Gauge<std::string, 0>::New(
"/tensorflow/monitoring/test/string_gauge", "Test gauge.");
auto* test_string_gauge = tsl::monitoring::Gauge<std::string, 0>::New(
"/tsl/monitoring/test/string_gauge", "Test gauge.");
auto* test_string_gauge_with_labels = monitoring::Gauge<std::string, 2>::New(
"/tensorflow/monitoring/test/string_gauge_with_labels", "Test gauge.",
"label1", "label2");
auto* test_string_gauge_with_labels =
tsl::monitoring::Gauge<std::string, 2>::New(
"/tsl/monitoring/test/string_gauge_with_labels", "Test gauge.",
"label1", "label2");
auto* test_bool_gauge = monitoring::Gauge<bool, 0>::New(
"/tensorflow/monitoring/test/bool_gauge", "Test gauge.");
auto* test_bool_gauge = tsl::monitoring::Gauge<bool, 0>::New(
"/tsl/monitoring/test/bool_gauge", "Test gauge.");
auto* test_bool_gauge_with_labels = monitoring::Gauge<bool, 2>::New(
"/tensorflow/monitoring/test/bool_gauge_with_labels", "Test gauge.",
"label1", "label2");
auto* test_bool_gauge_with_labels = tsl::monitoring::Gauge<bool, 2>::New(
"/tsl/monitoring/test/bool_gauge_with_labels", "Test gauge.", "label1",
"label2");
auto* test_percentiles = monitoring::PercentileSampler<0>::New(
{"/tensorflow/monitoring/test/percentiles", "Test percentiles."},
auto* test_percentiles = tsl::monitoring::PercentileSampler<0>::New(
{"/tsl/monitoring/test/percentiles", "Test percentiles."},
GetDefaultPercentiles(), /*max_samples=*/1024,
monitoring::UnitOfMeasure::kTime);
tsl::monitoring::UnitOfMeasure::kTime);
auto* test_percentiles_with_labels = monitoring::PercentileSampler<2>::New(
{"/tensorflow/monitoring/test/percentiles_with_labels", "Test percentiles.",
auto* test_percentiles_with_labels = tsl::monitoring::PercentileSampler<2>::New(
{"/tsl/monitoring/test/percentiles_with_labels", "Test percentiles.",
"label1", "label2"},
GetDefaultPercentiles(), /*max_samples=*/1024,
monitoring::UnitOfMeasure::kTime);
tsl::monitoring::UnitOfMeasure::kTime);
void IncrementLazyCounter() {
static auto* test_counter = monitoring::Counter<0>::New(
"/tensorflow/monitoring/test/lazy_counter", "Test lazy counter.");
"/tsl/monitoring/test/lazy_counter", "Test lazy counter.");
test_counter->GetCell()->IncrementBy(1);
}
TEST(CellReaderTest, CounterDeltaNoLabels) {
CellReader<int64_t> cell_reader("/tensorflow/monitoring/test/counter");
CellReader<int64_t> cell_reader("/tsl/monitoring/test/counter");
EXPECT_EQ(cell_reader.Delta(), 0);
test_counter->GetCell()->IncrementBy(5);
@ -106,7 +108,7 @@ TEST(CellReaderTest, CounterDeltaNoLabels) {
}
TEST(CellReaderTest, CounterReadNoLabels) {
CellReader<int64_t> cell_reader("/tensorflow/monitoring/test/counter");
CellReader<int64_t> cell_reader("/tsl/monitoring/test/counter");
EXPECT_EQ(cell_reader.Read(), 0);
test_counter->GetCell()->IncrementBy(5);
@ -120,7 +122,7 @@ TEST(CellReaderTest, CounterReadNoLabels) {
}
TEST(CellReaderTest, CounterDeltaAndReadNoLabels) {
CellReader<int64_t> cell_reader("/tensorflow/monitoring/test/counter");
CellReader<int64_t> cell_reader("/tsl/monitoring/test/counter");
EXPECT_EQ(cell_reader.Delta(), 0);
EXPECT_EQ(cell_reader.Read(), 0);
@ -138,8 +140,7 @@ TEST(CellReaderTest, CounterDeltaAndReadNoLabels) {
}
TEST(CellReaderTest, CounterDeltaWithLabels) {
CellReader<int64_t> cell_reader(
"/tensorflow/monitoring/test/counter_with_labels");
CellReader<int64_t> cell_reader("/tsl/monitoring/test/counter_with_labels");
EXPECT_EQ(cell_reader.Delta("x1", "y1"), 0);
EXPECT_EQ(cell_reader.Delta("x1", "y2"), 0);
EXPECT_EQ(cell_reader.Delta("x2", "y1"), 0);
@ -170,8 +171,7 @@ TEST(CellReaderTest, CounterDeltaWithLabels) {
}
TEST(CellReaderTest, CounterReadWithLabels) {
CellReader<int64_t> cell_reader(
"/tensorflow/monitoring/test/counter_with_labels");
CellReader<int64_t> cell_reader("/tsl/monitoring/test/counter_with_labels");
EXPECT_EQ(cell_reader.Read("x1", "y1"), 0);
EXPECT_EQ(cell_reader.Read("x1", "y2"), 0);
EXPECT_EQ(cell_reader.Read("x2", "y1"), 0);
@ -202,8 +202,7 @@ TEST(CellReaderTest, CounterReadWithLabels) {
}
TEST(CellReaderTest, CounterDeltaAndReadWithLabels) {
CellReader<int64_t> cell_reader(
"/tensorflow/monitoring/test/counter_with_labels");
CellReader<int64_t> cell_reader("/tsl/monitoring/test/counter_with_labels");
EXPECT_EQ(cell_reader.Delta("x1", "y1"), 0);
EXPECT_EQ(cell_reader.Delta("x1", "y2"), 0);
EXPECT_EQ(cell_reader.Delta("x2", "y1"), 0);
@ -250,9 +249,9 @@ TEST(CellReaderTest, CounterDeltaAndReadWithLabels) {
}
TEST(CellReaderTest, TwoCounterReaders) {
CellReader<int64_t> cell_reader("/tensorflow/monitoring/test/counter");
CellReader<int64_t> cell_reader("/tsl/monitoring/test/counter");
CellReader<int64_t> cell_reader_with_labels(
"/tensorflow/monitoring/test/counter_with_labels");
"/tsl/monitoring/test/counter_with_labels");
EXPECT_EQ(cell_reader.Delta(), 0);
EXPECT_EQ(cell_reader_with_labels.Delta("x1", "y1"), 0);
EXPECT_EQ(cell_reader_with_labels.Delta("x2", "y2"), 0);
@ -290,9 +289,9 @@ TEST(CellReaderTest, TwoCounterReaders) {
}
TEST(CellReaderTest, RepeatedReads) {
CellReader<int64_t> cell_reader("/tensorflow/monitoring/test/counter");
CellReader<int64_t> cell_reader("/tsl/monitoring/test/counter");
CellReader<int64_t> cell_reader_with_labels(
"/tensorflow/monitoring/test/counter_with_labels");
"/tsl/monitoring/test/counter_with_labels");
EXPECT_EQ(cell_reader.Delta(), 0);
EXPECT_EQ(cell_reader_with_labels.Delta("x1", "y1"), 0);
EXPECT_EQ(cell_reader_with_labels.Delta("x2", "y2"), 0);
@ -320,7 +319,7 @@ TEST(CellReaderTest, RepeatedReads) {
}
TEST(CellReaderTest, SamplerDeltaNoLabels) {
CellReader<Histogram> cell_reader("/tensorflow/monitoring/test/sampler");
CellReader<Histogram> cell_reader("/tsl/monitoring/test/sampler");
Histogram histogram = cell_reader.Delta();
EXPECT_FLOAT_EQ(histogram.num(), 0.0);
EXPECT_FLOAT_EQ(histogram.sum(), 0.0);
@ -398,7 +397,7 @@ TEST(CellReaderTest, SamplerDeltaNoLabels) {
}
TEST(CellReaderTest, SamplerReadNoLabels) {
CellReader<Histogram> cell_reader("/tensorflow/monitoring/test/sampler");
CellReader<Histogram> cell_reader("/tsl/monitoring/test/sampler");
Histogram histogram = cell_reader.Read();
EXPECT_FLOAT_EQ(histogram.num(), 0.0);
EXPECT_FLOAT_EQ(histogram.sum(), 0.0);
@ -476,7 +475,7 @@ TEST(CellReaderTest, SamplerReadNoLabels) {
}
TEST(CellReaderTest, SamplerDeltaAndReadNoLabels) {
CellReader<Histogram> cell_reader("/tensorflow/monitoring/test/sampler");
CellReader<Histogram> cell_reader("/tsl/monitoring/test/sampler");
Histogram histogram = cell_reader.Delta();
EXPECT_FLOAT_EQ(histogram.num(), 0.0);
EXPECT_FLOAT_EQ(histogram.sum(), 0.0);
@ -591,8 +590,7 @@ TEST(CellReaderTest, SamplerDeltaAndReadNoLabels) {
}
TEST(CellReaderTest, SamplerDeltaWithLabels) {
CellReader<Histogram> cell_reader(
"/tensorflow/monitoring/test/sampler_with_labels");
CellReader<Histogram> cell_reader("/tsl/monitoring/test/sampler_with_labels");
Histogram histogram = cell_reader.Delta("x1", "y1");
EXPECT_FLOAT_EQ(histogram.num(), 0.0);
EXPECT_FLOAT_EQ(histogram.sum(), 0.0);
@ -683,8 +681,7 @@ TEST(CellReaderTest, SamplerDeltaWithLabels) {
}
TEST(CellReaderTest, SamplerReadWithLabels) {
CellReader<Histogram> cell_reader(
"/tensorflow/monitoring/test/sampler_with_labels");
CellReader<Histogram> cell_reader("/tsl/monitoring/test/sampler_with_labels");
Histogram histogram = cell_reader.Read("x1", "y1");
EXPECT_FLOAT_EQ(histogram.num(), 0.0);
EXPECT_FLOAT_EQ(histogram.sum(), 0.0);
@ -775,8 +772,7 @@ TEST(CellReaderTest, SamplerReadWithLabels) {
}
TEST(CellReaderTest, SamplerRepeatedReads) {
CellReader<Histogram> cell_reader(
"/tensorflow/monitoring/test/sampler_with_labels");
CellReader<Histogram> cell_reader("/tsl/monitoring/test/sampler_with_labels");
Histogram histogram = cell_reader.Read("x1", "y1");
EXPECT_FLOAT_EQ(histogram.num(), 0.0);
EXPECT_FLOAT_EQ(histogram.sum(), 0.0);
@ -884,7 +880,7 @@ TEST(CellReaderTest, SamplerRepeatedReads) {
}
TEST(CellReaderTest, IntGaugeRead) {
CellReader<int64_t> cell_reader("/tensorflow/monitoring/test/int_gauge");
CellReader<int64_t> cell_reader("/tsl/monitoring/test/int_gauge");
EXPECT_EQ(cell_reader.Read(), 0);
test_int_gauge->GetCell()->Set(100);
@ -898,8 +894,7 @@ TEST(CellReaderTest, IntGaugeRead) {
}
TEST(CellReaderTest, IntGaugeReadWithLabels) {
CellReader<int64_t> cell_reader(
"/tensorflow/monitoring/test/int_gauge_with_labels");
CellReader<int64_t> cell_reader("/tsl/monitoring/test/int_gauge_with_labels");
EXPECT_EQ(cell_reader.Read("x1", "y1"), 0);
EXPECT_EQ(cell_reader.Read("x2", "y2"), 0);
@ -919,11 +914,12 @@ TEST(CellReaderTest, IntGaugeReadWithLabels) {
test_int_gauge_with_labels->GetCell("x1", "y1")->Set(0);
EXPECT_EQ(cell_reader.Read("x1", "y1"), 0);
EXPECT_EQ(cell_reader.Read("x2", "y2"), 100000);
test_int_gauge_with_labels->GetCell("x2", "y2")->Set(0);
EXPECT_EQ(cell_reader.Read("x2", "y2"), 0);
}
TEST(CellReaderTest, IntGaugeRepeatedSetAndRead) {
CellReader<int64_t> cell_reader(
"/tensorflow/monitoring/test/int_gauge_with_labels");
CellReader<int64_t> cell_reader("/tsl/monitoring/test/int_gauge_with_labels");
test_int_gauge_with_labels->GetCell("x1", "y1")->Set(-1);
test_int_gauge_with_labels->GetCell("x2", "y2")->Set(1);
@ -946,11 +942,12 @@ TEST(CellReaderTest, IntGaugeRepeatedSetAndRead) {
EXPECT_EQ(cell_reader.Read("x2", "y2"), -500);
EXPECT_EQ(cell_reader.Read("x1", "y1"), 0);
EXPECT_EQ(cell_reader.Read("x2", "y2"), -500);
test_int_gauge_with_labels->GetCell("x2", "y2")->Set(0);
EXPECT_EQ(cell_reader.Read("x2", "y2"), 0);
}
TEST(CellReaderTest, StringGaugeRead) {
CellReader<std::string> cell_reader(
"/tensorflow/monitoring/test/string_gauge");
CellReader<std::string> cell_reader("/tsl/monitoring/test/string_gauge");
EXPECT_EQ(cell_reader.Read(), "");
test_string_gauge->GetCell()->Set("gauge value");
@ -965,7 +962,7 @@ TEST(CellReaderTest, StringGaugeRead) {
TEST(CellReaderTest, StringGaugeReadWithLabels) {
CellReader<std::string> cell_reader(
"/tensorflow/monitoring/test/string_gauge_with_labels");
"/tsl/monitoring/test/string_gauge_with_labels");
EXPECT_EQ(cell_reader.Read("x1", "y1"), "");
EXPECT_EQ(cell_reader.Read("x2", "y2"), "");
@ -990,7 +987,7 @@ TEST(CellReaderTest, StringGaugeReadWithLabels) {
TEST(CellReaderTest, StringGaugeRepeatedSetAndRead) {
CellReader<std::string> cell_reader(
"/tensorflow/monitoring/test/string_gauge_with_labels");
"/tsl/monitoring/test/string_gauge_with_labels");
EXPECT_EQ(cell_reader.Read("x1", "y1"), "");
EXPECT_EQ(cell_reader.Read("x2", "y2"), "");
@ -1015,10 +1012,14 @@ TEST(CellReaderTest, StringGaugeRepeatedSetAndRead) {
EXPECT_EQ(cell_reader.Read("x2", "y2"), "-10");
EXPECT_EQ(cell_reader.Read("x1", "y1"), "-10");
EXPECT_EQ(cell_reader.Read("x2", "y2"), "-10");
test_string_gauge_with_labels->GetCell("x1", "y1")->Set("");
test_string_gauge_with_labels->GetCell("x2", "y2")->Set("");
EXPECT_EQ(cell_reader.Read("x1", "y1"), "");
EXPECT_EQ(cell_reader.Read("x2", "y2"), "");
}
TEST(CellReaderTest, BoolGaugeRead) {
CellReader<bool> cell_reader("/tensorflow/monitoring/test/bool_gauge");
CellReader<bool> cell_reader("/tsl/monitoring/test/bool_gauge");
EXPECT_EQ(cell_reader.Read(), false);
test_bool_gauge->GetCell()->Set(true);
@ -1029,8 +1030,7 @@ TEST(CellReaderTest, BoolGaugeRead) {
}
TEST(CellReaderTest, BoolGaugeReadWithLabels) {
CellReader<bool> cell_reader(
"/tensorflow/monitoring/test/bool_gauge_with_labels");
CellReader<bool> cell_reader("/tsl/monitoring/test/bool_gauge_with_labels");
EXPECT_EQ(cell_reader.Read("x1", "y1"), false);
EXPECT_EQ(cell_reader.Read("x2", "y2"), false);
@ -1054,8 +1054,7 @@ TEST(CellReaderTest, BoolGaugeReadWithLabels) {
}
TEST(CellReaderTest, BoolGaugeRepeatedSetAndRead) {
CellReader<bool> cell_reader(
"/tensorflow/monitoring/test/bool_gauge_with_labels");
CellReader<bool> cell_reader("/tsl/monitoring/test/bool_gauge_with_labels");
EXPECT_EQ(cell_reader.Read("x1", "y1"), false);
EXPECT_EQ(cell_reader.Read("x2", "y2"), false);
@ -1080,11 +1079,12 @@ TEST(CellReaderTest, BoolGaugeRepeatedSetAndRead) {
EXPECT_EQ(cell_reader.Read("x2", "y2"), true);
EXPECT_EQ(cell_reader.Read("x1", "y1"), false);
EXPECT_EQ(cell_reader.Read("x2", "y2"), true);
test_bool_gauge_with_labels->GetCell("x2", "y2")->Set(false);
EXPECT_EQ(cell_reader.Read("x2", "y2"), false);
}
TEST(CellReaderTest, PercentilesDeltaNoLabels) {
CellReader<Percentiles> cell_reader(
"/tensorflow/monitoring/test/percentiles");
CellReader<Percentiles> cell_reader("/tsl/monitoring/test/percentiles");
Percentiles percentiles = cell_reader.Delta();
EXPECT_EQ(percentiles.num(), 0);
EXPECT_FLOAT_EQ(percentiles.sum(), 0.0);
@ -1106,8 +1106,7 @@ TEST(CellReaderTest, PercentilesDeltaNoLabels) {
}
TEST(CellReaderTest, PercentilesReadNoLabels) {
CellReader<Percentiles> cell_reader(
"/tensorflow/monitoring/test/percentiles");
CellReader<Percentiles> cell_reader("/tsl/monitoring/test/percentiles");
Percentiles percentiles = cell_reader.Read();
EXPECT_EQ(percentiles.num(), 0);
EXPECT_FLOAT_EQ(percentiles.sum(), 0.0);
@ -1130,7 +1129,7 @@ TEST(CellReaderTest, PercentilesReadNoLabels) {
TEST(CellReaderTest, PercentilesWithLabels) {
CellReader<Percentiles> cell_reader(
"/tensorflow/monitoring/test/percentiles_with_labels");
"/tsl/monitoring/test/percentiles_with_labels");
Percentiles percentiles = cell_reader.Delta("x1", "y1");
EXPECT_EQ(percentiles.num(), 0);
EXPECT_FLOAT_EQ(percentiles.sum(), 0.0);
@ -1190,7 +1189,7 @@ TEST(CellReaderTest, PercentilesWithLabels) {
TEST(CellReaderTest, PercentilesRepeatedSetAndRead) {
CellReader<Percentiles> cell_reader(
"/tensorflow/monitoring/test/percentiles_with_labels");
"/tsl/monitoring/test/percentiles_with_labels");
Percentiles percentiles = cell_reader.Delta("x1", "y1");
EXPECT_EQ(percentiles.num(), 0);
EXPECT_FLOAT_EQ(percentiles.sum(), 0.0);
@ -1238,16 +1237,15 @@ TEST(CellReaderTest, PercentilesRepeatedSetAndRead) {
EXPECT_FLOAT_EQ(percentiles.sum(), -111.0);
}
#if GTEST_HAS_DEATH_TEST
TEST(CellReaderTest, WrongNumberOfLabels) {
CellReader<int64_t> cell_reader("/tensorflow/monitoring/test/counter");
CellReader<int64_t> cell_reader("/tsl/monitoring/test/counter");
EXPECT_EQ(cell_reader.Read(), 0);
EXPECT_DEATH(cell_reader.Read("label1"), "has 0 labels");
EXPECT_DEATH(cell_reader.Read("label1", "label2"), "has 0 labels");
EXPECT_DEATH(cell_reader.Read("label1", "label2", "label3"), "has 0 labels");
CellReader<int64_t> cell_reader_with_labels(
"/tensorflow/monitoring/test/counter_with_labels");
"/tsl/monitoring/test/counter_with_labels");
EXPECT_DEATH(cell_reader_with_labels.Read(), "has 2 labels");
EXPECT_DEATH(cell_reader_with_labels.Read("label1"), "has 2 labels");
EXPECT_EQ(cell_reader_with_labels.Read("label1", "label2"), 0);
@ -1263,29 +1261,27 @@ TEST(CellReaderTest, MetricIsNotFoundRead) {
}
TEST(CellReaderTest, StringGaugeDelta) {
CellReader<std::string> cell_reader(
"/tensorflow/monitoring/test/string_gauge");
CellReader<std::string> cell_reader("/tsl/monitoring/test/string_gauge");
CellReader<std::string> cell_reader_with_labels(
"/tensorflow/monitoring/test/string_gauge_with_labels");
"/tsl/monitoring/test/string_gauge_with_labels");
EXPECT_DEATH(cell_reader.Delta(), "Please use `Read` instead.");
EXPECT_DEATH(cell_reader_with_labels.Delta("x", "y"),
"Please use `Read` instead.");
}
TEST(CellReaderTest, BoolGaugeDelta) {
CellReader<bool> cell_reader("/tensorflow/monitoring/test/bool_gauge");
CellReader<bool> cell_reader("/tsl/monitoring/test/bool_gauge");
CellReader<bool> cell_reader_with_labels(
"/tensorflow/monitoring/test/bool_gauge_with_labels");
"/tsl/monitoring/test/bool_gauge_with_labels");
EXPECT_DEATH(cell_reader.Delta(), "Please use `Read` instead.");
EXPECT_DEATH(cell_reader_with_labels.Delta("x", "y"),
"Please use `Read` instead.");
}
TEST(CellReaderTest, InvalidType) {
CellReader<std::vector<int>> cell_reader(
"/tensorflow/monitoring/test/counter");
CellReader<std::vector<int>> cell_reader("/tsl/monitoring/test/counter");
CellReader<std::vector<int>> cell_reader_with_labels(
"/tensorflow/monitoring/test/counter_with_labels");
"/tsl/monitoring/test/counter_with_labels");
EXPECT_DEATH(cell_reader.Read(),
"Tensorflow CellReader does not support type");
EXPECT_DEATH(cell_reader_with_labels.Delta("x", "y"),
@ -1298,7 +1294,6 @@ TEST(CellReaderTest, InvalidType) {
EXPECT_DEATH(cell_reader_with_labels.Delta("x", "y"),
"Tensorflow CellReader does not support type");
}
#endif
TEST(CellReaderTest, MetricIsNotFoundDelta) {
CellReader<int64_t> cell_reader("/metric/does/not/exist");
@ -1308,12 +1303,12 @@ TEST(CellReaderTest, MetricIsNotFoundDelta) {
}
TEST(CellReaderTest, LazyInitializationDelta) {
CellReader<int64_t> cell_reader("/tensorflow/monitoring/test/lazy_counter");
CellReader<int64_t> cell_reader("/tsl/monitoring/test/lazy_counter");
EXPECT_EQ(cell_reader.Delta(), 0);
}
TEST(CellReaderTest, LazyInitializationDeltaAfterIncrement) {
CellReader<int64_t> cell_reader("/tensorflow/monitoring/test/lazy_counter");
CellReader<int64_t> cell_reader("/tsl/monitoring/test/lazy_counter");
IncrementLazyCounter();
EXPECT_EQ(cell_reader.Delta(), 1);
}
@ -1321,4 +1316,4 @@ TEST(CellReaderTest, LazyInitializationDeltaAfterIncrement) {
} // namespace
} // namespace testing
} // namespace monitoring
} // namespace tensorflow
} // namespace tsl