-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: Add CICD platform to metrics #2766
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
Conversation
c8eefb4 to
c575b58
Compare
c575b58 to
54b37c5
Compare
54b37c5 to
8c85279
Compare
samcli/lib/telemetry/cicd.py
Outdated
| # https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-env-vars.html | ||
| CICDPlatform.AWSCodeBuild: "CODEBUILD_BUILD_ID", | ||
| # https://www.jetbrains.com/help/teamcity/predefined-build-parameters.html | ||
| CICDPlatform.TeamCity: "CODEBUILD_BUILD_ID", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this also be CODEBUILD_BUILD_ID?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice catch!
samcli/lib/telemetry/cicd.py
Outdated
| # without re-calculating because CICD platform won't change once sam-cli starts. | ||
| try: | ||
| _cicd_platform: Optional[CICDPlatform] = next( | ||
| cicd_platform for cicd_platform in CICDPlatform if _is_cicd_platform(cicd_platform, os.environ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any order consideration in it? For example, if one env var appears in two platform. It will be fall in the first platform.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And related to this, dict order isn't guaranteed on Python 3.6, so we shouldn't depend on it.
Changed in version 3.7: Dictionary order is guaranteed to be insertion order. This behavior was an implementation detail of CPython from 3.6.
Edit: never mind it's iterating over the enum
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, the environment variables are very platform-specific if you look at them. Except for the last one CI, which is placed at the bottom as a "catch-all"
samcli/lib/telemetry/cicd.py
Outdated
| # without re-calculating because CICD platform won't change once sam-cli starts. | ||
| try: | ||
| _cicd_platform: Optional[CICDPlatform] = next( | ||
| cicd_platform for cicd_platform in CICDPlatform if _is_cicd_platform(cicd_platform, os.environ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And related to this, dict order isn't guaranteed on Python 3.6, so we shouldn't depend on it.
Changed in version 3.7: Dictionary order is guaranteed to be insertion order. This behavior was an implementation detail of CPython from 3.6.
Edit: never mind it's iterating over the enum
samcli/lib/telemetry/cicd.py
Outdated
|
|
||
| # detect CI/CD platform. Here we only calculate this value once so platform() can return this value | ||
| # without re-calculating because CICD platform won't change once sam-cli starts. | ||
| try: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure whether we should have code at the module scope, as this means the code is executed immediately when imported (not the usual expectation). Doesn't seem to be a problem here but could become a footgun later on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea, I moved them to Metric's __init__()
Which issue(s) does this change fix?
Why is this change necessary?
How does it address the issue?
What side effects does this change have?
Checklist
make prpassesmake update-reproducible-reqsif dependencies were changedBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.