Skip to content

Commit

Permalink
feat: Remove extension hello check as it's redundant (#516)
Browse files Browse the repository at this point in the history
* feat: Remove extension hello check as it's redundant

* feat: lint

---------

Co-authored-by: jordan gonzález <30836115+duncanista@users.noreply.github.com>
  • Loading branch information
astuyve and duncanista authored Mar 18, 2024
1 parent 9c44eab commit 904d2e9
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 22 deletions.
11 changes: 0 additions & 11 deletions src/metrics/extension.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
10 changes: 1 addition & 9 deletions src/metrics/extension.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -14,13 +13,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;
}

Expand Down
2 changes: 0 additions & 2 deletions src/metrics/listener.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
Expand Down Expand Up @@ -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"]);
});
Expand Down

0 comments on commit 904d2e9

Please sign in to comment.