Trending: Prepare static content for the new UTI
[csit.git] / docs / cpta / methodology / trend_analysis.rst
1 Trend Analysis
2 ^^^^^^^^^^^^^^
3
4 All measured performance trend data is treated as time-series data
5 that is modeled as a concatenation of groups,
6 within each group the samples come (independently) from
7 the same normal distribution (with some center and standard deviation).
8
9 Center of the normal distribution for the group (equal to population average)
10 is called a trend for the group.
11 All the analysis is based on finding the right partition into groups
12 and comparing their trends.
13
14 Anomalies in graphs
15 ~~~~~~~~~~~~~~~~~~~
16
17 In graphs, the start of the following group is marked as a regression (red
18 circle) or progression (green circle), if the new trend is lower (or higher
19 respectively) then the previous group's.
20
21 Implementation details
22 ~~~~~~~~~~~~~~~~~~~~~~
23
24 Partitioning into groups
25 ------------------------
26
27 While sometimes the samples within a group are far from being distributed
28 normally, currently we do not have a better tractable model.
29
30 Here, "sample" should be the result of single trial measurement, with group
31 boundaries set only at test run granularity. But in order to avoid detecting
32 causes unrelated to VPP performance, the current presentation takes average of
33 all trials within the run as the sample. Effectively, this acts as a single
34 trial with aggregate duration.
35
36 Performance graphs show the run average as a dot (not all individual trial
37 results).
38
39 The group boundaries are selected based on `Minimum Description Length`_.
40
41 Minimum Description Length
42 --------------------------
43
44 `Minimum Description Length`_ (MDL) is a particular formalization
45 of `Occam's razor`_ principle.
46
47 The general formulation mandates to evaluate a large set of models,
48 but for anomaly detection purposes, it is useful to consider
49 a smaller set of models, so that scoring and comparing them is easier.
50
51 For each candidate model, the data should be compressed losslessly,
52 which includes model definitions, encoded model parameters,
53 and the raw data encoded based on probabilities computed by the model.
54 The model resulting in shortest compressed message is the "the" correct model.
55
56 For our model set (groups of normally distributed samples),
57 we need to encode group length (which penalizes too many groups),
58 group average (more on that later), group stdev and then all the samples.
59
60 Luckily, the "all the samples" part turns out to be quite easy to compute.
61 If sample values are considered as coordinates in (multi-dimensional)
62 Euclidean space, fixing stdev means the point with allowed coordinates
63 lays on a sphere. Fixing average intersects the sphere with a (hyper)-plane,
64 and Gaussian probability density on the resulting sphere is constant.
65 So the only contribution is the "area" of the sphere, which only depends
66 on the number of samples and stdev.
67
68 A somehow ambiguous part is in choosing which encoding
69 is used for group size, average and stdev.
70 Different encodings cause different biases to large or small values.
71 In our implementation we have chosen probability density
72 corresponding to uniform distribution (from zero to maximal sample value)
73 for stdev and average of the first group,
74 but for averages of subsequent groups we have chosen a distribution
75 which discourages delimiting groups with averages close together.
76
77 Our implementation assumes that measurement precision is 1.0 pps.
78 Thus it is slightly wrong for trial durations other than 1.0 seconds.
79 Also, all the calculations assume 1.0 pps is totally negligible,
80 compared to stdev value.
81
82 The group selection algorithm currently has no parameters,
83 all the aforementioned encodings and handling of precision is hard-coded.
84 In principle, every group selection is examined, and the one encodable
85 with least amount of bits is selected.
86 As the bit amount for a selection is just sum of bits for every group,
87 finding the best selection takes number of comparisons
88 quadratically increasing with the size of data,
89 the overall time complexity being probably cubic.
90
91 The resulting group distribution looks good
92 if samples are distributed normally enough within a group.
93 But for obviously different distributions (for example `bimodal distribution`_)
94 the groups tend to focus on less relevant factors (such as "outlier" density).
95
96 Common Patterns
97 ~~~~~~~~~~~~~~~
98
99 When an anomaly is detected, it frequently falls into few known patterns,
100 each having its typical behavior over time.
101
102 We are going to describe the behaviors,
103 as they motivate our choice of trend compliance metrics.
104
105 Sample time and analysis time
106 -----------------------------
107
108 But first we need to distinguish two roles time plays in analysis,
109 so it is more clear which role we are referring to.
110
111 Sample time is the more obvious one.
112 It is the time the sample is generated.
113 It is the start time or the end time of the Jenkins job run,
114 does not really matter which (parallel runs are disabled,
115 and length of gap between samples does not affect metrics).
116
117 Analysis time is the time the current analysis is computed.
118 Again, the exact time does not usually matter,
119 what matters is how many later (and how fewer earlier) samples
120 were considered in the computation.
121
122 For some patterns, it is usual for a previously reported
123 anomaly to "vanish", or previously unseen anomaly to "appear late",
124 as later samples change which partition into groups is more probable.
125
126 Dashboard and graphs are always showing the latest analysis time,
127 the compliance metrics are using earlier sample time
128 with the same latest analysis time.
129
130 Alerting e-mails use the latest analysis time at the time of sending,
131 so the values reported there are likely to be different
132 from the later analysis time results shown in dashboard and graphs.
133
134 Ordinary regression
135 -------------------
136
137 The real performance changes from previously stable value
138 into a new stable value.
139
140 For medium to high magnitude of the change, one run
141 is enough for anomaly detection to mark this regression.
142
143 Ordinary progressions are detected in the same way.
144
145 Small regression
146 ----------------
147
148 The real performance changes from previously stable value
149 into a new stable value, but the difference is small.
150
151 For the anomaly detection algorithm, this change is harder to detect,
152 depending on the standard deviation of the previous group.
153
154 If the new performance value stays stable, eventually
155 the detection algorithm is able to detect this anomaly
156 when there are enough samples around the new value.
157
158 If the difference is too small, it may remain undetected
159 (as new performance change happens, or full history of samples
160 is still not enough for the detection).
161
162 Small progressions have the same behavior.
163
164 Reverted regression
165 -------------------
166
167 This pattern can have two different causes.
168 We would like to distinguish them, but that is usually
169 not possible to do just by looking at the measured values (and not telemetry).
170
171 In one cause, the real DUT performance has changed,
172 but got restored immediately.
173 In the other cause, no real performance change happened,
174 just some temporary infrastructure issue
175 has caused a wrong low value to be measured.
176
177 For small measured changes, this pattern may remain undetected.
178 For medium and big measured changes, this is detected when the regression
179 happens on just the last sample.
180
181 For big changes, the revert is also immediately detected
182 as a subsequent progression. The trend is usually different
183 from the previously stable trend (as the two population averages
184 are not likely to be exactly equal), but the difference
185 between the two trends is relatively small.
186
187 For medium changes, the detection algorithm may need several new samples
188 to detect a progression (as it dislikes single sample groups),
189 in the meantime reporting regressions (difference decreasing
190 with analysis time), until it stabilizes the same way as for big changes
191 (regression followed by progression, small difference
192 between the old stable trend and last trend).
193
194 As it is very hard for a fault code or an infrastructure issue
195 to increase performance, the opposite (temporary progression)
196 almost never happens.
197
198 Summary
199 -------
200
201 There is a trade-off between detecting small regressions
202 and not reporting the same old regressions for a long time.
203
204 For people reading e-mails, a sudden regression with a big number of samples
205 in the last group means this regression was hard for the algorithm to detect.
206
207 If there is a big regression with just one run in the last group,
208 we are not sure if it is real, or just a temporary issue.
209 It is useful to wait some time before starting an investigation.
210
211 With decreasing (absolute value of) difference, the number of expected runs
212 increases. If there is not enough runs, we still cannot distinguish
213 real regression from temporary regression just from the current metrics
214 (although humans frequently can tell by looking at the graph).
215
216 When there is a regression or progression with just a small difference,
217 it is probably an artifact of a temporary regression.
218 Not worth examining, unless temporary regressions happen somewhat frequently.
219
220 It is not easy for the metrics to locate the previous stable value,
221 especially if multiple anomalies happened in the last few weeks.
222 It is good to compare last trend with long term trend maximum,
223 as it highlights the difference between "now" and "what could be".
224 It is good to exclude last week from the trend maximum,
225 as including the last week would hide all real progressions.
226
227 .. _Minimum Description Length: https://en.wikipedia.org/wiki/Minimum_description_length
228 .. _Occam's razor: https://en.wikipedia.org/wiki/Occam%27s_razor
229 .. _bimodal distribution: https://en.wikipedia.org/wiki/Bimodal_distribution