Skip to content
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

chore(repo): Expand CW Metric logging to all tests #3912

Merged
merged 12 commits into from
Oct 10, 2023

Conversation

fjnoyp
Copy link
Contributor

@fjnoyp fjnoyp commented Oct 7, 2023

Issue #, if available:

Description of changes:

Add logic to send Cloudwatch metrics from all Github Action workflows.

Update aft to generate workflows that track metrics.
Update base github workflows to track metrics.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@fjnoyp fjnoyp requested a review from a team as a code owner October 7, 2023 12:34
@fjnoyp fjnoyp self-assigned this Oct 7, 2023
@fjnoyp
Copy link
Contributor Author

fjnoyp commented Oct 7, 2023

Please note that all dart unit tests on beta have been failing since an unknown time due to a compile issue with Object on a smithy http_operation. This will need to be fixed separately.

Failing scheduled dart test (same for all category dart tests):

https://github.com/aws-amplify/amplify-flutter/actions/runs/6439416299/job/17487065066

@fjnoyp fjnoyp changed the title Feat/mine/finalized dart action v4 chore(repo): Expand CW Metric logging to all tests Oct 7, 2023
kyle added 8 commits October 9, 2023 09:18
1. Take working-directory instead of package-name to find category
2. Matrix is not required in cases when matrix does not exist
3. Remove category input, will be calculated using working-directory input instead.
4. Refactory Github API response parse logic to use generated class files
Generated workflows now need additional permissions and inherit secrets to enable their sub workflow calls to be authorized to log metrics.
@fjnoyp fjnoyp force-pushed the feat/mine/finalizedDartActionV4 branch from 451aa57 to 3c01a85 Compare October 9, 2023 16:19
@@ -8,12 +8,11 @@ inputs:
github-token:
required: true
description: Github token for requesting failing steps.
package-name:
description: The name of the package being tested
working-directory:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Switch parameter sent because package-name does not give sufficient information on category information for smithy and other minor categories.

@@ -22,9 +21,6 @@ inputs:
test-type:
description: canary, integration, unit testType.
required: true
category:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is now computed based on working-directory

package-name: ${{ inputs.package-name }}
matrix: ${{ toJson(matrix) }}
working-directory: ${{ inputs.working-directory }}
matrix: ${{ toJson(matrix) != 'null' && toJson(matrix) || '' }}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to handle null matrix cases

# These permissions are needed to interact with GitHub's OIDC Token endpoint.
permissions:
id-token: write
contents: read
Copy link
Contributor Author

Choose a reason for hiding this comment

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

All workflows need these permissions now in order to send the Cloudwatch Metric

@@ -12,8 +12,7 @@ on:
type: string

jobs:
test:
name: Test
test-dart-ddc:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

NOTE: in order to properly distinguish jobs within a given workflow run, the jobs must not have a name field set and must have a unique identifiable name. Please see the comments added to log_cw_metric.dart for more information.

package-name: ${{ inputs.package-name }}
matrix: ${{ toJson(matrix) }}
working-directory: ${{ inputs.working-directory }}
matrix: ${{ toJson(matrix) != 'null' && toJson(matrix) || '' }}
Copy link
Member

Choose a reason for hiding this comment

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

I'm not following this. Is there a way to write this more clearly in code? If not, can you add a comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, this code can be improved. Updated to:

# Sending a null value will cause the action to fail so we must send an empty string here.
        matrix: ${{ matrix == '' && '{}' || toJSON(matrix) }}

If the matrix value is empty we send a blank {} else we convert to json and send back.

permissions: read-all
# These permissions are needed to interact with GitHub's OIDC Token endpoint.
permissions:
id-token: write
Copy link
Member

Choose a reason for hiding this comment

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

Why is write access needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Setting the permissions to write is required in order to request an OpenID Connect JWT.

https://stackoverflow.com/questions/72183048/what-is-the-permission-scope-of-id-token-in-github-action

Removing this permission causes logging to fail to assume the token.

Copy link
Contributor

Choose a reason for hiding this comment

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

