changeset 5336:dd9795dc380d

renamed MetricsType as MetricsUpdate to clarify
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 27 Jun 2023 15:56:04 +0200
parents c103b0e70d75
children b376abae664a 0854cc13b4d5
files OrthancFramework/Sources/MetricsRegistry.cpp OrthancFramework/Sources/MetricsRegistry.h OrthancFramework/UnitTestsSources/FrameworkTests.cpp OrthancServer/Plugins/Engine/PluginsEnumerations.cpp OrthancServer/Plugins/Engine/PluginsEnumerations.h OrthancServer/Sources/OrthancRestApi/OrthancRestApi.cpp
diffstat 6 files changed, 73 insertions(+), 73 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancFramework/Sources/MetricsRegistry.cpp	Tue Jun 27 15:42:07 2023 +0200
+++ b/OrthancFramework/Sources/MetricsRegistry.cpp	Tue Jun 27 15:56:04 2023 +0200
@@ -35,10 +35,10 @@
     return boost::posix_time::microsec_clock::universal_time();
   }
 
-  class MetricsRegistry::Item
+  class MetricsRegistry::Item : public boost::noncopyable
   {
   private:
-    MetricsType               type_;
+    MetricsUpdate             update_;
     boost::posix_time::ptime  time_;
     bool                      hasValue_;
     int64_t                   value_;
@@ -82,50 +82,50 @@
     }
 
   public:
-    explicit Item(MetricsType type) :
-      type_(type),
+    explicit Item(MetricsUpdate update) :
+      update_(update),
       hasValue_(false),
       value_(0)
     {
     }
 
-    MetricsType GetType() const
+    MetricsUpdate GetUpdate() const
     {
-      return type_;
+      return update_;
     }
 
     void Update(int64_t value)
     {
       const boost::posix_time::ptime now = GetNow();
 
-      switch (type_)
+      switch (update_)
       {
-        case MetricsType_Default:
+        case MetricsUpdate_Directly:
           SetValue(value, now);
           break;
           
-        case MetricsType_MaxOver10Seconds:
+        case MetricsUpdate_MaxOver10Seconds:
           if (IsLargerOverPeriod(value, 10, now))
           {
             SetValue(value, now);
           }
           break;
 
-        case MetricsType_MaxOver1Minute:
+        case MetricsUpdate_MaxOver1Minute:
           if (IsLargerOverPeriod(value, 60, now))
           {
             SetValue(value, now);
           }
           break;
 
-        case MetricsType_MinOver10Seconds:
+        case MetricsUpdate_MinOver10Seconds:
           if (IsSmallerOverPeriod(value, 10, now))
           {
             SetValue(value, now);
           }
           break;
 
-        case MetricsType_MinOver1Minute:
+        case MetricsUpdate_MinOver1Minute:
           if (IsSmallerOverPeriod(value, 60, now))
           {
             SetValue(value, now);
@@ -191,7 +191,7 @@
 
 
   void MetricsRegistry::Register(const std::string& name,
-                                 MetricsType type)
+                                 MetricsUpdate update)
   {
     boost::mutex::scoped_lock lock(mutex_);
 
@@ -199,7 +199,7 @@
 
     if (found == content_.end())
     {
-      content_[name] = new Item(type);
+      content_[name] = new Item(update);
     }
     else
     {
@@ -207,23 +207,23 @@
 
       // This metrics already exists: Only recreate it if there is a
       // mismatch in the type of metrics
-      if (found->second->GetType() != type)
+      if (found->second->GetUpdate() != update)
       {
         delete found->second;
-        found->second = new Item(type);
+        found->second = new Item(update);
       }
     }    
   }
 
 
   MetricsRegistry::Item& MetricsRegistry::GetItemInternal(const std::string& name,
-                                                          MetricsType type)
+                                                          MetricsUpdate update)
   {
     Content::iterator found = content_.find(name);
 
     if (found == content_.end())
     {
-      Item* item = new Item(type);
+      Item* item = new Item(update);
       content_[name] = item;
       return *item;
     }
@@ -242,13 +242,13 @@
 
   void MetricsRegistry::SetValue(const std::string &name,
                                  int64_t value,
-                                 MetricsType type)
+                                 MetricsUpdate update)
   {
     // Inlining to avoid loosing time if metrics are disabled
     if (enabled_)
     {
       boost::mutex::scoped_lock lock(mutex_);
-      GetItemInternal(name, type).Update(value);
+      GetItemInternal(name, update).Update(value);
     }
   }
 
@@ -260,7 +260,7 @@
     if (enabled_)
     {
       boost::mutex::scoped_lock lock(mutex_);
-      Item& item = GetItemInternal(name, MetricsType_Default);
+      Item& item = GetItemInternal(name, MetricsUpdate_Directly);
 
       if (item.HasValue())
       {
@@ -274,7 +274,7 @@
   }
 
 
-  MetricsType MetricsRegistry::GetMetricsType(const std::string& name)
+  MetricsUpdate MetricsRegistry::GetMetricsUpdate(const std::string& name)
   {
     boost::mutex::scoped_lock lock(mutex_);
 
@@ -287,7 +287,7 @@
     else
     {
       assert(found->second != NULL);
-      return found->second->GetType();
+      return found->second->GetUpdate();
     }
   }
 
@@ -331,7 +331,7 @@
 
   MetricsRegistry::SharedMetrics::SharedMetrics(MetricsRegistry &registry,
                                                 const std::string &name,
-                                                MetricsType type) :
+                                                MetricsUpdate update) :
     registry_(registry),
     name_(name),
     value_(0)
@@ -376,7 +376,7 @@
                                 const std::string &name) :
     registry_(registry),
     name_(name),
