Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FA] Add python packages info #34320

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

Conversation

coignetp
Copy link
Contributor

@coignetp coignetp commented Feb 21, 2025

What does this PR do?

Add python packages information in the metadata payload.

Motivation

The goal is for the backend to know in which state the agent is running. This will help understanding which custom packages are installed by the customers, as well as providing better support for extras & marketplace installation.
This is a pre-requisite if we want to re-install marketplace integrations through the agent upgrade workflow in fleet-automation.

Example:

{
    ...
   "python": {
        "python_packages": {
                 "cryptography": " https://agent-int-packages.datadoghq.com/built/cryptography/cryptography-43.0.1-20250218143943-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl#sha256=a7d7383a7eb5f2f60cb32046dba2b6997d923a57e7e8f518cb19897b88c0966d",
                "datadog-activemq": "5.0.0",
                "datadog-activemq-xml": "5.1.0"
        },
       "python_version": "3.12.8"
    }
    ...
}

Describe how you validated your changes

Possible Drawbacks / Trade-offs

Additional Notes

@coignetp coignetp added changelog/no-changelog qa/done QA done before merge and regressions are covered by tests labels Feb 21, 2025
@agent-platform-auto-pr
Copy link
Contributor

agent-platform-auto-pr bot commented Feb 21, 2025

Test changes on VM

Use this command from test-infra-definitions to manually test this PR changes on a VM:

inv aws.create-vm --pipeline-id=56848984 --os-family=ubuntu

Note: This applies to commit 6a8b0a0

@agent-platform-auto-pr
Copy link
Contributor

agent-platform-auto-pr bot commented Feb 21, 2025

Uncompressed package size comparison

Comparison with ancestor cd2d6fa0f3ceba769b14162034fa44ae69c196c0

Diff per package
package diff status size ancestor threshold
datadog-agent-x86_64-rpm 0.05MB ⚠️ 879.07MB 879.02MB 0.50MB
datadog-agent-x86_64-suse 0.05MB ⚠️ 879.07MB 879.02MB 0.50MB
datadog-agent-aarch64-rpm 0.04MB ⚠️ 868.35MB 868.32MB 0.50MB
datadog-agent-amd64-deb 0.02MB ⚠️ 869.28MB 869.25MB 0.50MB
datadog-agent-arm64-deb 0.01MB ⚠️ 858.58MB 858.57MB 0.50MB
datadog-heroku-agent-amd64-deb 0.00MB 446.32MB 446.32MB 0.50MB
datadog-iot-agent-amd64-deb 0.00MB 62.03MB 62.02MB 0.50MB
datadog-iot-agent-x86_64-rpm 0.00MB 62.10MB 62.09MB 0.50MB
datadog-iot-agent-x86_64-suse 0.00MB 62.10MB 62.09MB 0.50MB
datadog-iot-agent-arm64-deb 0.00MB 59.27MB 59.26MB 0.50MB
datadog-iot-agent-aarch64-rpm 0.00MB 59.34MB 59.33MB 0.50MB
datadog-dogstatsd-amd64-deb 0.00MB 41.40MB 41.40MB 0.50MB
datadog-dogstatsd-x86_64-rpm 0.00MB 41.48MB 41.48MB 0.50MB
datadog-dogstatsd-x86_64-suse 0.00MB 41.48MB 41.48MB 0.50MB
datadog-dogstatsd-arm64-deb 0.00MB 39.66MB 39.66MB 0.50MB

Decision

⚠️ Warning

@agent-platform-auto-pr
Copy link
Contributor

agent-platform-auto-pr bot commented Feb 21, 2025

Static quality checks ✅

Please find below the results from static quality gates

Successful checks

Info

Result Quality gate On disk size On disk size limit On wire size On wire size limit
static_quality_gate_agent_deb_amd64 840.38MiB 847.49MiB 203.07MiB 212.33MiB
static_quality_gate_agent_deb_arm64 830.15MiB 836.66MiB 183.97MiB 192.5MiB
static_quality_gate_agent_rpm_amd64 840.37MiB 847.82MiB 206.04MiB 215.76MiB
static_quality_gate_agent_rpm_arm64 830.14MiB 836.66MiB 185.4MiB 194.24MiB
static_quality_gate_agent_suse_amd64 840.37MiB 847.82MiB 206.04MiB 215.76MiB
static_quality_gate_agent_suse_arm64 830.14MiB 836.66MiB 185.4MiB 194.24MiB
static_quality_gate_dogstatsd_deb_amd64 39.56MiB 49.7MiB 10.55MiB 20.6MiB
static_quality_gate_dogstatsd_deb_arm64 37.9MiB 48.1MiB 9.13MiB 19.1MiB
static_quality_gate_dogstatsd_rpm_amd64 39.56MiB 49.7MiB 10.56MiB 20.6MiB
static_quality_gate_dogstatsd_suse_amd64 39.56MiB 49.7MiB 10.56MiB 20.6MiB
static_quality_gate_iot_agent_deb_amd64 59.22MiB 69.0MiB 14.89MiB 24.8MiB
static_quality_gate_iot_agent_deb_arm64 56.59MiB 66.4MiB 12.84MiB 22.8MiB
static_quality_gate_iot_agent_rpm_amd64 59.22MiB 69.0MiB 14.9MiB 24.8MiB
static_quality_gate_iot_agent_rpm_arm64 56.59MiB 66.4MiB 12.85MiB 22.8MiB
static_quality_gate_iot_agent_suse_amd64 59.22MiB 69.0MiB 14.9MiB 24.8MiB
static_quality_gate_docker_agent_amd64 925.15MiB 931.7MiB 309.16MiB 318.67MiB
static_quality_gate_docker_agent_arm64 938.21MiB 944.08MiB 294.15MiB 303.0MiB
static_quality_gate_docker_agent_jmx_amd64 1.1GiB 1.1GiB 384.28MiB 393.75MiB
static_quality_gate_docker_agent_jmx_arm64 1.1GiB 1.1GiB 365.24MiB 373.71MiB
static_quality_gate_docker_dogstatsd_amd64 47.7MiB 57.88MiB 18.26MiB 28.29MiB
static_quality_gate_docker_dogstatsd_arm64 46.08MiB 56.27MiB 17.02MiB 27.06MiB
static_quality_gate_docker_cluster_agent_amd64 264.95MiB 274.78MiB 106.36MiB 116.28MiB
static_quality_gate_docker_cluster_agent_arm64 280.92MiB 290.82MiB 101.18MiB 111.12MiB

Copy link

cit-pr-commenter bot commented Feb 21, 2025

Regression Detector

Regression Detector Results

Metrics dashboard
Target profiles
Run ID: 647c9030-e063-4037-98ea-94ca3f7f493a

Baseline: cd2d6fa
Comparison: 6a8b0a0
Diff

Optimization Goals: ✅ No significant changes detected

Fine details of change detection per experiment

perf experiment goal Δ mean % Δ mean % CI trials links
file_to_blackhole_1000ms_latency_linear_load egress throughput +0.18 [-0.29, +0.65] 1 Logs
file_to_blackhole_0ms_latency egress throughput +0.02 [-0.84, +0.88] 1 Logs
file_to_blackhole_300ms_latency egress throughput +0.02 [-0.61, +0.65] 1 Logs
uds_dogstatsd_to_api ingress throughput +0.02 [-0.25, +0.29] 1 Logs
file_to_blackhole_0ms_latency_http2 egress throughput +0.01 [-0.78, +0.80] 1 Logs
file_to_blackhole_100ms_latency egress throughput +0.01 [-0.63, +0.64] 1 Logs
tcp_dd_logs_filter_exclude ingress throughput -0.00 [-0.03, +0.02] 1 Logs
file_to_blackhole_0ms_latency_http1 egress throughput -0.01 [-0.78, +0.75] 1 Logs
file_to_blackhole_500ms_latency egress throughput -0.09 [-0.87, +0.70] 1 Logs
uds_dogstatsd_to_api_cpu % cpu utilization -0.14 [-1.04, +0.76] 1 Logs
tcp_syslog_to_blackhole ingress throughput -0.20 [-0.26, -0.13] 1 Logs
file_tree memory utilization -0.24 [-0.31, -0.18] 1 Logs
file_to_blackhole_1000ms_latency egress throughput -0.33 [-1.10, +0.44] 1 Logs
quality_gate_idle_all_features memory utilization -0.33 [-0.38, -0.28] 1 Logs bounds checks dashboard
quality_gate_idle memory utilization -0.54 [-0.58, -0.50] 1 Logs bounds checks dashboard
quality_gate_logs % cpu utilization -1.61 [-4.49, +1.27] 1 Logs

