Skip to content

Commit

Permalink
Fixed eventbridge size limit issue and ops central number of ops data…
Browse files Browse the repository at this point in the history
… items issue
  • Loading branch information
eamonnfaherty committed Oct 21, 2022
1 parent 2a229d8 commit 0283b77
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 24 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

[tool.poetry]
name = "aws-service-catalog-puppet"
version = "0.197.1"
version = "0.198.0"
description = "Making it easier to deploy ServiceCatalog products"
classifiers = ["Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "Programming Language :: Python :: 3", "License :: OSI Approved :: Apache Software License", "Operating System :: OS Independent", "Natural Language :: English"]
homepage = "https://service-catalog-tools-workshop.com/"
Expand Down
3 changes: 3 additions & 0 deletions servicecatalog_puppet/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,3 +341,6 @@

PREPARE_ACCOUNT_FOR_STACKS = "prepare-account-for-stacks"
CREATE_POLICIES = "create-policies"


PARAMETERS_TO_TRY_AS_OPERATIONAL_DATA = ["puppet_account_id", "account_id", "region", "task_reference"]
56 changes: 34 additions & 22 deletions servicecatalog_puppet/workflow/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,8 @@ def run_tasks(
if should_use_eventbridge:
entries.append(
{
# 'Time': ,
"Source": constants.SERVICE_CATALOG_PUPPET_EVENT_SOURCE,
"Resources": [
# 'string',
],
"DetailType": result.get("task_type"),
"Detail": result_contents,
Expand All @@ -344,11 +342,13 @@ def run_tasks(
operational_data = dict(
codebuild_id=dict(Value=codebuild_id, Type="SearchableString")
)
for param_name, param in params.items():
operational_data[param_name] = {
"Value": json.dumps(param, default=str),
"Type": "SearchableString",
}

for param_name in constants.PARAMETERS_TO_TRY_AS_OPERATIONAL_DATA:
if params.get(param_name):
operational_data[param_name] = {
"Value": json.dumps(params.get(param_name), default=str),
"Type": "SearchableString",
}
description = "\n".join(result.get("exception_stack_trace"))[-1024:]
ssm_client.create_ops_item(
Title=title,
Expand Down Expand Up @@ -379,21 +379,7 @@ def run_tasks(
config.get_puppet_role_arn(current_account_id),
f"{current_account_id}-{config.get_puppet_role_name()}",
) as events:
batches = [
entries[
i
* constants.EVENTBRIDGE_MAX_EVENTS_PER_CALL : (i + 1)
* constants.EVENTBRIDGE_MAX_EVENTS_PER_CALL
]
for i in range(
(
len(entries)
+ constants.EVENTBRIDGE_MAX_EVENTS_PER_CALL
- 1
)
// constants.EVENTBRIDGE_MAX_EVENTS_PER_CALL
)
]
batches = generate_batches(entries)
for batch in batches:
events.put_events(Entries=batch)
time.sleep(1)
Expand Down Expand Up @@ -432,6 +418,32 @@ def run_tasks(
sys.exit(0)


def generate_batches(entries):
batches = list()
current_batch = list()
batches.append(
current_batch
)
current_batch_size = 0
batch_size_limit = 256000
for e in entries:
current_entry_size = sys.getsizeof(e.get("Source"))
current_entry_size += sys.getsizeof(e.get("DetailType"))
current_entry_size += sys.getsizeof(serialisation_utils.json_dumps(e.get("Detail")))

if current_batch_size + current_entry_size > batch_size_limit or len(current_batch) >= 10:
current_batch_size = 0
current_batch = list()
batches.append(
current_batch
)

current_batch.append(e)
current_batch_size += current_entry_size

return batches


def run_tasks_for_bootstrap_spokes_in_ou(tasks_to_run, num_workers):
for result_type in [
"start",
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@

setup_kwargs = {
'name': 'aws-service-catalog-puppet',
'version': '0.197.1',
'version': '0.198.0',
'description': 'Making it easier to deploy ServiceCatalog products',
'long_description': '# aws-service-catalog-puppet\n\n![logo](./docs/logo.png) \n\n## Badges\n\n[![codecov](https://codecov.io/gh/awslabs/aws-service-catalog-puppet/branch/master/graph/badge.svg?token=e8M7mdsmy0)](https://codecov.io/gh/awslabs/aws-service-catalog-puppet)\n\n\n## What is it?\nThis is a python3 framework that makes it easier to share multi region AWS Service Catalog portfolios and makes it \npossible to provision products into accounts declaratively using a metadata based rules engine.\n\nWith this framework you define your accounts in a YAML file. You give each account a set of tags, a default region and \na set of enabled regions.\n\nOnce you have done this you can define portfolios should be shared with each set of accounts using the tags and you \ncan specify which regions the shares occur in.\n\nIn addition to this, you can also define products that should be provisioned into accounts using the same tag based \napproach. The framework will assume role into the target account and provision the product on your behalf.\n\n\n## Getting started\n\nYou can read the [installation how to](https://service-catalog-tools-workshop.com/30-how-tos/10-installation/30-service-catalog-puppet.html)\nor you can read through the [every day use](https://service-catalog-tools-workshop.com/30-how-tos/50-every-day-use.html)\nguides.\n\nYou can read the [documentation](https://aws-service-catalog-puppet.readthedocs.io/en/latest/) to understand the inner \nworkings. \n\n\n## Going further\n\nThe framework is one of a pair. The other is [aws-service-catalog-factory](https://github.com/awslabs/aws-service-catalog-factory).\nWith Service Catalog Factory you can create pipelines that deploy multi region portfolios very easily. \n\n## License\n\nThis library is licensed under the Apache 2.0 License. \n \n',
'author': 'Eamonn Faherty',
Expand Down

0 comments on commit 0283b77

Please sign in to comment.