From c5efdb593ac254ff239345f643c4a5daeb980249 Mon Sep 17 00:00:00 2001 From: AJ Stuyvenberg Date: Mon, 18 Mar 2024 10:26:59 -0400 Subject: [PATCH 1/2] feat: Remove extension hello check as it's redundant --- src/metrics/extension.spec.ts | 11 ----------- src/metrics/extension.ts | 7 ------- src/metrics/listener.spec.ts | 2 -- 3 files changed, 20 deletions(-) diff --git a/src/metrics/extension.spec.ts b/src/metrics/extension.spec.ts index ebb72e07..25286f66 100644 --- a/src/metrics/extension.spec.ts +++ b/src/metrics/extension.spec.ts @@ -11,20 +11,9 @@ describe("isAgentRunning", () => { mock({ "/opt/extensions/datadog-agent": Buffer.from([0]), }); - const scope = nock(AGENT_URL).get("/lambda/hello").reply(200); const ran = await isAgentRunning(); - expect(scope.isDone()).toBeTruthy(); expect(ran).toBeTruthy(); }); - it("returns false when agent doesn't respond", async () => { - mock({ - "/opt/extensions/datadog-agent": Buffer.from([0]), - }); - const scope = nock(AGENT_URL).get("/lambda/hello").replyWithError("Unreachable"); - const ran = await isAgentRunning(); - expect(scope.isDone()).toBeTruthy(); - expect(ran).toBeFalsy(); - }); it("returns false when agent doesn't exist", async () => { mock({}); const scope = nock(AGENT_URL).get("/lambda/hello").replyWithError("Unreachable"); diff --git a/src/metrics/extension.ts b/src/metrics/extension.ts index 52ec252d..138d9666 100644 --- a/src/metrics/extension.ts +++ b/src/metrics/extension.ts @@ -14,13 +14,6 @@ export async function isAgentRunning() { logDebug(`Agent isn't present in sandbox`); return false; } - - const url = new URL(HELLO_PATH, AGENT_URL); - const result = await get(url, { timeout: AGENT_TIMEOUT_MS }); - if (!result.success) { - logDebug(`Could not connect to agent. ${result.errorMessage}`); - return false; - } return true; } diff --git a/src/metrics/listener.spec.ts b/src/metrics/listener.spec.ts index 24a57f84..eaf31575 100644 --- a/src/metrics/listener.spec.ts +++ b/src/metrics/listener.spec.ts @@ -105,7 +105,6 @@ describe("MetricsListener", () => { expect(spy).toHaveBeenCalledWith(`{"e":1487076708,"m":"my-metric","t":["tag:a","tag:b"],"v":10}\n`); }); it("always sends metrics to statsD when extension is enabled, ignoring logForwarding=true", async () => { - const helloScope = nock(AGENT_URL).get("/lambda/hello").reply(200); const flushScope = nock(AGENT_URL).post("/lambda/flush", JSON.stringify({})).reply(200); mock({ "/opt/extensions/datadog-agent": Buffer.from([0]), @@ -135,7 +134,6 @@ describe("MetricsListener", () => { await listener.onStartInvocation({}); listener.sendDistributionMetric("my-metric", 10, false, "tag:a", "tag:b"); await listener.onCompleteInvocation(); - expect(helloScope.isDone()).toBeTruthy(); expect(flushScope.isDone()).toBeTruthy(); expect(distributionMock).toHaveBeenCalledWith("my-metric", 10, undefined, ["tag:a", "tag:b"]); }); From 3febed33f35396610c1812776a9c33ddc3510d80 Mon Sep 17 00:00:00 2001 From: AJ Stuyvenberg Date: Mon, 18 Mar 2024 10:28:19 -0400 Subject: [PATCH 2/2] feat: lint --- src/metrics/extension.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/metrics/extension.ts b/src/metrics/extension.ts index 138d9666..67bcf0d0 100644 --- a/src/metrics/extension.ts +++ b/src/metrics/extension.ts @@ -1,9 +1,8 @@ import { URL } from "url"; -import { get, post, logDebug, logError } from "../utils"; +import { post, logDebug, logError } from "../utils"; import fs from "fs"; export const AGENT_URL = "http://127.0.0.1:8124"; -const HELLO_PATH = "/lambda/hello"; const FLUSH_PATH = "/lambda/flush"; const EXTENSION_PATH = "/opt/extensions/datadog-agent"; const AGENT_TIMEOUT_MS = 100;