job_statistics_ut.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. #include <yt/cpp/mapreduce/interface/job_statistics.h>
  2. #include <yt/cpp/mapreduce/interface/operation.h>
  3. #include <library/cpp/yson/node/node_io.h>
  4. #include <library/cpp/testing/unittest/registar.h>
  5. using namespace NYT;
  6. Y_UNIT_TEST_SUITE(JobStatistics)
  7. {
  8. Y_UNIT_TEST(Simple)
  9. {
  10. const TString input = R"""(
  11. {
  12. "data" = {
  13. "output" = {
  14. "0" = {
  15. "uncompressed_data_size" = {
  16. "$" = {
  17. "completed" = {
  18. "simple_sort" = {
  19. "max" = 130;
  20. "count" = 1;
  21. "min" = 130;
  22. "sum" = 130;
  23. };
  24. "map" = {
  25. "max" = 42;
  26. "count" = 1;
  27. "min" = 42;
  28. "sum" = 42;
  29. };
  30. };
  31. "aborted" = {
  32. "simple_sort" = {
  33. "max" = 24;
  34. "count" = 1;
  35. "min" = 24;
  36. "sum" = 24;
  37. };
  38. };
  39. };
  40. };
  41. };
  42. };
  43. };
  44. })""";
  45. TJobStatistics stat(NodeFromYsonString(input));
  46. UNIT_ASSERT(stat.HasStatistics("data/output/0/uncompressed_data_size"));
  47. UNIT_ASSERT(!stat.HasStatistics("nonexistent-statistics"));
  48. UNIT_ASSERT_EXCEPTION_CONTAINS(stat.GetStatistics("BLAH-BLAH"), yexception, "Statistics");
  49. UNIT_ASSERT_VALUES_EQUAL(stat.GetStatisticsNames(), TVector<TString>{"data/output/0/uncompressed_data_size"});
  50. UNIT_ASSERT_VALUES_EQUAL(stat.GetStatistics("data/output/0/uncompressed_data_size").Max(), 130);
  51. UNIT_ASSERT_VALUES_EQUAL(stat.GetStatistics("data/output/0/uncompressed_data_size").Count(), 2);
  52. UNIT_ASSERT_VALUES_EQUAL(stat.GetStatistics("data/output/0/uncompressed_data_size").Min(), 42);
  53. UNIT_ASSERT_VALUES_EQUAL(stat.GetStatistics("data/output/0/uncompressed_data_size").Sum(), 172);
  54. UNIT_ASSERT_VALUES_EQUAL(stat.GetStatistics("data/output/0/uncompressed_data_size").Avg(), 172 / 2);
  55. UNIT_ASSERT_VALUES_EQUAL(stat.JobState({EJobState::Aborted}).GetStatistics("data/output/0/uncompressed_data_size").Sum(), 24);
  56. UNIT_ASSERT_VALUES_EQUAL(stat.JobType({EJobType::Map}).JobState({EJobState::Aborted}).GetStatistics("data/output/0/uncompressed_data_size").Sum(), TMaybe<i64>());
  57. }
  58. Y_UNIT_TEST(TestOtherTypes)
  59. {
  60. const TString input = R"""(
  61. {
  62. "time" = {
  63. "exec" = {
  64. "$" = {
  65. "completed" = {
  66. "map" = {
  67. "max" = 2482468;
  68. "count" = 38;
  69. "min" = 578976;
  70. "sum" = 47987270;
  71. };
  72. };
  73. };
  74. };
  75. };
  76. })""";
  77. TJobStatistics stat(NodeFromYsonString(input));
  78. UNIT_ASSERT_VALUES_EQUAL(stat.GetStatisticsAs<TDuration>("time/exec").Max(), TDuration::MilliSeconds(2482468));
  79. }
  80. Y_UNIT_TEST(Custom)
  81. {
  82. const TString input = R"""(
  83. {
  84. "custom" = {
  85. "some" = {
  86. "path" = {
  87. "$" = {
  88. "completed" = {
  89. "map" = {
  90. "max" = -1;
  91. "count" = 1;
  92. "min" = -1;
  93. "sum" = -1;
  94. };
  95. };
  96. };
  97. };
  98. };
  99. "another" = {
  100. "path" = {
  101. "$" = {
  102. "completed" = {
  103. "map" = {
  104. "max" = 1001;
  105. "count" = 2;
  106. "min" = 1001;
  107. "sum" = 2002;
  108. };
  109. };
  110. };
  111. };
  112. };
  113. };
  114. })""";
  115. TJobStatistics stat(NodeFromYsonString(input));
  116. UNIT_ASSERT(stat.HasCustomStatistics("some/path"));
  117. UNIT_ASSERT(!stat.HasCustomStatistics("nonexistent-statistics"));
  118. UNIT_ASSERT_EXCEPTION_CONTAINS(stat.GetCustomStatistics("BLAH-BLAH"), yexception, "Statistics");
  119. const auto names = stat.GetCustomStatisticsNames();
  120. const THashSet<TString> expected = {"some/path", "another/path"};
  121. UNIT_ASSERT_VALUES_EQUAL(THashSet<TString>(names.begin(), names.end()), expected);
  122. UNIT_ASSERT_VALUES_EQUAL(stat.GetCustomStatistics("some/path").Max(), -1);
  123. UNIT_ASSERT_VALUES_EQUAL(stat.GetCustomStatistics("another/path").Avg(), 1001);
  124. }
  125. Y_UNIT_TEST(TaskNames)
  126. {
  127. const TString input = R"""(
  128. {
  129. "data" = {
  130. "output" = {
  131. "0" = {
  132. "uncompressed_data_size" = {
  133. "$" = {
  134. "completed" = {
  135. "partition_map" = {
  136. "max" = 130;
  137. "count" = 1;
  138. "min" = 130;
  139. "sum" = 130;
  140. };
  141. "partition(0)" = {
  142. "max" = 42;
  143. "count" = 1;
  144. "min" = 42;
  145. "sum" = 42;
  146. };
  147. };
  148. "aborted" = {
  149. "simple_sort" = {
  150. "max" = 24;
  151. "count" = 1;
  152. "min" = 24;
  153. "sum" = 24;
  154. };
  155. };
  156. };
  157. };
  158. };
  159. };
  160. };
  161. })""";
  162. TJobStatistics stat(NodeFromYsonString(input));
  163. UNIT_ASSERT(stat.HasStatistics("data/output/0/uncompressed_data_size"));
  164. UNIT_ASSERT(!stat.HasStatistics("nonexistent-statistics"));
  165. UNIT_ASSERT_EXCEPTION_CONTAINS(stat.GetStatistics("BLAH-BLAH"), yexception, "Statistics");
  166. UNIT_ASSERT_VALUES_EQUAL(stat.GetStatisticsNames(), TVector<TString>{"data/output/0/uncompressed_data_size"});
  167. UNIT_ASSERT_VALUES_EQUAL(stat.GetStatistics("data/output/0/uncompressed_data_size").Max(), 130);
  168. UNIT_ASSERT_VALUES_EQUAL(stat.GetStatistics("data/output/0/uncompressed_data_size").Count(), 2);
  169. UNIT_ASSERT_VALUES_EQUAL(stat.GetStatistics("data/output/0/uncompressed_data_size").Min(), 42);
  170. UNIT_ASSERT_VALUES_EQUAL(stat.GetStatistics("data/output/0/uncompressed_data_size").Sum(), 172);
  171. UNIT_ASSERT_VALUES_EQUAL(stat.GetStatistics("data/output/0/uncompressed_data_size").Avg(), 172 / 2);
  172. UNIT_ASSERT_VALUES_EQUAL(
  173. stat
  174. .JobState({EJobState::Aborted})
  175. .GetStatistics("data/output/0/uncompressed_data_size")
  176. .Sum(),
  177. 24);
  178. UNIT_ASSERT_VALUES_EQUAL(
  179. stat
  180. .JobType({EJobType::Partition})
  181. .JobState({EJobState::Aborted})
  182. .GetStatistics("data/output/0/uncompressed_data_size")
  183. .Sum(),
  184. TMaybe<i64>());
  185. UNIT_ASSERT_VALUES_EQUAL(
  186. stat
  187. .TaskName({"partition(0)"})
  188. .GetStatistics("data/output/0/uncompressed_data_size")
  189. .Sum(),
  190. 42);
  191. UNIT_ASSERT_VALUES_EQUAL(
  192. stat
  193. .TaskName({"partition"})
  194. .GetStatistics("data/output/0/uncompressed_data_size")
  195. .Sum(),
  196. TMaybe<i64>());
  197. UNIT_ASSERT_VALUES_EQUAL(
  198. stat
  199. .TaskName({"partition_map(0)"})
  200. .GetStatistics("data/output/0/uncompressed_data_size")
  201. .Sum(),
  202. 130);
  203. UNIT_ASSERT_VALUES_EQUAL(
  204. stat
  205. .JobType({EJobType::Partition})
  206. .GetStatistics("data/output/0/uncompressed_data_size")
  207. .Sum(),
  208. 42);
  209. UNIT_ASSERT_VALUES_EQUAL(
  210. stat
  211. .JobType({EJobType::PartitionMap})
  212. .GetStatistics("data/output/0/uncompressed_data_size")
  213. .Sum(),
  214. 130);
  215. UNIT_ASSERT_VALUES_EQUAL(
  216. stat
  217. .TaskName({ETaskName::Partition0})
  218. .GetStatistics("data/output/0/uncompressed_data_size")
  219. .Sum(),
  220. 42);
  221. UNIT_ASSERT_VALUES_EQUAL(
  222. stat
  223. .TaskName({ETaskName::Partition1})
  224. .GetStatistics("data/output/0/uncompressed_data_size")
  225. .Sum(),
  226. TMaybe<i64>());
  227. UNIT_ASSERT_VALUES_EQUAL(
  228. stat
  229. .TaskName({ETaskName::PartitionMap0})
  230. .GetStatistics("data/output/0/uncompressed_data_size")
  231. .Sum(),
  232. 130);
  233. }
  234. }