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