-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* initial shift to ecs for ebsco adapter * add task definition * remove lambda traces, and add alerting * remove deployment hacks * Apply auto-formatting rules --------- Co-authored-by: Buildkite on behalf of Wellcome Collection <wellcomedigitalplatform@wellcome.ac.uk>
- Loading branch information
Showing
26 changed files
with
605 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FROM python:3.10 | ||
|
||
WORKDIR /app | ||
|
||
ADD src /app | ||
RUN pip install -r requirements.txt | ||
|
||
ENTRYPOINT ["python", "main.py"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Usage: ./run_local.sh <args> | ||
|
||
AWS_PROFILE=platform-developer | ||
|
||
export AWS_PROFILE | ||
|
||
FTP_PASSWORD=$(aws ssm get-parameter --name /catalogue_pipeline/ebsco_adapter/ftp_password --with-decryption --query "Parameter.Value" --output text) | ||
FTP_SERVER=$(aws ssm get-parameter --name /catalogue_pipeline/ebsco_adapter/ftp_server --query "Parameter.Value" --output text) | ||
FTP_USERNAME=$(aws ssm get-parameter --name /catalogue_pipeline/ebsco_adapter/ftp_username --query "Parameter.Value" --output text) | ||
CUSTOMER_ID=$(aws ssm get-parameter --name /catalogue_pipeline/ebsco_adapter/customer_id --query "Parameter.Value" --output text) | ||
FTP_REMOTE_DIR=$(aws ssm get-parameter --name /catalogue_pipeline/ebsco_adapter/ftp_remote_dir --query "Parameter.Value" --output text) | ||
S3_BUCKET=$(aws ssm get-parameter --name /catalogue_pipeline/ebsco_adapter/bucket_name --query "Parameter.Value" --output text) | ||
OUTPUT_TOPIC_ARN=$(aws ssm get-parameter --name /catalogue_pipeline/ebsco_adapter/output_topic_arn --query "Parameter.Value" --output text) | ||
|
||
# Update the S3_PREFIX to be the environment (use dev for local testing) | ||
S3_PREFIX=prod | ||
|
||
export FTP_PASSWORD FTP_SERVER FTP_USERNAME CUSTOMER_ID FTP_REMOTE_DIR S3_BUCKET S3_PREFIX OUTPUT_TOPIC_ARN | ||
|
||
# Ensure the docker image is up to date | ||
docker-compose --log-level ERROR build dev | ||
|
||
docker-compose run dev "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import boto3 | ||
import time | ||
|
||
|
||
class ProcessMetrics: | ||
def __init__(self, process_name: str): | ||
self.process_name = process_name | ||
|
||
def __enter__(self): | ||
self.start_time = time.time() | ||
return self | ||
|
||
def __exit__(self, exc_type, exc_val, exc_tb): | ||
end_time = time.time() | ||
duration = end_time - self.start_time | ||
|
||
if exc_type is not None: | ||
self.put_metric("ProcessDurationFailure", duration) | ||
else: | ||
self.put_metric("ProcessDurationSuccess", duration) | ||
|
||
def put_metric(self, metric_name: str, value: float): | ||
print(f"Putting metric {metric_name} ({self.process_name}) with value {value}s") | ||
boto3.client("cloudwatch").put_metric_data( | ||
Namespace="ebsco_adapter", | ||
MetricData=[ | ||
{ | ||
"MetricName": metric_name, | ||
"Dimensions": [ | ||
{"Name": "process_name", "Value": self.process_name} | ||
], | ||
"Value": value, | ||
"Unit": "Seconds", | ||
} | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
module "cloudwatch_alarm_to_slack_lambda" { | ||
source = "git@github.com:wellcomecollection/terraform-aws-lambda?ref=v1.2.0" | ||
|
||
name = "cloudwatch-alarm-to-slack" | ||
description = "Sends CloudWatch alarms to a Slack channel." | ||
runtime = "python3.10" | ||
|
||
filename = data.archive_file.cloudwatch_alarm_to_slack.output_path | ||
handler = "cloudwatch_alarm_to_slack.lambda_handler" | ||
memory_size = 512 | ||
timeout = 60 // 1 minute | ||
|
||
source_code_hash = data.archive_file.cloudwatch_alarm_to_slack.output_base64sha256 | ||
|
||
error_alarm_topic_arn = data.terraform_remote_state.monitoring.outputs["platform_lambda_error_alerts_topic_arn"] | ||
|
||
environment = { | ||
variables = { | ||
HOOK_URL = aws_ssm_parameter.cloudwatch_alarm_to_slack_hook_url.value | ||
SLACK_CHANNEL = aws_ssm_parameter.cloudwatch_alarm_to_slack_channel.value | ||
} | ||
} | ||
} | ||
|
||
resource "aws_ssm_parameter" "cloudwatch_alarm_to_slack_hook_url" { | ||
name = "/catalogue_pipeline/ebsco_adapter/cloudwatch_alarm_to_slack_hook_url" | ||
description = "The URL of the Slack webhook to send messages to" | ||
type = "String" | ||
value = "placeholder" | ||
|
||
lifecycle { | ||
ignore_changes = [ | ||
value | ||
] | ||
} | ||
} | ||
|
||
resource "aws_ssm_parameter" "cloudwatch_alarm_to_slack_channel" { | ||
name = "/catalogue_pipeline/ebsco_adapter/cloudwatch_alarm_to_slack_channel" | ||
description = "The Slack channel to send messages to" | ||
type = "String" | ||
value = "wc-platform-alerts" | ||
} | ||
|
||
module "cloudwatch_alarm_to_slack_topic" { | ||
source = "github.com/wellcomecollection/terraform-aws-sns-topic.git?ref=v1.0.0" | ||
name = "cloudwatch_alarm_to_slack" | ||
} | ||
|
||
resource "aws_sns_topic_subscription" "cloudwatch_alarm_to_slack_subscription" { | ||
topic_arn = module.cloudwatch_alarm_to_slack_topic.arn | ||
protocol = "lambda" | ||
endpoint = module.cloudwatch_alarm_to_slack_lambda.lambda.arn | ||
} | ||
|
||
resource "aws_lambda_permission" "allow_execution_from_sns" { | ||
statement_id = "AllowExecutionFromSNS" | ||
action = "lambda:InvokeFunction" | ||
function_name = module.cloudwatch_alarm_to_slack_lambda.lambda.function_name | ||
principal = "sns.amazonaws.com" | ||
source_arn = module.cloudwatch_alarm_to_slack_topic.arn | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
resource "aws_cloudwatch_metric_alarm" "ebsco_adapter_no_success_metric" { | ||
alarm_name = "ebsco-adapter-no-success-metric" | ||
comparison_operator = "LessThanThreshold" | ||
evaluation_periods = 1 | ||
metric_name = "ProcessDurationSuccess" | ||
namespace = "ebsco_adapter" | ||
period = 86400 | ||
statistic = "Sum" | ||
threshold = 1 | ||
alarm_description = "No success metrics have been sent in the last 24 hours" | ||
alarm_actions = [module.cloudwatch_alarm_to_slack_topic.arn] | ||
dimensions = { | ||
process_name = "scheduled" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
resource "aws_ecs_cluster" "cluster" { | ||
name = local.namespace | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# This directory contains generated files, ignore the zip files | ||
*.zip |
Oops, something went wrong.