Skip to content

Commit 5596a75

Browse files
authored
add backwards compatibility features for a wrapper library (#99)
1 parent 5e66b0d commit 5596a75

5 files changed

Lines changed: 30 additions & 4 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nflx-spectator",
3-
"version": "3.0.7",
3+
"version": "3.0.8",
44
"license": "Apache-2.0",
55
"homepage": "https://github.com/Netflix/spectator-js",
66
"author": "Netflix Telemetry Engineering <netflix-atlas@googlegroups.com>",

src/meter/counter.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@ export class Counter extends Meter {
1212
super(id, writer, "c");
1313
}
1414

15-
increment(delta: number = 1): Promise<void> {
16-
if (delta > 0) {
17-
const line = `${this._meter_type_symbol}:${this._id.spectatord_id}:${delta}`
15+
add(amount: number = 1): Promise<void> {
16+
return this.increment(amount);
17+
}
18+
19+
increment(amount: number = 1): Promise<void> {
20+
if (amount > 0) {
21+
const line = `${this._meter_type_symbol}:${this._id.spectatord_id}:${amount}`
1822
return this._writer.write(line);
1923
} else {
2024
return new Promise((resolve: (value: void | PromiseLike<void>) => void): void => {

src/registry.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ export class Registry {
3232
this.logger.debug(`Create Registry with extra_common_tags=${tags_toString(this._config.extra_common_tags)}`);
3333
}
3434

35+
config(): Config {
36+
return this._config;
37+
}
38+
3539
writer(): WriterUnion {
3640
return this._writer;
3741
}

test/meter/counter.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@ describe("Counter Tests", (): void => {
66

77
const tid = new Id("counter");
88

9+
it("add delegates to increment", (): void => {
10+
const c = new Counter(tid, new MemoryWriter());
11+
const writer = c.writer() as MemoryWriter;
12+
assert.isTrue(writer.is_empty());
13+
14+
c.add();
15+
assert.equal("c:counter:1", writer.last_line());
16+
17+
c.add(2);
18+
assert.equal("c:counter:2", writer.last_line());
19+
});
20+
921
it("increment", (): void => {
1022
const c = new Counter(tid, new MemoryWriter());
1123
const writer = c.writer() as MemoryWriter;

test/registry.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ describe("Registry Tests", (): void => {
3737
assert.isTrue(r.writer() instanceof UdpWriter);
3838
});
3939

40+
it("get config", (): void => {
41+
const r = new Registry();
42+
assert.equal("udp", r.config().location)
43+
assert.deepEqual({}, r.config().extra_common_tags)
44+
});
45+
4046
it("age_gauge", (): void => {
4147
const r = new Registry(new Config("memory"));
4248
const writer = r.writer() as MemoryWriter;

0 commit comments

Comments
 (0)