-    type_(MetricsType_MaxOver10Seconds)
+    update_(MetricsUpdate_MaxOver10Seconds)
   {
     Start();
   }
@@ -384,10 +384,10 @@
 
   MetricsRegistry::Timer::Timer(MetricsRegistry &registry,
                                 const std::string &name,
-                                MetricsType type) :
+                                MetricsUpdate update) :
     registry_(registry),
     name_(name),
-    type_(type)
+    update_(update)
   {
     Start();
   }
@@ -399,7 +399,7 @@
     {
       boost::posix_time::time_duration diff = GetNow() - start_;
       registry_.SetValue(
-            name_, static_cast<int64_t>(diff.total_milliseconds()), type_);
+        name_, static_cast<int64_t>(diff.total_milliseconds()), update_);
     }
   }
 }
--- a/OrthancFramework/Sources/MetricsRegistry.h	Tue Jun 27 15:42:07 2023 +0200
+++ b/OrthancFramework/Sources/MetricsRegistry.h	Tue Jun 27 15:56:04 2023 +0200
@@ -39,13 +39,13 @@
 
 namespace Orthanc
 {
-  enum MetricsType
+  enum MetricsUpdate
   {
-    MetricsType_Default,
-    MetricsType_MaxOver10Seconds,
-    MetricsType_MaxOver1Minute,
-    MetricsType_MinOver10Seconds,
-    MetricsType_MinOver1Minute
+    MetricsUpdate_Directly,
+    MetricsUpdate_MaxOver10Seconds,
+    MetricsUpdate_MaxOver1Minute,
+    MetricsUpdate_MinOver10Seconds,
+    MetricsUpdate_MinOver1Minute
   };
   
   class ORTHANC_PUBLIC MetricsRegistry : public boost::noncopyable
@@ -61,7 +61,7 @@
 
     // The mutex must be locked
     Item& GetItemInternal(const std::string& name,
-                          MetricsType type);
+                          MetricsUpdate update);
 
   public:
     MetricsRegistry();
@@ -73,22 +73,22 @@
     void SetEnabled(bool enabled);
 
     void Register(const std::string& name,
-                  MetricsType type);
+                  MetricsUpdate update);
 
     void SetValue(const std::string& name,
                   int64_t value,
-                  MetricsType type);
+                  MetricsUpdate update);
     
     void SetValue(const std::string& name,
                   int64_t value)
     {
-      SetValue(name, value, MetricsType_Default);
+      SetValue(name, value, MetricsUpdate_Directly);
     }
 
     void IncrementValue(const std::string& name,
                         int64_t delta);
 
-    MetricsType GetMetricsType(const std::string& name);
+    MetricsUpdate GetMetricsUpdate(const std::string& name);
 
     // https://prometheus.io/docs/instrumenting/exposition_formats/#text-based-format
     void ExportPrometheusText(std::string& s);
