Skip to content

Commit d0af35b

Browse files
committed
FFM-10325 Return early if no analytics events + don't log code 5002 for SSE heartbeats
1 parent 0ec2cff commit d0af35b

File tree

3 files changed

+28
-119
lines changed

3 files changed

+28
-119
lines changed

examples/getting_started/package-lock.json

-94
This file was deleted.

src/metrics.ts

+23-24
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,6 @@ export const MetricsProcessor = (
101101
};
102102

103103
const _summarize = (): Metrics | unknown => {
104-
if (!data) {
105-
log.debug('No metrics data!');
106-
return;
107-
}
108-
109104
const targetData: TargetData[] = [];
110105
const metricsData: MetricsData[] = [];
111106

@@ -184,30 +179,34 @@ export const MetricsProcessor = (
184179

185180
const _send = (): void => {
186181
if (closed) {
182+
log.debug('SDK has been closed before metrics can be sent');
183+
return;
184+
}
185+
186+
if (data.size == 0) {
187+
log.debug('No metrics to send in this interval');
187188
return;
188189
}
189190

190191
const metrics: Metrics = _summarize();
191192

192-
if (metrics && metrics.metricsData.length && metrics.targetData.length) {
193-
log.debug('Start sending metrics data');
194-
api
195-
.postMetrics(environment, cluster, metrics)
196-
.then((response) => {
197-
log.debug('Metrics server returns: ', response.status);
198-
infoMetricsSuccess(log);
199-
if (response.status >= 400) {
200-
log.error(
201-
'Error while sending metrics data with status code: ',
202-
response.status,
203-
);
204-
}
205-
})
206-
.catch((error: Error) => {
207-
warnPostMetricsFailed(`${error}`, log);
208-
log.debug('Metrics server returns error: ', error);
209-
});
210-
}
193+
log.debug('Start sending metrics data');
194+
api
195+
.postMetrics(environment, cluster, metrics)
196+
.then((response) => {
197+
log.debug('Metrics server returns: ', response.status);
198+
infoMetricsSuccess(log);
199+
if (response.status >= 400) {
200+
log.error(
201+
'Error while sending metrics data with status code: ',
202+
response.status,
203+
);
204+
}
205+
})
206+
.catch((error: Error) => {
207+
warnPostMetricsFailed(`${error}`, log);
208+
log.debug('Metrics server returns error: ', error);
209+
});
211210
};
212211

213212
const start = (): void => {

src/streaming.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ export class StreamProcessor {
143143

144144
res
145145
.on('data', (data) => {
146-
debugStreamEventReceived(this.log);
147146
this.processData(data);
148147
})
149148
.on('close', () => {
@@ -166,11 +165,16 @@ export class StreamProcessor {
166165

167166
private processData(data: any): void {
168167
const lines = data.toString().split(/\r?\n/);
168+
if (lines[0].startsWith(":")) {
169+
this.log.debug("SSE Heartbeat received")
170+
return;
171+
}
169172
lines.forEach((line) => this.processLine(line));
170173
}
171174

172175
private processLine(line: string): void {
173176
if (line.startsWith('data:')) {
177+
debugStreamEventReceived(this.log);
174178
this.log.debug('SSE GOT:', line.substring(5));
175179
const msg = JSON.parse(line.substring(5));
176180

0 commit comments

Comments
 (0)