mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
add logs to probe
This commit is contained in:
@@ -3,6 +3,7 @@ import Headers from './API/Headers';
|
||||
import URL from './API/URL';
|
||||
import HTML from './Html';
|
||||
import HTTPMethod from './API/HTTPMethod';
|
||||
import Dictionary from './Dictionary';
|
||||
|
||||
export interface WebsiteResponse {
|
||||
url: URL;
|
||||
@@ -45,7 +46,7 @@ export default class WebsiteRequest {
|
||||
return {
|
||||
url: url,
|
||||
requestHeaders: options.headers || {},
|
||||
responseHeaders: response.headers,
|
||||
responseHeaders: response.headers as Dictionary<string>,
|
||||
responseStatusCode: response.status,
|
||||
responseBody: new HTML(response.data),
|
||||
isOnline: true,
|
||||
|
||||
@@ -257,7 +257,7 @@ export default class API {
|
||||
const response: HTTPResponse<T> = new HTTPResponse<T>(
|
||||
result.status,
|
||||
result.data,
|
||||
result.headers
|
||||
result.headers as Dictionary<string>
|
||||
);
|
||||
|
||||
return response;
|
||||
@@ -280,8 +280,8 @@ export default class API {
|
||||
if (error.response) {
|
||||
return new HTTPErrorResponse(
|
||||
error.response.status,
|
||||
error.response.data,
|
||||
error.response.headers
|
||||
error.response.data as JSONObject | JSONArray,
|
||||
error.response.headers as Dictionary<string>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,11 +20,15 @@ const init: Function = async (): Promise<void> => {
|
||||
let workers: number = 0;
|
||||
|
||||
while (workers < PROBE_MONITORING_WORKERS) {
|
||||
new FetchListAndProbe().run().catch((err: any) => {
|
||||
logger.error('FetchListAndProbe Failed:');
|
||||
logger.error(err);
|
||||
});
|
||||
logger.info(`Starting worker ${workers}`);
|
||||
workers++;
|
||||
|
||||
new FetchListAndProbe('Worker ' + workers)
|
||||
.run()
|
||||
.catch((err: any) => {
|
||||
logger.error('FetchListAndProbe Failed:');
|
||||
logger.error(err);
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
logger.error('App Init Failed:');
|
||||
|
||||
@@ -14,13 +14,25 @@ import OneUptimeDate from 'Common/Types/Date';
|
||||
import Sleep from 'Common/Types/Sleep';
|
||||
|
||||
export default class FetchListAndProbe {
|
||||
private workerName: string = '';
|
||||
|
||||
public constructor(workerName: string) {
|
||||
this.workerName = workerName;
|
||||
}
|
||||
|
||||
public async run(): Promise<void> {
|
||||
logger.info(`Running worker ${this.workerName}`);
|
||||
|
||||
const runTIme: Date = OneUptimeDate.getCurrentDate();
|
||||
|
||||
// eslint-disable-next-line no-constant-condition
|
||||
while (true) {
|
||||
logger.info(`Probing monitors ${this.workerName}`);
|
||||
|
||||
await this.fetchListAndProbe();
|
||||
|
||||
logger.info(`Probing monitors ${this.workerName} complete`);
|
||||
|
||||
// if rumTime + 5 seconds is in the future, then this fetchLst either errored out or had no monitors in the list. Either way, wait for 5 seconds and proceed.
|
||||
|
||||
const fiveSecondsAdded: Date = OneUptimeDate.addRemoveSeconds(
|
||||
@@ -29,6 +41,9 @@ export default class FetchListAndProbe {
|
||||
);
|
||||
|
||||
if (OneUptimeDate.isInTheFuture(fiveSecondsAdded)) {
|
||||
logger.info(
|
||||
`Worker ${this.workerName} is waiting for 5 seconds`
|
||||
);
|
||||
await Sleep.sleep(5000);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,42 +9,57 @@ import '@types/jest';
|
||||
describe('Ping', () => {
|
||||
jest.setTimeout(10000);
|
||||
test('Ping.ping should return appropriate object if the valid hostname is given', async () => {
|
||||
let result: PingResponse = await Ping.ping(
|
||||
let result: PingResponse | null = await Ping.ping(
|
||||
new Hostname('google.com', 80)
|
||||
);
|
||||
expect(result.responseTimeInMS?.toNumber()).toBeGreaterThan(0);
|
||||
expect(result.responseTimeInMS?.toNumber()).toBeLessThanOrEqual(5000);
|
||||
expect(result.isOnline).toBe(true);
|
||||
|
||||
expect(result).not.toBeNull();
|
||||
expect(result!.responseTimeInMS?.toNumber()).toBeGreaterThan(0);
|
||||
expect(result!.responseTimeInMS?.toNumber()).toBeLessThanOrEqual(5000);
|
||||
expect(result!.isOnline).toBe(true);
|
||||
result = await Ping.ping(new Hostname('www.google.com', 80), {
|
||||
timeout: new PositiveNumber(5000),
|
||||
});
|
||||
expect(result.isOnline).toBe(true);
|
||||
expect(result.responseTimeInMS?.toNumber()).toBeGreaterThan(0);
|
||||
expect(result.responseTimeInMS?.toNumber()).toBeLessThanOrEqual(5000);
|
||||
|
||||
expect(result).not.toBeNull();
|
||||
expect(result!.isOnline).toBe(true);
|
||||
expect(result!.responseTimeInMS?.toNumber()).toBeGreaterThan(0);
|
||||
expect(result!.responseTimeInMS?.toNumber()).toBeLessThanOrEqual(5000);
|
||||
|
||||
result = await Ping.ping(new Hostname('www.google.com', 65000), {
|
||||
timeout: new PositiveNumber(5000),
|
||||
});
|
||||
expect(result.isOnline).toBe(false);
|
||||
expect(result.responseTimeInMS).toBeUndefined();
|
||||
expect(result).not.toBeNull();
|
||||
expect(result!.isOnline).toBe(false);
|
||||
expect(result!.responseTimeInMS).toBeUndefined();
|
||||
|
||||
result = await Ping.ping(new Hostname('www.a.com', 65000), {
|
||||
timeout: new PositiveNumber(5000),
|
||||
});
|
||||
expect(result.isOnline).toBe(false);
|
||||
expect(result.responseTimeInMS).toBeUndefined();
|
||||
expect(result).not.toBeNull();
|
||||
expect(result!.isOnline).toBe(false);
|
||||
expect(result!.isOnline).toBe(false);
|
||||
expect(result!.responseTimeInMS).toBeUndefined();
|
||||
});
|
||||
test('Ping.ping should return appropriate object if the valid IPV4 or IPV6 is given', async () => {
|
||||
let result: PingResponse;
|
||||
let result: PingResponse | null = null;
|
||||
|
||||
result = await Ping.ping(new IPv4('172.217.170.206'), {
|
||||
timeout: new PositiveNumber(5000),
|
||||
}); // One of the google ip
|
||||
expect(result.isOnline).toBe(true);
|
||||
expect(result.responseTimeInMS?.toNumber()).toBeGreaterThan(0);
|
||||
expect(result.responseTimeInMS?.toNumber()).toBeLessThanOrEqual(5000);
|
||||
expect(result).not.toBeNull();
|
||||
expect(result!.isOnline).toBe(true);
|
||||
expect(result!.responseTimeInMS?.toNumber()).toBeGreaterThan(0);
|
||||
expect(result!.responseTimeInMS?.toNumber()).toBeLessThanOrEqual(5000);
|
||||
|
||||
result = await Ping.ping(new IPv4('192.0.2.200')); //
|
||||
expect(result.isOnline).toBe(false);
|
||||
expect(result.responseTimeInMS).toBeUndefined();
|
||||
expect(result).not.toBeNull();
|
||||
expect(result!.isOnline).toBe(false);
|
||||
expect(result!.responseTimeInMS).toBeUndefined();
|
||||
|
||||
result = await Ping.ping(new IPv4('0.42.52.42')); // ip can't start 0
|
||||
expect(result.responseTimeInMS).toBeUndefined();
|
||||
expect(result.isOnline).toBe(false);
|
||||
expect(result).not.toBeNull();
|
||||
expect(result!.responseTimeInMS).toBeUndefined();
|
||||
expect(result!.isOnline).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user