Skip to content

Add workflow events#4096

Merged
hawflau merged 6 commits intoaws:customer-journeyfrom
Leo10Gama:workflow-events
Aug 8, 2022
Merged

Add workflow events#4096
hawflau merged 6 commits intoaws:customer-journeyfrom
Leo10Gama:workflow-events

Conversation

@Leo10Gama
Copy link
Contributor

Which issue(s) does this change fix?

N/A

Why is this change necessary?

Events previously exist to capture the runtime of functions as they are built. However, up until now, we do not have a way to capture the information of workflow configs.

How does it address the issue?

With a new WorkflowUsed Event, we will be able to capture and analyze data on which workflows customers are using most. This can reveal information such as the most common languages of workflows, most common dependency managers, and how many different workflow configs are used per build.

What side effects does this change have?

A new file, workflows.py, has been created to prevent a cyclic import, and allow for dynamic computing of Event values. Thus, for any new workflow to be added, it would need to be created there, and then be imported by workflow_config.py.

Mandatory Checklist

PRs will only be reviewed after checklist is complete

  • Add input/output type hints to new functions/methods
  • Write design document if needed (Do I need to write a design document?)
  • Write/update unit tests
  • Write/update integration tests
  • Write/update functional tests if needed
  • 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.

@github-actions github-actions bot added area/build sam build command pr/external stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. labels Aug 3, 2022
@Leo10Gama Leo10Gama changed the title Workflow events Add workflow events Aug 3, 2022
@Leo10Gama Leo10Gama marked this pull request as ready for review August 4, 2022 01:55
Copy link
Contributor

@mildaniel mildaniel left a comment

Choose a reason for hiding this comment

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

Looks good overall,left some minor comments. Can we also add some tests here to validate this functionality?

@Leo10Gama
Copy link
Contributor Author

Can we also add some tests here to validate this functionality?

I'm not sure whether tests would be necessary for a change like this. I intentionally designed the EventTracker to be lightweight, such that Events could be tracked quickly with only a line or two of code, and able to be removed just as quickly. My line of logic is, if in the future we didn't need this information and wanted to remove the tracker, we'd also have to dig through tests and remove the relevant ones to allow make pr to pass. I think it should be enough that the trackers are verified locally through a dummy project or two to ensure their logic is correct, though I could implement tests to verify this if we really wanted to be sure.

@mildaniel
Copy link
Contributor

I would generally disagree that the ability to make lightweight changes quickly is a reason against testing. If someone accidentally removes this logic in the future, they might think it's okay because all of the tests still pass. Not everyone has and will have the same context. For that reason, I think having tests as a guardrail against regression is already more valuable than the couple extra minutes someone will need to spend to remove a few tests later on.