@@ -105,7 +105,7 @@
     public:
       SharedMetrics(MetricsRegistry& registry,
                     const std::string& name,
-                    MetricsType type);
+                    MetricsUpdate update);
 
       void Add(int64_t delta);
     };
@@ -128,7 +128,7 @@
     private:
       MetricsRegistry&          registry_;
       std::string               name_;
-      MetricsType               type_;
+      MetricsUpdate             update_;
       bool                      active_;
       boost::posix_time::ptime  start_;
 
@@ -140,7 +140,7 @@
 
       Timer(MetricsRegistry& registry,
             const std::string& name,
-            MetricsType type);
+            MetricsUpdate update);
 
       ~Timer();
     };
--- a/OrthancFramework/UnitTestsSources/FrameworkTests.cpp	Tue Jun 27 15:42:07 2023 +0200
+++ b/OrthancFramework/UnitTestsSources/FrameworkTests.cpp	Tue Jun 27 15:56:04 2023 +0200
@@ -1321,7 +1321,7 @@
 
   {
     MetricsRegistry m;
-    m.Register("hello.world", MetricsType_Default);
+    m.Register("hello.world", MetricsUpdate_Directly);
     
     std::string s;
     m.ExportPrometheusText(s);
@@ -1331,8 +1331,8 @@
   {
     MetricsRegistry m;
     m.SetValue("hello.world", -42);
-    ASSERT_EQ(MetricsType_Default, m.GetMetricsType("hello.world"));
-    ASSERT_THROW(m.GetMetricsType("nope"), OrthancException);
+    ASSERT_EQ(MetricsUpdate_Directly, m.GetMetricsUpdate("hello.world"));
+    ASSERT_THROW(m.GetMetricsUpdate("nope"), OrthancException);
     
     std::string s;
     m.ExportPrometheusText(s);
@@ -1346,27 +1346,27 @@
 
   {
     MetricsRegistry m;
-    m.Register("hello.max", MetricsType_MaxOver10Seconds);
+    m.Register("hello.max", MetricsUpdate_MaxOver10Seconds);
     m.SetValue("hello.max", 10);
     m.SetValue("hello.max", 20);
     m.SetValue("hello.max", -10);
     m.SetValue("hello.max", 5);
 
-    m.Register("hello.min", MetricsType_MinOver10Seconds);
+    m.Register("hello.min", MetricsUpdate_MinOver10Seconds);
     m.SetValue("hello.min", 10);
     m.SetValue("hello.min", 20);
     m.SetValue("hello.min", -10);
     m.SetValue("hello.min", 5);
     
-    m.Register("hello.default", MetricsType_Default);
-    m.SetValue("hello.default", 10);
-    m.SetValue("hello.default", 20);
-    m.SetValue("hello.default", -10);
-    m.SetValue("hello.default", 5);
+    m.Register("hello.directly", MetricsUpdate_Directly);
+    m.SetValue("hello.directly", 10);
+    m.SetValue("hello.directly", 20);
+    m.SetValue("hello.directly", -10);
+    m.SetValue("hello.directly", 5);
     
-    ASSERT_EQ(MetricsType_MaxOver10Seconds, m.GetMetricsType("hello.max"));
-    ASSERT_EQ(MetricsType_MinOver10Seconds, m.GetMetricsType("hello.min"));
-    ASSERT_EQ(MetricsType_Default, m.GetMetricsType("hello.default"));
+    ASSERT_EQ(MetricsUpdate_MaxOver10Seconds, m.GetMetricsUpdate("hello.max"));
+    ASSERT_EQ(MetricsUpdate_MinOver10Seconds, m.GetMetricsUpdate("hello.min"));
+    ASSERT_EQ(MetricsUpdate_Directly, m.GetMetricsUpdate("hello.directly"));
 
     std::string s;
     m.ExportPrometheusText(s);
@@ -1386,25 +1386,25 @@
 
     ASSERT_EQ("20", u["hello.max"]);
     ASSERT_EQ("-10", u["hello.min"]);
-    ASSERT_EQ("5", u["hello.default"]);
+    ASSERT_EQ("5", u["hello.directly"]);
   }
 
   {
     MetricsRegistry m;
 
     m.SetValue("a", 10);
-    m.SetValue("b", 10, MetricsType_MinOver10Seconds);
+    m.SetValue("b", 10, MetricsUpdate_MinOver10Seconds);
 
-    m.Register("c", MetricsType_MaxOver10Seconds);
-    m.SetValue("c", 10, MetricsType_MinOver10Seconds);
+    m.Register("c", MetricsUpdate_MaxOver10Seconds);
+    m.SetValue("c", 10, MetricsUpdate_MinOver10Seconds);
 
-    m.Register("d", MetricsType_MaxOver10Seconds);
-    m.Register("d", MetricsType_Default);
+    m.Register("d", MetricsUpdate_MaxOver10Seconds);
+    m.Register("d", MetricsUpdate_Directly);
 
-    ASSERT_EQ(MetricsType_Default, m.GetMetricsType("a"));
-    ASSERT_EQ(MetricsType_MinOver10Seconds, m.GetMetricsType("b"));
-    ASSERT_EQ(MetricsType_MaxOver10Seconds, m.GetMetricsType("c"));
-    ASSERT_EQ(MetricsType_Default, m.GetMetricsType("d"));
+    ASSERT_EQ(MetricsUpdate_Directly, m.GetMetricsUpdate("a"));
+    ASSERT_EQ(MetricsUpdate_MinOver10Seconds, m.GetMetricsUpdate("b"));
+    ASSERT_EQ(MetricsUpdate_MaxOver10Seconds, m.GetMetricsUpdate("c"));
+    ASSERT_EQ(MetricsUpdate_Directly, m.GetMetricsUpdate("d"));
   }
 
   {
@@ -1412,11 +1412,11 @@
 
     {
       MetricsRegistry::Timer t1(m, "a");
-      MetricsRegistry::Timer t2(m, "b", MetricsType_MinOver10Seconds);
+      MetricsRegistry::Timer t2(m, "b", MetricsUpdate_MinOver10Seconds);
     }
 
-    ASSERT_EQ(MetricsType_MaxOver10Seconds, m.GetMetricsType("a"));
-    ASSERT_EQ(MetricsType_MinOver10Seconds, m.GetMetricsType("b"));
+    ASSERT_EQ(MetricsUpdate_MaxOver10Seconds, m.GetMetricsUpdate("a"));
+    ASSERT_EQ(MetricsUpdate_MinOver10Seconds, m.GetMetricsUpdate("b"));
   }
 }
 #endif
--- a/OrthancServer/Plugins/Engine/PluginsEnumerations.cpp	Tue Jun 27 15:42:07 2023 +0200
+++ b/OrthancServer/Plugins/Engine/PluginsEnumerations.cpp	Tue Jun 27 15:56:04 2023 +0200
@@ -580,15 +580,15 @@
     }
 
 
