Skip to content

Commit 951255c

Browse files
William ChrispJoshArmi
authored andcommitted
Update READMEs and Event Catalog Docs
1 parent 01a3819 commit 951255c

File tree

67 files changed

+1108
-546
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+1108
-546
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,3 +258,7 @@ Thumbs.db
258258
# CDKTF Specifics
259259
requirements.txt
260260
all_files/
261+
api_key_rotation/
262+
!api_key_rotation/main.py
263+
imports/
264+
cdktf.out

Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@ docs-run: docs-build
1616

1717
# Test Commands
1818
unittest:
19-
pipenv run pytest -m 'not integration' tests/
19+
pipenv run pytest -m 'not integration' tests/src tests/publisher
2020

2121
integration-test:
22-
pipenv run pytest -m 'integration' tests/
22+
pipenv run pytest -m 'integration' tests/src tests/publisher
2323

2424
test:
25-
pipenv run pytest --cov=src --cov=publisher --cov-fail-under=81 --cov-report term-missing tests/
25+
pipenv run pytest --cov=src --cov=publisher --cov-fail-under=81 --cov-report term-missing tests/src tests/publisher
2626

2727
watch:
28-
ptw -- -m 'not integration' tests/
28+
ptw -- -m 'not integration' tests/src tests/publisher
2929

3030
e2e:
31-
pipenv run behave
31+
cd tests/; pipenv run behave
3232

3333
# Infrastructure Commands
3434
build-python:

README.md

Lines changed: 34 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
<h1 align="center">Flight Controller on AWS Cloud Platform</h1>
2-
<p align="center">This repository contains the code necessary for Flight Controller on AWS.</p>
1+
<h1 align="center">Flight Controller</h1>
2+
<p align="center">This repository contains the code necessary for Flight Controller</p>
33

44
## What is Flight Controller?
55

@@ -9,33 +9,36 @@ The intent is to make it trivial to add new measures, allowing teams to be data
99

