Skip to content

Commit 72ad693

Browse files
authored
FFM-10325 Fix issue with detecting empty evaluation/target metrics (#101)
1 parent 0ec2cff commit 72ad693

File tree

6 files changed

+33
-32
lines changed

6 files changed

+33
-32
lines changed

examples/getting_started/package-lock.json

+1-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@harnessio/ff-nodejs-server-sdk",
3-
"version": "1.4.0",
3+
"version": "1.4.1",
44
"description": "Feature flags SDK for NodeJS environments",
55
"main": "dist/cjs/index.js",
66
"module": "dist/esm/index.mjs",

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

src/version.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export const VERSION = '1.4.0';
1+
export const VERSION = '1.4.1';

0 commit comments

Comments
 (0)