Skip to content

Commit 1118e49

Browse files
Add logs
1 parent 8429d40 commit 1118e49

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/sync/polling/fetchers/splitChangesFetcher.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { ISettings } from '../../../../types/splitio';
1+
import { ISettings } from '../../../types';
22
import { ISplitChangesResponse } from '../../../dtos/types';
33
import { IFetchSplitChanges, IResponse } from '../../../services/types';
44
import { IStorageBase } from '../../../storages/types';
55
import { FLAG_SPEC_VERSION } from '../../../utils/constants';
66
import { base } from '../../../utils/settingsValidation';
77
import { ISplitChangesFetcher } from './types';
8+
import { LOG_PREFIX_SYNC_SPLITS } from '../../../logger/constants';
89

910
const PROXY_CHECK_INTERVAL_MILLIS_CS = 60 * 60 * 1000; // 1 hour in Client Side
1011
const PROXY_CHECK_INTERVAL_MILLIS_SS = 24 * PROXY_CHECK_INTERVAL_MILLIS_CS; // 24 hours in Server Side
@@ -20,6 +21,7 @@ function sdkEndpointOverriden(settings: ISettings) {
2021
// @TODO breaking: drop support for Split Proxy below v5.10.0 and simplify the implementation
2122
export function splitChangesFetcherFactory(fetchSplitChanges: IFetchSplitChanges, settings: ISettings, storage: Pick<IStorageBase, 'splits' | 'rbSegments'>): ISplitChangesFetcher {
2223

24+
const log = settings.log;
2325
const PROXY_CHECK_INTERVAL_MILLIS = settings.core.key !== undefined ? PROXY_CHECK_INTERVAL_MILLIS_CS : PROXY_CHECK_INTERVAL_MILLIS_SS;
2426
let lastProxyCheckTimestamp: number | undefined;
2527

@@ -41,6 +43,7 @@ export function splitChangesFetcherFactory(fetchSplitChanges: IFetchSplitChanges
4143
// Handle proxy error with spec 1.3
4244
.catch((err) => {
4345
if (err.statusCode === 400 && sdkEndpointOverriden(settings) && settings.sync.flagSpecVersion === FLAG_SPEC_VERSION) {
46+
log.error(LOG_PREFIX_SYNC_SPLITS + 'Proxy error detected. If you are using Split Proxy, please upgrade to latest version');
4447
lastProxyCheckTimestamp = Date.now();
4548
settings.sync.flagSpecVersion = '1.2'; // fallback to 1.2 spec
4649
return fetchSplitChanges(since, noCache, till); // retry request without rbSince
@@ -66,6 +69,7 @@ export function splitChangesFetcherFactory(fetchSplitChanges: IFetchSplitChanges
6669

6770
// Proxy recovery
6871
if (lastProxyCheckTimestamp) {
72+
log.info(LOG_PREFIX_SYNC_SPLITS + 'Proxy error recovered');
6973
lastProxyCheckTimestamp = undefined;
7074
return Promise.all([storage.splits.clear(), storage.rbSegments.clear()])
7175
.then(() => splitChangesFetcher(storage.splits.getChangeNumber() as number, undefined, undefined, storage.rbSegments.getChangeNumber() as number));

0 commit comments

Comments
 (0)