changeset 5792:89a13d8ec80b find-refactoring

merged default -> find-refactoring
author Alain Mazy <am@orthanc.team>
date Wed, 18 Sep 2024 10:38:42 +0200
parents a3d283f61304 (current diff) 7fadeb395359 (diff)
children a8055aebc6cb
files NEWS
diffstat 3 files changed, 52 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Wed Sep 18 09:34:52 2024 +0200
+++ b/NEWS	Wed Sep 18 10:38:42 2024 +0200
@@ -48,6 +48,9 @@
   in very specific use-cases.
 * Fix extremely rare error when 2 threads are trying to create the same folder in the File Storage 
   at the same time.
+* Metrics:
+  - fix a few metrics that were not published
+  - added 2 metrics: orthanc_storage_cache_miss_count & orthanc_storage_cache_hit_count 
 * Upgraded dependencies for static builds:
   - curl 8.9.0
 * Added a new fallback when trying to decode a frame: transcode the file using the plugin
--- a/OrthancFramework/Sources/FileStorage/StorageAccessor.cpp	Wed Sep 18 09:34:52 2024 +0200
+++ b/OrthancFramework/Sources/FileStorage/StorageAccessor.cpp	Wed Sep 18 10:38:42 2024 +0200
@@ -44,6 +44,8 @@
 static const std::string METRICS_REMOVE_DURATION = "orthanc_storage_remove_duration_ms";
 static const std::string METRICS_READ_BYTES = "orthanc_storage_read_bytes";
 static const std::string METRICS_WRITTEN_BYTES = "orthanc_storage_written_bytes";
+static const std::string METRICS_CACHE_HIT_COUNT = "orthanc_storage_cache_hit_count";
+static const std::string METRICS_CACHE_MISS_COUNT = "orthanc_storage_cache_miss_count";
 
 
 namespace Orthanc
@@ -208,10 +210,19 @@
 
       if (!cacheAccessor.Fetch(content, info.GetUuid(), info.GetContentType()))
       {
+        if (metrics_ != NULL)
+        {
+          metrics_->IncrementIntegerValue(METRICS_CACHE_MISS_COUNT, 1);
+        }
+
         ReadWholeInternal(content, info);
 
         // always store the uncompressed data in cache
         cacheAccessor.Add(info.GetUuid(), info.GetContentType(), content);
+      } 
+      else if (metrics_ != NULL)
+      {
+        metrics_->IncrementIntegerValue(METRICS_CACHE_HIT_COUNT, 1);
       }
     }
   }
@@ -284,10 +295,19 @@
 
       if (!cacheAccessor.Fetch(content, info.GetUuid(), info.GetContentType()))
       {
+        if (metrics_ != NULL)
+        {
+          metrics_->IncrementIntegerValue(METRICS_CACHE_MISS_COUNT, 1);
+        }
+
         ReadRawInternal(content, info);
 
         cacheAccessor.Add(info.GetUuid(), info.GetContentType(), content);
       }
+      else if (metrics_ != NULL)
+      {
+        metrics_->IncrementIntegerValue(METRICS_CACHE_HIT_COUNT, 1);
+      }
     }
   }
 
@@ -353,24 +373,38 @@
       StorageCache::Accessor accessorStartRange(*cache_);
       if (!accessorStartRange.FetchStartRange(target, info.GetUuid(), info.GetContentType(), end))
       {
-        ReadStartRangeInternal(target, info, end);
-        accessorStartRange.AddStartRange(info.GetUuid(), info.GetContentType(), target);
-      }
-      else
-      {
+        // the start range is not in cache, let's check if the whole file is
         StorageCache::Accessor accessorWhole(*cache_);
         if (!accessorWhole.Fetch(target, info.GetUuid(), info.GetContentType()))
         {
-          ReadWholeInternal(target, info);
-          accessorWhole.Add(info.GetUuid(), info.GetContentType(), target);
-        }
+          if (metrics_ != NULL)
+          {
+            metrics_->IncrementIntegerValue(METRICS_CACHE_MISS_COUNT, 1);
+          }
 
-        if (target.size() < end)
+          // if nothing is in the cache, let's read and cache only the start
+          ReadStartRangeInternal(target, info, end);
+          accessorStartRange.AddStartRange(info.GetUuid(), info.GetContentType(), target);
+        }
+        else
         {
-          throw OrthancException(ErrorCode_CorruptedFile);
+          if (metrics_ != NULL)
+          {
+            metrics_->IncrementIntegerValue(METRICS_CACHE_HIT_COUNT, 1);
+          }
+
+          // we have read the whole file, check size and resize if needed
+          if (target.size() < end)
+          {
+            throw OrthancException(ErrorCode_CorruptedFile);
+          }
+
+          target.resize(end);
         }
-
-        target.resize(end);
+      }
+      else if (metrics_ != NULL)
+      {
+        metrics_->IncrementIntegerValue(METRICS_CACHE_HIT_COUNT, 1);
       }
     }
   }
--- a/OrthancFramework/Sources/MetricsRegistry.cpp	Wed Sep 18 09:34:52 2024 +0200
+++ b/OrthancFramework/Sources/MetricsRegistry.cpp	Wed Sep 18 10:38:42 2024 +0200
@@ -139,6 +139,8 @@
 
       void Increment(const T& delta)
       {
+        time_ = GetNow();
+
         if (hasValue_)
         {
           value_ += delta;
@@ -146,6 +148,7 @@
         else
         {
           value_ = delta;
+          hasValue_ = true;
         }
       }