Skip to content

Commit acc545f

Browse files
committed
Remove the capability of sending events to clearcut from the Performance SDK. This removes the need for fetching the RC configs to decide on the dispatch destination - so that is removed in the settings service and remote config service.
1 parent 3de5763 commit acc545f

File tree

5 files changed

+5
-210
lines changed

5 files changed

+5
-210
lines changed

packages/performance/src/services/remote_config_service.test.ts

Lines changed: 1 addition & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { SettingsService } from './settings_service';
2020
import { CONFIG_EXPIRY_LOCAL_STORAGE_KEY } from '../constants';
2121
import { setupApi, Api } from './api_service';
2222
import * as iidService from './iid_service';
23-
import { getConfig, isDestFl } from './remote_config_service';
23+
import { getConfig } from './remote_config_service';
2424
import { FirebaseApp } from '@firebase/app-types';
2525
import '../../test/setup';
2626

@@ -37,7 +37,6 @@ describe('Performance Monitoring > remote_config_service', () => {
3737
"fpr_log_endpoint_url":"https://firebaselogging.test.com",\
3838
"fpr_log_transport_key":"pseudo-transport-key",\
3939
"fpr_log_source":"2","fpr_vc_network_request_sampling_rate":"0.250000",\
40-
"fpr_log_transport_web_percent":"100.0",\
4140
"fpr_vc_session_sampling_rate":"0.250000","fpr_vc_trace_sampling_rate":"0.500000"},\
4241
"state":"UPDATE"}`;
4342
const PROJECT_ID = 'project1';
@@ -135,7 +134,6 @@ describe('Performance Monitoring > remote_config_service', () => {
135134
TRANSPORT_KEY
136135
);
137136
expect(SettingsService.getInstance().logSource).to.equal(LOG_SOURCE);
138-
expect(SettingsService.getInstance().shouldSendToFl).to.be.true;
139137
expect(
140138
SettingsService.getInstance().networkRequestsSamplingRate
141139
).to.equal(NETWORK_SAMPLIG_RATE);
@@ -176,7 +174,6 @@ describe('Performance Monitoring > remote_config_service', () => {
176174
TRANSPORT_KEY
177175
);
178176
expect(SettingsService.getInstance().logSource).to.equal(LOG_SOURCE);
179-
expect(SettingsService.getInstance().shouldSendToFl).to.be.true;
180177
expect(
181178
SettingsService.getInstance().networkRequestsSamplingRate
182179
).to.equal(NETWORK_SAMPLIG_RATE);
@@ -239,132 +236,5 @@ describe('Performance Monitoring > remote_config_service', () => {
239236

240237
expect(SettingsService.getInstance().loggingEnabled).to.be.true;
241238
});
242-
243-
it('marks event destination to cc if there is no template', async () => {
244-
setup(
245-
{
246-
// Expired local config.
247-
expiry: '1556524895320',
248-
config: NOT_VALID_CONFIG
249-
},
250-
{ reject: false, value: new Response('{"state":"NO_TEMPLATE"}') }
251-
);
252-
await getConfig(IID);
253-
254-
// If no template, will send to cc.
255-
expect(SettingsService.getInstance().shouldSendToFl).to.be.false;
256-
});
257-
258-
it('marks event destination to cc if instance state unspecified', async () => {
259-
setup(
260-
{
261-
// Expired local config.
262-
expiry: '1556524895320',
263-
config: NOT_VALID_CONFIG
264-
},
265-
{
266-
reject: false,
267-
value: new Response('{"state":"INSTANCE_STATE_UNSPECIFIED"}')
268-
}
269-
);
270-
await getConfig(IID);
271-
272-
// If instance state unspecified, will send to cc.
273-
expect(SettingsService.getInstance().shouldSendToFl).to.be.false;
274-
});
275-
276-
it("marks event destination to cc if state doesn't exist", async () => {
277-
setup(
278-
{
279-
// Expired local config.
280-
expiry: '1556524895320',
281-
config: NOT_VALID_CONFIG
282-
},
283-
{ reject: false, value: new Response('{}') }
284-
);
285-
await getConfig(IID);
286-
287-
// If "state" doesn't exist, will send to cc.
288-
expect(SettingsService.getInstance().shouldSendToFl).to.be.false;
289-
});
290-
291-
it('marks event destination to Fl if template exists but no rollout flag', async () => {
292-
const CONFIG_WITHOUT_ROLLOUT_FLAG = `{"entries":{"fpr_enabled":"true",\
293-
"fpr_log_endpoint_url":"https://firebaselogging.test.com",\
294-
"fpr_log_source":"2","fpr_vc_network_request_sampling_rate":"0.250000",\
295-
"fpr_vc_session_sampling_rate":"0.250000","fpr_vc_trace_sampling_rate":"0.500000"},\
296-
"state":"UPDATE"}`;
297-
setup(
298-
{
299-
// Expired local config.
300-
expiry: '1556524895320',
301-
config: NOT_VALID_CONFIG
302-
},
303-
{ reject: false, value: new Response(CONFIG_WITHOUT_ROLLOUT_FLAG) }
304-
);
305-
await getConfig(IID);
306-
307-
// If template exists but no rollout flag, will send to Fl.
308-
expect(SettingsService.getInstance().shouldSendToFl).to.be.true;
309-
});
310-
311-
it('marks event destination to cc when instance is outside of rollout range', async () => {
312-
const CONFIG_WITH_ROLLOUT_FLAG_10 = `{"entries":{"fpr_enabled":"true",\
313-
"fpr_log_endpoint_url":"https://firebaselogging.test.com",\
314-
"fpr_log_source":"2","fpr_vc_network_request_sampling_rate":"0.250000",\
315-
"fpr_log_transport_web_percent":"10.0",\
316-
"fpr_vc_session_sampling_rate":"0.250000","fpr_vc_trace_sampling_rate":"0.500000"},\
317-
"state":"UPDATE"}`;
318-
setup(
319-
{
320-
// Expired local config.
321-
expiry: '1556524895320',
322-
config: NOT_VALID_CONFIG
323-
},
324-
{ reject: false, value: new Response(CONFIG_WITH_ROLLOUT_FLAG_10) }
325-
);
326-
await getConfig(IID);
327-
328-
// If rollout flag exists, will send to cc when this instance is out of rollout scope.
329-
expect(SettingsService.getInstance().shouldSendToFl).to.be.false;
330-
});
331-
332-
it('marks event destination to Fl when instance is within rollout range', async () => {
333-
const CONFIG_WITH_ROLLOUT_FLAG_40 = `{"entries":{"fpr_enabled":"true",\
334-
"fpr_log_endpoint_url":"https://firebaselogging.test.com",\
335-
"fpr_log_source":"2","fpr_vc_network_request_sampling_rate":"0.250000",\
336-
"fpr_log_transport_web_percent":"40.0",\
337-
"fpr_vc_session_sampling_rate":"0.250000","fpr_vc_trace_sampling_rate":"0.500000"},\
338-
"state":"UPDATE"}`;
339-
setup(
340-
{
341-
// Expired local config.
342-
expiry: '1556524895320',
343-
config: NOT_VALID_CONFIG
344-
},
345-
{ reject: false, value: new Response(CONFIG_WITH_ROLLOUT_FLAG_40) }
346-
);
347-
await getConfig(IID);
348-
349-
// If rollout flag exists, will send to Fl when this instance is within rollout scope.
350-
expect(SettingsService.getInstance().shouldSendToFl).to.be.true;
351-
});
352-
});
353-
354-
describe('isDestFl', () => {
355-
it('marks traffic to cc when rollout percentage is 0', () => {
356-
const shouldSendToFl = isDestFl('abc', 0); // Hash percentage of "abc" is 38%.
357-
expect(shouldSendToFl).to.be.false;
358-
});
359-
360-
it('marks traffic to Fl when rollout percentage is 100', () => {
361-
const shouldSendToFl = isDestFl('abc', 100); // Hash percentage of "abc" is 38%.
362-
expect(shouldSendToFl).to.be.true;
363-
});
364-
365-
it('marks traffic to Fl if hash percentage is lower than rollout percentage 50%', () => {
366-
const shouldSendToFl = isDestFl('abc', 50); // Hash percentage of "abc" is 38%.
367-
expect(shouldSendToFl).to.be.true;
368-
});
369239
});
370240
});

packages/performance/src/services/remote_config_service.ts

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,14 @@ interface SecondaryConfig {
3434
logSource?: number;
3535
logEndPointUrl?: string;
3636
transportKey?: string;
37-
shouldSendToFl?: boolean;
3837
tracesSamplingRate?: number;
3938
networkRequestsSamplingRate?: number;
4039
}
4140

4241
// These values will be used if the remote config object is successfully
4342
// retrieved, but the template does not have these fields.
4443
const DEFAULT_CONFIGS: SecondaryConfig = {
45-
loggingEnabled: true,
46-
shouldSendToFl: true
47-
};
48-
49-
// These values will be used if the remote config object is successfully
50-
// retrieved, but the config object state shows unspecified or no template.
51-
const NO_TEMPLATE_CONFIGS: SecondaryConfig = {
52-
shouldSendToFl: false
44+
loggingEnabled: true
5345
};
5446

5547
/* eslint-disable camelcase */
@@ -75,12 +67,12 @@ const FIS_AUTH_PREFIX = 'FIREBASE_INSTALLATIONS_AUTH';
7567
export function getConfig(iid: string): Promise<void> {
7668
const config = getStoredConfig();
7769
if (config) {
78-
processConfig(iid, config);
70+
processConfig(config);
7971
return Promise.resolve();
8072
}
8173

8274
return getRemoteConfig(iid)
83-
.then(config => processConfig(iid, config))
75+
.then(config => processConfig(config))
8476
.then(
8577
config => storeConfig(config),
8678
/** Do nothing for error, use defaults set in settings service. */
@@ -170,15 +162,13 @@ function getRemoteConfig(
170162
* is valid.
171163
*/
172164
function processConfig(
173-
iid: string,
174165
config: RemoteConfigResponse | undefined
175166
): RemoteConfigResponse | undefined {
176167
if (!config) {
177168
return config;
178169
}
179170
const settingsServiceInstance = SettingsService.getInstance();
180171
const entries = config.entries || {};
181-
const state = config.state;
182172
if (entries.fpr_enabled !== undefined) {
183173
// TODO: Change the assignment of loggingEnabled once the received type is
184174
// known.
@@ -208,32 +198,6 @@ function processConfig(
208198
settingsServiceInstance.transportKey = DEFAULT_CONFIGS.transportKey;
209199
}
210200

211-
// If config object state indicates that no template has been set, that means it is new user of
212-
// Performance Monitoring and should use the old log endpoint, because it is guaranteed to work.
213-
if (
214-
state === undefined ||
215-
state === 'INSTANCE_STATE_UNSPECIFIED' ||
216-
state === 'NO_TEMPLATE'
217-
) {
218-
if (NO_TEMPLATE_CONFIGS.shouldSendToFl !== undefined) {
219-
settingsServiceInstance.shouldSendToFl =
220-
NO_TEMPLATE_CONFIGS.shouldSendToFl;
221-
}
222-
} else if (entries.fpr_log_transport_web_percent) {
223-
// If config object state doesn't indicate no template, it can only be UPDATE for now.
224-
// - Performance Monitoring doesn't set etag in request, therefore state cannot be NO_CHANGE.
225-
// - Sampling rate flags and master flag are required, therefore state cannot be EMPTY_CONFIG.
226-
// If config object state is UPDATE and rollout flag is present, determine endpoint by iid.
227-
settingsServiceInstance.shouldSendToFl = isDestFl(
228-
iid,
229-
Number(entries.fpr_log_transport_web_percent)
230-
);
231-
} else if (DEFAULT_CONFIGS.shouldSendToFl !== undefined) {
232-
// If config object state is UPDATE and rollout flag is not present, that means rollout is
233-
// complete and rollout flag is deprecated, therefore dispatch events to new transport endpoint.
234-
settingsServiceInstance.shouldSendToFl = DEFAULT_CONFIGS.shouldSendToFl;
235-
}
236-
237201
if (entries.fpr_vc_network_request_sampling_rate !== undefined) {
238202
settingsServiceInstance.networkRequestsSamplingRate = Number(
239203
entries.fpr_vc_network_request_sampling_rate

packages/performance/src/services/settings_service.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ export class SettingsService {
4747

4848
transportKey = mergeStrings('AzSC8r6ReiGqFMyfvgow', 'Iayx0u-XT3vksVM-pIV');
4949

50-
shouldSendToFl = false;
51-
5250
// Source type for performance event logs.
5351
logSource = 462;
5452

packages/performance/src/services/transport_service.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ describe('Firebase Performance > transport_service', () => {
4747
fetchStub.restore();
4848
clock.restore();
4949
resetTransportService();
50-
SettingsService.getInstance().shouldSendToFl = false;
5150
});
5251

5352
it('throws an error when logging an empty message', () => {
@@ -87,7 +86,6 @@ describe('Firebase Performance > transport_service', () => {
8786
const setting = SettingsService.getInstance();
8887
const flTransportFullUrl =
8988
setting.flTransportEndpointUrl + '?key=' + setting.transportKey;
90-
setting.shouldSendToFl = true;
9189
fetchStub.withArgs(flTransportFullUrl, match.any).resolves(
9290
// DELETE_REQUEST means event dispatch is successful.
9391
new Response(

packages/performance/src/services/transport_service.ts

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ function dispatchQueueEvents(): void {
112112
};
113113
/* eslint-enable camelcase */
114114

115-
postToEndpoint(data, staged).catch(() => {
115+
sendEventsToFl(data, staged).catch(() => {
116116
// If the request fails for some reason, add the events that were attempted
117117
// back to the primary queue to retry later.
118118
queue = [...staged, ...queue];
@@ -122,18 +122,6 @@ function dispatchQueueEvents(): void {
122122
});
123123
}
124124

125-
function postToEndpoint(
126-
data: TransportBatchLogFormat,
127-
staged: BatchEvent[]
128-
): Promise<void> {
129-
// Gradually rollout traffic from cc to transport using remote config.
130-
if (SettingsService.getInstance().shouldSendToFl) {
131-
return sendEventsToFl(data, staged);
132-
} else {
133-
return sendEventsToCc(data);
134-
}
135-
}
136-
137125
function sendEventsToFl(
138126
data: TransportBatchLogFormat,
139127
staged: BatchEvent[]
@@ -171,29 +159,6 @@ function sendEventsToFl(
171159
});
172160
}
173161

174-
function sendEventsToCc(data: TransportBatchLogFormat): Promise<void> {
175-
return fetch(SettingsService.getInstance().logEndPointUrl, {
176-
method: 'POST',
177-
body: JSON.stringify(data)
178-
})
179-
.then(res => {
180-
if (!res.ok) {
181-
consoleLogger.info('Call to Firebase backend failed.');
182-
}
183-
return res.json();
184-
})
185-
.then(res => {
186-
const wait = Number(res.next_request_wait_millis);
187-
// Find the next call wait time from the response.
188-
const requestOffset = isNaN(wait)
189-
? DEFAULT_SEND_INTERVAL_MS
190-
: Math.max(DEFAULT_SEND_INTERVAL_MS, wait);
191-
remainingTries = DEFAULT_REMAINING_TRIES;
192-
// Schedule the next process.
193-
processQueue(requestOffset);
194-
});
195-
}
196-
197162
function postToFlEndpoint(data: TransportBatchLogFormat): Promise<Response> {
198163
const flTransportFullUrl = SettingsService.getInstance().getFlTransportFullUrl();
199164
return fetch(flTransportFullUrl, {

0 commit comments

Comments
 (0)