kpetremann/mqtt-exporter

View on GitHub

Showing 7 of 9 total issues

File main.py has 359 lines of code (exceeds 250 allowed). Consider refactoring.
Open

#!/usr/bin/env python3
"""MQTT exporter."""

import argparse
import fnmatch
Severity: Minor
Found in mqtt_exporter/main.py - About 4 hrs to fix

    Function _parse_message has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

    def _parse_message(raw_topic, raw_payload):
        """Parse topic and payload to have exposable information."""
        # parse MQTT payload
        try:
            if not isinstance(raw_payload, str):
    Severity: Minor
    Found in mqtt_exporter/main.py - About 2 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function _parse_metrics has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

    def _parse_metrics(data, topic, client_id, prefix="", labels=None):
        """Attempt to parse a set of metrics.
    
        Note when `data` contains nested metrics this function will be called recursively.
        """
    Severity: Minor
    Found in mqtt_exporter/main.py - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function expose_metrics has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

    def expose_metrics(_, userdata, msg):
        """Expose metrics to prometheus when a message has been published (callback)."""
        for ignore in settings.IGNORED_TOPICS:
            if fnmatch.fnmatch(msg.topic, ignore):
                LOG.debug('Topic "%s" was ignored by entry "%s"', msg.topic, ignore)
    Severity: Minor
    Found in mqtt_exporter/main.py - About 55 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function _add_prometheus_sample has 5 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def _add_prometheus_sample(topic, prom_metric_id, metric_value, client_id, additional_labels):
    Severity: Minor
    Found in mqtt_exporter/main.py - About 35 mins to fix

      Function _parse_metrics has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      def _parse_metrics(data, topic, client_id, prefix="", labels=None):
      Severity: Minor
      Found in mqtt_exporter/main.py - About 35 mins to fix

        Function run has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

        def run():
            """Start the exporter."""
            if settings.MQTT_V5_PROTOCOL:
                client = mqtt.Client(
                    callback_api_version=mqtt.CallbackAPIVersion.VERSION2,
        Severity: Minor
        Found in mqtt_exporter/main.py - About 35 mins to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Severity
        Category
        Status
        Source
        Language