[Bps-public-commit] app-aws-cloudwatch-monitor branch 0.03/update-meta-data-caching-writes created. bf14385889a4699ca0ea58731bd419e548e0aabd
BPS Git Server
git at git.bestpractical.com
Thu May 19 19:27:38 UTC 2022
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "app-aws-cloudwatch-monitor".
The branch, 0.03/update-meta-data-caching-writes has been created
at bf14385889a4699ca0ea58731bd419e548e0aabd (commit)
- Log -----------------------------------------------------------------
commit bf14385889a4699ca0ea58731bd419e548e0aabd
Author: Blaine Motsinger <blaine at bestpractical.com>
Date: Thu May 19 13:30:35 2022 -0500
Fix meta-data caching writes
The meta-data cache files are written after every call, regardless
of the TTL variables. This presents a couple issues.
First, the age of the cache files never get older than the time of
the last call, effectively making the TTL time meaningless. This
leads to far too many unnecessary writes to the disk since the
cache files never age.
Second, since the TTL time is not honored, if the special meta-data
mount is incorrectly returning empty string (an issue at AWS or the
mount on the instance), the benefit of relying on a cached value is
lost.
This commit fixes the meta-data cache writes to now only write the
cache file if a value was retrieved from the special mount, which
only happens if the TTL is reached or the cache file doesn't exist
or doesn't contain a value.
diff --git a/lib/App/AWS/CloudWatch/Monitor/CloudWatchClient.pm b/lib/App/AWS/CloudWatch/Monitor/CloudWatchClient.pm
index 21c8845..bdbcaa4 100644
--- a/lib/App/AWS/CloudWatch/Monitor/CloudWatchClient.pm
+++ b/lib/App/AWS/CloudWatch/Monitor/CloudWatchClient.pm
@@ -124,18 +124,22 @@ sub get_meta_data {
my $use_cache = shift;
my $meta_data = read_meta_data( $resource, $meta_data_short_ttl );
- my $base_uri = 'http://169.254.169.254/latest/meta-data';
- my $data_value = !$meta_data ? get $base_uri. $resource : $meta_data;
+ # if we didn't get meta data from the cache (it might not exist, or the cache TTL expired),
+ # get the meta data from the meta-data mount.
+ unless ($meta_data) {
+ my $base_uri = 'http://169.254.169.254/latest/meta-data';
+ my $data_value = get $base_uri . $resource;
- if ( !$data_value ) {
- return "";
- }
+ if ($data_value) {
+ $meta_data = $data_value;
- if ($use_cache) {
- write_meta_data( $resource, $data_value );
+ if ($use_cache) {
+ write_meta_data( $resource, $data_value );
+ }
+ }
}
- return $data_value;
+ return $meta_data;
}
=item read_meta_data
-----------------------------------------------------------------------
hooks/post-receive
--
app-aws-cloudwatch-monitor
More information about the Bps-public-commit
mailing list