Skip to content

Commit 1689659

Browse files
azure-sdktimovv
andauthored
Sync eng/common directory with azure-sdk-tools for PR 5291 (Azure#28554)
* Move migration script to eng/common * Remove localization from link * Ignore the improper link * Fix links in Python migration guide to point to eng/common * Fix link --------- Co-authored-by: Timo van Veenendaal <timov@microsoft.com>
1 parent b939452 commit 1689659

File tree

4 files changed

+546
-12
lines changed

4 files changed

+546
-12
lines changed

doc/dev/recording_migration_guide.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ More technical documentation of the test proxy's out-of-repo recording support c
99
the `azure-sdk-tools` repository.
1010

1111
## Table of contents
12+
1213
- [Current recording setup](#current-recording-setup)
1314
- [New recording setup](#new-recording-setup)
1415
- [Initial recording migration](#initial-recording-migration)
@@ -49,8 +50,9 @@ migrating.
4950
This script -- [`generate-assets-json.ps1`][generate_assets_json] -- should be run once per package, and can be used
5051
either directly from an `azure-sdk-tools` repo clone or with a local download of the script. To download the script to
5152
your current working directory, use the following PowerShell command:
53+
5254
```PowerShell
53-
Invoke-WebRequest -OutFile "generate-assets-json.ps1" https://raw.githubusercontent.com/Azure/azure-sdk-tools/main/tools/test-proxy/scripts/transition-scripts/generate-assets-json.ps1
55+
Invoke-WebRequest -OutFile "generate-assets-json.ps1" https://raw.githubusercontent.com/Azure/azure-sdk-for-python/main/eng/common/testproxy/transition-scripts/generate-assets-json.ps1
5456
```
5557

5658
### Migration script prerequisites
@@ -70,19 +72,24 @@ Invoke-WebRequest -OutFile "generate-assets-json.ps1" https://raw.githubusercont
7072
In a PowerShell window:
7173

7274
1. Set your working directory to the root of the package you're migrating (`sdk/{service}/{package}`) -- for example:
75+
7376
```PowerShell
7477
cd C:\azure-sdk-for-python\sdk\keyvault\azure-keyvault-keys
7578
```
79+
7680
2. Run the following command:
81+
7782
```PowerShell
7883
<path-to-script>/generate-assets-json.ps1 -TestProxyExe "docker" -InitialPush
7984
```
8085

8186
If you run `git status` from within the language repo, you should see:
87+
8288
- Deleted files for each test recording in the package
8389
- A new `assets.json` file under the root of your package
8490

8591
The `assets.json` file will have the form:
92+
8693
```json
8794
{
8895
"AssetsRepo": "Azure/azure-sdk-assets",
@@ -105,26 +112,20 @@ The process for updating test recordings is slightly different than it was with
105112
primary ways:
106113

107114
1. When tests are run in recording mode, recording changes won't be visible in the language repo and will instead be
108-
tracked in a separate directory.
115+
tracked in a separate directory.
109116
2. When updated recordings are pushed to the assets repo, the `Tag` field in your package's `assets.json` file will be
110-
updated to point to these new recordings. This `assets.json` change is what you'll include in a pull request to update
111-
recordings in the language repo.
117+
updated to point to these new recordings. This `assets.json` change is what you'll include in a pull request to update
118+
recordings in the language repo.
112119

113120
For more details, refer to the documentation in [tests.md][recording_updates].
114121

115-
116122
[azure_sdk_assets]: https://github.com/Azure/azure-sdk-assets
117-
118123
[detailed_docs]: https://github.com/Azure/azure-sdk-tools/blob/main/tools/test-proxy/documentation/asset-sync/README.md
119124
[docker]: https://docs.docker.com/engine/install/
120-
121-
[generate_assets_json]: https://github.com/Azure/azure-sdk-tools/blob/main/tools/test-proxy/scripts/transition-scripts/generate-assets-json.ps1
125+
[generate_assets_json]: https://github.com/Azure/azure-sdk-for-python/blob/main/eng/common/testproxy/transition-scripts/generate-assets-json.ps1
122126
[git_setup]: https://git-scm.com/book/en/v2/Getting-Started-First-Time-Git-Setup
123127
[git_token]: https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token
124-
125128
[podman]: https://podman.io/getting-started/installation.html
126129
[powershell]: https://learn.microsoft.com/powershell/scripting/install/installing-powershell?view=powershell-latest
127-
128130
[recording_updates]: https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/tests.md#run-tests-with-out-of-repo-recordings
129-
130-
[transition_script]: https://github.com/Azure/azure-sdk-tools/tree/main/tools/test-proxy/scripts/transition-scripts
131+
[transition_script]: https://github.com/Azure/azure-sdk-for-python/tree/main/eng/common/testproxy/transition-scripts
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
# Transitioning recording assets from language repositories into <https://github.com/Azure/azure-sdk-assets>
2+
3+
## Setting some context
4+
5+
The azure-sdk monorepos are growing quickly due to the presence of recordings. Due to this, the engineering system team has been tasked with providing a mechanism that allows recordings to live _elsewhere_. The actual implementation of this goal is already present within the `test-proxy` tool, and this document reflects how to TRANSITION to storing recordings elsewhere!
6+
7+
The script `generate-assets-json.ps1` will execute the initial migration of your recordings from within a language repo to the [assets repo](https://github.com/Azure/azure-sdk-assets) as well as creating the assets.json file for those assets.
8+
9+
The script is [generate-assets-json.ps1](https://github.com/Azure/azure-sdk-tools/blob/main/eng/common/testproxy/transition-scripts/generate-assets-json.ps1)
10+
11+
### Download the transition script locally
12+
13+
```powershell
14+
Invoke-WebRequest -OutFile "generate-assets-json.ps1" https://raw.githubusercontent.com/Azure/azure-sdk-tools/main/eng/common/testproxy/transition-scripts/generate-assets-json.ps1
15+
```
16+
17+
```bash
18+
wget https://raw.githubusercontent.com/Azure/azure-sdk-tools/main/eng/common/testproxy/transition-scripts/generate-assets-json.ps1 -o generate-assets-json.ps1
19+
```
20+
21+
## Setup
22+
23+
Before running the script, understand that **only services that have migrated to use the `test-proxy` as their record/playback solution can store recordings into the external assets repository.** The test-proxy itself contains the code for `restoring`/`push`ing recordings, so if it is NOT being used for record/playback, that work must be completed before recordings can be moved.
24+
25+
Running the script requires these base requirements.
26+
27+
- [x] The targeted library is already migrated to use the test-proxy.
28+
- [x] Git version `>2.25.0` needs to be on the machine and in the path. Git is used by the script and test-proxy.
29+
- [x] [Powershell Core](https://learn.microsoft.com/powershell/scripting/install/installing-powershell?view=powershell-7.2) at least version 7.
30+
- [x] Ensure global git config settings for `user.name` and `user.email` are updated. [Reference](https://git-scm.com/book/en/v2/Getting-Started-First-Time-Git-Setup)
31+
- Override with environment variables `GIT_COMMIT_EMAIL` and `GIT_COMMIT_OWNER`. If either of these are set, they will override the default values pulled from `git config --global`.
32+
33+
Once the above requirements are met, developers are welcome to choose one of the following paths.
34+
35+
### `test-proxy` dotnet tool installed and called directly
36+
37+
Provide `TestProxyExe` argument of `test-proxy` or leave it **blank**. This is the default use-case of this transition script.
38+
39+
- [x] Test-proxy needs to be on the machine and in the path. Instructions for that are [here](https://github.com/Azure/azure-sdk-tools/blob/main/tools/test-proxy/Azure.Sdk.Tools.TestProxy/README.md#installation).
40+
41+
The newly installed test-proxy tool will be used during the recording migration portion of this script.
42+
43+
### `docker` or `podman` invocation
44+
45+
To utilize this methodology, the user must set input argument `TestProxyExe` to `docker` or `podman`.
46+
47+
Other requirements:
48+
49+
- [x] Install [docker](https://docs.docker.com/engine/install/) or [podman](https://podman.io/getting-started/installation.html)
50+
- [x] Set the environment variable `GIT_TOKEN` a valid token representing YOUR user
51+
52+
## Permissions
53+
54+
Check your github group membership. If you are part of the group `azure-sdk-write` directly or through a sub-team, you have the necessary permissions to create tags in the assets repository.
55+
56+
You will not be able to clean them up however. There exists [planned work](https://github.com/Azure/azure-sdk-tools/issues/4298) to clean up unused assets repo tags. Erroneously pushed tags will be auto cleaned.
57+
58+
## Nomenclature
59+
60+
- `language` repo - An individual language repository eg. azure-sdk-for-python or azure-sdk-for-net etc.
61+
- `assets` repo - The repository where assets are being moved to. <https://github.com/Azure/azure-sdk-assets>
62+
63+
The `test-proxy` tool is integrated with the ability to automatically restore these assets. This process is kick-started by the presence of an `assets.json` alongside a dev's actual code. This means that while assets will be cloned down externally, the _map_ to those assets will be stored alongside the tests. Normally, it is recommended to create an `assets.json` under the path `sdk/<ServiceDirectory>`. However, more granular storage is also possible.
64+
65+
Service/Package-Level examples:
66+
67+
- `sdk/storage/assets.json`
68+
- `sdk/storage/azure-storage-file-datalake/assets.json`
69+
70+
The location of the actual test code is referred to as the `language repo`.
71+
72+
The location of the automatically restored assets is colloquially referred to as the `assets repo`. There is an individual `assets repo` cloned for **each `assets.json` in the language repo.**
73+
74+
## Running the script
75+
76+
[generate-assets-json.ps1](https://github.com/Azure/azure-sdk-tools/blob/main/eng/common/testproxy/transition-scripts/generate-assets-json.ps1) is a standalone powershell script with no supporting script requirements. The easiest way to run the script would be to use a one-liner [defined above](#download-the-transition-script-locally) to grab the file directly. **Please ensure you have the newest version of this script before continuing!**
77+
78+
```powershell
79+
# if downloading the file singly, cd to the directory containing generate-assets-json.ps1
80+
cd "<target-language-repo>/sdk/<service>"
81+
<path-to-transition-script>/generate-assets-json.ps1
82+
```
83+
84+
The script needs to be executed inside an `sdk/<ServiceDirectory>` or deeper and from within an up to date language repository. A good rule here would be look at where the ci.yml is for an service directory. In the case where each library for a given service directory has their own pipelines, at the `sdk/<ServiceDirectory>/<Library>` level, it is recommended that the assets.json is created there. If the `ci.yml` exists deeper than the `sdk/<ServiceDirectory>/<Library>` level, then it is recommended to run the script from that directory.
85+
86+
```powershell
87+
# calling transition script against tool, given local clones of azure-sdk-for-java and azure-sdk-tools
88+
cd c:/src/azure-sdk-for-java/sdk/attestation
89+
<path-to-transition-script>/generate-assets-json.ps1 -InitialPush
90+
```
91+
92+
```powershell
93+
# calling transition script against docker, given local clones of azure-sdk-for-java and azure-sdk-tools
94+
$env:GIT_TOKEN="my git token"
95+
cd c:/src/azure-sdk-for-java/sdk/attestation
96+
<path-to-transition-script>/generate-assets-json.ps1 -TestProxyExe "docker" -InitialPush
97+
```
98+
99+
After running a script, executing a `git status` from within the language repo, where the script was invoked from, will reflect two primary results:
100+
101+
- A new `assets.json` present in the directory from which they invoked the transition script.
102+
- A **bunch** of deleted files from where their recordings _were_ before they were pushed to the assets repo.
103+
104+
Running the script without the `-InitialPush` option will just create the assets.json with an empty tag. No data movement.
105+
106+
### What's the script doing behind the scenes?
107+
108+
Given the previous example of `sdk/attestation` transition script invocation, users should see the following:
109+
110+
- Creation of the assets.json file in the `sdk/attestation` directory.
111+
- If `-InitialPush` has not been specified, the script stops here and exits.
112+
- test-proxy's CLI restore is called on the current assets.json. Since there's nothing there, it'll just initialize an empty assets directory under the `.assets` directory under repo root.
113+
- The recordings are moved from their initial directories within the language repo into a temp directory that was created in the previous step.
114+
- The relative paths from root are preserved.
115+
- For example, the recordings for `C:/src/azure-sdk-for-python/sdk/tables` live in the `azure-data-tables/tests/recordings` subdirectory and in the target repository they'll live in `python/sdk/tables/azure-data-tables/tests/recordings`. All the azure-sdk supported languages will leverage [Azure/azure-sdk-assets](https://github.com/Azure/azure-sdk-assets), so adding a prefix to the output path `python` ensures that these recordings can live alongside others in the assets repo.
116+
- Call `test-proxy push` on the assets.json created in the first step. The push will happen automatically and not require a manual PR.
117+
- On completion of the push, the newly created tag will be stamped into the assets.json.
118+
119+
At this point the script is complete. The assets.json and deleted recording files will need to be pushed into the language repository as a manual PR.
120+
121+
#### Why does the script analyze the remotes to compute the language?
122+
123+
This is necessary because the language is used in several places.
124+
125+
1. The AssetsRepoPrefixPath in assets.json is set to the language.
126+
2. The TagPrefix is set to the `<language>/<ServiceDirectory>` or `<language>/<ServiceDirectory>/<Library>` etc.
127+
3. The language also used to determine what the [recording directories within a repository are named](https://github.com/Azure/azure-sdk-tools/blob/main/eng/common/testproxy/transition-scripts/generate-assets-json.ps1#L47).
128+
129+
## A final note about the initial push
130+
131+
If a directory with several thousand recordings is being migrated, the move and the initial push can take several minutes. For example, java storage recordings were used as a stress test. There are 4,693 files, with a combined size of 666 MB, and the initial push took about 7 minutes. This is a one time cost as the files do not exist yet within the assets repository. Subsequent pushes should have dramatically reduced push time.

0 commit comments

Comments
 (0)