Skip to content

feat(metrics): collect the DOCKER_HOST environment variable path #8007

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 9 commits into
base: develop
Choose a base branch
from

Conversation

pendo324
Copy link

@pendo324 pendo324 commented May 2, 2025

Which issue(s) does this change fix?

Why is this change necessary?

It allows SAM CLI to have a proxy measurement on which tools users are using as its backend. This allows the SAM CLI team to prioritize testing and features from various tools which users may be using to provide their DOCKER_HOST.

How does it address the issue?

This change collects the last part of URIs/paths, in hope that these last parts shed light on which tool the user is using with SAM CLI. For example, if a user is using a local version of docker, this new metric would collect docker.sock. This is only checking the last part of paths in an effort to not needlessly collect what may be private URLs to remote docker hosts which user's might be using.

What side effects does this change have?

None?

Mandatory Checklist

PRs will only be reviewed after checklist is complete

  • [N/A] Add input/output type hints to new functions/methods
  • [N/A] Write design document if needed (Do I need to write a design document?)
  • [N/A] Write/update unit tests
  • [N/A] Write/update integration tests
  • [N.A] Write/update functional tests if needed
  • make pr passes
  • [N/A] make update-reproducible-reqs if dependencies were changed
  • [N/A] Write documentation

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@pendo324 pendo324 requested a review from a team as a code owner May 2, 2025 23:45
@github-actions github-actions bot added pr/external stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. labels May 2, 2025
@valerena
Copy link
Contributor

valerena commented May 3, 2025

Thanks for the contribution! There are a few errors on make pr (and in other tests), if you can take a look.

At least in make pr

samcli/lib/telemetry/metric.py:495: error: Missing positional argument "path" in call to "exists"  [call-arg]
samcli/lib/telemetry/metric.py:497: error: Returning Any from function declared to return "str"  [no-any-return]
samcli/lib/telemetry/metric.py:500: error: Returning Any from function declared to return "str"  [no-any-return]

The first one is because of if os.path.exists(): (I imagine there's a variable missing there, probably parsed.path)

The other ones might be just errors on typing with os.path.basepath 🤔. You might be able to just do str(..) to fix those.

Copy link
Contributor

@valerena valerena left a comment

Choose a reason for hiding this comment

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

There are some more tests failing on test_installed_metrics.py

I added another comment to confirm the logic.

You can run pytest -vv tests/integration/telemetry to check those. They don't run with the standard make pr because they're integration tests, but they should run quickly (as opposed to other integration tests which could take hours)

"""

parsed = urlparse(self._gc.docker_host)
if not parsed.scheme == "":
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you mean the opposite here? I imagine that if the schema is empty, then I can check if it's a file that exists, but here you're doing that if it's not empty. If it happens that it's not empty, then we could be calling os.path.exists("unix:///var/run/docker.sock") which returns False.

Copy link
Author

Choose a reason for hiding this comment

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

You're correct, but honestly I think this logic was a little too overcomplicated anyway. I've simplified and removed the conditional in the latest revision.

The integ tests are also passing on my local machine, just waiting for GitHub CI to trigger

pendo324 added 7 commits June 5, 2025 12:27
Signed-off-by: Justin Alvarez <alvajus@amazon.com>
Signed-off-by: Justin Alvarez <alvajus@amazon.com>
Signed-off-by: Justin Alvarez <alvajus@amazon.com>
Signed-off-by: Justin Alvarez <alvajus@amazon.com>
Signed-off-by: Justin Alvarez <alvajus@amazon.com>
Signed-off-by: Justin Alvarez <alvajus@amazon.com>
Signed-off-by: Justin Alvarez <alvajus@amazon.com>
@pendo324 pendo324 force-pushed the collect-docker-host-metrics branch from 3052dc8 to ad611c8 Compare June 5, 2025 17:39
pendo324 added 2 commits June 5, 2025 13:55
Signed-off-by: Justin Alvarez <alvajus@amazon.com>
Signed-off-by: Justin Alvarez <alvajus@amazon.com>
@pendo324
Copy link
Author

pendo324 commented Jun 5, 2025

@valerena, is the failing Windows smoke test related to this change? If so, I'm not sure how and could use some guidance on how to fix it

@pendo324 pendo324 requested a review from valerena June 5, 2025 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr/external stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants