Skip to content

Commit 8d01373

Browse files
authored
[FSSDK-10941] event processor files and directories cleanup - part 2 (#967)
1 parent 7770664 commit 8d01373

20 files changed

+185
-2382
lines changed

lib/event_processor/batch_event_processor.react_native.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ import { getMockRepeater } from '../tests/mock/mock_repeater';
5050
import { getMockAsyncCache } from '../tests/mock/mock_cache';
5151

5252
import { EventWithId } from './batch_event_processor';
53-
import { formatEvents } from './event_builder/build_event_v1';
53+
import { buildLogEvent } from './event_builder/build_event_v1';
5454
import { createImpressionEvent } from '../tests/mock/create_event';
5555
import { ProcessableEvent } from './event_processor';
5656

@@ -138,7 +138,7 @@ describe('ReactNativeNetInfoEventProcessor', () => {
138138

139139
await exhaustMicrotasks();
140140

141-
expect(eventDispatcher.dispatchEvent).toHaveBeenCalledWith(formatEvents(events));
141+
expect(eventDispatcher.dispatchEvent).toHaveBeenCalledWith(buildLogEvent(events));
142142
});
143143

144144
it('should unsubscribe from netinfo listener when stopped', async () => {

lib/event_processor/batch_event_processor.spec.ts

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { EventWithId, BatchEventProcessor } from './batch_event_processor';
1919
import { getMockSyncCache } from '../tests/mock/mock_cache';
2020
import { createImpressionEvent } from '../tests/mock/create_event';
2121
import { ProcessableEvent } from './event_processor';
22-
import { formatEvents } from './event_builder/build_event_v1';
22+
import { buildLogEvent } from './event_builder/build_event_v1';
2323
import { resolvablePromise } from '../utils/promise/resolvablePromise';
2424
import { advanceTimersByTime } from '../../tests/testUtils';
2525
import { getMockLogger } from '../tests/mock/mock_logger';
@@ -139,9 +139,9 @@ describe('QueueingEventProcessor', async () => {
139139
await exhaustMicrotasks();
140140

141141
expect(mockDispatch).toHaveBeenCalledTimes(3);
142-
expect(mockDispatch.mock.calls[0][0]).toEqual(formatEvents([events[0], events[1]]));
143-
expect(mockDispatch.mock.calls[1][0]).toEqual(formatEvents([events[2], events[3]]));
144-
expect(mockDispatch.mock.calls[2][0]).toEqual(formatEvents([events[4]]));
142+
expect(mockDispatch.mock.calls[0][0]).toEqual(buildLogEvent([events[0], events[1]]));
143+
expect(mockDispatch.mock.calls[1][0]).toEqual(buildLogEvent([events[2], events[3]]));
144+
expect(mockDispatch.mock.calls[2][0]).toEqual(buildLogEvent([events[4]]));
145145
});
146146
});
147147

@@ -202,7 +202,7 @@ describe('QueueingEventProcessor', async () => {
202202
await processor.process(event);
203203

204204
expect(eventDispatcher.dispatchEvent).toHaveBeenCalledTimes(1);
205-
expect(eventDispatcher.dispatchEvent.mock.calls[0][0]).toEqual(formatEvents(events));
205+
expect(eventDispatcher.dispatchEvent.mock.calls[0][0]).toEqual(buildLogEvent(events));
206206

207207
events = [event];
208208
for(let i = 101; i < 200; i++) {
@@ -217,7 +217,7 @@ describe('QueueingEventProcessor', async () => {
217217
await processor.process(event);
218218

219219
expect(eventDispatcher.dispatchEvent).toHaveBeenCalledTimes(2);
220-
expect(eventDispatcher.dispatchEvent.mock.calls[1][0]).toEqual(formatEvents(events));
220+
expect(eventDispatcher.dispatchEvent.mock.calls[1][0]).toEqual(buildLogEvent(events));
221221
});
222222

223223
it('should flush queue is context of the new event is different and enqueue the new event', async () => {
@@ -250,11 +250,11 @@ describe('QueueingEventProcessor', async () => {
250250
await processor.process(newEvent);
251251

252252
expect(eventDispatcher.dispatchEvent).toHaveBeenCalledTimes(1);
253-
expect(eventDispatcher.dispatchEvent.mock.calls[0][0]).toEqual(formatEvents(events));
253+
expect(eventDispatcher.dispatchEvent.mock.calls[0][0]).toEqual(buildLogEvent(events));
254254

255255
await dispatchRepeater.execute(0);
256256
expect(eventDispatcher.dispatchEvent).toHaveBeenCalledTimes(2);
257-
expect(eventDispatcher.dispatchEvent.mock.calls[1][0]).toEqual(formatEvents([newEvent]));
257+
expect(eventDispatcher.dispatchEvent.mock.calls[1][0]).toEqual(buildLogEvent([newEvent]));
258258
});
259259

260260
it('should store the event in the eventStore with increasing ids', async () => {
@@ -313,7 +313,7 @@ describe('QueueingEventProcessor', async () => {
313313
await dispatchRepeater.execute(0);
314314

315315
expect(eventDispatcher.dispatchEvent).toHaveBeenCalledTimes(1);
316-
expect(eventDispatcher.dispatchEvent.mock.calls[0][0]).toEqual(formatEvents(events));
316+
expect(eventDispatcher.dispatchEvent.mock.calls[0][0]).toEqual(buildLogEvent(events));
317317

318318
events = [];
319319
for(let i = 1; i < 15; i++) {
@@ -324,7 +324,7 @@ describe('QueueingEventProcessor', async () => {
324324

325325
await dispatchRepeater.execute(0);
326326
expect(eventDispatcher.dispatchEvent).toHaveBeenCalledTimes(2);
327-
expect(eventDispatcher.dispatchEvent.mock.calls[1][0]).toEqual(formatEvents(events));
327+
expect(eventDispatcher.dispatchEvent.mock.calls[1][0]).toEqual(buildLogEvent(events));
328328
});
329329

330330
it('should not retry failed dispatch if retryConfig is not provided', async () => {
@@ -397,7 +397,7 @@ describe('QueueingEventProcessor', async () => {
397397
expect(eventDispatcher.dispatchEvent).toHaveBeenCalledTimes(4);
398398
expect(backoffController.backoff).toHaveBeenCalledTimes(3);
399399

400-
const request = formatEvents(events);
400+
const request = buildLogEvent(events);
401401
for(let i = 0; i < 4; i++) {
402402
expect(eventDispatcher.dispatchEvent.mock.calls[i][0]).toEqual(request);
403403
}
@@ -444,7 +444,7 @@ describe('QueueingEventProcessor', async () => {
444444
expect(eventDispatcher.dispatchEvent).toHaveBeenCalledTimes(201);
445445
expect(backoffController.backoff).toHaveBeenCalledTimes(200);
446446

447-
const request = formatEvents(events);
447+
const request = buildLogEvent(events);
448448
for(let i = 0; i < 201; i++) {
449449
expect(eventDispatcher.dispatchEvent.mock.calls[i][0]).toEqual(request);
450450
}
@@ -723,7 +723,7 @@ describe('QueueingEventProcessor', async () => {
723723
await exhaustMicrotasks();
724724

725725
expect(mockDispatch).toHaveBeenCalledTimes(1);
726-
expect(mockDispatch.mock.calls[0][0]).toEqual(formatEvents(failedEvents));
726+
expect(mockDispatch.mock.calls[0][0]).toEqual(buildLogEvent(failedEvents));
727727

728728
const eventsInStore = [...cache.getAll().values()].sort((a, b) => a.id < b.id ? -1 : 1).map(e => e.event);
729729
expect(eventsInStore).toEqual(expect.arrayContaining([
@@ -761,7 +761,7 @@ describe('QueueingEventProcessor', async () => {
761761
dispatchRepeater.execute(0);
762762
await exhaustMicrotasks();
763763
expect(mockDispatch).toHaveBeenCalledTimes(1);
764-
expect(mockDispatch.mock.calls[0][0]).toEqual(formatEvents([eventA, eventB]));
764+
expect(mockDispatch.mock.calls[0][0]).toEqual(buildLogEvent([eventA, eventB]));
765765

766766
const failedEvents: ProcessableEvent[] = [];
767767

@@ -776,7 +776,7 @@ describe('QueueingEventProcessor', async () => {
776776
await exhaustMicrotasks();
777777

778778
expect(mockDispatch).toHaveBeenCalledTimes(2);
779-
expect(mockDispatch.mock.calls[1][0]).toEqual(formatEvents(failedEvents));
779+
expect(mockDispatch.mock.calls[1][0]).toEqual(buildLogEvent(failedEvents));
780780

781781
mockResult2.resolve({});
782782
await exhaustMicrotasks();
@@ -826,10 +826,10 @@ describe('QueueingEventProcessor', async () => {
826826
// events 0 1 4 5 6 7 have one context, and 2 3 have different context
827827
// batches should be [0, 1], [2, 3], [4, 5, 6], [7]
828828
expect(mockDispatch).toHaveBeenCalledTimes(4);
829-
expect(mockDispatch.mock.calls[0][0]).toEqual(formatEvents([failedEvents[0], failedEvents[1]]));
830-
expect(mockDispatch.mock.calls[1][0]).toEqual(formatEvents([failedEvents[2], failedEvents[3]]));
831-
expect(mockDispatch.mock.calls[2][0]).toEqual(formatEvents([failedEvents[4], failedEvents[5], failedEvents[6]]));
832-
expect(mockDispatch.mock.calls[3][0]).toEqual(formatEvents([failedEvents[7]]));
829+
expect(mockDispatch.mock.calls[0][0]).toEqual(buildLogEvent([failedEvents[0], failedEvents[1]]));
830+
expect(mockDispatch.mock.calls[1][0]).toEqual(buildLogEvent([failedEvents[2], failedEvents[3]]));
831+
expect(mockDispatch.mock.calls[2][0]).toEqual(buildLogEvent([failedEvents[4], failedEvents[5], failedEvents[6]]));
832+
expect(mockDispatch.mock.calls[3][0]).toEqual(buildLogEvent([failedEvents[7]]));
833833
});
834834
});
835835

@@ -873,7 +873,7 @@ describe('QueueingEventProcessor', async () => {
873873
await exhaustMicrotasks();
874874

875875
expect(mockDispatch).toHaveBeenCalledTimes(1);
876-
expect(mockDispatch.mock.calls[0][0]).toEqual(formatEvents(failedEvents));
876+
expect(mockDispatch.mock.calls[0][0]).toEqual(buildLogEvent(failedEvents));
877877

878878
const eventsInStore = [...cache.getAll().values()].sort((a, b) => a.id < b.id ? -1 : 1).map(e => e.event);
879879
expect(eventsInStore).toEqual(expect.arrayContaining([
@@ -913,7 +913,7 @@ describe('QueueingEventProcessor', async () => {
913913
dispatchRepeater.execute(0);
914914
await exhaustMicrotasks();
915915
expect(mockDispatch).toHaveBeenCalledTimes(1);
916-
expect(mockDispatch.mock.calls[0][0]).toEqual(formatEvents([eventA, eventB]));
916+
expect(mockDispatch.mock.calls[0][0]).toEqual(buildLogEvent([eventA, eventB]));
917917

918918
const failedEvents: ProcessableEvent[] = [];
919919

@@ -928,7 +928,7 @@ describe('QueueingEventProcessor', async () => {
928928
await exhaustMicrotasks();
929929

930930
expect(mockDispatch).toHaveBeenCalledTimes(2);
931-
expect(mockDispatch.mock.calls[1][0]).toEqual(formatEvents(failedEvents));
931+
expect(mockDispatch.mock.calls[1][0]).toEqual(buildLogEvent(failedEvents));
932932

933933
mockResult2.resolve({});
934934
await exhaustMicrotasks();
@@ -980,10 +980,10 @@ describe('QueueingEventProcessor', async () => {
980980
// events 0 1 4 5 6 7 have one context, and 2 3 have different context
981981
// batches should be [0, 1], [2, 3], [4, 5, 6], [7]
982982
expect(mockDispatch).toHaveBeenCalledTimes(4);
983-
expect(mockDispatch.mock.calls[0][0]).toEqual(formatEvents([failedEvents[0], failedEvents[1]]));
984-
expect(mockDispatch.mock.calls[1][0]).toEqual(formatEvents([failedEvents[2], failedEvents[3]]));
985-
expect(mockDispatch.mock.calls[2][0]).toEqual(formatEvents([failedEvents[4], failedEvents[5], failedEvents[6]]));
986-
expect(mockDispatch.mock.calls[3][0]).toEqual(formatEvents([failedEvents[7]]));
983+
expect(mockDispatch.mock.calls[0][0]).toEqual(buildLogEvent([failedEvents[0], failedEvents[1]]));
984+
expect(mockDispatch.mock.calls[1][0]).toEqual(buildLogEvent([failedEvents[2], failedEvents[3]]));
985+
expect(mockDispatch.mock.calls[2][0]).toEqual(buildLogEvent([failedEvents[4], failedEvents[5], failedEvents[6]]));
986+
expect(mockDispatch.mock.calls[3][0]).toEqual(buildLogEvent([failedEvents[7]]));
987987
});
988988
});
989989

@@ -1012,7 +1012,7 @@ describe('QueueingEventProcessor', async () => {
10121012
await dispatchRepeater.execute(0);
10131013

10141014
expect(dispatchListener).toHaveBeenCalledTimes(1);
1015-
expect(dispatchListener.mock.calls[0][0]).toEqual(formatEvents([event, event2]));
1015+
expect(dispatchListener.mock.calls[0][0]).toEqual(buildLogEvent([event, event2]));
10161016
});
10171017

10181018
it('should remove event handler when function returned from onDispatch is called', async () => {
@@ -1041,7 +1041,7 @@ describe('QueueingEventProcessor', async () => {
10411041
await dispatchRepeater.execute(0);
10421042

10431043
expect(dispatchListener).toHaveBeenCalledTimes(1);
1044-
expect(dispatchListener.mock.calls[0][0]).toEqual(formatEvents([event, event2]));
1044+
expect(dispatchListener.mock.calls[0][0]).toEqual(buildLogEvent([event, event2]));
10451045

10461046
unsub();
10471047

@@ -1119,7 +1119,7 @@ describe('QueueingEventProcessor', async () => {
11191119

11201120
processor.stop();
11211121
expect(closingEventDispatcher.dispatchEvent).toHaveBeenCalledTimes(1);
1122-
expect(closingEventDispatcher.dispatchEvent).toHaveBeenCalledWith(formatEvents(events));
1122+
expect(closingEventDispatcher.dispatchEvent).toHaveBeenCalledWith(buildLogEvent(events));
11231123
});
11241124

11251125
it('should cancel retry of active dispatches', async () => {

lib/event_processor/batch_event_processor.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
import { EventProcessor, ProcessableEvent } from "./event_processor";
1818
import { Cache } from "../utils/cache/cache";
19-
import { EventDispatcher, EventDispatcherResponse, EventV1Request } from "./event_dispatcher";
20-
import { formatEvents } from "./event_builder/build_event_v1";
19+
import { EventDispatcher, EventDispatcherResponse, LogEvent } from "./event_dispatcher";
20+
import { buildLogEvent } from "./event_builder/log_event";
2121
import { BackoffController, ExponentialBackoff, IntervalRepeater, Repeater } from "../utils/repeater/repeater";
2222
import { LoggerFacade } from "../modules/logging";
2323
import { BaseService, ServiceState, StartupLog } from "../service";
@@ -26,7 +26,7 @@ import { RunResult, runWithRetry } from "../utils/executor/backoff_retry_runner"
2626
import { isSuccessStatusCode } from "../utils/http_request_handler/http_util";
2727
import { EventEmitter } from "../utils/event_emitter/event_emitter";
2828
import { IdGenerator } from "../utils/id_generator";
29-
import { areEventContextsEqual } from "./events";
29+
import { areEventContextsEqual } from "./event_builder/user_event";
3030

3131
export type EventWithId = {
3232
id: string;
@@ -51,7 +51,7 @@ export type BatchEventProcessorConfig = {
5151
};
5252

5353
type EventBatch = {
54-
request: EventV1Request,
54+
request: LogEvent,
5555
ids: string[],
5656
}
5757

@@ -66,7 +66,7 @@ export class BatchEventProcessor extends BaseService implements EventProcessor {
6666
private idGenerator: IdGenerator = new IdGenerator();
6767
private runningTask: Map<string, RunResult<EventDispatcherResponse>> = new Map();
6868
private dispatchingEventIds: Set<string> = new Set();
69-
private eventEmitter: EventEmitter<{ dispatch: EventV1Request }> = new EventEmitter();
69+
private eventEmitter: EventEmitter<{ dispatch: LogEvent }> = new EventEmitter();
7070
private retryConfig?: RetryConfig;
7171

7272
constructor(config: BatchEventProcessorConfig) {
@@ -85,7 +85,7 @@ export class BatchEventProcessor extends BaseService implements EventProcessor {
8585
this.failedEventRepeater?.setTask(() => this.retryFailedEvents());
8686
}
8787

88-
onDispatch(handler: Consumer<EventV1Request>): Fn {
88+
onDispatch(handler: Consumer<LogEvent>): Fn {
8989
return this.eventEmitter.on('dispatch', handler);
9090
}
9191

@@ -119,7 +119,7 @@ export class BatchEventProcessor extends BaseService implements EventProcessor {
119119
if (currentBatch.length === this.batchSize ||
120120
(currentBatch.length > 0 && !areEventContextsEqual(currentBatch[0].event, event.event))) {
121121
batches.push({
122-
request: formatEvents(currentBatch.map((e) => e.event)),
122+
request: buildLogEvent(currentBatch.map((e) => e.event)),
123123
ids: currentBatch.map((e) => e.id),
124124
});
125125
currentBatch = [];
@@ -129,7 +129,7 @@ export class BatchEventProcessor extends BaseService implements EventProcessor {
129129

130130
if (currentBatch.length > 0) {
131131
batches.push({
132-
request: formatEvents(currentBatch.map((e) => e.event)),
132+
request: buildLogEvent(currentBatch.map((e) => e.event)),
133133
ids: currentBatch.map((e) => e.id),
134134
});
135135
}
@@ -153,10 +153,10 @@ export class BatchEventProcessor extends BaseService implements EventProcessor {
153153
});
154154

155155
this.eventQueue = [];
156-
return { request: formatEvents(events), ids };
156+
return { request: buildLogEvent(events), ids };
157157
}
158158

159-
private async executeDispatch(request: EventV1Request, closing = false): Promise<EventDispatcherResponse> {
159+
private async executeDispatch(request: LogEvent, closing = false): Promise<EventDispatcherResponse> {
160160
const dispatcher = closing && this.closingEventDispatcher ? this.closingEventDispatcher : this.eventDispatcher;
161161
return dispatcher.dispatchEvent(request).then((res) => {
162162
if (res.statusCode && !isSuccessStatusCode(res.statusCode)) {

lib/event_processor/default_dispatcher.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
*/
1616
import { expect, vi, describe, it } from 'vitest';
1717
import { DefaultEventDispatcher } from './default_dispatcher';
18-
import { EventV1 } from './event_builder/build_event_v1';
18+
import { EventBatch } from './event_builder/build_event_v1';
1919

20-
const getEvent = (): EventV1 => {
20+
const getEvent = (): EventBatch => {
2121
return {
2222
account_id: 'string',
2323
project_id: 'string',

lib/event_processor/default_dispatcher.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616
import { RequestHandler } from '../utils/http_request_handler/http';
17-
import { EventDispatcher, EventDispatcherResponse, EventV1Request } from './event_dispatcher';
17+
import { EventDispatcher, EventDispatcherResponse, LogEvent } from './event_dispatcher';
1818

1919
export class DefaultEventDispatcher implements EventDispatcher {
2020
private requestHandler: RequestHandler;
@@ -24,7 +24,7 @@ export class DefaultEventDispatcher implements EventDispatcher {
2424
}
2525

2626
async dispatchEvent(
27-
eventObj: EventV1Request
27+
eventObj: LogEvent
2828
): Promise<EventDispatcherResponse> {
2929
// Non-POST requests not supported
3030
if (eventObj.httpVerb !== 'POST') {

0 commit comments

Comments
 (0)