Skip to content

Commit 4da87c2

Browse files
authored
Merge pull request #15 from LBHackney-IT/content-migration
Migrate content from sites that form playbook
2 parents 72bcdc4 + aa32c42 commit 4da87c2

File tree

324 files changed

+12198
-84
lines changed

Some content is hidden

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

324 files changed

+12198
-84
lines changed

docs/api-playbook/11-faqs.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Frequently Asked Questions
2+
3+
## How can I find Base URLs for APIs?:
4+
5+
You can do this by looking up the API in AWS API Gateway.
6+
1. Go to the relevant [AWS Account](https://d-936715b9ec.awsapps.com/start#/) that the API is deployed to;
7+
2. Choose "API Gateway" under "Services" in AWS;
8+
3. Click on your API;
9+
4. Click on "Stages";
10+
5. Choose the stage you want to use;
11+
6. Now you can see the entire URL inside a blue box on the top with the heading "Invoke URL";
12+
13+
## How do I find out whether an API is healthy?:
14+
15+
You can utilise AWS Canaries, which we use for uptime monitoring.
16+
1. Go to the relevant [AWS Account](https://d-936715b9ec.awsapps.com/start#/) that the API is deployed to;
17+
2. Choose “CloudWatch” under “Services” in AWS;
18+
3. Click on “Synthetics Canaries” in the sidebar (under “Application Monitoring”);
19+
4. This will list all of the canaries and their statuses;
20+
21+
To see more information about canaries and how to set them up, visit the relevant page [here](../DevOps practices/Monitoring/uptime_monitoring).
22+
23+
## Where do I find my token to use to authenticate access to APIs?:
24+
25+
1. Visit the [Hackney Authentication Service](https://auth.hackney.gov.uk/auth?redirect_uri=https://auth.hackney.gov.uk/auth/check_token) website to check your Hackney JWT token. You may need to log in during this;
26+
2. Inspect your cookies to find the `hackneyToken` cookie. This will depend on your browser. See [here](https://cookie-script.com/documentation/how-to-check-cookies-on-chrome-and-firefox) for instructions on how to find cookies on Google Chrome or Firefox;
27+
3. Add this token value to the `Authorization` header in all API requests. This will allow you to authenticate access to Hackney APIs;
28+
29+
## How do I find the authentication process used for an API?:
30+
31+
You can do this by looking up the API in AWS API Gateway.
32+
1. Go to the relevant [AWS Account](https://d-936715b9ec.awsapps.com/start#/) that the API is deployed to;
33+
2. Choose "API Gateway" under "Services" in AWS;
34+
3. Click on your API;
35+
4. Click on "Resources" and select **`/{proxy+}`**. This is the API endpoint;
36+
5. This will bring up a box that looks like this:
37+
![API Authorization](./doc-images/api_authorisation.png)
38+
- If it says `Authorization: Custom`, that means this API uses a lambda authoriser;
39+
- If it says `API Key: Required`, this means that this API uses an API key;
40+
41+
## Where do I find the API Key value from?:
42+
43+
This can be found through API Gateway.
44+
1. Go to the relevant [AWS Account](https://d-936715b9ec.awsapps.com/start#/) that the API is deployed to;
45+
2. Choose "API Gateway" under "Services" in AWS;
46+
3. Choose “API Keys” from the sidebar;
47+
4. This will bring up a list of API Keys. Choose the relevant API Key, select the blue ‘Show’ link, and you will see the API Key value;
48+
49+
## How can I access our CircleCI Pipelines?:
50+
51+
Visit [https://app.circleci.com/pipelines/github/LBHackney-IT](https://app.circleci.com/pipelines/github/LBHackney-IT) to view workflows from projects you follow at Hackney.
52+
53+
If you aren't subscribed to any projects, simply navigate to the'projects' tab on the sidebar to view and search for all Hackney projects.
54+
55+
![Circle CI Sidebar - Click on the second icon (projects) to view all projects in a workspace](./doc-images/CircleCI_sidebar.png)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
position: 8
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# Setting Up AWS DMS
2+
3+
# What is AWS DMS?:
4+
5+
AWS Data Migration Service (DMS) is a service that allows us to migrate data between a source (in our case, on-premises database) and a target (in our case, Postgres database hosted in AWS).
6+
## DMS supported replication types:
7+
8+
- **Continuous replication (CDC)**:
9+
* When we want to do a one-off migration of all data and then continuously capture new inserts, updates and deletes and reflect them in our target database.
10+
11+
- **One-off data migration**:
12+
* When the goal is to migrate all data from a source, and is expected that changes will not be captured and reflected.
13+
14+
15+
# Which AWS DMS set up to use?:
16+
17+
## For continuous migration:
18+
19+
### CDC:
20+
21+
CDC is a SQL server feature, available only on Enterprise and Developer editions.
22+
23+
It allows for changes to be captured (inserts/updates/deletes).
24+
25+
#### Use case:
26+
27+
When the source database does not have primary keys and you want to migrate data continuously.
28+
29+
### MS Replication:
30+
31+
MS Replication is a SQL server feature available on all editions.
32+
33+
It creates a “distribution” database and every time there is a change, it is captured and stored in the “distribution” database.
34+
35+
.MS will then read from that database to reflect the changes in the target database.
36+
37+
**Note:** The sql user created must have **sysadmin** permissions to set up replication.
38+
39+
**Additional notes:** Configuration on the source database is required (please see below section). Additionally, SQL servers DO NOT come with MS replication features pre-installed, so the server might require a set up.
40+
41+
#### Use cases:
42+
43+
- When you want to migrate data continuously;
44+
45+
- When the SQL server is not Enterprise/Developer edition;
46+
47+
- When the source database has tables, which make use of primary keys;
48+
49+
## For one-off set up:
50+
51+
- No database configuration is required;
52+
53+
- The sql user must have at least db_owner permissions;
54+
55+
- The replication runs ones and migrates the data specified;
56+
57+
- There are no subsequent runs of the migration task, unless triggered with other means;
58+
59+
### Use cases:
60+
61+
1. When only a one-off migration is required;
62+
63+
2. When the underlying source database is a reporting server and there are no possible ways to capture updates. In this scenario, we need to daily run a one-off migration, after the reporting server was updated with the latest data;
64+
65+
66+
# How to set up DMS:
67+
68+
## Database set up:
69+
70+
- [DMS with SQL CDC](https://docs.google.com/document/d/1EaZ-a8ejQwWQ40OGDGobxhTqtxXvtX9Ydk5mTFASUMo/edit).
71+
72+
- [DMS with MS Replication](https://docs.google.com/document/d/14kNirloRWXCnla08brXiTihCMIm24chygc1lGUjNVbE/edit?usp=sharing).
73+
74+
## AWS DMS set up via Terraform:
75+
76+
Both DMS and Postgres can be created via Terraform.
77+
### DMS:
78+
79+
[Template repository and example usage](https://github.com/LBHackney-IT/aws-dms-terraform).
80+
81+
82+
![DMS example usage](../doc-images/data_migration.png).
83+
84+
85+
**Notes:**:
86+
87+
- Follow the example usage, which also demonstrates how to add table mappings (specifying which tables are to be replicated);
88+
89+
- The source DB server should be specified with IP and not the server name;
90+
91+
- DMS instance should be in the VPC, where the VPN is set up to ensure communication to on-prem is possible;
92+
93+
- <u> Make sure your DMS instance’s subnet group has only private subnets in it! </u>;
94+
### Postgres:
95+
96+
[Template repository and example usage](https://github.com/LBHackney-IT/aws-hackney-common-terraform/tree/master/modules/database/postgres)
97+
98+
![PostgreSQL example usage](../doc-images/data2.png)
99+
100+
**Notes:**:
101+
102+
- DMS does not support Postgres version 12, so use version 11 or older;
103+
- Always store passwords in parameter store and do not hardcode them;
104+
- “Multi_az” should be true for production databases;
105+
- “subnet_ids” requires subnets in 2 different AZs. Make sure those are private subnets to ensure that the database is secure;
106+
- Currently not terraformed: To enable traffic from DMS to your Postgres instance, ensure you add to the ingress rules of the database’s security group all traffic from DMS security group;
107+
108+
![AWS console](../doc-images/data3.png)
109+
110+
111+
## Data migration using a data pipeline:
112+
113+
** What is a data pipeline? **
114+
115+
A data pipeline is an automated flow that gets data stored in one location (source) and uploads it to a target destination.
116+
117+
### Data pipeline - CSV to Postgres:
118+
119+
As of 26/06/2020, we have implemented one data pipeline.
120+
121+
The pipeline takes data uploaded in an S3 bucket in .csv format and uploads the data into a Postgres database.
122+
123+
![Data pipelines](../doc-images/data4.png)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Data Pipeline Implementation
2+
3+
## S3:
4+
5+
The source S3 bucket has been configured to invoke a Lambda function when a file has been uploaded with extension `.csv`.
6+
7+
![S3 Bucket](../doc-images/data5.png)
8+
9+
The configuration for the source S3 bucket is done using the pipeline’s serverless implementation - <u> no manual set up is required for events </u>.
10+
11+
![S3 configuration](../doc-images/data6.png)
12+
13+
## Lambda:
14+
15+
The lambda function implements the following:
16+
17+
- Receives S3 notifications;
18+
- Retrieves bucket and file details from the notification;
19+
- Truncates the target table in the target database;
20+
- Makes use of AWS Postgres function that copies data from an csv file in S3 to Postgres to migrate the data;
21+
- Logs any exceptions and errors to Cloudwatch;
22+
23+
** Note: The Postgres database and table to match the CSV format needs to be created separately. **
24+
25+
## How to set up the data pipeline for a project:
26+
27+
[Template repository for the data pipeline code implementation](https://github.com/LBHackney-IT/s3-to-postgres-data-pipeline)
28+
29+
1. Create a repository for your pipeline by using the above template;
30+
2. Update the code by replacing the names of the existing pipeline to the name of your project’s pipeline;
31+
3. Ensure you populate the specified environment variables in the README file of the repository;
32+
4. Deploy using serverless - this will deploy the Lambda and it will set up an existing S3 bucket with the event it needs to listen for;
33+
34+
** Notes **
35+
36+
- You need to create the S3 bucket separately and provide the name in the serverless.yml file of the pipeline repository;
37+
- You need to create the Postgres separately and create the table that will be the “target” with the same columns as the ones expected to be present in the .csv that will be uploaded to S3;
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Alerting
2+
3+
## Application monitoring and alerting:
4+
5+
In Hackney, we use AWS CloudWatch to implement monitoring and alerting.
6+
7+
Any logs created in our APIs are recorded and accessible in AWS CloudWatch. Creation of log groups is automated via the current serverless setup.
8+
## Metric filters:
9+
10+
### Filter and Pattern Syntax:
11+
12+
13+
Metric filters are a useful feature that allows you to find patterns and terms in your logs. Following the logging standards identified earlier in this document, metric filters can be created to easily identify logs related to a certain phrase or term like `ERROR`.
14+
15+
Using the filters, developers can easily narrow down the logs they see to only the ones related to any error that has occurred, hiding all other logs such as ones for successful requests.
16+
17+
CloudWatch also provides a way to create alarms based on metric filters, so we can get notified if a log with matching a certain pattern/term has occurred.
18+
19+
### Metric filters that should be created per API:
20+
21+
TBC;
22+
23+
_Needs to be filters we want commonly available for each API_
24+
25+
### Alarms should be created for the following metric filters:
26+
27+
TBC;
28+
29+
_Need to decide which logs should have an alarm associated with them_
30+
31+
## Availability monitoring and alerting:
32+
33+
We use AWS CloudWatch Canaries to monitor the availability of our APIs and front-end applications.
34+
35+
## AWS CloudWatch Canaries:
36+
37+
### AWS Canaries for APIs:
38+
39+
- Set to run every 5 mins;
40+
41+
- A canary invokes an API endpoint to check it’s availability;
42+
43+
- Needs to be set up per API endpoint to ensure all endpoints provided by an API are functioning as expected;
44+
45+
- The current creation process for a canary is **manual**;
46+
47+
[See the guidance for Canaries here](./uptime_monitoring.md)
48+
49+
### AWS Canaries for front end applications:
50+
51+
- Can monitor the availability of a web page;
52+
53+
- Alarms can be set to alert if availability of a given web page falls down;
54+
55+
- Logs recorded can be used to identify performance issues associated with loading a specific item;
56+
57+
- Can check for broken links;
58+
59+
- A max number of links to follow is set up;
60+
61+
- The canary crawls through the links and returns the first broken link identified;
62+
63+
## AWS CloudWatch Alarms:
64+
65+
We also use CloudWatch alarms to monitor for specific events in the log streams.
66+
67+
Specific metrics can be established as triggers on application logs which can fire off alerts in the form of emails or other messaging mediums. We can create up to 5000 alarms per region per account which should give us sufficient capacity.
68+
69+
It may also be possible to consolidate these alarms if we have a standard format for logs (this may also be achievable by creating composite alarms but uses up available alarms.
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Application Logging Guidelines
2+
3+
## Introduction:
4+
5+
This document defines a set of guidelines used to produce rich application logging for applications belonging to a microservice architecture.
6+
Providing rich logging information will make it easier to investigate issues without making use of intrusive approaches (i.e: debug, memory dump), also making visible the behaviour of services by using monitoring tools to extract and/or query these logs.
7+
## Categories:
8+
9+
### Application:
10+
11+
Logs related to the application behaviour that does not result into exceptions and would not be visible externally if not logged. Common scenarios are conditional behaviours that will generate different outputs based on the contents of the command or state of the resource being manipulated. Application logs should be the only log level required within the application and must be used with caution to avoid excessive log entries without value for issues investigation.
12+
### Events:
13+
14+
Events are application notifications used to inform external components that an activity has happened within the application. In some cases the event will let external subscribers know if an operation happened successfully or failed. Every operation will raise at least two types of events, success or failure, but in some cases, it might generate different events based on the context of the operation. All events raised by an application are logged by the infrastructure components, so adding a log information to notify an event has happened is not required and will make the logging redundant.
15+
### Exceptions:
16+
17+
Exceptions is an execution flow mechanism used to interrupt the current processing flow either because, the application or one of it’s dependent components behaved unexpectedly and can’t proceed, or an application logic is aware it can’t proceed because doing so will/may cause issues. All exceptions raised by an application or it’s dependencies are logged by the infrastructure components, so adding a log information to notify an exception has happened is not required and will make the logging redundant.
18+
### Tracing and Context Correlation:
19+
20+
Whether an application executes a task successfully or not is often highly dependent on the input from the user. As a result, this contextual information may be vital when trying to diagnose a fault.
21+
22+
This can be achieved by setting a property of your logging platform during the startup of a component.
23+
This allows to view the unified stream of "events", but also to segregate per role when required to troubleshoot an individual component.
24+
Every operation in an application is initiated by a trigger either externally or internally (synchronous processing). In general, these triggers do not have visibility of the behaviour for each service, and just expect a result as output from a request.
25+
In many cases, these operations may trigger operations into dependent services to accomplish the initial operation. These chain of events need to be correlated in order to identify possible failures or for auditing purposes. For this reason, enter into scene the CorrelationId and TracingContext.
26+
## Correlation Id:
27+
28+
In order to identify any operation executed across different components and layers but that are part of the same context, there should be a correlationId sent from the client triggering the operation.
29+
CorrelationId is a global unique identifier (GUID) attribute provided by callers (or auto-generated when one is not provided) to identify the chain of calls between services.
30+
For instance, an HTTP client should send a correlationId header for every call. The downstream systems should pass along this correlationId to any downstream layer so that all traces/logs can be identified as part of the same operation.
31+
### Tracing Context:
32+
33+
Tracing Context is the name given to the correlated chain of calls that happened from an initial trigger until it reached the current state. By default the Tracing Context will be using the CorrelationId to identify all events raised since the first trigger initiate the operation.
34+
Currently, the correlation identify the events in a chronological order and events happening in parallel on separate services will be mixed up.
35+
36+
** Additional Attributes to Consider (Custom Dimensions) **
37+
38+
| Attribute Name | Attribute Name | Attribute Name | Attribute Name |
39+
| -------------- | -------------- | -------------- | -------------- |
40+
| Domain * | Application Instance | tenure | Domain name which the service belongs to |
41+
| Service * | Application Instance | tenure-listener / tenure-api | The service name generating the logs |
42+
| Environment * | Application Instance | dev | Environment name |
43+
| Version * | Application Instance | 1.2.345 | Semantic Version Number |
44+
| CorrelationId * | Per Operation | 3fa85f64-5717-4562-b3fc-2c963f-66afa6 | Id used to chain events and logs executed by multiple operations |
45+
| OperationId | Per Operation | 3fa85f64-5717-4562-b3fc-2c963f-66afa6 | Unique Id that identifies one occurrence of the operation i.e: Requestid |
46+
| OperationName | Per Operation | Update Tenure | Name of operation being executed |
47+
| UserId | Per Operation | KJS827HJS88S | Id of user triggering the operation |
48+
| Logger(SourceContext) | Per Log Entry | Company.Solution.ClassName | Name of component or class generating the logs. |
49+
| ResourceId | Per Log Entry | tenure-12345 | When an operation is being executred in the context of an existing resource (i.e. a repair) the logs should make the id of the order being modified available. |
50+
51+
** NOTE: **
52+
Attributes marked with a * indicate _high importance_.
53+
## Scopes:
54+
55+
### Application Instance:
56+
57+
Each deployed instance of an application will provide the same log attributes to all log entries generated. It does not change in the scope of the operations generating
58+
the logs.
59+
### Per Operation:
60+
61+
When an operation is started (API request, message from a Queue), the attributes will be set and used throughout the chain of calls using the same attributes. It does not change based on the context within the application. In case the value does not come from external calls, should be generated internally.
62+
### Per Log Entry:
63+
Each class or logger will have it’s own set of attributes used within it’s context to identify the source component that is generating the logs. i.e: The class name writing to the logs, the Resource Id being manipulated, or any data available only in the context of the logger.
64+
## Filters and Masking:
65+
66+
### Filters:
67+
68+
- To reduce the high volume of log entries, the applications should add the following log filters:
69+
- Filter out healthcheck logs (keep errors);
70+
- Limit the log level to;
71+
- Non production environments = Information;
72+
- Production environments = Warning;
73+
- Don't let ASP.NET Core Console Logging Slow your App down;
74+
- Logging in .NET Core and ASP.NET Core;
75+
### Masking:
76+
77+
Prevent log entries containing Personal Identifiable Information (PII) by removing the attributes, or, masking part of the value.

0 commit comments

Comments
 (0)