@hawflau hawflau merged commit 1b02888 into aws:customer-journey Aug 8, 2022
@Leo10Gama Leo10Gama deleted the workflow-events branch August 10, 2022 18:30
hawflau added a commit that referenced this pull request Aug 23, 2022
* Add project metadata tracking with telemetry (#3929)

* Implement project metadata metrics

* Implement metric metadata integration tests

* Tweak methods so tests don't fail on Linux machines

* Repair failing integration test

* Implement proper exception handling for subprocesses

* Format according to standard

* Refactor function names and encryption logic

* Remove unnecessary file

* Add type hints to new functions

* Fix retrieval process for directory name (#3962)

* Implement event data structure and relevant unit tests (#3955)

* Implement event data structure and relevant unit tests

* Implement requested changes

* Remove unused (useless) file

* Remove unnecessary ABC class

* Implement tracker methods (#3970)

* Implement tracker methods

* Improve readability of Event's __repr__ method

* Add method to convert Event to dictionary for JSON-compatibility

* Send Event metrics via Telemetry (#3979)

* Send Event metrics via Telemetry

* Add unit tests for event telemetry

* Simplify event telemetry unit tests

* Clean up unit tests

* Add BuildRuntime event and trackers (#3994)

* Add BuildRuntime Events

* Remove unnecessary file

* Prevent tracked Event 'spillage' from previous tests

* Fix builder logic

* Redefine BuildRuntime to focus on function runtimes

* Remove unnecessary file (again)

* Add UsedFeature event and trackers (#4003)

* Add UsedFeature command and trackers

* Remove LocalTest events
Events regarding sam local will be implemented at a later time.

* Prevent methods from failing if track_event fails

* Reformat code to match current standard

* Use correct string formatting

* Use proper LOG message

* Add thread lock to EventTracker (#4019)

* Add thread lock to EventTracker

* Place lock in appropriate methods

* Refactor Event data structure (#4027)

* Add new attributes to Event datastructure

* Fix non-JSON-serializable field in Event

* Fix repr to ensure SQL casting will work

* Add comment for timestamp method clarity

* Update tests to verify EventTracker thread lock is working (#4035)

* Add send_events method to EventTracker (#4039)

* Add framework for Event-sending method

* Perform some general refactors and cleanup

* Implement EventTracker Telemetry unit tests

* Cleanup tests and unused imports

* Update Metric name for consistency

* Repair failing unit test

* (Hopefully) repair broken integration test

* *Actually* repair broken integration test
I had the >= logic backwards lol

* Fix integration test
For sure this time

* Really fix the integration test
Windows development is not fun

* Properly fix integration test

* Reformat files

* Implement requested changes

* Add Lock logic to send_events method

* Implement requested changes

* Repair failing tests

* Upgrade encryption algorithm from SHA-1 to SHA-256 (#4061)

* Upgrade encryption algorithm from SHA1 to SHA256

* Make return value of hash JSON-serializable

* Add long event tracker (#4067)

* Send events via thread when at capacity (#4072)

* Switch send_events to thread when at capacity

* Repair failing unit test

* Add `sam sync` Events (#4076)

* Add sam sync Events

* Refactor methods for tracking sync events

* Improve SyncFlow tracking

* Add additional SyncFlow value

* Add workflow events (#4096)

* Add workflow_config events

* Refactor workflow Events

* Add tests for verifying workflow events

* Remove redundant (UsedFeature, ESBuild) event

* Repair failing unit test

* Rename workflow event to prevent ambiguity

* Fix send_events logic (#4104)

* Make minor tweaks before launch (#4111)

* Apply minor changes (some major)

* Add session_id for multithreaded send_events

* Adjust tests for new multithreading

* Fix failing integration test

* *Actually* fix failing integration test

* Properly fix integration test

* This time for sure

* Really really repair that test

* OK this one SHOULD work I swear

* This time for sure

* FIX INTEGRATION TEST

* IT'S A LIST

* Remove unused imports

* Add debug log for EventTracker session ID

* Place debug log in better position

Co-authored-by: Wing Fung Lau <4760060+hawflau@users.noreply.github.com>
torresxb1 pushed a commit to torresxb1/aws-sam-cli that referenced this pull request Sep 2, 2022
* Add project metadata tracking with telemetry (aws#3929)

* Implement project metadata metrics

* Implement metric metadata integration tests

* Tweak methods so tests don't fail on Linux machines

* Repair failing integration test

* Implement proper exception handling for subprocesses

* Format according to standard

* Refactor function names and encryption logic

* Remove unnecessary file

* Add type hints to new functions

* Fix retrieval process for directory name (aws#3962)

* Implement event data structure and relevant unit tests (aws#3955)

* Implement event data structure and relevant unit tests

* Implement requested changes

* Remove unused (useless) file

* Remove unnecessary ABC class

* Implement tracker methods (aws#3970)

* Implement tracker methods

* Improve readability of Event's __repr__ method

* Add method to convert Event to dictionary for JSON-compatibility

* Send Event metrics via Telemetry (aws#3979)

* Send Event metrics via Telemetry

* Add unit tests for event telemetry

* Simplify event telemetry unit tests

* Clean up unit tests

* Add BuildRuntime event and trackers (aws#3994)

* Add BuildRuntime Events

* Remove unnecessary file

* Prevent tracked Event 'spillage' from previous tests

* Fix builder logic

* Redefine BuildRuntime to focus on function runtimes

* Remove unnecessary file (again)

* Add UsedFeature event and trackers (aws#4003)

* Add UsedFeature command and trackers

* Remove LocalTest events
Events regarding sam local will be implemented at a later time.

* Prevent methods from failing if track_event fails

* Reformat code to match current standard

* Use correct string formatting

* Use proper LOG message

* Add thread lock to EventTracker (aws#4019)

* Add thread lock to EventTracker

* Place lock in appropriate methods

* Refactor Event data structure (aws#4027)

* Add new attributes to Event datastructure

* Fix non-JSON-serializable field in Event

* Fix repr to ensure SQL casting will work

* Add comment for timestamp method clarity

* Update tests to verify EventTracker thread lock is working (aws#4035)

* Add send_events method to EventTracker (aws#4039)

* Add framework for Event-sending method

* Perform some general refactors and cleanup

* Implement EventTracker Telemetry unit tests

* Cleanup tests and unused imports

* Update Metric name for consistency

* Repair failing unit test

* (Hopefully) repair broken integration test

* *Actually* repair broken integration test
I had the >= logic backwards lol

* Fix integration test
For sure this time

* Really fix the integration test
Windows development is not fun

* Properly fix integration test

* Reformat files

* Implement requested changes

* Add Lock logic to send_events method

* Implement requested changes

* Repair failing tests

* Upgrade encryption algorithm from SHA-1 to SHA-256 (aws#4061)

* Upgrade encryption algorithm from SHA1 to SHA256

* Make return value of hash JSON-serializable

* Add long event tracker (aws#4067)

* Send events via thread when at capacity (aws#4072)

* Switch send_events to thread when at capacity

* Repair failing unit test

* Add `sam sync` Events (aws#4076)

* Add sam sync Events

* Refactor methods for tracking sync events

* Improve SyncFlow tracking

* Add additional SyncFlow value

* Add workflow events (aws#4096)

* Add workflow_config events

* Refactor workflow Events

* Add tests for verifying workflow events

* Remove redundant (UsedFeature, ESBuild) event

* Repair failing unit test

* Rename workflow event to prevent ambiguity

* Fix send_events logic (aws#4104)

* Make minor tweaks before launch (aws#4111)

* Apply minor changes (some major)

* Add session_id for multithreaded send_events

* Adjust tests for new multithreading

* Fix failing integration test

* *Actually* fix failing integration test

* Properly fix integration test

* This time for sure

* Really really repair that test

* OK this one SHOULD work I swear

* This time for sure

* FIX INTEGRATION TEST

* IT'S A LIST

* Remove unused imports

* Add debug log for EventTracker session ID

* Place debug log in better position

Co-authored-by: Wing Fung Lau <4760060+hawflau@users.noreply.github.com>
hawflau added a commit that referenced this pull request May 17, 2023
* Add project metadata tracking with telemetry (#3929)

* Implement project metadata metrics

* Implement metric metadata integration tests

* Tweak methods so tests don't fail on Linux machines

* Repair failing integration test

* Implement proper exception handling for subprocesses

* Format according to standard

* Refactor function names and encryption logic

* Remove unnecessary file

* Add type hints to new functions

* Fix retrieval process for directory name (#3962)

* Implement event data structure and relevant unit tests (#3955)

* Implement event data structure and relevant unit tests

* Implement requested changes

* Remove unused (useless) file

* Remove unnecessary ABC class

* Implement tracker methods (#3970)

* Implement tracker methods

* Improve readability of Event's __repr__ method

* Add method to convert Event to dictionary for JSON-compatibility

* Send Event metrics via Telemetry (#3979)

* Send Event metrics via Telemetry

* Add unit tests for event telemetry

* Simplify event telemetry unit tests

* Clean up unit tests

* Add BuildRuntime event and trackers (#3994)

* Add BuildRuntime Events

* Remove unnecessary file

* Prevent tracked Event 'spillage' from previous tests

* Fix builder logic

* Redefine BuildRuntime to focus on function runtimes

* Remove unnecessary file (again)

* Add UsedFeature event and trackers (#4003)

* Add UsedFeature command and trackers

* Remove LocalTest events
Events regarding sam local will be implemented at a later time.

* Prevent methods from failing if track_event fails

* Reformat code to match current standard

* Use correct string formatting

* Use proper LOG message

* Add thread lock to EventTracker (#4019)

* Add thread lock to EventTracker

* Place lock in appropriate methods

* Refactor Event data structure (#4027)

* Add new attributes to Event datastructure

* Fix non-JSON-serializable field in Event

* Fix repr to ensure SQL casting will work

* Add comment for timestamp method clarity

* Update tests to verify EventTracker thread lock is working (#4035)

* Add send_events method to EventTracker (#4039)

* Add framework for Event-sending method

* Perform some general refactors and cleanup

* Implement EventTracker Telemetry unit tests

* Cleanup tests and unused imports

* Update Metric name for consistency

* Repair failing unit test

* (Hopefully) repair broken integration test

* *Actually* repair broken integration test
I had the >= logic backwards lol

* Fix integration test
For sure this time

* Really fix the integration test
Windows development is not fun

* Properly fix integration test

* Reformat files

* Implement requested changes

* Add Lock logic to send_events method

* Implement requested changes

* Repair failing tests

* Upgrade encryption algorithm from SHA-1 to SHA-256 (#4061)

* Upgrade encryption algorithm from SHA1 to SHA256

* Make return value of hash JSON-serializable

* Add long event tracker (#4067)

* Send events via thread when at capacity (#4072)

* Switch send_events to thread when at capacity

* Repair failing unit test

* Add `sam sync` Events (#4076)

* Add sam sync Events

* Refactor methods for tracking sync events

* Improve SyncFlow tracking

* Add additional SyncFlow value

* Add workflow events (#4096)

* Add workflow_config events

* Refactor workflow Events

* Add tests for verifying workflow events

* Remove redundant (UsedFeature, ESBuild) event

* Repair failing unit test

* Rename workflow event to prevent ambiguity

* Fix send_events logic (#4104)

* Make minor tweaks before launch (#4111)

* Apply minor changes (some major)

* Add session_id for multithreaded send_events

* Adjust tests for new multithreading

* Fix failing integration test

* *Actually* fix failing integration test

* Properly fix integration test

* This time for sure

* Really really repair that test

* OK this one SHOULD work I swear

* This time for sure

* FIX INTEGRATION TEST

* IT'S A LIST

* Remove unused imports

* Add debug log for EventTracker session ID

* Place debug log in better position

* Fix thread ID bug in EventTracker

* Reformat files to standard

* Clean up unnecessary files

* Add thread ID tracking to infra sync executor

* Add missing thread ID to tracked event

---------

Co-authored-by: Wing Fung Lau <4760060+hawflau@users.noreply.github.com>
Co-authored-by: Leonardo Gama <leogama@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/build sam build command 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.

3 participants