Skip to content

Send webhooks via the Agent EVP Proxy when supported#316

Merged
albertvaka merged 15 commits into
masterfrom
albertvaka/webhooks-via-agent
Nov 28, 2022
Merged

Send webhooks via the Agent EVP Proxy when supported#316
albertvaka merged 15 commits into
masterfrom
albertvaka/webhooks-via-agent

Conversation

@albertvaka

@albertvaka albertvaka commented Oct 31, 2022

Copy link
Copy Markdown
Collaborator

What does this PR do?

  • Checks whether the Agent supports the EVP Proxy endpoint.
  • If it does, it generates webhooks instead of traces and sends them using the EVP Proxy.
  • If it doesn't, continues to generate traces and send them via APM.

I also added tests for the whole webhooks logic, which didn't have any. They are mostly copies of the tests for the traces logic.

Description of the Change

  • Adds a fetchAgentSupportedEndpoints() method to DatadogAgentClient that queries the /info Agent API.
  • Makes the postWebhook() method part of the abstract DatadogClient so that DatadogWebhookBuildLogic and DatadogWebhookPipelineLogic can call it on either a DatadogAgentClient or a DatadogHttpClient instance.
  • Implements postWebhook() in DatadogAgentClient. It sends webhook-type payloads using the Agent EVP Proxy.
  • The public methods in DatadogTraceBuildLogic and DatadogWebhookBuildLogic are now @Overrides of abstract methods of their parent DatadogBaseBuildLogic so DatadogAgentClient can use either implementation (depending on the output of fetchAgentSupportedEndpoints). Same for Datadog*PipelineLogic.

Verification Process

  • Test against an Agent that supports EVP Proxy and one that doesn't

Open Questions

  • If Jenkins starts before the Agent, then the EVP Proxy support will be disabled because we won't be able to query the /info API when initializing the DatadogAgentClient. Is this okay?
    • I've added 3 retries at startup time to wait for the Agent.
    • I've made checking the /info endpoint lazy. See my comment below.

@albertvaka
albertvaka force-pushed the albertvaka/webhooks-via-agent branch from 916b09e to cc56d74 Compare November 2, 2022 23:10
@albertvaka
albertvaka marked this pull request as ready for review November 2, 2022 23:10
@albertvaka
albertvaka force-pushed the albertvaka/webhooks-via-agent branch 2 times, most recently from ded1755 to 3f00968 Compare November 3, 2022 11:52
Comment thread src/main/java/org/datadog/jenkins/plugins/datadog/clients/DatadogAgentClient.java Outdated
Comment thread src/main/java/org/datadog/jenkins/plugins/datadog/clients/DatadogAgentClient.java Outdated
Comment thread src/main/java/org/datadog/jenkins/plugins/datadog/clients/DatadogAgentClient.java Outdated
Comment thread src/main/java/org/datadog/jenkins/plugins/datadog/clients/DatadogHttpClient.java Outdated
@albertvaka
albertvaka force-pushed the albertvaka/webhooks-via-agent branch from 9836328 to 77679f6 Compare November 8, 2022 16:38
Comment thread src/main/java/org/datadog/jenkins/plugins/datadog/clients/DatadogAgentClient.java Outdated
@albertvaka

albertvaka commented Nov 15, 2022

Copy link
Copy Markdown
Collaborator Author

I've changed the detection of the EVP Proxy support to be lazy, so it is checked when it's first needed and the result is cached for 1 hour.

This way we don't block at boot time and in the worst case scenario we add a 10 second delay (the timeout of the /info request) once every hour. Most times, the Agent will respond in a few milliseconds or not respond at all (ie: if it's not there or doesn't support the /info API) which will not block.

This also lets us support Agent upgrades without having to restart Jenkins.

@albertvaka
albertvaka force-pushed the albertvaka/webhooks-via-agent branch 8 times, most recently from b53f7d8 to 2386e37 Compare November 17, 2022 10:41
@albertvaka
albertvaka force-pushed the albertvaka/webhooks-via-agent branch from 2386e37 to 576f959 Compare November 18, 2022 12:54
@albertvaka
albertvaka force-pushed the albertvaka/webhooks-via-agent branch from 19fa753 to a0d6d5f Compare November 18, 2022 16:11
@albertvaka
albertvaka force-pushed the albertvaka/webhooks-via-agent branch from a0d6d5f to 612116c Compare November 18, 2022 16:13
@albertvaka
albertvaka force-pushed the albertvaka/webhooks-via-agent branch from 8f8b206 to c265e86 Compare November 24, 2022 00:10

protected boolean checkEvpProxySupportAndUpdateLogic() {
if (evpProxySupported) {
return true; // Once we have seen an Agent that supports EVP Proxy, we never check again.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we have the case of customers downgrading the DD Agent?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to not support that case so we don't have to always query /info.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess dropping a log message or pointing this case on docs would be great.

Comment on lines +498 to +499
traceBuildLogic = new DatadogWebhookBuildLogic(this);
tracePipelineLogic = new DatadogWebhookPipelineLogic(this);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we have race conditions here? Like, the logic started using the version with APM, and then, the logic changes, and it changes to WebHooks? Do we need to protect this case?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If some spans get sent as traces and others as webhooks, nothing bad happens. I just checked it and the backend even displays them as the same pipeline because of the same trace id!

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

drodriguezhdez
drodriguezhdez previously approved these changes Nov 28, 2022

@drodriguezhdez drodriguezhdez left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM


protected boolean checkEvpProxySupportAndUpdateLogic() {
if (evpProxySupported) {
return true; // Once we have seen an Agent that supports EVP Proxy, we never check again.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess dropping a log message or pointing this case on docs would be great.

Comment on lines +498 to +499
traceBuildLogic = new DatadogWebhookBuildLogic(this);
tracePipelineLogic = new DatadogWebhookPipelineLogic(this);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

@albertvaka
albertvaka merged commit a7f3b94 into master Nov 28, 2022
@albertvaka
albertvaka deleted the albertvaka/webhooks-via-agent branch November 28, 2022 16:11
@albertvaka albertvaka added the changelog/Added Added features results into a minor version bump label Dec 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/Added Added features results into a minor version bump

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants