Skip to content

PMM-11826 Refactor vmagent configuration handling. #4049

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

Open
wants to merge 5 commits into
base: v3
Choose a base branch
from

Conversation

BupycHuk
Copy link
Member

@BupycHuk BupycHuk commented May 27, 2025

PMM-11826

Link to the Feature Build: SUBMODULES-3939

This PR is made by AI under my control.

If this PR adds or removes or alters one or more API endpoints, please review and add or update the relevant API documents as well:

  • API Docs updated

If this PR is related to some other PRs in this or other repositories, please provide links to those PRs:

  • Links to related pull requests (optional).

Moved VM configuration flags from command-line arguments to environment variables to enhance flexibility and system override. Added support for extracting credentials from external Victoria Metrics URLs. Updated test coverage for various credentials and environment scenarios.
@BupycHuk BupycHuk requested a review from a team as a code owner May 27, 2025 08:11
@BupycHuk BupycHuk requested review from idoqo, JiriCtvrtka and Copilot and removed request for a team May 27, 2025 08:11
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors vmagent configuration handling by moving most flags into environment variables, introducing URL credential extraction, and updating tests to match the new env-based setup.

  • Switch most vmagent settings from Args to Env with an -envflag prefix and handle system‐provided VMAGENT_ variables.
  • Add extractCredentialsFromURL to parse basic auth from external VM URLs and wire it into vmAgentConfig.
  • Update unit tests (vmagent_test.go and supervisor_test.go) to validate the new Env outputs and credential behavior.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
managed/services/agents/vmagent.go Refactored vmAgentConfig to use envflag, extract URL credentials, and build Env vars
managed/services/agents/vmagent_test.go Updated tests to assert on actual.Env instead of actual.Args and cover new credential cases
agent/agents/supervisor/supervisor_test.go Added a supervisor integration test for VM Agent reflecting updated Args/Env
Comments suppressed due to low confidence (1)

managed/services/agents/vmagent_test.go:187

  • The external VM tests exercise URL and credential extraction but don't verify that other defaults (e.g. VMAGENT_remoteWrite_tlsInsecureSkipVerify, VMAGENT_promscrape_maxScrapeSize, VMAGENT_remoteWrite_maxDiskUsagePerURL, VMAGENT_loggerLevel) are present. Consider adding assertions to cover these default environment variables.
assert.Contains(t, actual.Env, "VMAGENT_remoteWrite_url="+expectedURL)

Copy link

codecov bot commented May 27, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 43.69%. Comparing base (037643e) to head (8c4615e).
Report is 3 commits behind head on v3.

Additional details and impacted files
@@            Coverage Diff             @@
##               v3    #4049      +/-   ##
==========================================
+ Coverage   43.63%   43.69%   +0.05%     
==========================================
  Files         369      369              
  Lines       45225    45263      +38     
==========================================
+ Hits        19735    19778      +43     
+ Misses      23785    23778       -7     
- Partials     1705     1707       +2     
Flag Coverage Δ
agent 52.79% <ø> (+0.06%) ⬆️
managed 45.02% <100.00%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@@ -31,48 +32,103 @@ var (
maxScrapeSizeDefault = "64MiB"
)

// extractCredentialsFromURL extracts username and password from a URL string.
Copy link
Contributor

Choose a reason for hiding this comment

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

Are comments for not exposed func needed? I mena do we want to keep them? Since func naming is good and clear. Same applies for rest.

Copy link
Member Author

Choose a reason for hiding this comment

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

it depends, but in this case AI just followed our codebase where we write comments for private functions. It's not necessary, hovewer doesn't harm.

@BupycHuk BupycHuk requested a review from JiriCtvrtka May 27, 2025 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants