Skip to content

Commit 2e0350d

Browse files
authored
Fb/initial log (#83)
* impl * update snaps * fix space problem and add unique name log check to integration tests * take out old plurality code
1 parent 2a704bc commit 2e0350d

File tree

3 files changed

+23
-46
lines changed

3 files changed

+23
-46
lines changed

src/feature-toggles.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
// TODO locale for validation messages
1414

15-
const { promisify } = require("util");
15+
const util = require("util");
1616
const pathlib = require("path");
1717
const { readFile } = require("fs");
1818
const VError = require("verror");
@@ -112,7 +112,7 @@ const SCOPE_PREFERENCE_ORDER_MASKS = [
112112
],
113113
];
114114

115-
const readFileAsync = promisify(readFile);
115+
const readFileAsync = util.promisify(readFile);
116116
let logger = new Logger(COMPONENT_NAME);
117117

118118
/**
@@ -314,6 +314,7 @@ class FeatureToggles {
314314
redisChannel = DEFAULT_REDIS_CHANNEL,
315315
redisKey = DEFAULT_REDIS_KEY,
316316
} = {}) {
317+
this.__uniqueName = uniqueName;
317318
this.__redisChannel = uniqueName ? redisChannel + "-" + uniqueName : redisChannel;
318319
this.__redisKey = uniqueName ? redisKey + "-" + uniqueName : redisKey;
319320

@@ -857,13 +858,18 @@ class FeatureToggles {
857858
const totalCount =
858859
toggleCounts[CONFIG_SOURCE.RUNTIME] + toggleCounts[CONFIG_SOURCE.FILE] + toggleCounts[CONFIG_SOURCE.AUTO];
859860
logger.info(
860-
"finished initialization with %i feature toggle%s (%i runtime, %i file, %i auto) with %s",
861-
totalCount,
862-
totalCount === 1 ? "" : "s",
863-
toggleCounts[CONFIG_SOURCE.RUNTIME],
864-
toggleCounts[CONFIG_SOURCE.FILE],
865-
toggleCounts[CONFIG_SOURCE.AUTO],
866-
redisIntegrationMode
861+
[
862+
"finished initialization",
863+
...(this.__uniqueName ? [`of "${this.__uniqueName}"`] : []),
864+
util.format(
865+
"with %i feature toggles (%i runtime, %i file, %i auto)",
866+
totalCount,
867+
toggleCounts[CONFIG_SOURCE.RUNTIME],
868+
toggleCounts[CONFIG_SOURCE.FILE],
869+
toggleCounts[CONFIG_SOURCE.AUTO]
870+
),
871+
`using ${redisIntegrationMode}`,
872+
].join(" ")
867873
);
868874
this.__isInitialized = true;
869875
return this;

test/integration-local/feature-toggles.integration.test.js

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ let toggles;
2020

2121
describe("local integration test", () => {
2222
beforeEach(async () => {
23+
process.env.BTP_FEATURES_UNIQUE_NAME = "unicorn";
2324
jest.resetModules();
2425
toggles = require("../../src/");
2526

@@ -141,13 +142,7 @@ describe("local integration test", () => {
141142
expect(featureTogglesLoggerSpy.info.mock.calls).toMatchInlineSnapshot(`
142143
[
143144
[
144-
"finished initialization with %i feature toggle%s (%i runtime, %i file, %i auto) with %s",
145-
4,
146-
"s",
147-
2,
148-
1,
149-
1,
150-
"NO_REDIS",
145+
"finished initialization of "unicorn" with 4 feature toggles (2 runtime, 1 file, 1 auto) using NO_REDIS",
151146
],
152147
]
153148
`);
@@ -291,13 +286,7 @@ describe("local integration test", () => {
291286
expect(featureTogglesLoggerSpy.info.mock.calls).toMatchInlineSnapshot(`
292287
[
293288
[
294-
"finished initialization with %i feature toggle%s (%i runtime, %i file, %i auto) with %s",
295-
9,
296-
"s",
297-
9,
298-
0,
299-
0,
300-
"NO_REDIS",
289+
"finished initialization of "unicorn" with 9 feature toggles (9 runtime, 0 file, 0 auto) using NO_REDIS",
301290
],
302291
]
303292
`);
@@ -327,13 +316,7 @@ describe("local integration test", () => {
327316
expect(featureTogglesLoggerSpy.info.mock.calls).toMatchInlineSnapshot(`
328317
[
329318
[
330-
"finished initialization with %i feature toggle%s (%i runtime, %i file, %i auto) with %s",
331-
9,
332-
"s",
333-
9,
334-
0,
335-
0,
336-
"NO_REDIS",
319+
"finished initialization of "unicorn" with 9 feature toggles (9 runtime, 0 file, 0 auto) using NO_REDIS",
337320
],
338321
]
339322
`);
@@ -470,13 +453,7 @@ describe("local integration test", () => {
470453
expect(featureTogglesLoggerSpy.info.mock.calls).toMatchInlineSnapshot(`
471454
[
472455
[
473-
"finished initialization with %i feature toggle%s (%i runtime, %i file, %i auto) with %s",
474-
9,
475-
"s",
476-
9,
477-
0,
478-
0,
479-
"NO_REDIS",
456+
"finished initialization of "unicorn" with 9 feature toggles (9 runtime, 0 file, 0 auto) using NO_REDIS",
480457
],
481458
]
482459
`);
@@ -573,13 +550,7 @@ describe("local integration test", () => {
573550
expect(featureTogglesLoggerSpy.info.mock.calls).toMatchInlineSnapshot(`
574551
[
575552
[
576-
"finished initialization with %i feature toggle%s (%i runtime, %i file, %i auto) with %s",
577-
9,
578-
"s",
579-
9,
580-
0,
581-
0,
582-
"NO_REDIS",
553+
"finished initialization of "unicorn" with 9 feature toggles (9 runtime, 0 file, 0 auto) using NO_REDIS",
583554
],
584555
]
585556
`);

test/shared/logger.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ describe("logger test", () => {
8484
}",
8585
],
8686
[
87-
"88:88:88.888 | INFO | /test | finished initialization with 9 feature toggles (9 runtime, 0 file, 0 auto) with CF_REDIS",
87+
"88:88:88.888 | INFO | /test | finished initialization with 9 feature toggles (9 runtime, 0 file, 0 auto) using CF_REDIS",
8888
],
8989
]
9090
`);
@@ -126,7 +126,7 @@ describe("logger test", () => {
126126
"{"level":"warn","msg":"FeatureTogglesError: found invalid fallback values during initialization\\n{\\n validationErrors: '[{\\"featureKey\\":\\"test/feature_b\\",\\"errorMessage\\":\\"registered validator \\\\\\\\\\"{0}\\\\\\\\\\" failed for value \\\\\\\\\\"{1}\\\\\\\\\\" with error {2}\\",\\"errorMessageValues\\":[\\"mockConstructor\\",1,\\"bad validator\\"]}]'\\n}","type":"log","layer":"/test"}",
127127
],
128128
[
129-
"{"level":"info","msg":"finished initialization with 9 feature toggles (9 runtime, 0 file, 0 auto) with CF_REDIS","type":"log","layer":"/test"}",
129+
"{"level":"info","msg":"finished initialization with 9 feature toggles (9 runtime, 0 file, 0 auto) using CF_REDIS","type":"log","layer":"/test"}",
130130
],
131131
]
132132
`);

0 commit comments

Comments
 (0)