From 7dcdc0902a048e1eb6f8d265898cb323a1a40a67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Antonio=20Fern=C3=A1ndez=20de=20Alba?= Date: Tue, 19 Mar 2024 11:48:04 +0100 Subject: [PATCH] [ci-visibility] Fix v3 evp proxy version (#4159) --- .../exporters/agent-proxy/index.js | 7 +++- .../exporters/agent-proxy/agent-proxy.spec.js | 35 +++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/packages/dd-trace/src/ci-visibility/exporters/agent-proxy/index.js b/packages/dd-trace/src/ci-visibility/exporters/agent-proxy/index.js index 2491f562d2e..bb1367057f4 100644 --- a/packages/dd-trace/src/ci-visibility/exporters/agent-proxy/index.js +++ b/packages/dd-trace/src/ci-visibility/exporters/agent-proxy/index.js @@ -38,10 +38,15 @@ class AgentProxyCiVisibilityExporter extends CiVisibilityExporter { this.getAgentInfo((err, agentInfo) => { this._isInitialized = true - const latestEvpProxyVersion = getLatestEvpProxyVersion(err, agentInfo) + let latestEvpProxyVersion = getLatestEvpProxyVersion(err, agentInfo) const isEvpCompatible = latestEvpProxyVersion >= 2 const isGzipCompatible = latestEvpProxyVersion >= 4 + // v3 does not work well citestcycle, so we downgrade to v2 + if (latestEvpProxyVersion === 3) { + latestEvpProxyVersion = 2 + } + const evpProxyPrefix = `${AGENT_EVP_PROXY_PATH_PREFIX}${latestEvpProxyVersion}` if (isEvpCompatible) { this._isUsingEvpProxy = true diff --git a/packages/dd-trace/test/ci-visibility/exporters/agent-proxy/agent-proxy.spec.js b/packages/dd-trace/test/ci-visibility/exporters/agent-proxy/agent-proxy.spec.js index 189defedf4e..e13da1381a6 100644 --- a/packages/dd-trace/test/ci-visibility/exporters/agent-proxy/agent-proxy.spec.js +++ b/packages/dd-trace/test/ci-visibility/exporters/agent-proxy/agent-proxy.spec.js @@ -285,4 +285,39 @@ describe('AgentProxyCiVisibilityExporter', () => { expect(scope.isDone()).to.be.true }) }) + + describe('evpProxyPrefix', () => { + it('should set evpProxyPrefix to v2 if the newest version is v3', async () => { + const scope = nock('http://localhost:8126') + .get('/info') + .reply(200, JSON.stringify({ + endpoints: ['/evp_proxy/v2', '/evp_proxy/v3'] + })) + + const agentProxyCiVisibilityExporter = new AgentProxyCiVisibilityExporter({ port, tags }) + + expect(agentProxyCiVisibilityExporter).not.to.be.null + + await agentProxyCiVisibilityExporter._canUseCiVisProtocolPromise + + expect(agentProxyCiVisibilityExporter.evpProxyPrefix).to.equal('/evp_proxy/v2') + expect(scope.isDone()).to.be.true + }) + it('should set evpProxyPrefix to v4 if the newest version is v4', async () => { + const scope = nock('http://localhost:8126') + .get('/info') + .reply(200, JSON.stringify({ + endpoints: ['/evp_proxy/v2', '/evp_proxy/v3', '/evp_proxy/v4/'] + })) + + const agentProxyCiVisibilityExporter = new AgentProxyCiVisibilityExporter({ port, tags }) + + expect(agentProxyCiVisibilityExporter).not.to.be.null + + await agentProxyCiVisibilityExporter._canUseCiVisProtocolPromise + + expect(agentProxyCiVisibilityExporter.evpProxyPrefix).to.equal('/evp_proxy/v4') + expect(scope.isDone()).to.be.true + }) + }) })