splitSeriesIntoCompleteAndIncomplete.spec.tsx 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. import {resetMockDate, setMockDate} from 'sentry-test/utils';
  2. import type {TimeseriesData} from '../common/types';
  3. import {splitSeriesIntoCompleteAndIncomplete} from './splitSeriesIntoCompleteAndIncomplete';
  4. describe('splitSeriesIntoCompleteAndIncomplete', () => {
  5. beforeEach(() => {
  6. setMockDate(new Date('2024-10-24T15:59:00.000Z'));
  7. });
  8. afterEach(() => {
  9. resetMockDate();
  10. });
  11. it('Does not split a series with all complete data', () => {
  12. const serie: TimeseriesData = {
  13. field: 'p99(span.duration)',
  14. data: [
  15. {
  16. value: 90,
  17. timestamp: '2024-10-24T15:54:00.000Z',
  18. },
  19. {
  20. value: 100,
  21. timestamp: '2024-10-24T15:55:00.000Z',
  22. },
  23. {
  24. value: 110,
  25. timestamp: '2024-10-24T15:56:00.000Z',
  26. },
  27. ],
  28. };
  29. const [completeSerie, incompleteSerie] = splitSeriesIntoCompleteAndIncomplete(
  30. serie,
  31. 90
  32. );
  33. expect(completeSerie?.data).toEqual([
  34. {
  35. value: 90,
  36. timestamp: '2024-10-24T15:54:00.000Z',
  37. },
  38. {
  39. value: 100,
  40. timestamp: '2024-10-24T15:55:00.000Z',
  41. },
  42. {
  43. value: 110,
  44. timestamp: '2024-10-24T15:56:00.000Z',
  45. },
  46. ]);
  47. expect(incompleteSerie).toEqual(undefined);
  48. });
  49. it('Does not split a series with all incomplete data', () => {
  50. const serie: TimeseriesData = {
  51. field: 'p99(span.duration)',
  52. data: [
  53. {
  54. value: 90,
  55. timestamp: '2024-10-24T15:58:05.000Z',
  56. },
  57. {
  58. value: 100,
  59. timestamp: '2024-10-24T15:58:10.000Z',
  60. },
  61. {
  62. value: 110,
  63. timestamp: '2024-10-24T15:58:15.000Z',
  64. },
  65. {
  66. value: 120,
  67. timestamp: '2024-10-24T15:58:20.000Z',
  68. },
  69. ],
  70. };
  71. const [completeSerie, incompleteSerie] = splitSeriesIntoCompleteAndIncomplete(
  72. serie,
  73. 90
  74. );
  75. expect(completeSerie).toEqual(undefined);
  76. expect(incompleteSerie?.data).toEqual([
  77. {
  78. value: 90,
  79. timestamp: '2024-10-24T15:58:05.000Z',
  80. },
  81. {
  82. value: 100,
  83. timestamp: '2024-10-24T15:58:10.000Z',
  84. },
  85. {
  86. value: 110,
  87. timestamp: '2024-10-24T15:58:15.000Z',
  88. },
  89. {
  90. value: 120,
  91. timestamp: '2024-10-24T15:58:20.000Z',
  92. },
  93. ]);
  94. });
  95. it('Splits a series with partial incomplete data', () => {
  96. const serie: TimeseriesData = {
  97. field: 'p99(span.duration)',
  98. data: [
  99. {
  100. value: 100,
  101. timestamp: '2024-10-24T15:55:00.000Z',
  102. },
  103. {
  104. value: 110,
  105. timestamp: '2024-10-24T15:56:00.000Z',
  106. },
  107. {
  108. value: 120,
  109. timestamp: '2024-10-24T15:57:00.000Z',
  110. },
  111. {
  112. value: 130,
  113. timestamp: '2024-10-24T15:58:00.000Z',
  114. },
  115. {
  116. value: 140,
  117. timestamp: '2024-10-24T15:59:00.000Z',
  118. },
  119. ],
  120. };
  121. const [completeSerie, incompleteSerie] = splitSeriesIntoCompleteAndIncomplete(
  122. serie,
  123. 90
  124. );
  125. expect(completeSerie?.data).toEqual([
  126. {
  127. value: 100,
  128. timestamp: '2024-10-24T15:55:00.000Z',
  129. },
  130. {
  131. value: 110,
  132. timestamp: '2024-10-24T15:56:00.000Z',
  133. },
  134. ]);
  135. expect(incompleteSerie?.data).toEqual([
  136. {
  137. value: 110,
  138. timestamp: '2024-10-24T15:56:00.000Z',
  139. },
  140. {
  141. value: 120,
  142. timestamp: '2024-10-24T15:57:00.000Z',
  143. },
  144. {
  145. value: 130,
  146. timestamp: '2024-10-24T15:58:00.000Z',
  147. },
  148. {
  149. value: 140,
  150. timestamp: '2024-10-24T15:59:00.000Z',
  151. },
  152. ]);
  153. });
  154. it('Splits a series with long buckets', () => {
  155. // The time buckets are an hour long. The ingestion delay is 90s. The last buckets should be marked incomplete.
  156. //
  157. const serie: TimeseriesData = {
  158. field: 'p99(span.duration)',
  159. data: [
  160. {
  161. value: 110,
  162. timestamp: '2024-10-24T12:00:00.000Z',
  163. },
  164. {
  165. value: 120,
  166. timestamp: '2024-10-24T13:00:00.000Z',
  167. },
  168. {
  169. value: 130,
  170. timestamp: '2024-10-24T14:00:00.000Z',
  171. },
  172. {
  173. value: 140,
  174. timestamp: '2024-10-24T15:00:00.000Z',
  175. },
  176. ],
  177. };
  178. const [completeSerie, incompleteSerie] = splitSeriesIntoCompleteAndIncomplete(
  179. serie,
  180. 90
  181. );
  182. expect(completeSerie?.data).toEqual([
  183. {
  184. value: 110,
  185. timestamp: '2024-10-24T12:00:00.000Z',
  186. },
  187. {
  188. value: 120,
  189. timestamp: '2024-10-24T13:00:00.000Z',
  190. },
  191. {
  192. value: 130,
  193. timestamp: '2024-10-24T14:00:00.000Z',
  194. },
  195. ]);
  196. expect(incompleteSerie?.data).toEqual([
  197. {
  198. value: 130,
  199. timestamp: '2024-10-24T14:00:00.000Z',
  200. },
  201. {
  202. value: 140,
  203. timestamp: '2024-10-24T15:00:00.000Z',
  204. },
  205. ]);
  206. });
  207. });