Skip to content

perf: parallelize network calls and skip redundant operations#409

Merged
chouetz merged 11 commits intomainfrom
nschweitzer/speedup-install-script
Apr 2, 2026
Merged

perf: parallelize network calls and skip redundant operations#409
chouetz merged 11 commits intomainfrom
nschweitzer/speedup-install-script

Conversation

@chouetz
Copy link
Copy Markdown
Member

@chouetz chouetz commented Mar 6, 2026

Summary

Speeds up the install script by parallelizing network operations and skipping redundant work:

  • Parallelize 6 exit telemetry network checkscurl -I --max-time 5 calls were running sequentially (up to 30s total), now run concurrently (~5s max)
  • Parallelize telemetry uploads — logs + trace payloads sent concurrently instead of sequentially
  • Parallelize APT GPG key downloads — 5 keys downloaded with & + wait, imported in a single gpg --import call
  • Parallelize SUSE11 RPM GPG key downloads — download concurrently before sequential rpm --import
  • Skip apt-get update if deps already present — check dpkg -s first, skip entire update+install loop if curl/gnupg already installed
  • Remove redundant HEAD request in _install_installer_scriptcurl -f already fails on HTTP errors, no need for a separate availability check before downloading

Motivation

https://datadoghq.atlassian.net/browse/ACIX-1390

The new-e2e-fleet-config CI job runs this install script ~10 times per platform (install + uninstall per test). These savings compound to 2.5-6.5 minutes per platform depending on network conditions. For production customers, install time is reduced by ~15-40s per run.

Test plan

🤖 Generated with Claude Code

chouetz added 3 commits March 6, 2026 23:00
- Parallelize 6 network health-check curls in exit telemetry (was
  sequential with 5s timeout each, up to 30s total → now ~5s max)
- Send logs and trace telemetry payloads in parallel (was sequential
  with 10s timeout + 5 retries each → now runs concurrently)
- Download APT GPG keys in parallel and import in a single gpg call
  (was 5 sequential download+import cycles)
- Download SUSE11 RPM GPG keys in parallel before importing
- Skip apt-get update + dependency install when curl/gnupg are already
  present (common on most systems, saves a full apt-get update cycle)
- Remove redundant HEAD request in _install_installer_script before
  the actual download (curl -f already fails on HTTP errors)

These changes reduce install script execution time by ~15-40s per run,
with the biggest gains from parallelizing exit telemetry network checks.
@chouetz chouetz marked this pull request as ready for review March 18, 2026 17:29
@chouetz chouetz requested review from a team as code owners March 18, 2026 17:29
@chouetz chouetz requested review from gpalmz and removed request for a team March 18, 2026 17:29
@gpalmz
Copy link
Copy Markdown
Contributor

gpalmz commented Mar 18, 2026

Approved pending @codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f8c446864a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@gpalmz
Copy link
Copy Markdown
Contributor

gpalmz commented Mar 23, 2026

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9c2ca15f29

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chouetz
Copy link
Copy Markdown
Member Author

chouetz commented Mar 24, 2026

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7db9a26fd2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chouetz
Copy link
Copy Markdown
Member Author

chouetz commented Mar 25, 2026

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ed87cc1ccd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chouetz
Copy link
Copy Markdown
Member Author

chouetz commented Mar 25, 2026

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: eb86683fb6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chouetz
Copy link
Copy Markdown
Member Author

chouetz commented Mar 26, 2026

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8b8168d963

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

# Check if all dependencies are already installed to skip apt-get update + install
all_deps_installed=true
for dep in "${APT_DEPS[@]}"; do
if ! dpkg -s "$dep" >/dev/null 2>&1; then
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Check APT deps by install state before skipping install

The new all_deps_installed fast path uses dpkg -s as a boolean installed check, but dpkg -s also returns success for packages in non-installed states like deinstall ok config-files. In that state curl/gnupg binaries may be absent, yet this branch skips the dependency install loop and later fails when the script invokes curl/gpg for key setup. This introduces install failures on hosts with residual package metadata; the skip condition should verify the package status is actually installed (or validate command availability) before bypassing apt-get install.

Useful? React with 👍 / 👎.

@chouetz
Copy link
Copy Markdown
Member Author

chouetz commented Mar 26, 2026

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9add5c9b5f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

exit 1
fi
# Import all keys in a single gpg call
$sudo_cmd cat "${APT_GPG_KEYS[@]/#//tmp/}" | $sudo_cmd gpg --import --batch --no-default-keyring --keyring "$apt_usr_share_keyring"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Fail when any APT key import is invalid

Importing all downloaded key files in one gpg --import call can silently accept partial failures: if one key file is malformed (for example, curl -sSL saved an HTTP error page) but another file is valid, gpg can still exit successfully, so the script continues without all expected signing keys. Before this change each file was imported separately, so a bad key aborted immediately. This regression can surface later as package signature failures (especially for version-pinned installs that need non-current keys) while the installer reports key setup as successful.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

@chouetz chouetz Mar 31, 2026

Choose a reason for hiding this comment

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

Investigation: batched gpg --import behavior with mixed valid/invalid keys

The concern: combining all downloaded key files into a single cat ... | gpg --import call could silently accept partial failures if one key file is malformed.

Local test (gpg 2.x on macOS):
Created a valid GPG key (good.gpg) and a garbage file (bad.gpg containing "not a real key"), then tested three scenarios:

  $ cat bad.gpg good.gpg | gpg --import --batch
  gpg: no valid OpenPGP data found.
  Exit code: 2

  $ cat good.gpg bad.gpg | gpg --import --batch
  gpg: [don't know]: invalid packet (ctb=6e)
  gpg: read_block: read error: Invalid packet
  gpg: import from '[stdin]' failed: Invalid keyring
  Exit code: 2

  $ cat bad.gpg | gpg --import --batch
  gpg: no valid OpenPGP data found.
  Exit code: 2

In all three cases, gpg returned exit code 2 and imported zero keys — it did not silently import the valid key while skipping the bad one.

What the man page says:

RETURN VALUE: The program returns 0 if there are no severe errors, 1 if at least a signature was bad, and other error codes for fatal errors.

The man page doesn't specifically document per-stream --import behavior with mixed data, but classifies non-zero/non-one codes as
"fatal errors."

GnuPG maintainer (Werner Koch) on gnupg.org (T769): states that gpg "imports the parts of the key which are clean and ignores the garbled stuff" — suggesting that in some cases with partially malformed OpenPGP data (e.g., a valid key with a corrupted subpacket), gpg may import what it can. However, when a file is entirely non-OpenPGP data (which is the failure mode here — curl saving an HTTP error page), gpg treats this as a fatal error and rejects the entire stream.

Conclusion: The realistic failure scenario (curl saves an HTML error page instead of a key) causes gpg to hard-fail with exit 2, which is already caught by set -e. The batched import is not a regression for this case. The per-key loop on main would have failed on the bad key too — the only behavioral difference is that the loop would have already imported the preceding good keys before failing, while the batched version imports none. Both paths abort the script.

@chouetz chouetz merged commit 00d4108 into main Apr 2, 2026
89 of 237 checks passed
@chouetz chouetz deleted the nschweitzer/speedup-install-script branch April 2, 2026 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants