xref: /aosp_15_r20/development/tools/repo_diff/service/repodiff/README.md (revision 90c8c64db3049935a07c6143d7fd006e26f8ecca)
1*90c8c64dSAndroid Build Coastguard Worker# To Setup Application:
2*90c8c64dSAndroid Build Coastguard Worker
3*90c8c64dSAndroid Build Coastguard Worker1.  It is assumed that the Go runtime has been installed with a properly set
4*90c8c64dSAndroid Build Coastguard Worker    $GOPATH
5*90c8c64dSAndroid Build Coastguard Worker2.  Run `make bootstrap`
6*90c8c64dSAndroid Build Coastguard Worker
7*90c8c64dSAndroid Build Coastguard Worker# To Provision a Database
8*90c8c64dSAndroid Build Coastguard Worker
9*90c8c64dSAndroid Build Coastguard Worker**Use Google Cloud**. This is one assumption made based on the idea that Google
10*90c8c64dSAndroid Build Coastguard WorkerData Studio will visualize the data.
11*90c8c64dSAndroid Build Coastguard Worker
12*90c8c64dSAndroid Build Coastguard Worker1.  Log in to [the Google Cloud Platform](https://pantheon.corp.google.com)
13*90c8c64dSAndroid Build Coastguard Worker2.  Under the **Storage** section, navigate to **SQL**
14*90c8c64dSAndroid Build Coastguard Worker3.  Click **Create Instance**, select **MySQL** and hit **Next**
15*90c8c64dSAndroid Build Coastguard Worker4.  Choose **MySQL Second Generation** (the default)
16*90c8c64dSAndroid Build Coastguard Worker5.  Set Instance ID and root password, then click **Create**
17*90c8c64dSAndroid Build Coastguard Worker6.  Wait for the instance to initialize, then navigate to **databases** and then
18*90c8c64dSAndroid Build Coastguard Worker    click **create database**; choose the defaults and make note of the chosen
19*90c8c64dSAndroid Build Coastguard Worker    database name.
20*90c8c64dSAndroid Build Coastguard Worker7.  Navigate to **Users** and **Create user account** for the purpose of
21*90c8c64dSAndroid Build Coastguard Worker    creating a non-root user to log into the database; Make note of the username
22*90c8c64dSAndroid Build Coastguard Worker    and password chosen.
23*90c8c64dSAndroid Build Coastguard Worker
24*90c8c64dSAndroid Build Coastguard WorkerThe application assumes that both a development and production environment
25*90c8c64dSAndroid Build Coastguard Workerexist, therefore the above steps will need to be completed a second time. Now
26*90c8c64dSAndroid Build Coastguard Workerthe following environment variables will need to be set in your application
27*90c8c64dSAndroid Build Coastguard Workerenvironment:
28*90c8c64dSAndroid Build Coastguard Worker
29*90c8c64dSAndroid Build Coastguard Worker*   GCP_DB_INSTANCE_CONNECTION_NAME_DEV: The instance ID of the provisioned
30*90c8c64dSAndroid Build Coastguard Worker    database server; this is listed on the SQL homepage in Google Cloud
31*90c8c64dSAndroid Build Coastguard Worker    alongside the respective database instance
32*90c8c64dSAndroid Build Coastguard Worker*   GCP_DB_NAME_DEV: the database name created from step 6
33*90c8c64dSAndroid Build Coastguard Worker*   GCP_DB_USER_DEV: the username created from step 7
34*90c8c64dSAndroid Build Coastguard Worker*   GCP_DB_PASSWORD_DEV: the password created from step 7
35*90c8c64dSAndroid Build Coastguard Worker*   GCP_DB_PROXY_PORT_DEV: an arbitrary, unique port used for the local secure
36*90c8c64dSAndroid Build Coastguard Worker    MySQL proxy
37*90c8c64dSAndroid Build Coastguard Worker
38*90c8c64dSAndroid Build Coastguard WorkerThe same environment variables should be set for production. The names are the
39*90c8c64dSAndroid Build Coastguard Workersame but replace **"DEV"** with **"PROD"**
40*90c8c64dSAndroid Build Coastguard Worker
41*90c8c64dSAndroid Build Coastguard WorkerOne the environment variables are set, the database can be readied by running:
42*90c8c64dSAndroid Build Coastguard Worker
43*90c8c64dSAndroid Build Coastguard Worker`make db_upgrade`
44*90c8c64dSAndroid Build Coastguard Worker
45*90c8c64dSAndroid Build Coastguard WorkerTo run the same set of upgrades for production, run:
46*90c8c64dSAndroid Build Coastguard Worker
47*90c8c64dSAndroid Build Coastguard Worker`ROLE="prod" make db_upgrade`
48*90c8c64dSAndroid Build Coastguard Worker
49*90c8c64dSAndroid Build Coastguard Worker# Running the Application
50*90c8c64dSAndroid Build Coastguard Worker
51*90c8c64dSAndroid Build Coastguard WorkerExecuting the application will by default:
52*90c8c64dSAndroid Build Coastguard Worker
53*90c8c64dSAndroid Build Coastguard Worker1.  Clone all of the repositories specified in config.json and write the
54*90c8c64dSAndroid Build Coastguard Worker    observed differentials to the database
55*90c8c64dSAndroid Build Coastguard Worker2.  Run application-specified analytics on the persisted data and write the
56*90c8c64dSAndroid Build Coastguard Worker    output to designated denormalized tables; those tables are tightly coupled
57*90c8c64dSAndroid Build Coastguard Worker    to Datastudio data sources in the [AOSP Branch
58*90c8c64dSAndroid Build Coastguard Worker    Differentials](https://datastudio.google.com/c/u/0/org/UTgoe29uR0C3F1FBAYBSww/reporting/1lTzMXHBWiVvc0Dnb2DJvRQeTVCAIuvGF/page/9rqP)
59*90c8c64dSAndroid Build Coastguard Worker3.  Generate CSV reports based on persisted data
60*90c8c64dSAndroid Build Coastguard Worker
61*90c8c64dSAndroid Build Coastguard WorkerApplications steps can be optionally disabled for presumably one-off runs:
62*90c8c64dSAndroid Build Coastguard Worker`ROLE="prod" ./repodiff
63*90c8c64dSAndroid Build Coastguard Worker[--execute-diff=false][--denormalize-data=false][--generate-report=false]`
64*90c8c64dSAndroid Build Coastguard Worker
65*90c8c64dSAndroid Build Coastguard Worker`config.json` will specify input and output parameters for the application;
66*90c8c64dSAndroid Build Coastguard Workerupdate to reflect your own environment.
67*90c8c64dSAndroid Build Coastguard Worker
68*90c8c64dSAndroid Build Coastguard WorkerTo run:
69*90c8c64dSAndroid Build Coastguard Worker
70*90c8c64dSAndroid Build Coastguard Worker`make run`
71*90c8c64dSAndroid Build Coastguard Worker
72*90c8c64dSAndroid Build Coastguard WorkerFor production: `ROLE="prod" make run`
73*90c8c64dSAndroid Build Coastguard Worker
74*90c8c64dSAndroid Build Coastguard Worker# Tooling
75*90c8c64dSAndroid Build Coastguard Worker
76*90c8c64dSAndroid Build Coastguard WorkerTo connect to the MySQL server used by the application, run:
77*90c8c64dSAndroid Build Coastguard Worker
78*90c8c64dSAndroid Build Coastguard Worker`make db_shell`
79*90c8c64dSAndroid Build Coastguard Worker
80*90c8c64dSAndroid Build Coastguard WorkerTo create new, canonical migration scripts to update the database schema, run:
81*90c8c64dSAndroid Build Coastguard Worker
82*90c8c64dSAndroid Build Coastguard Worker`make sql_script`
83*90c8c64dSAndroid Build Coastguard Worker
84*90c8c64dSAndroid Build Coastguard WorkerTo undo the latest database migration, run:
85*90c8c64dSAndroid Build Coastguard Worker
86*90c8c64dSAndroid Build Coastguard Worker`make db_downgrade`
87*90c8c64dSAndroid Build Coastguard Worker
88*90c8c64dSAndroid Build Coastguard WorkerTo upgrade to the latest database version, run:
89*90c8c64dSAndroid Build Coastguard Worker
90*90c8c64dSAndroid Build Coastguard Worker`make db_upgrade`
91*90c8c64dSAndroid Build Coastguard Worker
92*90c8c64dSAndroid Build Coastguard WorkerTo run tests, run:
93*90c8c64dSAndroid Build Coastguard Worker
94*90c8c64dSAndroid Build Coastguard Worker`make test`
95*90c8c64dSAndroid Build Coastguard Worker
96*90c8c64dSAndroid Build Coastguard Worker# Consuming the Application Output
97*90c8c64dSAndroid Build Coastguard Worker
98*90c8c64dSAndroid Build Coastguard WorkerTLDR: Use [Google Data Studio](https://datastudio.google.com); Your datasource
99*90c8c64dSAndroid Build Coastguard Workerwill be tables from the provisioned database set up in the provisioning
100*90c8c64dSAndroid Build Coastguard Workerinstructions. All intended consumable tables are prefixed with
101*90c8c64dSAndroid Build Coastguard Worker**denormalized_view_**
102*90c8c64dSAndroid Build Coastguard Worker
103*90c8c64dSAndroid Build Coastguard WorkerThe rationale behind the application is that setup in Data Studio should require
104*90c8c64dSAndroid Build Coastguard Workerlittle to no learning curve (for developers especially), and views are simple
105*90c8c64dSAndroid Build Coastguard Workerprojections of the underlying model. The application, then, should run whatever
106*90c8c64dSAndroid Build Coastguard Workernecessary logic to produce desired analytics that can be written to a
107*90c8c64dSAndroid Build Coastguard Workerdenormalized database table for straightforward consumption.
108