]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr: include only capturing groups into osd perf query subkeys
authorMykola Golub <mgolub@suse.com>
Fri, 14 Dec 2018 15:23:27 +0000 (15:23 +0000)
committerMykola Golub <mgolub@suse.com>
Fri, 14 Dec 2018 15:23:27 +0000 (15:23 +0000)
Signed-off-by: Mykola Golub <mgolub@suse.com>
src/mgr/BaseMgrModule.cc
src/mgr/OSDPerfMetricTypes.h
src/osd/DynamicPerfStats.h
src/pybind/mgr/osd_perf_query/module.py
src/pybind/mgr/prometheus/module.py

index 9aeca666996ea3c01d305ee0ea7572d4d98f3471..20a4e9f434fe77d156dc714774644cd07d940a9e 100644 (file)
@@ -799,6 +799,12 @@ ceph_add_osd_perf_query(BaseMgrModule *self, PyObject *args)
                    << " contains invalid regex " << d.regex_str << dendl;
               Py_RETURN_NONE;
             }
+            if (d.regex.mark_count() == 0) {
+              derr << __func__ << " query " << query_param_name << " item " << j
+                   << " regex " << d.regex_str << ": no capturing groups"
+                   << dendl;
+              Py_RETURN_NONE;
+            }
           } else {
             derr << __func__ << " query " << query_param_name << " item " << j
                  << " contains invalid param " << param_name << dendl;
index 054363943c2867ccb33140f945c66e32d8ac736b..b40c3de88cf3b1187763dfc2363f0695019e9cc9 100644 (file)
@@ -117,6 +117,10 @@ struct denc_traits<OSDPerfMetricKeyDescriptor> {
         v.clear();
         return;
       }
+      if (d.regex.mark_count() == 0) {
+        v.clear();
+        return;
+      }
       v.push_back(std::move(d));
     }
   }
index f6d44c0e0561b18cfcf0265fb6cce4a21f8a0f7d..38f55d1eea628084b40b16b00467c9e868b72398 100644 (file)
@@ -152,8 +152,11 @@ public:
           if (!std::regex_search(match_string, match, d.regex)) {
             return false;
           }
-          for (auto &sub_match : match) {
-            sub_key->push_back(sub_match.str());
+          if (match.size() <= 1) {
+            return false;
+          }
+          for (size_t i = 1; i < match.size(); i++) {
+            sub_key->push_back(match[i].str());
           }
           return true;
         };
index 2d4fa6b5ab88cba893882ad1a85770fbe57a0386..32057544235a822aeb327e83fa627343207f1019 100644 (file)
@@ -44,7 +44,7 @@ class OSDPerfQuery(MgrModule):
 
     CLIENT_ID_QUERY = {
         'key_descriptor': [
-            {'type': 'client_id', 'regex': '^.+$'},
+            {'type': 'client_id', 'regex': '^(.+)$'},
         ],
         'performance_counter_descriptors': [
             'bytes', 'write_ops', 'read_ops', 'write_bytes', 'read_bytes',
@@ -55,7 +55,7 @@ class OSDPerfQuery(MgrModule):
 
     RBD_IMAGE_ID_QUERY = {
         'key_descriptor': [
-            {'type': 'pool_id', 'regex': '^.+$'},
+            {'type': 'pool_id', 'regex': '^(.+)$'},
             {'type': 'object_name', 'regex': '^rbd_data\.([^.]+)\.'},
         ],
         'performance_counter_descriptors': [
@@ -67,14 +67,14 @@ class OSDPerfQuery(MgrModule):
 
     ALL_SUBKEYS_QUERY = {
         'key_descriptor': [
-            {'type': 'client_id', 'regex': '^.*$'},
-            {'type': 'client_address', 'regex': '^.*$'},
-            {'type': 'pool_id', 'regex': '^.*$'},
-            {'type': 'namespace', 'regex': '^.*$'},
-            {'type': 'osd_id', 'regex': '^.*$'},
-            {'type': 'pg_id', 'regex': '^.*$'},
-            {'type': 'object_name', 'regex': '^.*$'},
-            {'type': 'snap_id', 'regex': '^.*$'},
+            {'type': 'client_id', 'regex': '^(.*)$'},
+            {'type': 'client_address', 'regex': '^(.*)$'},
+            {'type': 'pool_id', 'regex': '^(.*)$'},
+            {'type': 'namespace', 'regex': '^(.*)$'},
+            {'type': 'osd_id', 'regex': '^(.*)$'},
+            {'type': 'pg_id', 'regex': '^(.*)$'},
+            {'type': 'object_name', 'regex': '^(.*)$'},
+            {'type': 'snap_id', 'regex': '^(.*)$'},
         ],
         'performance_counter_descriptors': [
             'write_ops', 'read_ops',
@@ -137,10 +137,7 @@ class OSDPerfQuery(MgrModule):
                     i = descriptors.index(query['limit']['order_by'])
                     res['counters'].sort(key=lambda x: x['c'][i], reverse=True)
             for c in res['counters'][:max_count]:
-                if query == self.RBD_IMAGE_ID_QUERY:
-                    row = [c['k'][0][0], c['k'][1][1]]
-                else:
-                    row = [sk[0] for sk in c['k']]
+                row = [sk[0] for sk in c['k']]
                 counters = c['c']
                 for i in range(len(descriptors)):
                     if descriptors[i] in ['bytes']:
index f741f461c73a4d0e1822f25706a61b7324ea3ad9..a8ae6d95881569ff63d37e553665a807b3c15979 100644 (file)
@@ -572,7 +572,7 @@ class Module(MgrModule):
 
         pool_ids = list(self.rbd_stats['pools'])
         pool_ids.sort()
-        pool_id_regex = '|'.join(['^%s$' % x for x in pool_ids])
+        pool_id_regex = '^(' + '|'.join([str(x) for x in pool_ids]) + ')$'
 
         if 'query' in self.rbd_stats and \
            pool_id_regex != self.rbd_stats['query']['key_descriptor'][0]['regex']:
@@ -605,8 +605,8 @@ class Module(MgrModule):
         for c in res['counters']:
             # if the pool id is not found in the object name use id of the
             # pool where the object is located
-            if c['k'][1][1]:
-                pool_id = int(c['k'][1][1])
+            if c['k'][1][0]:
+                pool_id = int(c['k'][1][0])
             else:
                 pool_id = int(c['k'][0][0])
             if pool_id not in self.rbd_stats['pools'] and not pools_refreshed:
@@ -614,7 +614,7 @@ class Module(MgrModule):
                 pools_refreshed = True
             if pool_id not in self.rbd_stats['pools']:
                 continue
-            image_id = c['k'][1][2]
+            image_id = c['k'][1][1]
             pool = self.rbd_stats['pools'][pool_id]
             if image_id not in pool['images'] and not pools_refreshed:
                 self.refresh_rbd_stats_pools(pools)