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
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,8 @@ test:
.PHONY: coverage
coverage:
npm run test-with-coverage

## lint: run test-with-coverage
.PHONY: lint
lint:
npm run lint
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.14",
"version": "3.0.15",
"license": "Apache-2.0",
"homepage": "https://github.com/Netflix/spectator-js",
"author": "Netflix Telemetry Engineering <[email protected]>",
Expand Down
30 changes: 30 additions & 0 deletions src/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ export class Registry {
}

age_gauge_with_id(id: Id): AgeGauge {
if (id.invalid) {
return new AgeGauge(id, new NoopWriter());
}
return new AgeGauge(id, this._writer);
}

Expand All @@ -90,6 +93,9 @@ export class Registry {
}

counter_with_id(id: Id): Counter {
if (id.invalid) {
return new Counter(id, new NoopWriter());
}
return new Counter(id, this._writer);
}

Expand All @@ -102,6 +108,9 @@ export class Registry {
}

distribution_summary_with_id(id: Id): DistributionSummary {
if (id.invalid) {
return new DistributionSummary(id, new NoopWriter());
}
return new DistributionSummary(id, this._writer);
}

Expand All @@ -114,6 +123,9 @@ export class Registry {
}

gauge_with_id(id: Id, ttl_seconds?: number): Gauge {
if (id.invalid) {
return new Gauge(id, new NoopWriter(), ttl_seconds);
}
return new Gauge(id, this._writer, ttl_seconds);
}

Expand All @@ -126,6 +138,9 @@ export class Registry {
}

max_gauge_with_id(id: Id): MaxGauge {
if (id.invalid) {
return new MaxGauge(id, new NoopWriter());
}
return new MaxGauge(id, this._writer);
}

Expand All @@ -138,6 +153,9 @@ export class Registry {
}

monotonic_counter_with_id(id: Id): MonotonicCounter {
if (id.invalid) {
return new MonotonicCounter(id, new NoopWriter());
}
return new MonotonicCounter(id, this._writer);
}

Expand All @@ -150,6 +168,9 @@ export class Registry {
}

monotonic_counter_uint_with_id(id: Id): MonotonicCounterUint {
if (id.invalid) {
return new MonotonicCounterUint(id, new NoopWriter());
}
return new MonotonicCounterUint(id, this._writer);
}

Expand All @@ -162,6 +183,9 @@ export class Registry {
}

pct_distribution_summary_with_id(id: Id): PercentileDistributionSummary {
if (id.invalid) {
return new PercentileDistributionSummary(id, new NoopWriter());
}
return new PercentileDistributionSummary(id, this._writer);
}

Expand All @@ -174,6 +198,9 @@ export class Registry {
}

pct_timer_with_id(id: Id): PercentileTimer {
if (id.invalid) {
return new PercentileTimer(id, new NoopWriter());
}
return new PercentileTimer(id, this._writer);
}

Expand All @@ -186,6 +213,9 @@ export class Registry {
}

