-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathextension.ts
34 lines (30 loc) · 1001 Bytes
/
extension.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { URL } from "url";
import { post, logDebug, logError } from "../utils";
import fs from "fs";
export const EXTENSION_URL = "http://127.0.0.1:8124";
const EXTENSION_PATH = "/opt/extensions/datadog-agent";
const LOCAL_FLUSH_PATH = "/lambda/flush";
const LOCAL_FLUSH_TIMEOUT_MS = 100;
export async function isExtensionRunning() {
const extensionExists = await fileExists(EXTENSION_PATH);
if (!extensionExists) {
logDebug(`Extension Layer is not present`);
return false;
}
return true;
}
export async function flushExtension(): Promise<boolean> {
const url = new URL(LOCAL_FLUSH_PATH, EXTENSION_URL);
const result = await post(url, {}, { timeout: LOCAL_FLUSH_TIMEOUT_MS });
if (!result.success) {
logError(`Failed to flush extension. ${result.errorMessage}`);
return false;
}
return true;
}
function fileExists(filename: string): Promise<boolean> {
return fs.promises
.access(filename, fs.constants.F_OK)
.then(() => true)
.catch(() => false);
}