123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- import {resetMockDate, setMockDate} from 'sentry-test/utils';
- import type {TimeseriesData} from '../common/types';
- import {splitSeriesIntoCompleteAndIncomplete} from './splitSeriesIntoCompleteAndIncomplete';
- describe('splitSeriesIntoCompleteAndIncomplete', () => {
- beforeEach(() => {
- setMockDate(new Date('2024-10-24T15:59:00.000Z'));
- });
- afterEach(() => {
- resetMockDate();
- });
- it('Does not split a series with all complete data', () => {
- const serie: TimeseriesData = {
- field: 'p99(span.duration)',
- data: [
- {
- value: 90,
- timestamp: '2024-10-24T15:54:00.000Z',
- },
- {
- value: 100,
- timestamp: '2024-10-24T15:55:00.000Z',
- },
- {
- value: 110,
- timestamp: '2024-10-24T15:56:00.000Z',
- },
- ],
- };
- const [completeSerie, incompleteSerie] = splitSeriesIntoCompleteAndIncomplete(
- serie,
- 90
- );
- expect(completeSerie?.data).toEqual([
- {
- value: 90,
- timestamp: '2024-10-24T15:54:00.000Z',
- },
- {
- value: 100,
- timestamp: '2024-10-24T15:55:00.000Z',
- },
- {
- value: 110,
- timestamp: '2024-10-24T15:56:00.000Z',
- },
- ]);
- expect(incompleteSerie).toEqual(undefined);
- });
- it('Does not split a series with all incomplete data', () => {
- const serie: TimeseriesData = {
- field: 'p99(span.duration)',
- data: [
- {
- value: 90,
- timestamp: '2024-10-24T15:58:05.000Z',
- },
- {
- value: 100,
- timestamp: '2024-10-24T15:58:10.000Z',
- },
- {
- value: 110,
- timestamp: '2024-10-24T15:58:15.000Z',
- },
- {
- value: 120,
- timestamp: '2024-10-24T15:58:20.000Z',
- },
- ],
- };
- const [completeSerie, incompleteSerie] = splitSeriesIntoCompleteAndIncomplete(
- serie,
- 90
- );
- expect(completeSerie).toEqual(undefined);
- expect(incompleteSerie?.data).toEqual([
- {
- value: 90,
- timestamp: '2024-10-24T15:58:05.000Z',
- },
- {
- value: 100,
- timestamp: '2024-10-24T15:58:10.000Z',
- },
- {
- value: 110,
- timestamp: '2024-10-24T15:58:15.000Z',
- },
- {
- value: 120,
- timestamp: '2024-10-24T15:58:20.000Z',
- },
- ]);
- });
- it('Splits a series with partial incomplete data', () => {
- const serie: TimeseriesData = {
- field: 'p99(span.duration)',
- data: [
- {
- value: 100,
- timestamp: '2024-10-24T15:55:00.000Z',
- },
- {
- value: 110,
- timestamp: '2024-10-24T15:56:00.000Z',
- },
- {
- value: 120,
- timestamp: '2024-10-24T15:57:00.000Z',
- },
- {
- value: 130,
- timestamp: '2024-10-24T15:58:00.000Z',
- },
- {
- value: 140,
- timestamp: '2024-10-24T15:59:00.000Z',
- },
- ],
- };
- const [completeSerie, incompleteSerie] = splitSeriesIntoCompleteAndIncomplete(
- serie,
- 90
- );
- expect(completeSerie?.data).toEqual([
- {
- value: 100,
- timestamp: '2024-10-24T15:55:00.000Z',
- },
- {
- value: 110,
- timestamp: '2024-10-24T15:56:00.000Z',
- },
- ]);
- expect(incompleteSerie?.data).toEqual([
- {
- value: 110,
- timestamp: '2024-10-24T15:56:00.000Z',
- },
- {
- value: 120,
- timestamp: '2024-10-24T15:57:00.000Z',
- },
- {
- value: 130,
- timestamp: '2024-10-24T15:58:00.000Z',
- },
- {
- value: 140,
- timestamp: '2024-10-24T15:59:00.000Z',
- },
- ]);
- });
- it('Splits a series with long buckets', () => {
- // The time buckets are an hour long. The ingestion delay is 90s. The last buckets should be marked incomplete.
- //
- const serie: TimeseriesData = {
- field: 'p99(span.duration)',
- data: [
- {
- value: 110,
- timestamp: '2024-10-24T12:00:00.000Z',
- },
- {
- value: 120,
- timestamp: '2024-10-24T13:00:00.000Z',
- },
- {
- value: 130,
- timestamp: '2024-10-24T14:00:00.000Z',
- },
- {
- value: 140,
- timestamp: '2024-10-24T15:00:00.000Z',
- },
- ],
- };
- const [completeSerie, incompleteSerie] = splitSeriesIntoCompleteAndIncomplete(
- serie,
- 90
- );
- expect(completeSerie?.data).toEqual([
- {
- value: 110,
- timestamp: '2024-10-24T12:00:00.000Z',
- },
- {
- value: 120,
- timestamp: '2024-10-24T13:00:00.000Z',
- },
- {
- value: 130,
- timestamp: '2024-10-24T14:00:00.000Z',
- },
- ]);
- expect(incompleteSerie?.data).toEqual([
- {
- value: 130,
- timestamp: '2024-10-24T14:00:00.000Z',
- },
- {
- value: 140,
- timestamp: '2024-10-24T15:00:00.000Z',
- },
- ]);
- });
- });
|