timer_with_id(id: Id): Timer {
if (id.invalid) {
return new Timer(id, new NoopWriter());
}
return new Timer(id, this._writer);
}
}
110 changes: 90 additions & 20 deletions test/registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,21 @@ describe("Registry Tests", (): void => {
const r = new Registry(new Config("memory"));
const writer = r.writer() as MemoryWriter;

const g: AgeGauge = r.age_gauge("g");
const g1: AgeGauge = r.age_gauge("g");
assert.isTrue(writer.is_empty());

g.set(1);
g1.set(1);
assert.isTrue(writer.is_empty());

const g2: AgeGauge = r.age_gauge_with_id(r.new_id("g"));
assert.isTrue(writer.is_empty());

g2.set(1);
assert.isTrue(writer.is_empty());

const expected: string[] = [
"WARN: Id(name=g, tags={}) is invalid, because the name is not a string, it is too short (< 2), or it is too long (> 255); metric will not be reported",
"WARN: Id(name=g, tags={}) is invalid, because the name is not a string, it is too short (< 2), or it is too long (> 255); metric will not be reported",
];
assert.deepEqual(expected, messages);
console.log = f;
Expand Down Expand Up @@ -122,14 +129,21 @@ describe("Registry Tests", (): void => {
const r = new Registry(new Config("memory"));
const writer = r.writer() as MemoryWriter;

const c: Counter = r.counter("c");
const c1: Counter = r.counter("c");
assert.isTrue(writer.is_empty());

c.increment();
c1.increment();
assert.isTrue(writer.is_empty());

const c2: Counter = r.counter_with_id(r.new_id("c"));
assert.isTrue(writer.is_empty());

c2.increment();
assert.isTrue(writer.is_empty());

const expected: string[] = [
"WARN: Id(name=c, tags={}) is invalid, because the name is not a string, it is too short (< 2), or it is too long (> 255); metric will not be reported",
"WARN: Id(name=c, tags={}) is invalid, because the name is not a string, it is too short (< 2), or it is too long (> 255); metric will not be reported",
];
assert.deepEqual(expected, messages);
console.log = f;
Expand Down Expand Up @@ -171,14 +185,21 @@ describe("Registry Tests", (): void => {
const r = new Registry(new Config("memory"));
const writer = r.writer() as MemoryWriter;

const d: DistributionSummary = r.distribution_summary("d");
const d1: DistributionSummary = r.distribution_summary("d");
assert.isTrue(writer.is_empty());

d.record(42);
d1.record(42);
assert.isTrue(writer.is_empty());

const d2: DistributionSummary = r.distribution_summary_with_id(r.new_id("d"));
assert.isTrue(writer.is_empty());

d2.record(42);
assert.isTrue(writer.is_empty());

const expected: string[] = [
"WARN: Id(name=d, tags={}) is invalid, because the name is not a string, it is too short (< 2), or it is too long (> 255); metric will not be reported",
"WARN: Id(name=d, tags={}) is invalid, because the name is not a string, it is too short (< 2), or it is too long (> 255); metric will not be reported",
];
assert.deepEqual(expected, messages);
console.log = f;
Expand Down Expand Up @@ -214,14 +235,21 @@ describe("Registry Tests", (): void => {
const r = new Registry(new Config("memory"));
const writer = r.writer() as MemoryWriter;

const g: Gauge = r.gauge("g");
const g1: Gauge = r.gauge("g");
assert.isTrue(writer.is_empty());

g.set(42);
g1.set(42);
assert.isTrue(writer.is_empty());

const g2: Gauge = r.gauge_with_id(r.new_id("g"));
assert.isTrue(writer.is_empty());

g2.set(42);
assert.isTrue(writer.is_empty());

const expected: string[] = [
"WARN: Id(name=g, tags={}) is invalid, because the name is not a string, it is too short (< 2), or it is too long (> 255); metric will not be reported",
"WARN: Id(name=g, tags={}) is invalid, because the name is not a string, it is too short (< 2), or it is too long (> 255); metric will not be reported",
];
assert.deepEqual(expected, messages);
console.log = f;
Expand Down Expand Up @@ -279,14 +307,21 @@ describe("Registry Tests", (): void => {
const r = new Registry(new Config("memory"));
const writer = r.writer() as MemoryWriter;

const g: MaxGauge = r.max_gauge("g");
const g1: MaxGauge = r.max_gauge("g");
assert.isTrue(writer.is_empty());

g.set(42);
g1.set(42);
assert.isTrue(writer.is_empty());

const g2: MaxGauge = r.max_gauge_with_id(r.new_id("g"));
assert.isTrue(writer.is_empty());

g2.set(42);
assert.isTrue(writer.is_empty());

const expected: string[] = [
"WARN: Id(name=g, tags={}) is invalid, because the name is not a string, it is too short (< 2), or it is too long (> 255); metric will not be reported",
"WARN: Id(name=g, tags={}) is invalid, because the name is not a string, it is too short (< 2), or it is too long (> 255); metric will not be reported",
];
assert.deepEqual(expected, messages);
console.log = f;
Expand Down Expand Up @@ -322,14 +357,21 @@ describe("Registry Tests", (): void => {
const r = new Registry(new Config("memory"));
const writer = r.writer() as MemoryWriter;

const c: MonotonicCounter = r.monotonic_counter("c");
const c1: MonotonicCounter = r.monotonic_counter("c");
assert.isTrue(writer.is_empty());

c.set(42);
c1.set(42);
assert.isTrue(writer.is_empty());

const c2: MonotonicCounter = r.monotonic_counter_with_id(r.new_id("c"));
assert.isTrue(writer.is_empty());

c2.set(42);
assert.isTrue(writer.is_empty());

const expected: string[] = [
"WARN: Id(name=c, tags={}) is invalid, because the name is not a string, it is too short (< 2), or it is too long (> 255); metric will not be reported",
"WARN: Id(name=c, tags={}) is invalid, because the name is not a string, it is too short (< 2), or it is too long (> 255); metric will not be reported",
];
assert.deepEqual(expected, messages);
console.log = f;
Expand Down Expand Up @@ -365,14 +407,21 @@ describe("Registry Tests", (): void => {
const r = new Registry(new Config("memory"));
const writer = r.writer() as MemoryWriter;

const c: MonotonicCounterUint = r.monotonic_counter_uint("c");
const c1: MonotonicCounterUint = r.monotonic_counter_uint("c");
assert.isTrue(writer.is_empty());

c.set(BigInt(42));
c1.set(BigInt(42));
assert.isTrue(writer.is_empty());

const c2: MonotonicCounterUint = r.monotonic_counter_uint_with_id(r.new_id("c"));
assert.isTrue(writer.is_empty());

c2.set(BigInt(42));
assert.isTrue(writer.is_empty());

const expected: string[] = [
"WARN: Id(name=c, tags={}) is invalid, because the name is not a string, it is too short (< 2), or it is too long (> 255); metric will not be reported",
"WARN: Id(name=c, tags={}) is invalid, because the name is not a string, it is too short (< 2), or it is too long (> 255); metric will not be reported",
];
assert.deepEqual(expected, messages);
console.log = f;
Expand Down Expand Up @@ -418,14 +467,21 @@ describe("Registry Tests", (): void => {
const r = new Registry(new Config("memory"));
const writer = r.writer() as MemoryWriter;

const d: PercentileDistributionSummary = r.pct_distribution_summary("d");
const d1: PercentileDistributionSummary = r.pct_distribution_summary("d");
assert.isTrue(writer.is_empty());

d.record(42);
d1.record(42);
assert.isTrue(writer.is_empty());

const d2: PercentileDistributionSummary = r.pct_distribution_summary_with_id(r.new_id("d"));
assert.isTrue(writer.is_empty());

d2.record(42);
assert.isTrue(writer.is_empty());

const expected: string[] = [
"WARN: Id(name=d, tags={}) is invalid, because the name is not a string, it is too short (< 2), or it is too long (> 255); metric will not be reported",
"WARN: Id(name=d, tags={}) is invalid, because the name is not a string, it is too short (< 2), or it is too long (> 255); metric will not be reported",
];
assert.deepEqual(expected, messages);
console.log = f;
Expand Down Expand Up @@ -461,14 +517,21 @@ describe("Registry Tests", (): void => {
const r = new Registry(new Config("memory"));
const writer = r.writer() as MemoryWriter;

const t: PercentileTimer = r.pct_timer("t");
const t1: PercentileTimer = r.pct_timer("t");
assert.isTrue(writer.is_empty());

t.record(42);
t1.record(42);
assert.isTrue(writer.is_empty());

const t2: PercentileTimer = r.pct_timer_with_id(r.new_id("t"));
assert.isTrue(writer.is_empty());

t2.record(42);
assert.isTrue(writer.is_empty());

const expected: string[] = [
"WARN: Id(name=t, tags={}) is invalid, because the name is not a string, it is too short (< 2), or it is too long (> 255); metric will not be reported",
"WARN: Id(name=t, tags={}) is invalid, because the name is not a string, it is too short (< 2), or it is too long (> 255); metric will not be reported",
];
assert.deepEqual(expected, messages);
console.log = f;
Expand Down Expand Up @@ -504,14 +567,21 @@ describe("Registry Tests", (): void => {
const r = new Registry(new Config("memory"));
const writer = r.writer() as MemoryWriter;

const t: Timer = r.timer("t");
const t1: Timer = r.timer("t");
assert.isTrue(writer.is_empty());

t.record(42);
t1.record(42);
assert.isTrue(writer.is_empty());

const t2: Timer = r.timer_with_id(r.new_id("t"));
assert.isTrue(writer.is_empty());

t2.record(42);
assert.isTrue(writer.is_empty());

const expected: string[] = [
"WARN: Id(name=t, tags={}) is invalid, because the name is not a string, it is too short (< 2), or it is too long (> 255); metric will not be reported",
"WARN: Id(name=t, tags={}) is invalid, because the name is not a string, it is too short (< 2), or it is too long (> 255); metric will not be reported",
];
assert.deepEqual(expected, messages);
console.log = f;
Expand Down