Skip to content

[Process Agent] Add Version Command - #11230

Merged
just-chillin merged 9 commits into
mainfrom
corrina.sivak/version-cmd
Mar 11, 2022
Merged

just-chillin merged 9 commits into
mainfrom
corrina.sivak/version-cmd

Conversation

@just-chillin

@just-chillin just-chillin commented Mar 9, 2022 •

Copy link
Copy Markdown
Contributor

What does this PR do?

This PR migrates the process agent to the core agent's version package, and creates a brand new version command for the process agent. It also displays a deprecation message when the user uses the old --version flag.

Motivation

The goal of this PR is to make the process agent's cli more similar to the core agent's cli.

Additional Notes

Possible Drawbacks / Trade-offs

Describe how to test/QA your changes

  • Make sure that the status and info commands still show version information as expected.
  • Ensure that the version command works as expected after installing the agent.

Reviewer's Checklist

  • If known, an appropriate milestone has been selected; otherwise the Triage milestone is set.
  • Use the major_change label if your change either has a major impact on the code base, is impacting multiple teams or is changing important well-established internals of the Agent. This label will be use during QA to make sure each team pay extra attention to the changed behavior. For any customer facing change use a releasenote.
  • A release note has been added or the changelog/no-changelog label has been applied.
  • Changed code has automated tests for its functionality.
  • Adequate QA/testing plan information is provided if the qa/skip-qa label is not applied.
  • At least one team/.. label has been applied, indicating the team(s) that should QA this change.
  • If applicable, docs team has been notified or an issue has been opened on the documentation repo.
  • If applicable, the need-change/operator and need-change/helm labels have been applied.
  • If applicable, the config template has been updated.

@just-chillin
just-chillin requested a review from a team March 9, 2022 23:08
@just-chillin just-chillin added this to the 7.36.0 milestone Mar 9, 2022
@just-chillin just-chillin added the [deprecated] team/processes DEPRECATED: please use team/container-experiences label Mar 9, 2022
@just-chillin
just-chillin requested a review from a team as a code owner March 9, 2022 23:33
@just-chillin
just-chillin force-pushed the corrina.sivak/version-cmd branch from d783511 to dca150b Compare March 10, 2022 03:15

@jtappa jtappa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍🏻 from docs team

@robertjli robertjli left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just a few nits and questions (mostly for my own benefit) 🙂

Comment thread cmd/process-agent/app/version.go Resolved
Comment thread cmd/process-agent/app/version.go Resolved
Comment thread cmd/process-agent/info.go Resolved
Comment thread tasks/process_agent.py
build_include=None,
build_exclude=None,
flavor=AgentFlavor.base.name,
go_version=None,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just for my own understanding, why is this being removed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's a bit redundant, since we can always just call runtime.Version() from the standard library and get the exact same data.

Comment thread cmd/process-agent/info.go Resolved
Comment thread cmd/process-agent/info_test.go Resolved

@xornivore xornivore left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍

Comment thread cmd/process-agent/main_common.go Resolved
RunE: func(cmd *cobra.Command, args []string) error {
return WriteVersion(os.Stdout)
},
SilenceUsage: true,

@mbotarro mbotarro Mar 11, 2022 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there a specific reason to use SilenceUsage here? Don't we want to show errors if they come up?

@just-chillin just-chillin Mar 11, 2022 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

SilenceUsage doesn't suppress errors, it just makes sure that the help text isn't displayed in addition to any errors that might occur, which adds a bunch of noise. However, upon testing I realize that it inherits this value from the parent command, so including it is a no-op.

extraHeaders.Set(headers.TimestampHeader, strconv.Itoa(int(start.Unix())))
extraHeaders.Set(headers.HostHeader, l.cfg.HostName)
extraHeaders.Set(headers.ProcessVersionHeader, Version)
extraHeaders.Set(headers.ProcessVersionHeader, agentVersion.GetNumber())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since we're changing all payloads header here, are we sure that agent.GetNumber() returns the same value as Version?

@just-chillin just-chillin Mar 11, 2022 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

They should be the same format. Both github.com/DataDog/datadog-agent/cmd/process-agent.Version and github.com/DataDog/datadog-agent/pkg/version.AgentVersion are sourced from the same get_version function in the python build script.

def get_version(
ctx, include_git=False, url_safe=False, git_sha_length=7, prefix=None, major_version='7', include_pipeline_id=False
):
# we only need the git info for the non omnibus builds, omnibus includes all this information by default
version = ""
version, pre, commits_since_version, git_sha, pipeline_id = query_version(
ctx, git_sha_length, prefix, major_version_hint=major_version
)
is_nightly = is_allowed_repo_nightly_branch(os.getenv("BUCKET_BRANCH"))
if pre:
version = f"{version}-{pre}"
if not commits_since_version and is_nightly and include_git:
if url_safe:
version = f"{version}.git.{0}.{git_sha}"
else:
version = f"{version}+git.{0}.{git_sha}"
if commits_since_version and include_git:
if url_safe:
version = f"{version}.git.{commits_since_version}.{git_sha}"
else:
version = f"{version}+git.{commits_since_version}.{git_sha}"
if is_nightly and include_git and include_pipeline_id and pipeline_id is not None:
version = f"{version}.pipeline.{pipeline_id}"
# version could be unicode as it comes from `query_version`
return str(version)

The only difference is that in non-release builds it will include the git hash since the last build, although that isn't included in GetNumber.

func (v *Version) GetNumber() string {
return fmt.Sprintf("%d.%d.%d", v.Major, v.Minor, v.Patch)
}

Comment thread cmd/process-agent/app/version.go Resolved
@just-chillin
just-chillin merged commit ead90f5 into main Mar 11, 2022
@just-chillin
just-chillin deleted the corrina.sivak/version-cmd branch March 11, 2022 21:51
gh-worker-dd-mergequeue-cf854d Bot pushed a commit that referenced this pull request Nov 9, 2026
…` builds (#59871)

### What does this PR do?
Drop the `ld_vars` blocks of `security-agent.build` and `cws-instrumentation.build`, which pass `-X` ldflags for `main.Version`, `main.GoVersion`, `main.GitBranch`, `main.GitCommit` and `main.BuildDate`, along with `get_go_version`, their last caller.

### Motivation
Neither `cmd/security-agent` nor `cmd/cws-instrumentation` has ever declared those variables, so **the linker drops the flags**, while the tasks still run `git` and `go version` for them at every build.

The block originates from the process agent, whose `main` package declared those variables at the time:
- #5440 copied it into the security agent's scaffold,
- #11230 removed it from the process agent, along with those variables, in favor of `pkg/version`, which both binaries already report,
- #18620 copied the security agent's block into `tasks/cws_instrumentation.py`, leaving these 2 copies as the last ones.

### Describe how you validated your changes
Built `security-agent` and `cws-instrumentation` with and without the change, and checked that:
- each kept its size and build settings,
- `security-agent` (the only one not stripped) kept its symbols (none of which is one of those variables) as well as its `version` output.

Co-authored-by: regis.desgroppes <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[deprecated] team/processes DEPRECATED: please use team/container-experiences

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants