aboutsummaryrefslogtreecommitdiffstats
path: root/yt/cpp/mapreduce/interface/job_statistics_ut.cpp
blob: 0cf53d771ac43b2ecfd87f33694d142008d179d7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
#include <yt/cpp/mapreduce/interface/job_statistics.h>
#include <yt/cpp/mapreduce/interface/operation.h>

#include <library/cpp/yson/node/node_io.h>

#include <library/cpp/testing/unittest/registar.h>

using namespace NYT;

Y_UNIT_TEST_SUITE(JobStatistics)
{
    Y_UNIT_TEST(Simple)
    {
        const TString input = R"""(
            {
               "data" = {
                  "output" = {
                      "0" = {
                          "uncompressed_data_size" = {
                              "$" = {
                                  "completed" = {
                                      "simple_sort" = {
                                          "max" = 130;
                                          "count" = 1;
                                          "min" = 130;
                                          "sum" = 130;
                                      };
                                      "map" = {
                                          "max" = 42;
                                          "count" = 1;
                                          "min" = 42;
                                          "sum" = 42;
                                      };
                                  };
                                  "aborted" = {
                                      "simple_sort" = {
                                          "max" = 24;
                                          "count" = 1;
                                          "min" = 24;
                                          "sum" = 24;
                                      };
                                  };
                              };
                          };
                      };
                  };
              };
            })""";

        TJobStatistics stat(NodeFromYsonString(input));

        UNIT_ASSERT(stat.HasStatistics("data/output/0/uncompressed_data_size"));
        UNIT_ASSERT(!stat.HasStatistics("nonexistent-statistics"));
        UNIT_ASSERT_EXCEPTION_CONTAINS(stat.GetStatistics("BLAH-BLAH"), yexception, "Statistics");

        UNIT_ASSERT_VALUES_EQUAL(stat.GetStatisticsNames(), TVector<TString>{"data/output/0/uncompressed_data_size"});

        UNIT_ASSERT_VALUES_EQUAL(stat.GetStatistics("data/output/0/uncompressed_data_size").Max(), 130);
        UNIT_ASSERT_VALUES_EQUAL(stat.GetStatistics("data/output/0/uncompressed_data_size").Count(), 2);
        UNIT_ASSERT_VALUES_EQUAL(stat.GetStatistics("data/output/0/uncompressed_data_size").Min(), 42);
        UNIT_ASSERT_VALUES_EQUAL(stat.GetStatistics("data/output/0/uncompressed_data_size").Sum(), 172);
        UNIT_ASSERT_VALUES_EQUAL(stat.GetStatistics("data/output/0/uncompressed_data_size").Avg(), 172 / 2);

        UNIT_ASSERT_VALUES_EQUAL(stat.JobState({EJobState::Aborted}).GetStatistics("data/output/0/uncompressed_data_size").Sum(), 24);
        UNIT_ASSERT_VALUES_EQUAL(stat.JobType({EJobType::Map}).JobState({EJobState::Aborted}).GetStatistics("data/output/0/uncompressed_data_size").Sum(), TMaybe<i64>());
    }

    Y_UNIT_TEST(TestOtherTypes)
    {
        const TString input = R"""(
        {
           "time" = {
               "exec" = {
                   "$" = {
                       "completed" = {
                           "map" = {
                               "max" = 2482468;
                               "count" = 38;
                               "min" = 578976;
                               "sum" = 47987270;
                           };
                       };
                   };
               };
           };
        })""";

        TJobStatistics stat(NodeFromYsonString(input));

        UNIT_ASSERT_VALUES_EQUAL(stat.GetStatisticsAs<TDuration>("time/exec").Max(), TDuration::MilliSeconds(2482468));
    }

    Y_UNIT_TEST(Custom)
    {
        const TString input = R"""(
            {
                "custom" = {
                    "some" = {
                        "path" = {
                            "$" = {
                                "completed" = {
                                    "map" = {
                                        "max" = -1;
                                        "count" = 1;
                                        "min" = -1;
                                        "sum" = -1;
                                    };
                                };
                            };
                        };
                    };
                    "another" = {
                        "path" = {
                            "$" = {
                                "completed" = {
                                    "map" = {
                                        "max" = 1001;
                                        "count" = 2;
                                        "min" = 1001;
                                        "sum" = 2002;
                                    };
                                };
                            };
                        };
                    };
                };
            })""";

        TJobStatistics stat(NodeFromYsonString(input));

        UNIT_ASSERT(stat.HasCustomStatistics("some/path"));
        UNIT_ASSERT(!stat.HasCustomStatistics("nonexistent-statistics"));
        UNIT_ASSERT_EXCEPTION_CONTAINS(stat.GetCustomStatistics("BLAH-BLAH"), yexception, "Statistics");

        const auto names = stat.GetCustomStatisticsNames();
        const THashSet<TString> expected = {"some/path", "another/path"};
        UNIT_ASSERT_VALUES_EQUAL(THashSet<TString>(names.begin(), names.end()), expected);

        UNIT_ASSERT_VALUES_EQUAL(stat.GetCustomStatistics("some/path").Max(), -1);
        UNIT_ASSERT_VALUES_EQUAL(stat.GetCustomStatistics("another/path").Avg(), 1001);
    }

    Y_UNIT_TEST(TaskNames)
    {
        const TString input = R"""(
            {
               "data" = {
                  "output" = {
                      "0" = {
                          "uncompressed_data_size" = {
                              "$" = {
                                  "completed" = {
                                      "partition_map" = {
                                          "max" = 130;
                                          "count" = 1;
                                          "min" = 130;
                                          "sum" = 130;
                                      };
                                      "partition(0)" = {
                                          "max" = 42;
                                          "count" = 1;
                                          "min" = 42;
                                          "sum" = 42;
                                      };
                                  };
                                  "aborted" = {
                                      "simple_sort" = {
                                          "max" = 24;
                                          "count" = 1;
                                          "min" = 24;
                                          "sum" = 24;
                                      };
                                  };
                              };
                          };
                      };
                  };
              };
            })""";

        TJobStatistics stat(NodeFromYsonString(input));

        UNIT_ASSERT(stat.HasStatistics("data/output/0/uncompressed_data_size"));
        UNIT_ASSERT(!stat.HasStatistics("nonexistent-statistics"));
        UNIT_ASSERT_EXCEPTION_CONTAINS(stat.GetStatistics("BLAH-BLAH"), yexception, "Statistics");

        UNIT_ASSERT_VALUES_EQUAL(stat.GetStatisticsNames(), TVector<TString>{"data/output/0/uncompressed_data_size"});

        UNIT_ASSERT_VALUES_EQUAL(stat.GetStatistics("data/output/0/uncompressed_data_size").Max(), 130);
        UNIT_ASSERT_VALUES_EQUAL(stat.GetStatistics("data/output/0/uncompressed_data_size").Count(), 2);
        UNIT_ASSERT_VALUES_EQUAL(stat.GetStatistics("data/output/0/uncompressed_data_size").Min(), 42);
        UNIT_ASSERT_VALUES_EQUAL(stat.GetStatistics("data/output/0/uncompressed_data_size").Sum(), 172);
        UNIT_ASSERT_VALUES_EQUAL(stat.GetStatistics("data/output/0/uncompressed_data_size").Avg(), 172 / 2);

        UNIT_ASSERT_VALUES_EQUAL(
            stat
                .JobState({EJobState::Aborted})
                .GetStatistics("data/output/0/uncompressed_data_size")
                .Sum(),
            24);
        UNIT_ASSERT_VALUES_EQUAL(
            stat
                .JobType({EJobType::Partition})
                .JobState({EJobState::Aborted})
                .GetStatistics("data/output/0/uncompressed_data_size")
                .Sum(),
            TMaybe<i64>());
        UNIT_ASSERT_VALUES_EQUAL(
            stat
                .TaskName({"partition(0)"})
                .GetStatistics("data/output/0/uncompressed_data_size")
                .Sum(),
            42);
        UNIT_ASSERT_VALUES_EQUAL(
            stat
                .TaskName({"partition"})
                .GetStatistics("data/output/0/uncompressed_data_size")
                .Sum(),
            TMaybe<i64>());
        UNIT_ASSERT_VALUES_EQUAL(
            stat
                .TaskName({"partition_map(0)"})
                .GetStatistics("data/output/0/uncompressed_data_size")
                .Sum(),
            130);
        UNIT_ASSERT_VALUES_EQUAL(
            stat
                .JobType({EJobType::Partition})
                .GetStatistics("data/output/0/uncompressed_data_size")
                .Sum(),
            42);
        UNIT_ASSERT_VALUES_EQUAL(
            stat
                .JobType({EJobType::PartitionMap})
                .GetStatistics("data/output/0/uncompressed_data_size")
                .Sum(),
            130);
        UNIT_ASSERT_VALUES_EQUAL(
            stat
                .TaskName({ETaskName::Partition0})
                .GetStatistics("data/output/0/uncompressed_data_size")
                .Sum(),
            42);
        UNIT_ASSERT_VALUES_EQUAL(
            stat
                .TaskName({ETaskName::Partition1})
                .GetStatistics("data/output/0/uncompressed_data_size")
                .Sum(),
            TMaybe<i64>());
        UNIT_ASSERT_VALUES_EQUAL(
            stat
                .TaskName({ETaskName::PartitionMap0})
                .GetStatistics("data/output/0/uncompressed_data_size")
                .Sum(),
            130);
    }
}