Skip to content

Commit

Permalink
[ci][ez] Add job_id to emit_metrics (#113099)
Browse files Browse the repository at this point in the history
As in title.

Also print the job id in the step since I'm struggling to find it
Pull Request resolved: #113099
Approved by: https://github.com/seemethere
  • Loading branch information
clee2000 authored and pytorchmergebot committed Nov 8, 2023
1 parent 3914566 commit 6e73ae2
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/scripts/get_workflow_job_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ def set_output(name: str, val: Any) -> None:
if os.getenv("GITHUB_OUTPUT"):
with open(str(os.getenv("GITHUB_OUTPUT")), "a") as env:
print(f"{name}={val}", file=env)
print(f"setting {name}={val}")
else:
print(f"::set-output name={name}::{val}")

Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/_bazel-build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ jobs:
GITHUB_RUN_ID: ${{ github.run_id }}
GITHUB_RUN_NUMBER: ${{ github.run_number }}
GITHUB_RUN_ATTEMPT: ${{ github.run_attempt }}
JOB_ID: ${{ steps.get-job-id.outputs.job-id }}
PYTORCH_RETRY_TEST_CASES: 1
PYTORCH_OVERRIDE_FLAKY_SIGNAL: 1
REENABLED_ISSUES: ${{ needs.filter.outputs.reenabled-issues }}
Expand Down Expand Up @@ -147,6 +148,7 @@ jobs:
-e GITHUB_JOB \
-e GITHUB_RUN_NUMBER \
-e GITHUB_RUN_ATTEMPT \
-e JOB_ID \
-e GIT_DEFAULT_BRANCH="$GIT_DEFAULT_BRANCH" \
-e SHARD_NUMBER \
-e NUM_TEST_SHARDS \
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/_linux-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ jobs:
GITHUB_RUN_ID: ${{ github.run_id }}
GITHUB_RUN_NUMBER: ${{ github.run_number }}
GITHUB_RUN_ATTEMPT: ${{ github.run_attempt }}
JOB_ID: ${{ steps.get-job-id.outputs.job-id }}
BRANCH: ${{ steps.parse-ref.outputs.branch }}
SHA1: ${{ github.event.pull_request.head.sha || github.sha }}
BASE_SHA: ${{ github.event.pull_request.base.sha || github.sha }}
Expand Down Expand Up @@ -204,6 +205,7 @@ jobs:
-e GITHUB_RUN_ID \
-e GITHUB_RUN_NUMBER \
-e GITHUB_RUN_ATTEMPT \
-e JOB_ID \
-e BASE_SHA \
-e BRANCH \
-e SHA1 \
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/_mac-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ jobs:
GITHUB_RUN_ID: ${{ github.run_id }}
GITHUB_RUN_NUMBER: ${{ github.run_number }}
GITHUB_RUN_ATTEMPT: ${{ github.run_attempt }}
JOB_ID: ${{ steps.get-job-id.outputs.job-id }}
REENABLED_ISSUES: ${{ steps.keep-going.outputs.reenabled-issues }}
run: |
# shellcheck disable=SC1090
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/_rocm-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ jobs:
GITHUB_RUN_ID: ${{ github.run_id }}
GITHUB_RUN_NUMBER: ${{ github.run_number }}
GITHUB_RUN_ATTEMPT: ${{ github.run_attempt }}
JOB_ID: ${{ steps.get-job-id.outputs.job-id }}
BRANCH: ${{ steps.parse-ref.outputs.branch }}
SHA1: ${{ github.event.pull_request.head.sha || github.sha }}
PYTORCH_RETRY_TEST_CASES: 1
Expand Down Expand Up @@ -162,6 +163,7 @@ jobs:
-e GITHUB_RUN_ID \
-e GITHUB_RUN_NUMBER \
-e GITHUB_RUN_ATTEMPT \
-e JOB_ID \
-e BRANCH \
-e SHA1 \
-e AWS_DEFAULT_REGION \
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/_win-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ jobs:
GITHUB_RUN_ID: ${{ github.run_id }}
GITHUB_RUN_NUMBER: ${{ github.run_number }}
GITHUB_RUN_ATTEMPT: ${{ github.run_attempt }}
JOB_ID: ${{ steps.get-job-id.outputs.job-id }}
SHA1: ${{ github.event.pull_request.head.sha || github.sha }}
CUDA_VERSION: ${{ inputs.cuda-version }}
PYTORCH_FINAL_PACKAGE_DIR: /c/${{ github.run_id }}/build-results/
Expand Down
1 change: 1 addition & 0 deletions tools/stats/upload_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ def emit_metric(
EnvVarMetric("run_id", "GITHUB_RUN_ID", type_conversion_fn=int),
EnvVarMetric("run_number", "GITHUB_RUN_NUMBER", type_conversion_fn=int),
EnvVarMetric("run_attempt", "GITHUB_RUN_ATTEMPT", type_conversion_fn=int),
EnvVarMetric("job_id", "JOB_ID", type_conversion_fn=int),
]

# Use info about the function that invoked this one as a namespace and a way to filter metrics.
Expand Down
3 changes: 3 additions & 0 deletions tools/test/test_upload_stats_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
RUN_NUMBER = 123
RUN_ATTEMPT = 3
PR_NUMBER = 6789
JOB_ID = 234


class TestUploadStats(unittest.TestCase):
Expand All @@ -36,6 +37,7 @@ def setUp(self) -> None:
"GITHUB_RUN_ID": str(RUN_ID),
"GITHUB_RUN_NUMBER": str(RUN_NUMBER),
"GITHUB_RUN_ATTEMPT": str(RUN_ATTEMPT),
"JOB_ID": str(JOB_ID),
},
clear=True, # Don't read any preset env vars
).start()
Expand Down Expand Up @@ -67,6 +69,7 @@ def test_emits_default_and_given_metrics(self, mock_resource: Any) -> None:
"run_attempt": RUN_ATTEMPT,
"some_number": 123,
"float_number": decimal.Decimal(str(32.34)),
"job_id": JOB_ID,
}

# Preserve the metric emitted
Expand Down

0 comments on commit 6e73ae2

Please sign in to comment.