Fix hostname not being set for worker nodes in freestyle jobs#328
Merged
Conversation
If a job has no child stages (eg: in a freestyle job), updatedBuildData will never actually be updated, so even if we are in a worker node everything we read from it will be the main node's info. When this happens, try to read the hostname from the DD_CI_HOSTNAME env var directly.
| buildSpan.putMeta(CITags._DD_HOSTNAME, HOSTNAME_NONE); | ||
| String envHostnameOrNone = HOSTNAME_NONE; | ||
| try { | ||
| Map<String, String> env = run.getEnvironment(new LogTaskListener(logger, Level.INFO)); |
Collaborator
There was a problem hiding this comment.
This is trick to have the env from the worker? I didn't have this LogTaskListener class in my radar.
Collaborator
Author
There was a problem hiding this comment.
You can also do getEnv() which does this under the hood but it is now deprecated in favor of this. The listener thing is only used to log if there's an error.
drodriguezhdez
approved these changes
Feb 10, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Try to read hostname from the environment if not in
updatedBuildData.If a job has no child stages (eg: in a freestyle job),
updatedBuildDatainDatadogWebhookBuildLogicwill never actually be updated becauseDatadogWebhookPipelineLogicdidn't run. Because of this even if the job runs in a worker node everything we read fromupdatedBuildDatawill be the main node's info.When this happens, this PR adds a workaround to read the hostname from the
DD_CI_HOSTNAMEenv var directly fromDatadogWebhookBuildLogic.Alternate Designs
Ideally we should have a single way to get the workers info that works both for pipelines and for single jobs. But the logic is too convoluted and I'm not confident enough to do a bigger change.
Verification Process
Run a freestyle job on a worker with the
DD_CI_HOSTNAMEvariable set, check that the host is set properly in the payloads.Review checklist (to be filled by reviewers)
changelog/label attached. If applicable it should have thebackward-incompatiblelabel attached.do-not-merge/label attached.kind/andseverity/labels attached at least.