|
1 | 1 | #include "envoy/grpc/async_client.h"
|
2 | 2 |
|
| 3 | +#include "source/common/protobuf/protobuf.h" |
3 | 4 | #include "source/common/tracing/null_span_impl.h"
|
4 | 5 | #include "source/extensions/stat_sinks/open_telemetry/open_telemetry_impl.h"
|
5 | 6 |
|
|
9 | 10 | #include "test/mocks/stats/mocks.h"
|
10 | 11 | #include "test/test_common/simulated_time_system.h"
|
11 | 12 |
|
12 |
| -#include "google/protobuf/text_format.h" |
13 | 13 | #include "gtest/gtest.h"
|
14 | 14 |
|
15 | 15 | using testing::_;
|
@@ -914,32 +914,28 @@ class OpenTelemetryGrpcSinkTests : public OpenTelemetryStatsSinkTests {
|
914 | 914 | public:
|
915 | 915 | OpenTelemetryGrpcSinkTests()
|
916 | 916 | : flusher_(std::make_shared<MockOtlpMetricsFlusher>()),
|
917 |
| - exporter_(std::make_shared<MockOpenTelemetryGrpcMetricsExporter>()) { |
918 |
| - time_t expected_time_2 = 1213; |
919 |
| - expected_time_ns_2_ = expected_time_2 * 1000000000; |
920 |
| - SystemTime time_2 = std::chrono::system_clock::from_time_t(expected_time_2); |
921 |
| - EXPECT_CALL(snapshot2_, snapshotTime()).WillRepeatedly(Return(time_2)); |
922 |
| - } |
| 917 | + exporter_(std::make_shared<MockOpenTelemetryGrpcMetricsExporter>()) {} |
923 | 918 |
|
924 |
| - long long int expected_time_ns_2_; |
925 |
| - NiceMock<Stats::MockMetricSnapshot> snapshot2_; |
926 |
| - const std::shared_ptr<MockOtlpMetricsFlusher> flusher_; |
927 |
| - const std::shared_ptr<MockOpenTelemetryGrpcMetricsExporter> exporter_; |
| 919 | + std::shared_ptr<MockOtlpMetricsFlusher> flusher_; |
| 920 | + std::shared_ptr<MockOpenTelemetryGrpcMetricsExporter> exporter_; |
928 | 921 | };
|
929 | 922 |
|
930 | 923 | TEST_F(OpenTelemetryGrpcSinkTests, BasicFlow) {
|
931 |
| - // First flush: last_flush_time_ns should be 0. |
932 |
| - MetricsExportRequestPtr request1 = std::make_unique<MetricsExportRequest>(); |
933 |
| - EXPECT_CALL(*flusher_, flush(_, 0)).WillOnce(Return(ByMove(std::move(request1)))); |
934 |
| - EXPECT_CALL(*exporter_, send(_)).Times(2); |
| 924 | + // Initialize the sink with a created_at time of 1000. |
| 925 | + OpenTelemetryGrpcSink sink(flusher_, exporter_, 1000); |
935 | 926 |
|
936 |
| - OpenTelemetryGrpcSink sink(flusher_, exporter_); |
| 927 | + // First flush: last_flush_time_ns should be the created_at value (1000). |
| 928 | + MetricsExportRequestPtr request1 = std::make_unique<MetricsExportRequest>(); |
| 929 | + EXPECT_CALL(*flusher_, flush(_, 1000)).WillOnce(Return(ByMove(std::move(request1)))); |
| 930 | + EXPECT_CALL(*exporter_, send(_)); |
937 | 931 | sink.flush(snapshot_);
|
938 | 932 |
|
939 |
| - // Second flush: last_flush_time_ns should be the time of the first snapshot. |
| 933 | + // Second flush: last_flush_time_ns should be the snapshotTime() of the |
| 934 | + // snapshot used in the first flush, which is expected_time_ns_. |
940 | 935 | MetricsExportRequestPtr request2 = std::make_unique<MetricsExportRequest>();
|
941 | 936 | EXPECT_CALL(*flusher_, flush(_, expected_time_ns_)).WillOnce(Return(ByMove(std::move(request2))));
|
942 |
| - sink.flush(snapshot2_); |
| 937 | + EXPECT_CALL(*exporter_, send(_)); |
| 938 | + sink.flush(snapshot_); |
943 | 939 | }
|
944 | 940 |
|
945 | 941 | } // namespace
|
|
0 commit comments