Explorar el Código

Merge pull request #40 from greg-junkietech/feature/#34-prometheus-export-format_fix

fixed feature #34: regression region metrics not outputted
Andrey hace 3 años
padre
commit
c594e58817

+ 25 - 0
metrixpp/ext/std/tools/view.py

@@ -660,8 +660,33 @@ def cout_txt(data, loader):
                 "Directory content:",
                 details)
     
+def cout_prom_regions(path, regions, indent = 0):
+    for region in regions:
+        details = []
+        for namespace in sorted(list(region['data'].keys())):
+            diff_data = {}
+            if '__diff__' in list(region['data'][namespace].keys()):
+                diff_data = region['data'][namespace]['__diff__']
+            for field in sorted(list(region['data'][namespace].keys())):
+                diff_str = ""
+                if field == '__diff__':
+                    continue
+                if field in list(diff_data.keys()):
+                    diff_str = " [" + ("+" if diff_data[field] >= 0 else "") + str(diff_data[field]) + "]"
+                details.append((namespace + ":" + field, str(region['data'][namespace][field]) + diff_str))
+        promout.notify(path = path,
+                        region = region['info']['name'],
+                        metric = "",
+                        details = details)
+        if 'subregions' in list(region.keys()):
+            cout_txt_regions(path, region['subregions'], indent=indent+1)
+            
 def cout_prom(data, loader):
     
+    for key in list(data['file-data'].keys()):
+        if key == 'regions':
+            cout_prom_regions(data['info']['path'], data['file-data'][key])
+
     for namespace in sorted(list(data['aggregated-data'].keys())):
         for field in sorted(list(data['aggregated-data'][namespace].keys())):
             details = []

+ 8 - 2
metrixpp/tests/general/test_basic.py

@@ -226,8 +226,14 @@ class Test(tests.common.TestCase):
 
         runner = tests.common.ToolRunner('view', ['--format=xml'], prefix='xml')
         self.assertExec(runner.run())
-        
-        runner = tests.common.ToolRunner('view', ['--format=prometheus'], prefix='prometheus')
+
+        runner = tests.common.ToolRunner('view', ['--format=prometheus', '--log-level=ERROR'], prefix='prometheus')
+        self.assertExec(runner.run())
+
+        runner = tests.common.ToolRunner('view',
+                                         ['--format=prometheus', '--log-level=ERROR'],
+                                         prefix='prometheus_simple.cpp',
+                                         dirs_list=['./simple.cpp'])
         self.assertExec(runner.run())
         
         runner = tests.common.ToolRunner('collect',

+ 23 - 0
metrixpp/tests/general/test_basic/test_view_format_view_prometheus_simple.cpp_stdout.gold.txt

@@ -0,0 +1,23 @@
+
+
+
+std_code_complexity_cyclomatic {file="./simple.cpp", region="A"} 3
+
+std_code_complexity_cyclomatic {file="./simple.cpp", region="func"} 1
+
+
+std_code_complexity_cyclomatic {file="./simple.cpp", region="embeded"} 1
+
+std_code_complexity_cyclomatic {file="./simple.cpp", region="func_to_be_removed_in_new_sources"} 2
+
+
+std_code_complexity_cyclomatic {file="./simple.cpp", region="embeded"} 1
+
+std_code_complexity_cyclomatic {file="./simple.cpp", region="never"} 1
+
+std_code_complexity_cyclomatic_avg {file="./simple.cpp"} 1.5
+std_code_complexity_cyclomatic_min {file="./simple.cpp"} 1
+std_code_complexity_cyclomatic_max {file="./simple.cpp"} 3
+std_code_complexity_cyclomatic_total {file="./simple.cpp"} 9.0
+
+