Skip to content

Commit 5488458

Browse files
Add analytics data name to storages for reusability in logs
1 parent 3c7dedc commit 5488458

13 files changed

+24
-22
lines changed

src/storages/inMemory/EventsCacheInMemory.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const MAX_QUEUE_BYTE_SIZE = 5 * 1024 * 1024; // 5M
55

66
export class EventsCacheInMemory implements IEventsCacheSync {
77

8+
public name = 'events';
89
private onFullQueue?: () => void;
910
private readonly maxQueue: number;
1011
private queue: SplitIO.EventData[];

src/storages/inMemory/ImpressionCountsCacheInMemory.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { DEFAULT_CACHE_SIZE } from '../inRedis/constants';
33
import { IImpressionCountsCacheSync } from '../types';
44

55
export class ImpressionCountsCacheInMemory implements IImpressionCountsCacheSync {
6+
7+
public name = 'impression counts';
68
protected cache: Record<string, number> = {};
79
private readonly maxStorage: number;
810
protected onFullQueue?: () => void;

src/storages/inMemory/ImpressionsCacheInMemory.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import SplitIO from '../../../types/splitio';
33

44
export class ImpressionsCacheInMemory implements IImpressionsCacheSync {
55

6+
public name = 'impressions';
67
private onFullQueue?: () => void;
78
private readonly maxQueue: number;
89
private queue: SplitIO.ImpressionDTO[];

src/storages/inMemory/TelemetryCacheInMemory.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ export function shouldRecordTelemetry({ settings }: IStorageFactoryParams) {
2525

2626
export class TelemetryCacheInMemory implements ITelemetryCacheSync {
2727

28+
public name = 'telemetry stats';
29+
2830
constructor(private splits?: ISplitsCacheSync, private segments?: ISegmentsCacheSync, private largeSegments?: ISegmentsCacheSync) { }
2931

3032
// isEmpty flag

src/storages/inMemory/UniqueKeysCacheInMemory.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { IUniqueKeysCacheBase } from '../types';
1+
import { IUniqueKeysCacheSync } from '../types';
22
import { UniqueKeysPayloadSs } from '../../sync/submitters/types';
33
import { DEFAULT_CACHE_SIZE } from '../inRedis/constants';
44
import { setToArray } from '../../utils/lang/sets';
@@ -22,8 +22,8 @@ export function fromUniqueKeysCollector(uniqueKeys: { [featureName: string]: Set
2222
return { keys: payload };
2323
}
2424

25-
export class UniqueKeysCacheInMemory implements IUniqueKeysCacheBase {
26-
25+
export class UniqueKeysCacheInMemory implements IUniqueKeysCacheSync {
26+
public name = 'unique keys';
2727
protected onFullQueue?: () => void;
2828
private readonly maxStorage: number;
2929
private uniqueTrackerSize = 0;

src/storages/inMemory/UniqueKeysCacheInMemoryCS.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { IUniqueKeysCacheBase } from '../types';
1+
import { IUniqueKeysCacheSync } from '../types';
22
import { UniqueKeysPayloadCs } from '../../sync/submitters/types';
33
import { DEFAULT_CACHE_SIZE } from '../inRedis/constants';
44
import { setToArray } from '../../utils/lang/sets';
55

6-
export class UniqueKeysCacheInMemoryCS implements IUniqueKeysCacheBase {
7-
6+
export class UniqueKeysCacheInMemoryCS implements IUniqueKeysCacheSync {
7+
public name = 'unique keys';
88
private onFullQueue?: () => void;
99
private readonly maxStorage: number;
1010
private uniqueTrackerSize = 0;

src/storages/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ export interface IUniqueKeysCacheBase {
325325

326326
// API methods for sync recorder storages, used by submitters in standalone mode to pop data and post it to Split BE.
327327
export interface IRecorderCacheSync<T> {
328+
name: string,
328329
// @TODO names are inconsistent with spec
329330
/* Checks if cache is empty. Returns true if the cache was just created or cleared */
330331
isEmpty(): boolean

src/sync/submitters/eventsSubmitter.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import { submitterFactory, firstPushWindowDecorator } from './submitter';
22
import { SUBMITTERS_PUSH_FULL_QUEUE } from '../../logger/constants';
33
import { ISdkFactoryContextSync } from '../../sdkFactory/types';
44

5-
const DATA_NAME = 'events';
6-
75
/**
86
* Submitter that periodically posts tracked events
97
*/
@@ -16,15 +14,15 @@ export function eventsSubmitterFactory(params: ISdkFactoryContextSync) {
1614
} = params;
1715

1816
// don't retry events.
19-
let submitter = submitterFactory(log, postEventsBulk, events, eventsPushRate, DATA_NAME);
17+
let submitter = submitterFactory(log, postEventsBulk, events, eventsPushRate);
2018

2119
// Set a timer for the first push window of events.
2220
if (eventsFirstPushWindow > 0) submitter = firstPushWindowDecorator(submitter, eventsFirstPushWindow);
2321

2422
// register events submitter to be executed when events cache is full
2523
events.setOnFullQueueCb(() => {
2624
if (submitter.isRunning()) {
27-
log.info(SUBMITTERS_PUSH_FULL_QUEUE, [DATA_NAME]);
25+
log.info(SUBMITTERS_PUSH_FULL_QUEUE, [events.name]);
2826
submitter.execute();
2927
}
3028
// If submitter is stopped (e.g., user consent declined or unknown, or app state offline), we don't send the data.

src/sync/submitters/impressionCountsSubmitter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,5 @@ export function impressionCountsSubmitterFactory(params: ISdkFactoryContextSync)
4040
} = params;
4141

4242
// retry impressions counts only once.
43-
return submitterFactory(log, postTestImpressionsCount, impressionCounts, IMPRESSIONS_COUNT_RATE, 'impression counts', fromImpressionCountsCollector, 1);
43+
return submitterFactory(log, postTestImpressionsCount, impressionCounts, IMPRESSIONS_COUNT_RATE, fromImpressionCountsCollector, 1);
4444
}

src/sync/submitters/impressionsSubmitter.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,13 @@ import { ImpressionsPayload } from './types';
55
import { SUBMITTERS_PUSH_FULL_QUEUE } from '../../logger/constants';
66
import { ISdkFactoryContextSync } from '../../sdkFactory/types';
77

8-
const DATA_NAME = 'impressions';
9-
108
/**
119
* Converts `impressions` data from cache into request payload.
1210
*/
1311
export function fromImpressionsCollector(sendLabels: boolean, data: SplitIO.ImpressionDTO[]): ImpressionsPayload {
1412
let groupedByFeature = groupBy(data, 'feature');
1513
let dto: ImpressionsPayload = [];
1614

17-
// using forOwn instead of for...in since the last also iterates over prototype enumerables
1815
forOwn(groupedByFeature, (value, name) => {
1916
dto.push({
2017
f: name, // Test Name
@@ -50,12 +47,12 @@ export function impressionsSubmitterFactory(params: ISdkFactoryContextSync) {
5047
} = params;
5148

5249
// retry impressions only once.
53-
const syncTask = submitterFactory(log, postTestImpressionsBulk, impressions, impressionsRefreshRate, DATA_NAME, fromImpressionsCollector.bind(undefined, labelsEnabled), 1);
50+
const syncTask = submitterFactory(log, postTestImpressionsBulk, impressions, impressionsRefreshRate, fromImpressionsCollector.bind(undefined, labelsEnabled), 1);
5451

5552
// register impressions submitter to be executed when impressions cache is full
5653
impressions.setOnFullQueueCb(() => {
5754
if (syncTask.isRunning()) {
58-
log.info(SUBMITTERS_PUSH_FULL_QUEUE, [DATA_NAME]);
55+
log.info(SUBMITTERS_PUSH_FULL_QUEUE, [impressions.name]);
5956
syncTask.execute();
6057
}
6158
// If submitter is stopped (e.g., user consent declined or unknown, or app state offline), we don't send the data.

0 commit comments

Comments
 (0)