[Bps-public-commit] app-aws-cloudwatch-monitor branch 0.03/update-meta-data-cachcing-writes created. da755f20179c1cba982efa22ba885feda9caf469

BPS Git Server git at git.bestpractical.com
Thu May 19 18:42:06 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-cachcing-writes has been created
        at  da755f20179c1cba982efa22ba885feda9caf469 (commit)

- Log -----------------------------------------------------------------
commit da755f20179c1cba982efa22ba885feda9caf469
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 gets 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.
    
    Second, if the special meta-data mount is incorrectly returning
    empty string (incase of an issue at AWS), a cached value isn't
    used.
    
    This commit fixes the meta-data cache writes to now honor the TTL
    time before writing a new 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