Passed
Push — master ( f9598b...4c4a55 )
by Vlad
01:28
created

test.test_metrics.TestMetrics.setUp()   B

Complexity

Conditions 1

Size

Total Lines 62
Code Lines 49

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 49
dl 0
loc 62
rs 8.669
c 0
b 0
f 0
cc 1
nop 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
from unittest import TestCase
0 ignored issues
show
Coding Style introduced by
This module should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
2
3
from kibana_collector import Metrics
0 ignored issues
show
introduced by
Unable to import 'kibana_collector'
Loading history...
4
5
6
class TestMetrics(TestCase):
0 ignored issues
show
Coding Style introduced by
This class should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
7
    def setUp(self) -> None:
8
        self.metrics_dict = {
9
            'last_updated': '2019-04-02T03:56:41.078Z',
10
            'collection_interval_in_millis': 15000,
11
            'process': {
12
                'memory': {
13
                    'heap': {
14
                        'total_in_bytes': 175874048,
15
                        'used_in_bytes': 157139288,
16
                        'size_limit': 1526909922
17
                    },
18
                    'resident_set_size_in_bytes': 285655040
19
                },
20
                'event_loop_delay': 0.08109402656555176,
21
                'pid': 18595,
22
                'uptime_in_millis': 2494490
23
            },
24
            'os': {
25
                'load': {
26
                    '1m': 0.16357421875,
27
                    '5m': 0.13720703125,
28
                    '15m': 0.13037109375
29
                },
30
                'memory': {
31
                    'total_in_bytes': 8257908736,
32
                    'free_in_bytes': 193777664,
33
                    'used_in_bytes': 8064131072
34
                },
35
                'uptime_in_millis': 1212738000,
36
                'platform': 'linux',
37
                'platformRelease': 'linux-4.15.0-1034-aws',
38
                'distro': 'Ubuntu Linux',
39
                'distroRelease': 'Ubuntu Linux-18.04',
40
                'cgroup': {
41
                    'cpuacct': {
42
                        'control_group': '/system.slice/kibana.service',
43
                        'usage_nanos': 24967412414
44
                    },
45
                    'cpu': {
46
                        'control_group': '/system.slice/kibana.service',
47
                        'cfs_period_micros': 100000,
48
                        'cfs_quota_micros': -1,
49
                        'stat': {
50
                            'number_of_elapsed_periods': 0,
51
                            'number_of_times_throttled': 0,
52
                            'time_throttled_nanos': 0
53
                        }
54
                    }
55
                }
56
            },
57
            'response_times': {
58
                'avg_in_millis': 2.3333333333333335, 'max_in_millis': 3
59
            },
60
            'requests': {
61
                'disconnects': 0,
62
                'statusCodes': {},
63
                'total': 3,
64
                'status_codes': {
65
                    '302': 3
66
                }
67
            },
68
            'concurrent_connections': 0
69
        }
70
71
    def test_all_metrics_have_timestamps(self):
72
        metrics = Metrics(self.metrics_dict)
73
        for metric in metrics:
74
            for sample in metric.samples:
75
                self.assertIsNotNone(sample.timestamp, sample)
76