Skip to content
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nflx-spectator",
"version": "3.0.15",
"version": "3.0.16",
"license": "Apache-2.0",
"homepage": "https://github.com/Netflix/spectator-js",
"author": "Netflix Telemetry Engineering <[email protected]>",
Expand Down
10 changes: 5 additions & 5 deletions test/common_tags.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe("Common Tags Tests", (): void => {

it("get tags from env vars", (): void => {
setup_environment();
assert.deepEqual(all_expected_tags(), tags_from_env_vars());
assert.deepEqual(tags_from_env_vars(), all_expected_tags());
clear_environment();
});

Expand All @@ -36,7 +36,7 @@ describe("Common Tags Tests", (): void => {

const expected_tags: Record<string, string> = all_expected_tags();
delete expected_tags["nf.container"];
assert.deepEqual(expected_tags, tags_from_env_vars());
assert.deepEqual(tags_from_env_vars(), expected_tags);

clear_environment();
});
Expand All @@ -47,20 +47,20 @@ describe("Common Tags Tests", (): void => {

const expected_tags: Record<string, string> = all_expected_tags();
delete expected_tags["nf.container"];
assert.deepEqual(expected_tags, tags_from_env_vars());
assert.deepEqual(tags_from_env_vars(), expected_tags);

clear_environment();
});

it("get tags from env vars with whitespace ignored", (): void => {
setup_environment();
process.env.TITUS_CONTAINER_NAME = " main \t\t";
assert.deepEqual(all_expected_tags(), tags_from_env_vars());
assert.deepEqual(tags_from_env_vars(), all_expected_tags());
clear_environment();
});

it("validate tags skips zero length strings", (): void => {
const tags = {"a": "", "": "b", "cc": "1"};
assert.deepEqual({"cc": "1"}, validate_tags(tags));
assert.deepEqual(validate_tags(tags), {"cc": "1"});
});
});
22 changes: 11 additions & 11 deletions test/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ describe("Config Tests", (): void => {
setup_environment();
const config = new Config();
assert.deepEqual(all_expected_tags(), config.extra_common_tags);
assert.equal("udp", config.location);
assert.equal(config.location, "udp");
clear_environment();
});

it("env location override", (): void => {
process.env.SPECTATOR_OUTPUT_LOCATION = "memory";
const config = new Config();
assert.equal("memory", config.location);
assert.equal(config.location, "memory");
clear_environment();
});