We need a token in order to post the log to cloudwatch, I assume?

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 that's correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This utilizes the same framework that AppSec signed off several months ago when we just started sending Cloudwatch logs from our canaries.

actions/bin/log_cw_metric.dart Outdated Show resolved Hide resolved
actions/bin/log_cw_metric.dart Outdated Show resolved Hide resolved
@fjnoyp fjnoyp requested a review from Jordan-Nelson October 9, 2023 20:16
Jordan-Nelson
Jordan-Nelson previously approved these changes Oct 9, 2023
working-directory: ${{ inputs.working-directory }}

# Sending a null value will cause the action to fail so we must send an empty string here.
matrix: ${{ matrix == '' && '{}' || toJSON(matrix) }}
Copy link
Contributor

Choose a reason for hiding this comment

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

Question asked out of ignorance: Where does the matrix var come from, and why wouldn't we do ${{ toJSON(matrix) || matrix == '' && '{}' }}?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

matrix is a github context variable see: https://docs.github.com/en/actions/learn-github-actions/contexts#matrix-context

I guess we could do it that way as it's just an inversion of the logic.

Copy link
Contributor

@haverchuck haverchuck Oct 9, 2023

Choose a reason for hiding this comment

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

I read this statement as:

if matrix equals "{}", assign the matrix yaml value to "true".
ELSE
parse the matrix yaml value from json

I don't understand that logic. Why would we set the matrix yaml value to "true"? Or am I misreading this? I'm very new to GH actions so it's entirely possible I am missing something crucial here.

Also - I don't understand how a single value can evaluate to both '' and '{}' at the same time? Is this javascript?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't have ternary operators in Github Actions but that's essentially what we're trying to do here. If matrix is null we want to send {} otherwise we send a json version of matrix.

To do that we first check if matrix environment variable is empty or not. If it's empty we send {} this is achieved via &&, otherwise (||) we send toJSON(matrix).

Yes it is a javascript style logical operators. It is not evaluating to both '' and '{}' at the same time, it is using the '' to check matrix value before returning {} in that case.

${{ matrix == '' && '{}' || toJSON(matrix) }}

haverchuck
haverchuck previously approved these changes Oct 9, 2023
@fjnoyp fjnoyp dismissed stale reviews from haverchuck and Jordan-Nelson via 4d6e399 October 9, 2023 23:17
@fjnoyp fjnoyp force-pushed the feat/mine/finalizedDartActionV4 branch from 4d54849 to 4d6e399 Compare October 9, 2023 23:17
@fjnoyp fjnoyp merged commit 40f20fc into main Oct 10, 2023
290 of 335 checks passed
@fjnoyp fjnoyp deleted the feat/mine/finalizedDartActionV4 branch October 10, 2023 16:39
Equartey pushed a commit that referenced this pull request Oct 26, 2023
* chore(repo): Update Metric Logging Logic

1. Take working-directory instead of package-name to find category
2. Matrix is not required in cases when matrix does not exist
3. Remove category input, will be calculated using working-directory input instead.
4. Refactory Github API response parse logic to use generated class files

Generated workflows now need additional permissions and inherit secrets to enable their sub workflow calls to be authorized to log metrics.
Equartey pushed a commit that referenced this pull request Oct 30, 2023
* chore(repo): Update Metric Logging Logic

1. Take working-directory instead of package-name to find category
2. Matrix is not required in cases when matrix does not exist
3. Remove category input, will be calculated using working-directory input instead.
4. Refactory Github API response parse logic to use generated class files

Generated workflows now need additional permissions and inherit secrets to enable their sub workflow calls to be authorized to log metrics.
khatruong2009 pushed a commit that referenced this pull request Nov 7, 2023
* chore(repo): Update Metric Logging Logic

1. Take working-directory instead of package-name to find category
2. Matrix is not required in cases when matrix does not exist
3. Remove category input, will be calculated using working-directory input instead.
4. Refactory Github API response parse logic to use generated class files

Generated workflows now need additional permissions and inherit secrets to enable their sub workflow calls to be authorized to log metrics.
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