-    MetricsType Convert(OrthancPluginMetricsType type)
+    MetricsUpdate Convert(OrthancPluginMetricsType type)
     {
       switch (type)
       {
         case OrthancPluginMetricsType_Default:
-          return MetricsType_Default;
+          return MetricsUpdate_Directly;
 
         case OrthancPluginMetricsType_Timer:
-          return MetricsType_MaxOver10Seconds;
+          return MetricsUpdate_MaxOver10Seconds;
 
         default:
           throw OrthancException(ErrorCode_ParameterOutOfRange);
--- a/OrthancServer/Plugins/Engine/PluginsEnumerations.h	Tue Jun 27 15:42:07 2023 +0200
+++ b/OrthancServer/Plugins/Engine/PluginsEnumerations.h	Tue Jun 27 15:56:04 2023 +0200
@@ -73,7 +73,7 @@
 
     StorageCommitmentFailureReason Convert(OrthancPluginStorageCommitmentFailureReason reason);
 
-    MetricsType Convert(OrthancPluginMetricsType type);
+    MetricsUpdate Convert(OrthancPluginMetricsType type);
   }
 }
 
--- a/OrthancServer/Sources/OrthancRestApi/OrthancRestApi.cpp	Tue Jun 27 15:42:07 2023 +0200
+++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestApi.cpp	Tue Jun 27 15:56:04 2023 +0200
@@ -259,7 +259,7 @@
     resetRequestReceived_(false),
     activeRequests_(context.GetMetricsRegistry(), 
                     "orthanc_rest_api_active_requests", 
-                    MetricsType_MaxOver10Seconds)
+                    MetricsUpdate_MaxOver10Seconds)
   {
     RegisterSystem(orthancExplorerEnabled);