Skip to content

Conversation

@aahung
Copy link
Contributor

@aahung aahung commented Mar 25, 2021

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

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

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

@aahung aahung force-pushed the identify-cicd-telemetry branch 2 times, most recently from c8eefb4 to c575b58 Compare March 25, 2021 22:14
@aahung aahung requested review from CoshUS, sriram-mv and wchengru March 25, 2021 22:15
@aahung aahung force-pushed the identify-cicd-telemetry branch from c575b58 to 54b37c5 Compare March 25, 2021 22:19
@aahung aahung force-pushed the identify-cicd-telemetry branch from 54b37c5 to 8c85279 Compare March 25, 2021 22:19
@aahung aahung requested a review from hoffa March 25, 2021 22:20
# 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",
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nice catch!

# 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)
Copy link
Contributor

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.

Copy link
Contributor

@hoffa hoffa Mar 25, 2021

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

Copy link
Contributor Author

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"

# 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)
Copy link
Contributor

@hoffa hoffa Mar 25, 2021

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


# 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:
Copy link
Contributor

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.

Copy link
Contributor Author

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__()

@aahung aahung requested review from hoffa and wchengru March 25, 2021 23:54
@aahung aahung merged commit b30072e into aws:develop Mar 26, 2021
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.

4 participants