Skip to content

Fixed issue 20 and 22 #23

Merged
merged 1 commit into from
Mar 28, 2022
Merged

Fixed issue 20 and 22 #23

merged 1 commit into from
Mar 28, 2022

Conversation

cho00013
Copy link
Contributor

Issue 20

  1. For all ec2 API calls, added MAX_API_RETRY logic. It was hard to reproduce the problem in my lab, but I added several dummy API commands to trip the limit. Twice I was able to see the limit passed and the logic correctly looped until it was able to handle the issue.
  2. Also added more logging (INFO/ERROR) level in the event where certain activities do not happen.

Issue 22

  1. Modified put_tem_in_dynamodb_table (line 279) portion to write the result after json.dumps instead of performing str(dictionary). This provides a more resilient writing and reading of the data.
  2. Modified get_item_in_dynamodb_table grab the string and them perform json.loads. Also added 7 replace commands to handle any DDB item that were written prior to this change.

Comment on lines +1509 to +1516
# these 7 lines are handling for legacy DDB items created prior how items were written
instance_attribute = instance_attribute.replace("'", '"')
instance_attribute = instance_attribute.replace(" True,", ' "True",')
instance_attribute = instance_attribute.replace(" True}", ' "True"}')
instance_attribute = instance_attribute.replace(" True,", ' "True",')
instance_attribute = instance_attribute.replace(" False,", ' "False",')
instance_attribute = instance_attribute.replace(" False,", ' "False",')
instance_attribute = instance_attribute.replace(" False,", ' "False",')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this instead of the DDB serialization/deserialization calls?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

those are only to cover DDB items created prior to this code change. The DDB serial/deserial code doesn't work for us because the DDB items is just 1 attribute (InstanceAttributes). All of the Instance Attribute is combined into a single string field and written in to the InstanceAttributes, so the code to serialize/deserialize doesn't add anything.

So simple json.dumps and json.loads of the string before and after does the trick to handle the various double quotes, true, True, false, False differences between.

Anyway, those 7 lines above, I kept because there are several (27 currently) DDB items that were written in the "old" method. So to correctly parse them, those 7 lines will/should handle those 27 legacy items.

Any new DDB items will not require those 7 lines (and replace will find nothing to replace) since the string written in the InstanceAttributes field should already be in the correct string format (double quotes and lower case true/false/none). So when performing json.loads, it will handle it better.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we deleted ALL existing 27 items (meaning the associated A/PTR/TXT records were deleted) then we could have taken out the 7 commands above.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanation. This should not be needed in any new implementations, and in theory if we scrub ma8-gov and start fresh, we'd not need them either, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right - if we somehow were able to scrub the 27 existing records, Then yes, the 7 lines above that I have put in, can be "removed". I'm not sure what's the easiest way to scrub these:

All of these of course requires that we update the Lambda with the latest.

  1. Stop and restart the associated ec2 instance(s). This will delete the DDB item and re-create it with the proper formatted.
  2. Manually retrieve the DDB item and reformat the InstanceAttribute field and rewrite it. We can actually run the 7 replace commands and that should do the tricky.

Copy link
Contributor

@badra001 badra001 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

@badra001 badra001 merged commit 0127437 into master Mar 28, 2022
@badra001 badra001 deleted the awspeter_issue22_issue20 branch March 28, 2022 14:39
@badra001
Copy link
Contributor

Closed #20 Closed #22

@cho00013
Copy link
Contributor Author

@badra001, Let's also increase the MAX_API_RETRY from 10 to 15 in the ENV variable. I don't think it should add much longer to the overall run time, but in my testing, I saw it reaching up to 9 so it's possible that we may be close to the limit of 10. I think 15 will add potentially another 1 min to the run time possibly if needed.

@cho00013
Copy link
Contributor Author

@badra001 and one more... enable DEBUG as well.

@badra001
Copy link
Contributor

It's already enabled as debug. This is deployed to the region, so it covers all VPCs in ma8-gov. I will do my instances testing in dev though.

Sign in to join this conversation on GitHub.
Labels
None yet
Projects
None yet
2 participants