Expand All @@ -52,19 +52,19 @@ describe("Config Tests", (): void => {
it("extra common tags", (): void => {
setup_environment();
const config = new Config(undefined, {"extra-tag": "foo"});
assert.equal("udp", config.location);
assert.deepEqual({"extra-tag": "foo", "nf.container": "main", "nf.process": "nodejs"}, config.extra_common_tags);
assert.equal(config.location, "udp");
assert.deepEqual(config.extra_common_tags, {"extra-tag": "foo", "nf.container": "main", "nf.process": "nodejs"});
clear_environment();
});

it("valid output locations", (): void => {
assert.equal("none", get_location("none"));
assert.equal("memory", get_location("memory"));
assert.equal("stderr", get_location("stderr"));
assert.equal("stdout", get_location("stdout"));
assert.equal("udp", get_location("udp"));
assert.equal("file://", get_location("file://"));
assert.equal("udp://", get_location("udp://"));
assert.equal(get_location("none"), "none");
assert.equal(get_location("memory"), "memory");
assert.equal(get_location("stderr"), "stderr");
assert.equal(get_location("stdout"), "stdout");
assert.equal(get_location("udp"), "udp");
assert.equal(get_location("file://"), "file://");
assert.equal(get_location("udp://"), "udp://");
});

it("invalid output location throws", (): void => {
Expand Down
6 changes: 5 additions & 1 deletion test/logger/logger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ describe("Logger Tests", (): void => {
log.warn("stern warning");
log.error("error message");

assert.deepEqual(["WARN: stern warning", "ERROR: error message"], messages);
const expected: string[] = [
"WARN: stern warning",
"ERROR: error message"
];
assert.deepEqual(messages, expected);
console.log = f;
});
});
4 changes: 2 additions & 2 deletions test/meter/age_gauge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe("AgeGauge Tests", (): void => {
assert.isTrue(writer.is_empty());

g.now();
assert.equal("A:age_gauge:0", writer.last_line());
assert.equal(writer.last_line(), "A:age_gauge:0");
});

it("set", (): void => {
Expand All @@ -21,6 +21,6 @@ describe("AgeGauge Tests", (): void => {
assert.isTrue(writer.is_empty());

g.set(10);
assert.equal("A:age_gauge:10", writer.last_line());
assert.equal(writer.last_line(), "A:age_gauge:10");
});
});
8 changes: 4 additions & 4 deletions test/meter/counter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ describe("Counter Tests", (): void => {
assert.isTrue(writer.is_empty());

c.add();
assert.equal("c:counter:1", writer.last_line());
assert.equal(writer.last_line(), "c:counter:1");

c.add(2);
assert.equal("c:counter:2", writer.last_line());
assert.equal(writer.last_line(), "c:counter:2");
});

it("increment", (): void => {
Expand All @@ -24,10 +24,10 @@ describe("Counter Tests", (): void => {
assert.isTrue(writer.is_empty());

c.increment();
assert.equal("c:counter:1", writer.last_line());
assert.equal(writer.last_line(), "c:counter:1");

c.increment(2);
assert.equal("c:counter:2", writer.last_line());
assert.equal(writer.last_line(), "c:counter:2");
});

it("increment negative", (): void => {
Expand Down
4 changes: 2 additions & 2 deletions test/meter/dist_summary.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe("DistributionSummary Tests", (): void => {
assert.isTrue(writer.is_empty());

d.record(42);
assert.equal("d:dist_summary:42", writer.last_line());
assert.equal(writer.last_line(), "d:dist_summary:42");
});

it("record negative", (): void => {
Expand All @@ -26,6 +26,6 @@ describe("DistributionSummary Tests", (): void => {
const d = new DistributionSummary(tid, new MemoryWriter());
const writer = d.writer() as MemoryWriter;
d.record(0);
assert.equal("d:dist_summary:0", writer.last_line());
assert.equal(writer.last_line(), "d:dist_summary:0");
});
});
6 changes: 3 additions & 3 deletions test/meter/gauge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe("Gauge Tests", (): void => {
assert.isTrue(writer.is_empty());

g.set(1);
assert.equal("g:gauge:1", writer.last_line());
assert.equal(writer.last_line(), "g:gauge:1");
});

it("update delegates to set", (): void => {
Expand All @@ -21,13 +21,13 @@ describe("Gauge Tests", (): void => {
assert.isTrue(writer.is_empty());

g.update(1);
assert.equal("g:gauge:1", writer.last_line());
assert.equal(writer.last_line(), "g:gauge:1");
});

it("ttl_seconds", (): void => {
const g = new Gauge(tid, new MemoryWriter(), 120);
const writer = g.writer() as MemoryWriter;
g.set(42);
assert.equal("g,120:gauge:42", writer.last_line());
assert.equal(writer.last_line(), "g,120:gauge:42");
});
});
4 changes: 2 additions & 2 deletions test/meter/max_gauge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe("MaxGauge Tests", (): void => {
assert.isTrue(writer.is_empty());

g.set(0);
assert.equal("m:max_gauge:0", writer.last_line());
assert.equal(writer.last_line(), "m:max_gauge:0");
});

it("update delegates to set", (): void => {
Expand All @@ -21,6 +21,6 @@ describe("MaxGauge Tests", (): void => {
assert.isTrue(writer.is_empty());

g.update(0);
assert.equal("m:max_gauge:0", writer.last_line());
assert.equal(writer.last_line(), "m:max_gauge:0");
});
});
4 changes: 2 additions & 2 deletions test/meter/monotonic_counter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe("MonotonicCounter Tests", (): void => {
assert.isTrue(writer.is_empty());

c.set(1);
assert.equal("C:monotonic_counter:1", writer.last_line());
assert.equal(writer.last_line(), "C:monotonic_counter:1");
});

it("set negative", (): void => {
Expand All @@ -21,6 +21,6 @@ describe("MonotonicCounter Tests", (): void => {
assert.isTrue(writer.is_empty());

c.set(-1);
assert.equal("C:monotonic_counter:-1", writer.last_line());
assert.equal(writer.last_line(), "C:monotonic_counter:-1");
});
});
4 changes: 2 additions & 2 deletions test/meter/monotonic_counter_uint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe("MonotonicCounterUint Tests", (): void => {
assert.isTrue(writer.is_empty());

c.set(BigInt(1));
assert.equal("U:monotonic_counter_uint:1", writer.last_line());
assert.equal(writer.last_line(), "U:monotonic_counter_uint:1");
});

it("set negative", (): void => {
Expand All @@ -21,6 +21,6 @@ describe("MonotonicCounterUint Tests", (): void => {
assert.isTrue(writer.is_empty());

c.set(BigInt(-1));
assert.equal("U:monotonic_counter_uint:18446744073709551615", writer.last_line());
assert.equal(writer.last_line(), "U:monotonic_counter_uint:18446744073709551615");
});
});
4 changes: 2 additions & 2 deletions test/meter/percentile_dist_summary.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe("PercentileDistributionSummary Tests", (): void => {
assert.isTrue(writer.is_empty());

d.record(42);
assert.equal("D:percentile_dist_summary:42", writer.last_line());
assert.equal(writer.last_line(), "D:percentile_dist_summary:42");
});

it("record negative", (): void => {
Expand All @@ -26,6 +26,6 @@ describe("PercentileDistributionSummary Tests", (): void => {
const d = new PercentileDistributionSummary(tid, new MemoryWriter());
const writer = d.writer() as MemoryWriter;
d.record(0);
assert.equal("D:percentile_dist_summary:0", writer.last_line());
assert.equal(writer.last_line(), "D:percentile_dist_summary:0");
});
});
10 changes: 5 additions & 5 deletions test/meter/percentile_timer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe("PercentileTimer Tests", (): void => {
assert.isTrue(writer.is_empty());

t.record(42);
assert.equal("T:percentile_timer:42", writer.last_line());
assert.equal(writer.last_line(), "T:percentile_timer:42");
});

it("record negative", (): void => {
Expand All @@ -26,14 +26,14 @@ describe("PercentileTimer Tests", (): void => {
const t = new PercentileTimer(tid, new MemoryWriter());
const writer = t.writer() as MemoryWriter;
t.record(0);
assert.equal("T:percentile_timer:0", writer.last_line());
assert.equal(writer.last_line(), "T:percentile_timer:0");
});

it("record bigint nanoseconds", (): void => {
const t = new PercentileTimer(tid, new MemoryWriter());
const writer = t.writer() as MemoryWriter;
t.record(BigInt(1e9));
assert.equal("T:percentile_timer:1", writer.last_line());
assert.equal(writer.last_line(), "T:percentile_timer:1");
});

it("record latency from hrtime", (): void => {
Expand All @@ -55,11 +55,11 @@ describe("PercentileTimer Tests", (): void => {
const t = new PercentileTimer(tid, new MemoryWriter());
const writer = t.writer() as MemoryWriter;
t.record(process.hrtime(start)); // two calls to hrtime = 1ms + 2ms = 3ms
assert.equal("T:percentile_timer:0.003", writer.last_line());
assert.equal(writer.last_line(), "T:percentile_timer:0.003");

const [seconds, nanoseconds] = process.hrtime(start);
t.record(seconds, nanoseconds); // three calls to hrtime = 1ms + 2ms + 3ms = 6ms
assert.equal("T:percentile_timer:0.006", writer.last_line());
assert.equal(writer.last_line(), "T:percentile_timer:0.006");

Object.defineProperty(process, "hrtime", f);
});
Expand Down
10 changes: 5 additions & 5 deletions test/meter/timer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe("Timer Tests", (): void => {
assert.isTrue(writer.is_empty());

t.record(42);
assert.equal("t:timer:42", writer.last_line());
assert.equal(writer.last_line(), "t:timer:42");
});

it("record negative", (): void => {
Expand All @@ -26,14 +26,14 @@ describe("Timer Tests", (): void => {
const t = new Timer(tid, new MemoryWriter());
const writer = t.writer() as MemoryWriter;
t.record(0);
assert.equal("t:timer:0", writer.last_line());
assert.equal(writer.last_line(), "t:timer:0");
});

it("record bigint nanoseconds", (): void => {
const t = new Timer(tid, new MemoryWriter());
const writer = t.writer() as MemoryWriter;
t.record(BigInt(1e9));
assert.equal("t:timer:1", writer.last_line());
assert.equal(writer.last_line(), "t:timer:1");
});

it("record latency from hrtime", (): void => {
Expand All @@ -55,11 +55,11 @@ describe("Timer Tests", (): void => {
const t = new Timer(tid, new MemoryWriter());
const writer = t.writer() as MemoryWriter;
t.record(process.hrtime(start)); // two calls to hrtime = 1ms + 2ms = 3ms
assert.equal("t:timer:0.003", writer.last_line());
assert.equal(writer.last_line(), "t:timer:0.003");

const [seconds, nanoseconds] = process.hrtime(start);
t.record(seconds, nanoseconds); // three calls to hrtime = 1ms + 2ms + 3ms = 6ms
assert.equal("t:timer:0.006", writer.last_line());
assert.equal(writer.last_line(), "t:timer:0.006");

Object.defineProperty(process, "hrtime", f);
});
Expand Down
Loading