Skip to content

Commit 94f1b91

Browse files
committed
fix(ya-vigil-reporter): respect the http api (path)
- `reporter/probe_id/node_id/` - `reporter/probe_id/node_id/replica_id/`
1 parent e18929d commit 94f1b91

File tree

6 files changed

+33
-20
lines changed

6 files changed

+33
-20
lines changed

README.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export interface IYaVigilReporter {
7171
/** Cron is running ? */
7272
get isRunning(): boolean;
7373

74-
/** Manual reporting */
74+
/** Report the replica */
7575
report(args?: { /** @default true */ reThrow?: boolean }): Promise<YaVigilReportResult>;
7676

7777
/** Flush the replica */
@@ -89,14 +89,15 @@ export interface YaVigilReporterOptions {
8989
/** `reporter_token` from Vigil `config.cfg` */
9090
token: string;
9191

92-
/** Probe ID containing the parent Node for Replica */
93-
probe_id: string;
94-
95-
/** Node ID containing Replica */
92+
/** The parent node of the reporting replica */
9693
node_id: string;
9794

98-
/** Replica ID */
95+
/** The parent probe of the node */
96+
probe_id: string;
97+
98+
/** The replica unique identifier (eg. the server LAN IP) */
9999
replica_id: string;
100+
100101
/**
101102
* Reporting interval in seconds
102103
*
@@ -122,6 +123,10 @@ export interface YaVigilReporterOptions {
122123
}
123124
```
124125

126+
## Vigil HTTP API Specifications
127+
128+
- [Vigil Reporter HTTP API](https://github.com/valeriansaliou/vigil/blob/master/PROTOCOL.md#vigil-reporter-http-api) protocol specifications.
129+
- [Vigil Manager HTTP API](https://github.com/valeriansaliou/vigil/blob/master/PROTOCOL.md#vigil-manager-http-api) protocol specifications.
125130

126131
# Coverage
127132
[![codecov](https://codecov.io/gh/aegenet/ya-vigil-reporter/branch/main/graph/badge.svg?token=NRN5ODOY91)](https://codecov.io/gh/aegenet/ya-vigil-reporter)

src/i-ya-vigil-reporter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export interface IYaVigilReporter {
1616
/** Cron is running ? */
1717
get isRunning(): boolean;
1818

19-
/** Manual reporting */
19+
/** Report the replica */
2020
report(args?: { /** @default true */ reThrow?: boolean }): Promise<YaVigilReportResult>;
2121

2222
/** Flush the replica */

src/models/ya-vigil-reporter-options.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ export interface YaVigilReporterOptions {
88
/** `reporter_token` from Vigil `config.cfg` */
99
token: string;
1010

11-
/** Probe ID containing the parent Node for Replica */
12-
probe_id: string;
13-
14-
/** Node ID containing Replica */
11+
/** The parent node of the reporting replica */
1512
node_id: string;
1613

17-
/** Replica ID */
14+
/** The parent probe of the node */
15+
probe_id: string;
16+
17+
/** The replica unique identifier (eg. the server LAN IP) */
1818
replica_id: string;
19+
1920
/**
2021
* Reporting interval in seconds
2122
*

src/tests/create-fake-vigil-server.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { delay } from '../utils/ya-workload.spec';
33

44
export function createFakeVigilServer() {
55
const server = fastify({ logger: true });
6-
server.post('/reporter/:probe_id/:node_id', async (request: FastifyRequest, reply: FastifyReply) => {
6+
server.post('/reporter/:probe_id/:node_id/', async (request: FastifyRequest, reply: FastifyReply) => {
77
const { probe_id, node_id } = request.params as any;
88
const { replica, interval, load } = request.body as any;
99

@@ -41,7 +41,7 @@ export function createFakeVigilServer() {
4141
reply.status(400).send((error as Error).message);
4242
}
4343
});
44-
server.delete('/reporter/:probe_id/:node_id/:replica', async (request: FastifyRequest, reply: FastifyReply) => {
44+
server.delete('/reporter/:probe_id/:node_id/:replica/', async (request: FastifyRequest, reply: FastifyReply) => {
4545
const { probe_id, node_id, replica } = request.params as any;
4646

4747
try {

src/ya-vigil-reporter.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ describe('ya-vigil-reporter', () => {
142142
assert.ok(err);
143143
assert.ok(!vigilReporter.isRunning);
144144
},
145+
flush: true,
145146
});
146147
});
147148

src/ya-vigil-reporter.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export class YaVigilReporter implements IYaVigilReporter {
3939
if (!baseURL.endsWith('/')) {
4040
baseURL += '/';
4141
}
42-
baseURL += `reporter/${encodeURIComponent(probe_id)}/${encodeURIComponent(node_id)}`;
42+
baseURL += `reporter/${encodeURIComponent(probe_id)}/${encodeURIComponent(node_id)}/`;
4343
this._baseURL = baseURL;
4444
this._reporterAuthz = `Basic ${Buffer.from(':' + token).toString('base64')}`;
4545
this._reporterHeader = {
@@ -90,12 +90,18 @@ export class YaVigilReporter implements IYaVigilReporter {
9090
/** @inheritdoc */
9191
public async end(args?: { flush?: boolean; done?: (error?: Error) => void }): Promise<void> {
9292
args ||= {};
93+
let doneFunc = args!.done;
9394
await this.stop(args)
94-
.then(() => {
95-
args!.done?.();
96-
})
9795
.catch(error => {
98-
args!.done?.(error);
96+
try {
97+
doneFunc?.(error);
98+
} finally {
99+
// avoid another call if doneFunc throw an error
100+
doneFunc = undefined;
101+
}
102+
})
103+
.then(() => {
104+
doneFunc?.();
99105
});
100106
}
101107

@@ -166,7 +172,7 @@ export class YaVigilReporter implements IYaVigilReporter {
166172
this._options.logger?.info?.('ya-vigil-reporter.flush');
167173

168174
await yaFetchWTimeout(
169-
this._baseURL + '/' + encodeURIComponent(this._options.replica_id),
175+
this._baseURL + encodeURIComponent(this._options.replica_id) + '/',
170176
{
171177
method: 'DELETE',
172178
headers: {

0 commit comments

Comments
 (0)