aboutsummaryrefslogtreecommitdiffstats
path: root/yt/cpp/mapreduce/interface/ut/job_statistics_ut.cpp
blob: 90d40623c174faab0db632f58eb5a50b6df48763 (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
#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/gtest/gtest.h>

using namespace NYT;

TEST(TJobStatisticsTest, 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));

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

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

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

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

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

    TJobStatistics stat(NodeFromYsonString(input));

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

TEST(TJobStatisticsTest, 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));

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

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

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

TEST(TJobStatisticsTest, 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));

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

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

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

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