Skip to content

Commit 7de117b

Browse files
authored
Issues/173 (#182)
* issues/173: changed default resource names to allow multiple deployments. BREAKING CHANGE, requires migrating using the new module inputs (see readme) * issues/181: Added retry logic for Harmony jobs that fail with 5xx errors
1 parent 02f9d68 commit 7de117b

12 files changed

Lines changed: 147 additions & 10 deletions

File tree

.github/workflows/cicd-pipeline.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,13 @@ jobs:
309309
terraform init -backend=false -upgrade
310310
terraform validate -no-color
311311
312+
- name: Log in to the Container registry
313+
uses: docker/login-action@v3
314+
with:
315+
registry: ${{ env.REGISTRY }}
316+
username: ${{ github.actor }}
317+
password: ${{ secrets.GITHUB_TOKEN }}
318+
312319
- name: Deploy to venue
313320
id: terraform-deploy
314321
working-directory: examples/cumulus-tf

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99
### Added
1010
- [issues/150](https://github.com/podaac/bignbit/issues/150): Added support for mixed NRT & Standard collections with configurable regex.
1111
### Changed
12+
- [issues/173](https://github.com/podaac/bignbit/issues/173): Changed resource names (e.g. ECR repo name) to include deployment level prefixes. This allows for deploying multiple copies of bignbit to a single AWS account/venue.
1213
- Removed MD5 checksum hash computation to optimize performance of `handle_big_result` lambda.
1314
### Deprecated
1415
### Removed
1516
### Fixed
1617
- [issues/83](https://github.com/podaac/bignbit/issues/83): Use "_" instead of ":" in CNM filenames for Mac and Linux compatibility
18+
- [issues/181](https://github.com/podaac/bignbit/issues/181): Auto-retry logic for Harmony jobs that fail with transient server errors (5xx errors)
1719
### Security
1820
- [issues/151](https://github.com/podaac/bignbit/issues/151): Added ExpectedBucketOwner parameter when making S3 requests.
1921

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ This module uses the following input variables:
115115
| app_name | string | | "bignbit" |
116116
| default_tags | map(string) | | {} |
117117
| lambda_container_image_uri | string | | "" |
118+
| force_delete_ecr | bool | Force delete the ECR repository and all its images on destroy. Set to true when migrating resource names to avoid manual cleanup. | false |
119+
| force_destroy_staging_bucket | bool | Force destroy the staging S3 bucket and all its contents on destroy. Set to true when migrating resource names to avoid manual cleanup. | false |
118120
| harmony_job_status_interval_seconds | number | Interval in seconds for checking Harmony job status | 20 |
119121
| harmony_job_status_max_attempts | number | Maximum number of attempts to check Harmony job status | 15 |
120122
| harmony_job_status_backoff_rate | number | Backoff rate for Harmony job status checks | 1.0 |

bignbit/get_harmony_job_status.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import logging
33
import os
44

5+
import requests
56
from cumulus_logger import CumulusLogger
67
from cumulus_process import Process
78
from harmony import LinkType
@@ -12,6 +13,13 @@
1213
CUMULUS_LOGGER = CumulusLogger('get_harmony_job_status')
1314

1415

16+
class HarmonyTransientError(Exception):
17+
"""Exception raised when the Harmony API returns a transient 5xx error"""
18+
19+
def __init__(self, message):
20+
super().__init__(message)
21+
22+
1523
class HarmonyJobIncompleteError(Exception):
1624
"""Exception raised when a harmony job is not complete"""
1725

@@ -98,12 +106,26 @@ def check_harmony_job(
98106
"""
99107

100108
harmony_client = utils.get_harmony_client(cmr_env)
101-
job_status = harmony_client.status(harmony_job_id)
109+
try:
110+
job_status = harmony_client.status(harmony_job_id)
111+
except requests.exceptions.HTTPError as exc:
112+
if exc.response is not None and exc.response.status_code >= 500:
113+
raise HarmonyTransientError(
114+
f'Harmony API returned a transient error checking status of job {harmony_job_id}: {exc}'
115+
) from exc
116+
raise
102117

103118
# For a successful job, return the status; for all other states, raise an exception.
104119
if job_status.get('status') == 'successful':
105120
# Check that the harmony job returned data to confirm that the job was successful
106-
result_urls = list(harmony_client.result_urls(harmony_job_id, link_type=LinkType.s3))
121+
try:
122+
result_urls = list(harmony_client.result_urls(harmony_job_id, link_type=LinkType.s3))
123+
except requests.exceptions.HTTPError as exc:
124+
if exc.response is not None and exc.response.status_code >= 500:
125+
raise HarmonyTransientError(
126+
f'Harmony API returned a transient error fetching result URLs for job {harmony_job_id}: {exc}'
127+
) from exc
128+
raise
107129
if not result_urls:
108130
error_msg = (
109131
f'Harmony job {harmony_job_id} completed successfully but returned no data for {variable} and {crs}'

examples/cumulus-tf/tfvars/sit.tfvars

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ prefix = "podaac-sit-svc"
66
gibs_region="mocked"
77
gibs_queue_name="mocked"
88
gibs_account_id="mocked"
9+
10+
force_delete_ecr = false
11+
force_destroy_staging_bucket = false

terraform/lambda_functions.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ data "aws_ecr_authorization_token" "token" {}
33
locals {
44
lambda_container_image_uri_split = split("/", var.lambda_container_image_uri)
55
ecr_image_name_and_tag = split(":", element(local.lambda_container_image_uri_split, length(local.lambda_container_image_uri_split) - 1))
6-
ecr_image_name = "${local.environment}-${element(local.ecr_image_name_and_tag, 0)}"
6+
ecr_image_name = "${local.aws_resources_name}-${element(local.ecr_image_name_and_tag, 0)}"
77
ecr_image_tag = element(local.ecr_image_name_and_tag, 1)
88

99
# Truncate all function names to max 64 characters for AWS Lambda
@@ -21,7 +21,8 @@ locals {
2121

2222

2323
resource aws_ecr_repository "lambda-image-repo" {
24-
name = local.ecr_image_name
24+
name = local.ecr_image_name
25+
force_delete = var.force_delete_ecr
2526
}
2627

2728

terraform/main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ locals {
2121

2222
account_id = data.aws_caller_identity.current.account_id
2323

24-
aws_resources_name = terraform.workspace == "default" ? "svc-${var.app_name}-${var.prefix}" : "svc-${var.app_name}-${var.prefix}-${terraform.workspace}"
24+
aws_resources_name = terraform.workspace == "default" ? "${var.prefix}-${var.app_name}" : "${var.prefix}-${var.app_name}-${terraform.workspace}"
25+
sns_topic_name = terraform.workspace == "default" ? "${var.app_name}-${var.prefix}" : "${var.app_name}-${var.prefix}-${terraform.workspace}"
2526

2627
default_tags = length(var.default_tags) == 0 ? {
2728
team : "TVA",

terraform/s3.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ locals {
55
}
66

77
resource "aws_s3_bucket" "bignbit_staging_bucket" {
8-
count = local.create_bucket ? 1 : 0
9-
bucket = "${local.aws_resources_name}-staging"
8+
count = local.create_bucket ? 1 : 0
9+
bucket = "${local.aws_resources_name}-staging"
10+
force_destroy = var.force_destroy_staging_bucket
1011

1112
lifecycle {
1213
ignore_changes = [

terraform/sqs_sns.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ resource "aws_sns_topic_policy" "default" {
2121
}
2222

2323
resource "aws_sns_topic" "gibs_response_topic" {
24-
name = "${local.aws_resources_name}-gibs-response-topic"
24+
name = "svc-${local.sns_topic_name}-gibs-response-topic"
2525
lifecycle {
2626
# GIBS publishes to this topic, so we want to avoid destroying it unless coordinating the change with GIBS
2727
prevent_destroy = true

terraform/state_machine_definition.tpl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,14 @@
338338
"BackoffRate":${HarmonyJobStatusBackoffRate},
339339
"MaxDelaySeconds":${HarmonyJobStatusMaxDelaySeconds}
340340
},
341+
{
342+
"ErrorEquals":[
343+
"HarmonyTransientError"
344+
],
345+
"IntervalSeconds":2,
346+
"MaxAttempts":6,
347+
"BackoffRate":2
348+
},
341349
{
342350
"ErrorEquals":[
343351
"Lambda.ServiceException",

0 commit comments

Comments
 (0)