Bounds Checks: ✅ Passed

perf experiment bounds_check_name replicates_passed links
file_to_blackhole_0ms_latency lost_bytes 10/10
file_to_blackhole_0ms_latency memory_usage 10/10
file_to_blackhole_0ms_latency_http1 lost_bytes 10/10
file_to_blackhole_0ms_latency_http1 memory_usage 10/10
file_to_blackhole_0ms_latency_http2 lost_bytes 10/10
file_to_blackhole_0ms_latency_http2 memory_usage 10/10
file_to_blackhole_1000ms_latency memory_usage 10/10
file_to_blackhole_1000ms_latency_linear_load memory_usage 10/10
file_to_blackhole_100ms_latency lost_bytes 10/10
file_to_blackhole_100ms_latency memory_usage 10/10
file_to_blackhole_300ms_latency lost_bytes 10/10
file_to_blackhole_300ms_latency memory_usage 10/10
file_to_blackhole_500ms_latency lost_bytes 10/10
file_to_blackhole_500ms_latency memory_usage 10/10
quality_gate_idle intake_connections 10/10 bounds checks dashboard
quality_gate_idle memory_usage 10/10 bounds checks dashboard
quality_gate_idle_all_features intake_connections 10/10 bounds checks dashboard
quality_gate_idle_all_features memory_usage 10/10 bounds checks dashboard
quality_gate_logs intake_connections 10/10
quality_gate_logs lost_bytes 10/10
quality_gate_logs memory_usage 10/10

Explanation

Confidence level: 90.00%
Effect size tolerance: |Δ mean %| ≥ 5.00%

Performance changes are noted in the perf column of each table:

  • ✅ = significantly better comparison variant performance
  • ❌ = significantly worse comparison variant performance
  • ➖ = no significant change in performance

A regression test is an A/B test of target performance in a repeatable rig, where "performance" is measured as "comparison variant minus baseline variant" for an optimization goal (e.g., ingress throughput). Due to intrinsic variability in measuring that goal, we can only estimate its mean value for each experiment; we report uncertainty in that value as a 90.00% confidence interval denoted "Δ mean % CI".

For each experiment, we decide whether a change in performance is a "regression" -- a change worth investigating further -- if all of the following criteria are true:

  1. Its estimated |Δ mean %| ≥ 5.00%, indicating the change is big enough to merit a closer look.

  2. Its 90.00% confidence interval "Δ mean % CI" does not contain zero, indicating that if our statistical model is accurate, there is at least a 90.00% chance there is a difference in performance between baseline and comparison variants.

  3. Its configuration does not mark it "erratic".

CI Pass/Fail Decision

Passed. All Quality Gates passed.

  • quality_gate_idle_all_features, bounds check memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_idle_all_features, bounds check intake_connections: 10/10 replicas passed. Gate passed.
  • quality_gate_idle, bounds check intake_connections: 10/10 replicas passed. Gate passed.
  • quality_gate_idle, bounds check memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_logs, bounds check lost_bytes: 10/10 replicas passed. Gate passed.
  • quality_gate_logs, bounds check intake_connections: 10/10 replicas passed. Gate passed.
  • quality_gate_logs, bounds check memory_usage: 10/10 replicas passed. Gate passed.

