Skip to content

Commit

Permalink
chore: update ut
Browse files Browse the repository at this point in the history
  • Loading branch information
catdogpandas committed Nov 18, 2024
1 parent 83105da commit 74c5671
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions core/unittest/prometheus/ScrapeSchedulerUnittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "common/StringTools.h"
#include "common/http/HttpResponse.h"
#include "common/timer/Timer.h"
#include "models/RawEvent.h"
#include "prometheus/Constants.h"
#include "prometheus/async/PromFuture.h"
#include "prometheus/labels/Labels.h"
Expand Down Expand Up @@ -154,33 +155,27 @@ void ScrapeSchedulerUnittest::TestStreamMetricWriteCallback() {
auto& res = httpResponse.GetBody<PromMetricResponseBody>()->mEventGroup;
APSARA_TEST_EQUAL(7UL, res.GetEvents().size());
APSARA_TEST_EQUAL("go_gc_duration_seconds{quantile=\"0\"} 1.5531e-05",
res.GetEvents()[0].Cast<LogEvent>().GetContent(prometheus::PROMETHEUS).to_string());
res.GetEvents()[0].Cast<RawEvent>().GetContent());
APSARA_TEST_EQUAL("go_gc_duration_seconds{quantile=\"0.25\"} 3.9357e-05",
res.GetEvents()[1].Cast<LogEvent>().GetContent(prometheus::PROMETHEUS).to_string());
res.GetEvents()[1].Cast<RawEvent>().GetContent());
APSARA_TEST_EQUAL("go_gc_duration_seconds{quantile=\"0.5\"} 4.1114e-05",
res.GetEvents()[2].Cast<LogEvent>().GetContent(prometheus::PROMETHEUS).to_string());
res.GetEvents()[2].Cast<RawEvent>().GetContent());
APSARA_TEST_EQUAL("go_gc_duration_seconds{quantile=\"0.75\"} 4.3372e-05",
res.GetEvents()[3].Cast<LogEvent>().GetContent(prometheus::PROMETHEUS).to_string());
res.GetEvents()[3].Cast<RawEvent>().GetContent());
APSARA_TEST_EQUAL("go_gc_duration_seconds{quantile=\"1\"} 0.000112326",
res.GetEvents()[4].Cast<LogEvent>().GetContent(prometheus::PROMETHEUS).to_string());
APSARA_TEST_EQUAL("go_gc_duration_seconds_sum 0.034885631",
res.GetEvents()[5].Cast<LogEvent>().GetContent(prometheus::PROMETHEUS).to_string());
APSARA_TEST_EQUAL("go_gc_duration_seconds_count 850",
res.GetEvents()[6].Cast<LogEvent>().GetContent(prometheus::PROMETHEUS).to_string());
res.GetEvents()[4].Cast<RawEvent>().GetContent());
APSARA_TEST_EQUAL("go_gc_duration_seconds_sum 0.034885631", res.GetEvents()[5].Cast<RawEvent>().GetContent());
APSARA_TEST_EQUAL("go_gc_duration_seconds_count 850", res.GetEvents()[6].Cast<RawEvent>().GetContent());
// httpResponse.GetBody<MetricResponseBody>()->mEventGroup = PipelineEventGroup(std::make_shared<SourceBuffer>());
PromMetricWriteCallback(
body2.data(), (size_t)1, (size_t)body2.length(), (void*)httpResponse.GetBody<PromMetricResponseBody>());
httpResponse.GetBody<PromMetricResponseBody>()->FlushCache();
APSARA_TEST_EQUAL(11UL, res.GetEvents().size());

APSARA_TEST_EQUAL("go_goroutines 7",
res.GetEvents()[7].Cast<LogEvent>().GetContent(prometheus::PROMETHEUS).to_string());
APSARA_TEST_EQUAL("go_info{version=\"go1.22.3\"} 1",
res.GetEvents()[8].Cast<LogEvent>().GetContent(prometheus::PROMETHEUS).to_string());
APSARA_TEST_EQUAL("go_memstats_alloc_bytes 6.742688e+06",
res.GetEvents()[9].Cast<LogEvent>().GetContent(prometheus::PROMETHEUS).to_string());
APSARA_TEST_EQUAL("go_memstats_alloc_bytes_total 1.5159292e+08",
res.GetEvents()[10].Cast<LogEvent>().GetContent(prometheus::PROMETHEUS).to_string());
APSARA_TEST_EQUAL("go_goroutines 7", res.GetEvents()[7].Cast<RawEvent>().GetContent());
APSARA_TEST_EQUAL("go_info{version=\"go1.22.3\"} 1", res.GetEvents()[8].Cast<RawEvent>().GetContent());
APSARA_TEST_EQUAL("go_memstats_alloc_bytes 6.742688e+06", res.GetEvents()[9].Cast<RawEvent>().GetContent());
APSARA_TEST_EQUAL("go_memstats_alloc_bytes_total 1.5159292e+08", res.GetEvents()[10].Cast<RawEvent>().GetContent());
}

void ScrapeSchedulerUnittest::TestReceiveMessage() {
Expand Down

0 comments on commit 74c5671

Please sign in to comment.