1010
The approach to scaling a landing zone on AWS is [elaborated here](https://aws.amazon.com/blogs/mt/flight-controller-by-contino-a-solution-built-on-aws-control-tower/).
1111

12-
## Architecture
12+
## Repository Structure
1313

14-
![Flight Controller Architecture](images/flight_controller.png)
14+
- [Flight Controller Event Catalog](https://legendary-spoon-f82c1640.pages.github.io): `docs/`
15+
- [README.md](docs/README.md)
16+
- Flight Controller Infrastructure Terraform CDK Code - `infrastructure/`
17+
- [README.md](infrastructure/README.md)
18+
- Flight Controller Custom Publisher Code - `publisher/`
19+
- [README.md](publisher/README.md)
20+
- Flight Controller Code - `src/`
21+
- [README.md](src/README.md)
22+
- Flight Controller Tests - `tests/`
23+
- [README.md](tests/README.md)
1524

1625
## Development
1726

1827
### Prerequisites
1928

2029
- Python version 3.10
2130
- Pipenv (version 2022.10.12 proven working)
22-
- Terraform version 1.2.7
23-
- Docker installed
31+
- Terraform CDK version 0.15.5
32+
- Docker
2433

25-
- Terraform CDK
26-
- NVM -> npm and node https://github.com/nvm-sh/nvm#usage
27-
- Terraform
28-
- Yarn -> npm install --global yarn
29-
- TFCDK -> npm install --global cdktf-cli@latest -- WARNING required NODE 16.13
30-
31-
Optional
34+
#### Optional
3235

3336
- For macOS get graphviz for the diagrams to work
34-
- brew install graphviz
35-
- Granted https://granted.dev/
36-
- brew tap common-fate/granted
37-
- brew install granted
38-
- granted registry add https://github.com/contino/apac-scaffolding-granted-registry.git/granted.yml
37+
- brew install graphviz
38+
- [Granted](https://granted.dev/)
39+
- brew tap common-fate/granted
40+
- brew install granted
41+
- granted registry add https://github.com/contino/apac-scaffolding-granted-registry.git/granted.yml
3942

4043
### Start of the day
4144

@@ -45,7 +48,7 @@ Optional
4548

4649
`make local`
4750

48-
### Make Commands
51+
### General Make Commands
4952

5053
- `make local` setup local environment and install dependencies.
5154
- `make docs-run` install, build and run a dev version of the docs.
@@ -55,114 +58,38 @@ Optional
5558
- `make destroy` destroys the both infra & Grafana with TF CDK.
5659

5760
Testing is split into four commands:
61+
5862
- `make unittest` runs all the unit tests (i.e. tests that are not [marked as integration](https://docs.pytest.org/en/7.1.x/example/markers.html)).
5963
- `make integration-test` run all the integration tests.
6064
- `make test` runs all the tests and reports on coverage.
6165
- `make e2e` runs the end to end BDD tests using [behave](https://github.com/behave/behave).
66+
- `make watch` runs all the unit tests on file change. Allowing the test code while making live changes.
6267

68+
### Merging changes
6369

64-
### Testing from console
65-
66-
After you deploy your infrastructure you can interact with the eventbridge on AWS by sending different messages by running the following from the 'infra_aws_cdk' folder:
67-
68-
- Send Project requested event
69-
- `aws events put-events --entries file://./tests/events/test-eventR.json`
70-
- Send Project assigned event
71-
- `aws events put-events --entries file://./tests/events/test-eventA.json`
72-
- Send Project created event
73-
- `aws events put-events --entries file://./tests/events/test-eventC.json`
74-
70+
At the current time there are no branch protections. However, as the build process creates a commit for every build, to keep the git history clean, please `rebase/squash` your commits before pushing. You can do this by running `git fetch origin main && git rebase -i origin/main`, `edit`ing the first commit, and applying `fixup` to all following commits.
7571

7672
### Code Structure
7773

7874
The code is structured in the [Clean Architecture](https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html) pattern.
7975

8076
![Clean Architecture](images/CleanArchitecture.jpeg)
8177

82-
The current layers are:
83-
84-
1. `Entities`, which contains domain objects
85-
2. `Usecases`, which orchestrate domain objects
86-
3. `Adapters`, which convert events and data into known types
87-
4. `Drivers`, which interact with data storage
88-
5. `Entrypoints`, which handle the event from AWS, retrieve and store data through drivers and call adapters to perform the needed business logic
89-
9078
The core rule of Clean Architecture, is that a layer can only depend on the layers that have come before it. E.g. code in the `usecases` layer, may depend on `entities`, but cannot depend on `adapters` or `drivers`.
9179

9280
When developing, it is simplest to start at the first layer and work down ending up with the entrypoint. This forces you to focus on the domain objects first before considering external services.
9381

94-
### Deploying a change
95-
96-
- Assume the correct AWS account/refresh credentials
97-
- Synth, plan and deploy both infra & Grafana Dashboard.
98-
- `make build`
99-
- `make plan`
100-
- `make deploy`
101-
102-
### Managing Grafana API Keys
103-
104-
While writing this, Grafana API Keys are valid for maximum 30 days only.
105-
Hopefully, Amazon will address this limitation in the future - but in the meantime, this simple pattern can be used to automatically rotate an API key every 29 days and store it for use in AWS Secrets Manager.
106-
107-
![Grafana](images/manage_grafana_api_key.png)
108-
109-
110-
The solution is made up of two components:
111-
112-
1. AWS Secret is created with a rotation lifecycle policy that will trigger a Lambda function every 29 days
113-
2. AWS Lambda Function that will create a new API key in Amazon Managed Grafana and update the AWS Secret with the new key
114-
115-
116-
Python code handling the rotation is stored at `src/entrypoint/grafana_lambda.py`. The code expects two input variables to retrieve secret values from AWS Secrets Manager viz. `grafana_api_key_name` and `grafana_workspace_id`. As the name suggest these values are secret names being used as filters.
117-
118-
119-
### Merging changes
120-
121-
At the current time there are no branch protections. However, as the build process creates a commit for every build, to keep the git history clean, please `rebase/squash` your commits before pushing. You can do this by running `git fetch origin main && git rebase -i origin/main`, `edit`ing the first commit, and applying `fixup` to all following commits.
122-
123-
# How to create a new metric?
124-
125-
1. First of all, you need to define a SLO. In this example we will work with 2 SLO's. These SLO's are related to creation of a "project" at a client.
126-
127-
- "time taken between requesting a project and assigning the request to be executed"
128-
- "time taken between requesting a project and finally creating the project"
129-
130-
2. Next you need to understand the "process" for "creating a project". This includes actors, systems, and automation that contributes to creation of a "project" from start to end. From the process diagram we need to identify the events that are associated each component of the "process". "Event" in the process should have minimum the following fields
131-
132-
- `aggregate_id`: this is id to all events that is part of an instantioantion of a process. For example, when one requests, assigns, and creates a project all the events will have the same correlation id.
133-
- `event_type`: this is the type of event, this can be any string representing what happened.
134-
- `event_version`: this is the version of the event.
135-
- `time`: time when the event happened
136-
- (Optional) `payload`: Any other detail one needs to add to the event for additional needs.
137-
138-
3. Map the event to entities by creating a python file for entities under code/src/entities. See for example the projects.py for entities. Entities come in two form:
139-
140-
- Event Entites: corresponding to the events of the domain
141-
- Metric Entities: corresponding to the SLO's you have defined in step 1
142-
143-
![See diagram](images/processDiagram.png)
144-
145-
4. Calculation of metrics are handled in the usescases. Insert a new use case under code/src/usecases that calculates the metric you are after. You can see the example how the project creation metrics are calculated in the projects.py.
146-
147-
5. Controller is where you covert external message to "entity". It delegates the metric handling to "usecases" above. you can find the controller at code/src/adapters folder
148-
149-
6. Once you have finised the entites, usecases, and adaptors it is time to build the external layers. First one is the driver layer where events are stored. Drivers are implemented based on the choice of cloud environment. you can see two examples one being the bigquery and the other is DynamoDB+TimesStream. these dirvers interact with the actual DB that stores the entities and metrics to be used. This layer also contains the UI where the metrics are shown.
150-
151-
7. One last code is needed to provide an entry point to the system. This is the part where platform message comes in and every part of the system is orchestrated.
152-
153-
![See diagram](images/UMLdiagram.png)
154-
155-
156-
### Manage Grafana Dashboards
157-
158-
TF CDK is used to build and modify Grafana dashboard and the panels that goes inside dashboard. Dashboard configuration is magnaged via `dashboard.json` located within the `infrastructure` folder.
159-
160-
16182
# Roadmap
16283

16384
- [ ] Update integration and automation tests
16485
- [ ] Create Dockerized lambda code for product creation metric
16586

166-
# Questions
87+
# Frequently Asked Questions
88+
89+
- How do I create a new metric?
90+
- [README.md](src/README.md#how-to-create-a-new-metric)
91+
- How do I update the Grafana Panels?
92+
- TF CDK is used to build and modify Grafana dashboard and the panels that goes inside dashboard. Dashboard configuration is managed via `dashboard.json` located within the `infrastructure` folder. Export the new configuration from grafana after making your changes, now update the dashboard.json with the updated configuration.
16793

168-
- How can I use the timestream with the hosted grafana?
94+
- How do I update the Event Docs?
95+
- [README.md](docs/README.md)

docs/README.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,27 @@
1-
# My Event Catalog
1+
<h1 align="center">Flight Controller - Event Catalog</h1>
2+
<p align="center">Documentation for Flight Controller's Events</p>
3+
4+
## Link
5+
6+
[Flight Controller Event Catalog](https://legendary-spoon-f82c1640.pages.github.io)
7+
8+
## Documentation Structure
9+
10+
- Event Domains (EG. Account, Backup, Guardrail): `domains/`
11+
- Domain Events (EG. AccountCreated, AccountRequested): `domains/${DOMAIN}/events/`
12+
- Event Services (Account Vending Machine, Flight Controller): `services/`
13+
14+
## Development
15+
16+
Making changes to the Event Catalog Documentation is pretty straight forward. You will need to add and update the relevant files within the 3 folders listed above. See others for examples.
17+
More info in the official Event Catalog [documentation](https://www.eventcatalog.dev/docs/introduction).
18+
19+
### Running Locally
20+
21+
`make docs_run`. This can be useful to confirm your changes.
22+
23+
### Make Commands
24+
25+
- `make docs_install` (npm install) Will install all NPM requirements
26+
- `make docs_build` (npm install & npm run build) Will build the Event Catalog and output to the folder `docs/out`. This is used to confirm you changes are valid.
27+
- `make docs_run` (npm install & npm run build & npm run dev) Will run a local dev instance of the site, so you can see you changes.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"Source": "contino.custom",
3+
"DetailType": "Account Created",
4+
"Detail": {
5+
"event_type": "account_created",
6+
"aggregate_id": "123456789",
7+
"time": "1679368469"
8+
},
9+
"EventBusName": "main_lambda_bus_cdktf"
10+
}

docs/domains/Account/events/AccountCreated/examples/example.json

Lines changed: 0 additions & 12 deletions
This file was deleted.

docs/domains/Account/events/AccountCreatedLeadTime[Metric]/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,8 @@ owners:
99
- josharmi
1010
---
1111

12+
## <u>Details</u>
13+
14+
Flight Controller looks at the last pertinent account requested event and calculates the time from it being requested to created.
15+
1216
<NodeGraph title="Consumer / Producer Diagram" />
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"Source": "contino.custom",
3+
"DetailType": "Account Deleted",
4+
"Detail": {
5+
"event_type": "account_deleted",
6+
"aggregate_id": "123456789",
7+
"time": "1679368469"
8+
},
9+
"EventBusName": "main_lambda_bus_cdktf"
10+
}

docs/domains/Account/events/AccountDeleted/examples/example.json

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"Source": "contino.custom",
3+
"DetailType": "Account Requested",
4+
"Detail": {
5+
"event_type": "account_requested",
6+
"aggregate_id": "123456789",
7+
"time": "1679368469"
8+
},
9+
"EventBusName": "main_lambda_bus_cdktf"
10+
}

0 commit comments

Comments
 (0)