@coignetp coignetp marked this pull request as ready for review February 25, 2025 11:01
@coignetp coignetp requested review from a team as code owners February 25, 2025 11:01
@coignetp coignetp requested a review from hush-hush February 25, 2025 11:01
Comment on lines 65 to 67
- `python` - **object**:
- `python_version` - **string**: The version of the embedded python.
- `python_packages` - **dict of string to string**: All the python packages installed in the embedded python with their versions.
Copy link
Member

Choose a reason for hiding this comment

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

How do you plan to store this in REDAPL ? We can't have a row per python packages since we want a single row per Agent. Are we storing a JSON blob and using SQL JSON operator ?

If not, maybe a dedicated table would be more valuable, WDYT ?

I guess the question is: how do you plan to query this ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That would most likely be a dedicated REDAPL table yes, used by fleet services to know what is installed/what is expected to be installed

Comment on lines 297 to 302
args := []string{
"-m",
"pip",
"freeze",
}
pipCmd := exec.Command(pythonBinPath, args...)
Copy link
Member

@hush-hush hush-hush Feb 25, 2025

Choose a reason for hiding this comment

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

The result of pip freeze can be massive. We have limitation regarding payload size imposed by the intake. We're also need to be mindful of the size in REDAPL. We currently have ~320 result from pip freeze, 320 rows for each Agent out there is way to much I think.

Could we filter the result to only include python package not ship by default with the Agent ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Related to #34320 (comment)
This helps us having a reliable source of what's currently running within the agent, without merging multiple sources and try to correct error of what kind go wrong (what happens for marketplace integration? If a user upgraded a datadog dep manually?)

// Get the python packages version
// New packages can be installed, but they're not taken into account until the agent is restarted,
// so it's safe to cache the versions here.
cache.Cache.Set(pythonPackagesCacheKey, getPythonPackagesVersion(pythonBinPath), cache.NoExpiration)
Copy link
Member

Choose a reason for hiding this comment

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

What if someone start the agent, install a new package and upgrade the Agent ? Unless I'm missing something we would miss the newly installed package, right ?

Is that an issue ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If they upgrade the agent there will be a "restart", so we should re-run this part

@github-actions github-actions bot added long review PR is complex, plan time to review it and removed medium review PR review might take time labels Feb 25, 2025
// Get the python packages version
// New packages can be installed, but they're not taken into account until the agent is restarted,
// so it's safe to cache the versions here.
cache.Cache.Set(pythonPackagesCacheKey, getPythonPackagesVersion(pythonBinPath), cache.NoExpiration)
Copy link
Contributor

Choose a reason for hiding this comment

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

As this can take nontrivial amount of time, and doesn't depend on the actual state of the embedded Python interpreter, I think this probably shouldn't be done during init. And with #32611 this won't even happen at startup any more, so you may be missing data in a hard to predict way.

Given that this doesn't depend on the embedded interpreter at all, I would suggest moving this code to pkg/util instead and driving the collection directly from the inventories code, rather than plugging it here and depending on the cache.

// Or `package @ url`
// Or `-e package`
pkgVersion := strings.SplitN(string(line), "==", 2)
pkgURL := strings.SplitN(string(line), "@", 2)
Copy link
Contributor

Choose a reason for hiding this comment

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

Each string(line) creates a new copy, which is unnecessary.

Since the package and url format includes spaces, would it make sense to use that as a separator? Otherwise we probably should remove whitespace from the fields when we use them.

Suggested change
pkgURL := strings.SplitN(string(line), "@", 2)
pkgURL := strings.SplitN(line, " @ ", 2)

// This is a local package, we don't care about the version
packageVersions[strings.TrimPrefix(string(line), "-e ")] = "local"
} else {
log.Infof("Unable to parse python package version, it won't appear in the metadata payload: %s", line)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this something that the customer can fix? If not, it should probably be debug level.

Suggested change
log.Infof("Unable to parse python package version, it won't appear in the metadata payload: %s", line)
log.Infof("Unable to parse python package version, it won't appear in the metadata payload: %q", line)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog/no-changelog long review PR is complex, plan time to review it qa/done QA done before merge and regressions are covered by tests team/agent-configuration team/agent-metric-pipelines
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants