Skip to content

Commit 9fef834

Browse files
authored
Merge branch 'develop' into feature/eema1-NRL-474-authorBasicValidation
2 parents f72ff7b + ff0fcfb commit 9fef834

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,3 +511,26 @@ Once you have a new release version ready, you can deploy it through our environ
511511
2. If any issues arise in the deployment, fix the issues, create a new release version and start this process again.
512512
3. Once the deployments are complete, use the "Persistent Environment Deploy" Github Action workflow to deploy the release version to `ref`.
513513
4. Once that is complete, use the "Persistent Environment Deploy" workflow to deploy the release version to `prod`.
514+
515+
## Reports
516+
517+
Reports are provided as scripts in the `reports/` directory. To run a report:
518+
519+
1. Login to your AWS account on the command line, choosing the account that contains the resources you want to report on.
520+
2. Run your chosen report script, giving the script the resource names and parameters it requires. See each report script for details.
521+
522+
For example, to count the number of pointers from X26 in the pointers table in the dev environment:
523+
524+
```
525+
$ poetry run python ./scripts/count_pointers_for_custodian.py \
526+
nhsd-nrlf--dev-pointers-table \
527+
X26
528+
```
529+
530+
### Running reports in the prod environment
531+
532+
The reports scripts may require resources that could affect the performance of the live production system. Because of this, it is recommended that you take steps to minimise this impact before running reports.
533+
534+
If you are running a report against the DynamoDB pointers table in prod, you should create a copy (or restore a PITR backup) of the table and run your report against the copy.
535+
536+
Please ensure any duplicated resource/data is deleted from the prod environment once you have finished using it.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
from datetime import datetime, timedelta, timezone
2+
from typing import Any, Optional
3+
4+
import boto3
5+
import fire
6+
7+
dynamodb = boto3.client("dynamodb")
8+
paginator = dynamodb.get_paginator("scan")
9+
10+
11+
def _count_pointers(
12+
table_name: str, ods_code: str, created_date: Optional[str] = None
13+
) -> dict[str, float]:
14+
"""
15+
Count the number of pointers for a given custodian (ODS code) in the pointers table.
16+
Parameters:
17+
- table_name: The name of the pointers table to use.
18+
- ods_code: The custodian ODS code to find pointers for.
19+
- created_date: The created date to filter pointers on. (optional)
20+
"""
21+
22+
print(f"Counting pointers for {ods_code} in table {table_name}....") # noqa
23+
24+
params: dict[str, Any] = {
25+
"TableName": table_name,
26+
"FilterExpression": "custodian = :ods_code",
27+
"ExpressionAttributeValues": {":ods_code": {"S": ods_code}},
28+
"Select": "COUNT",
29+
"PaginationConfig": {"PageSize": 100},
30+
}
31+
32+
if created_date:
33+
params["FilterExpression"] += " AND starts_with(created_on, :created_date)"
34+
params["ExpressionAttributeValues"][":created_date"] = {"S": created_date}
35+
36+
custodian_pointers_count = 0
37+
total_scanned_count = 0
38+
39+
start_time = datetime.now(tz=timezone.utc)
40+
41+
for page in paginator.paginate(**params):
42+
custodian_pointers_count += page["Count"]
43+
total_scanned_count += page["ScannedCount"]
44+
45+
if total_scanned_count % 1000 == 0:
46+
print(".", end="", flush=True) # noqa
47+
48+
end_time = datetime.now(tz=timezone.utc)
49+
50+
print(" Done") # noqa
51+
return {
52+
"items_found": custodian_pointers_count,
53+
"scanned_count": total_scanned_count,
54+
"took-secs": timedelta.total_seconds(end_time - start_time),
55+
}
56+
57+
58+
if __name__ == "__main__":
59+
fire.Fire(_count_pointers)

0 commit comments

Comments
 (0)