Skip to content

Commit 565f590

Browse files
Merge pull request #4710 from linuxfoundation/unicron-research-which-v1-and-v2-apis-are-still-used
Utils to lookup for V1/V2 Py APIs still used on dev & prod
2 parents 11a68fd + aba2e34 commit 565f590

File tree

4 files changed

+129
-3
lines changed

4 files changed

+129
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,3 +245,4 @@ cla-backend/run-python-test-example-*.py
245245
# LG
246246
out
247247
*.secret
248+
*log*.json

docs/Python_APIs.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# V1/V2 python APIs still used
2+
3+
1. EasyCLA backend [here](https://github.com/linuxfoundation/easycla/blob/main/.github/workflows/deploy-prod.yml#L127).
4+
- `/v2/health`. Health check while `dev`/`prod` deployment.
5+
6+
7+
2. EasyCLA contributor console [here](https://github.com/communitybridge/easycla-contributor-console/blob/main/src/app/core/services/cla-contributor.service.ts), found via `` find.sh . '*' /vN ``.
8+
- `/v1/api/health` [here](https://github.com/communitybridge/easycla-contributor-console/blob/main/test/functional/cypress/integration/api-tests/health-check.spec.ts#L4).
9+
- `/v1/user/gerrit`.
10+
- `/v2/user/<userId>`.
11+
- `/v2/project/<projectId>`.
12+
- `/v2/user/<userId>/active-signature`.
13+
- `/v2/check-prepare-employee-signature`.
14+
- `/v2/request-employee-signature`.
15+
- `/v2/user/<userId>/project/<projectId>/last-signature`.
16+
- `/v2/project/<projectId>`.
17+
18+
19+
3. EasyCLA corporate console [here](https://github.com/LF-Engineering/lfx-corp-cla-console/blob/main/backend/src/data/cla-api.ts):
20+
- No V1 or V2 APIs used.
21+
22+
23+
4. PCC [here](https://github.com/linuxfoundation/lfx-pcc/blob/main/apps/v1-backend/src/modules/cla-services/model/index.ts):
24+
- No V1 or V2 APIs used.
25+
26+
27+
5. GitHub/Gitlab/Gerrit ({provider}) app/bot [here]() (there is no list of which particular APIs are used by GitHub/GitLab/Gerrit):
28+
- `/v2/github/activity`.
29+
- `/v2/repository-provider/{provider}/sign/{installation_id}/{github_repository_id}/{change_request_id}`.
30+
- `/v2/github/installation`.
31+
- `/v1/user/gerrit`.
32+
- `/v2/signed/individual/{installation_id}/{github_repository_id}/{change_request_id}` ?
33+
- `/v2/repository-provider/{provider}/activity` ?
34+
- `/v2/repository-provider/{provider}/oauth2_redirect` ?
35+
- `/v2/signed/gitlab/individual/{user_id}/{organization_id}/{gitlab_repository_id}/{merge_request_id}` ?
36+
- `/v2/signed/gerrit/individual/{user_id}` ?
37+
- `cla-backend/cla/routes.py`: `GitHub Routes`, `Gerrit Routes`, `Gerrit instance routes`.
38+
39+
40+
6. Manually check which APIs were actually called on `dev` and `prod` via:
41+
42+
- `prod` analysis: `` DEBUG=1 NO_ECHO=1 STAGE=prod REGION=us-east-1 DTFROM='10 days ago' DTTO='1 second ago' OUT=api-logs-prod.json ./utils/search_aws_logs.sh 'LG:api-request-path' && jq -r '.[].message' api-logs-prod.json | grep -o 'LG:api-request-path:[^[:space:]]*' | sed 's/^LG:api-request-path://' | sed -E 's/[0-9a-fA-F-]{36}/<uuid>/g' | sed -E 's/\b[0-9]{2,}\b/<id>/g' | sort | uniq -c | sort -nr ``:
43+
```
44+
377727 /v2/github/activity
45+
1783 /v2/repository-provider/github/sign/<id>/<id>/<id>
46+
347 /v2/github/installation
47+
212 /v2/project/<uuid>
48+
211 /v2/user/<uuid>
49+
187 /v2/user/<uuid>/active-signature
50+
157 /v2/check-prepare-employee-signature
51+
146 /v2/return-url/<uuid>
52+
61 /v2/request-employee-signature
53+
16 /v1/file/icon/seo/<uuid>.png
54+
8 /v2/gerrit/<uuid>/corporate/agreementUrl.html
55+
7 /v1/user/gerrit
56+
2 /v2/health
57+
1 /v2/user-from-token
58+
1 /v2/repository-provider/github/icon.svg
59+
```
60+
61+
- `dev` analysis (but this can contain API calls made by developer and not actually used): `` DEBUG=1 STAGE=dev REGION=us-east-1 DTFROM='10 days ago' DTTO='1 second ago' OUT=api-logs-dev.json ./utils/search_aws_logs.sh 'LG:api-request-path' && jq -r '.[].message' api-logs-prod.json | grep -o 'LG:api-request-path:[^[:space:]]*' | sed 's/^LG:api-request-path://' | sed -E 's/[0-9a-fA-F-]{36}/<uuid>/g' | sed -E ':a;s#/([0-9]{1,})(/|$)#/<id>\2#g;ta' | sort | uniq -c | sort -nr ``:
62+
```
63+
113 /v2/project/<uuid>
64+
53 /v2/user/<uuid>
65+
39 /v2/github/activity
66+
14 /v2/user/<uuid>/active-signature
67+
13 /v2/repository-provider/github/sign/<id>/<id>/<id>
68+
12 /v2/user-from-token
69+
8 /v2/github/installation
70+
5 /v2/health
71+
1 /v2/users/company/abcd
72+
1 /v2/user-from-session
73+
1 /v2/return-url/<uuid>
74+
1 /v2/check-prepare-employee-signature
75+
1 /v1/users/company/abcd
76+
```
77+
78+
File renamed without changes.

utils/search_aws_logs.sh

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,20 @@
33
# Copyright The Linux Foundation and each contributor to LFX.
44
# SPDX-License-Identifier: MIT
55

6-
# REGION=us-east-1|us-east-2 STAGE=dev DEBUG=1 DTFROM='3 days ago' DTTO='2 days ago' ./utils/search_aws_logs.sh 'error'
6+
# REGION=us-east-1|us-east-2 STAGE=dev DEBUG=1 DTFROM='3 days ago' DTTO='2 days ago' OUT=logs.json ./utils/search_aws_logs.sh 'error'
7+
# DEBUG=1 STAGE=dev REGION=us-east-1 DTFROM='10 days ago' DTTO='1 second ago' OUT=api-logs-dev.json ./utils/search_aws_logs.sh 'LG:api-request-path' && jq -r '.[].message' api-logs-dev.json | grep -o 'LG:api-request-path:[^[:space:]]*' | sed 's/^LG:api-request-path://' | sed -E 's/[0-9a-fA-F-]{36}/<uuid>/g' | sed -E 's/\b[0-9]{2,}\b/<id>/g' | sort | uniq -c | sort -nr
8+
# DEBUG=1 STAGE=prod REGION=us-east-1 NO_ECHO=1 DTFROM='10 days ago' DTTO='1 second ago' OUT=api-logs-prod.json ./utils/search_aws_logs.sh 'LG:api-request-path' && jq -r '.[].message' api-logs-prod.json | grep -o 'LG:api-request-path:[^[:space:]]*' | sed 's/^LG:api-request-path://' | sed -E 's/[0-9a-fA-F-]{36}/<uuid>/g' | sed -E ':a;s#/([0-9]{1,})(/|$)#/<id>\2#g;ta' | sort | uniq -c | sort -nr
79
# To find distinct log groups: | jq -r 'map(.logGroupName) | unique | .[]'
810
# in us-east-1 (mostly V1, V2 and V3):
911
# To see specific log group: | jq 'map(select(.logGroupName == "/aws/lambda/cla-backend-dev-apiv1"))'
1012
# To filter out one log group: | jq 'map(select(.logGroupName != "/aws/lambda/cla-backend-dev-apiv2"))'
1113
# To filter out one log group: | jq 'map(select(.logGroupName != "cla-backend-dev-api-v3-lambda"))'
1214
# in us-east-2 (V4):
1315
# To filter out one log group: | jq 'map(select(.logGroupName != "cla-backend-go-api-v4-lambda"))'
16+
# To exclude some log groups: EXCL_LOGS="apiv1,apiv3"
17+
# To include only specific log groups INCL_LOGS="apiv1,apiv3"
18+
# All log groups in us-east-1: backend-dev-api-v3-lambda,backend-dev-apiv1,backend-dev-apiv2,backend-dev-authorizer,backend-dev-dynamo-events-events-lambda,backend-dev-dynamo-github-orgs-events-lambda,backend-dev-dynamo-projects-cla-groups-events-lambda,backend-dev-dynamo-projects-lambda,backend-dev-dynamo-repositories-events-lambda,backend-dev-dynamo-signatures-events-lambda,backend-dev-githubactivity,backend-dev-githubinstall,backend-dev-gitlab-repository-check-lambda,backend-dev-report-metrics-lambda,backend-dev-salesforceprojectbyID,backend-dev-salesforceprojects,backend-dev-save-metrics-lambda,backend-dev-user-event-handler-lambda,backend-dev-zip-builder-lambda,backend-dev-zip-builder-scheduler-lambda,backend-go-api,dev-stream-test-handler,dynamo-events-lambda,landing-page-dev-clientEdge,metrics-lamdba-test,prasanna-zip-builder,prasanna-zipbuilder-schedular,test-zipbuilder-lambda
19+
# All log groups in us-east-2: backend-go-api-v4-lambda
1420

1521
if [ -z "${STAGE}" ]
1622
then
@@ -44,9 +50,43 @@ else
4450
fi
4551

4652
mapfile -t log_groups_array < <(aws --region "${REGION}" --profile "lfproduct-${STAGE}" logs describe-log-groups --log-group-name-prefix "/aws/lambda/cla-" --query "logGroups[].logGroupName" | jq -r '.[]')
53+
54+
IFS=',' read -ra INCL_LOGS_ARRAY <<< "${INCL_LOGS}"
55+
IFS=',' read -ra EXCL_LOGS_ARRAY <<< "${EXCL_LOGS}"
56+
4757
results=()
4858
for log_group in "${log_groups_array[@]}"
4959
do
60+
short_log_group="${log_group#/aws/lambda/cla-}"
61+
# Skip if not in INCLUDE list (when it's set)
62+
if [ ! -z "${INCL_LOGS}" ]
63+
then
64+
skip_included=true
65+
for incl in "${INCL_LOGS_ARRAY[@]}"
66+
do
67+
if [[ "$short_log_group" == *"$incl"* ]]
68+
then
69+
skip_included=false
70+
break
71+
fi
72+
done
73+
if [ "$skip_included" = true ]
74+
then
75+
[ ! -z "$DEBUG" ] && echo "Skipping (not in INCLUDE): $log_group" >&2
76+
continue
77+
fi
78+
fi
79+
80+
# Skip if in EXCLUDE list
81+
for excl in "${EXCL_LOGS_ARRAY[@]}"
82+
do
83+
if [[ "$short_log_group" == *"$excl"* ]]
84+
then
85+
[ ! -z "$DEBUG" ] && echo "Skipping (in EXCLUDE): $log_group" >&2
86+
continue 2
87+
fi
88+
done
89+
5090
if [ ! -z "${DEBUG}" ]
5191
then
5292
echo "lookup log group '${log_group}': aws --region "${REGION}" --profile \"lfproduct-${STAGE}\" logs filter-log-events --log-group-name \"$log_group\" --start-time \"${DTFROM}\" --end-time \"${DTTO}\" --filter-pattern \"${search}\"" >&2
@@ -68,11 +108,18 @@ done
68108

69109
jsons=""
70110
for log in "${results[@]}"; do
71-
if [ -n "$jsons" ]
111+
if [ ! -z "$jsons" ]
72112
then
73113
jsons+=$'\n'
74114
fi
75115
jsons+=$(echo "$log" | jq -r '.')
76116
done
77117

78-
echo "$jsons" | jq -s 'sort_by(.dt) | reverse'
118+
if [ ! -z "${OUT}" ]
119+
then
120+
echo "$jsons" | jq -s 'sort_by(.dt) | reverse' > "${OUT}"
121+
fi
122+
if [ -z "${NO_ECHO}" ]
123+
then
124+
echo "$jsons" | jq -s 'sort_by(.dt) | reverse'
125+
fi

0 commit comments

Comments
 (0)