Skip to content

FFM-10325 Fix issue with detecting empty evaluation/target metrics #101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions examples/getting_started/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@harnessio/ff-nodejs-server-sdk",
"version": "1.4.0",
"version": "1.4.1",
"description": "Feature flags SDK for NodeJS environments",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.mjs",
Expand Down
47 changes: 23 additions & 24 deletions src/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,6 @@ export const MetricsProcessor = (
};

const _summarize = (): Metrics | unknown => {
if (!data) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data is initialized when it is declared so this will always be true

log.debug('No metrics data!');
return;
}

const targetData: TargetData[] = [];
const metricsData: MetricsData[] = [];

Expand Down Expand Up @@ -184,30 +179,34 @@ export const MetricsProcessor = (

const _send = (): void => {
if (closed) {
log.debug('SDK has been closed before metrics can be sent');
return;
}

if (data.size == 0) {
log.debug('No metrics to send in this interval');
return;
}

const metrics: Metrics = _summarize();

if (metrics && metrics.metricsData.length && metrics.targetData.length) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can safely remove this check, because the earlier data check now works correctly.

log.debug('Start sending metrics data');
api
.postMetrics(environment, cluster, metrics)
.then((response) => {
log.debug('Metrics server returns: ', response.status);
infoMetricsSuccess(log);
if (response.status >= 400) {
log.error(
'Error while sending metrics data with status code: ',
response.status,
);
}
})
.catch((error: Error) => {
warnPostMetricsFailed(`${error}`, log);
log.debug('Metrics server returns error: ', error);
});
}
log.debug('Start sending metrics data');
api
.postMetrics(environment, cluster, metrics)
.then((response) => {
log.debug('Metrics server returns: ', response.status);
infoMetricsSuccess(log);
if (response.status >= 400) {
log.error(
'Error while sending metrics data with status code: ',
response.status,
);
}
})
.catch((error: Error) => {
warnPostMetricsFailed(`${error}`, log);
log.debug('Metrics server returns error: ', error);
});
};

const start = (): void => {
Expand Down
6 changes: 5 additions & 1 deletion src/streaming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ export class StreamProcessor {

res
.on('data', (data) => {
debugStreamEventReceived(this.log);
this.processData(data);
})
.on('close', () => {
Expand All @@ -166,11 +165,16 @@ export class StreamProcessor {

private processData(data: any): void {
const lines = data.toString().split(/\r?\n/);
if (lines[0].startsWith(":")) {
this.log.debug("SSE Heartbeat received")
return;
}
lines.forEach((line) => this.processLine(line));
}

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

Expand Down
2 changes: 1 addition & 1 deletion src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const VERSION = '1.4.0';
export const VERSION = '1.4.1';