wikimedia/mediawiki-extensions-CirrusSearch

View on GitHub
scripts/check_indices.py

Summary

Maintainability
C
1 day
Test Coverage

File check_indices.py has 310 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""
Reconcile expected indices against live cluster state

Reconciles the state of multiple elasticsearch clusters against the expected
state of multiple wikis. The reconciliation process is accept based. Some
Severity: Minor
Found in scripts/check_indices.py - About 3 hrs to fix

    Function explain has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

        def explain(
            self,
            problem: Problem,
            es_state: Mapping[Tuple[str, str], ElasticsearchState],
        ) -> Optional[str]:
    Severity: Minor
    Found in scripts/check_indices.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 accept has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        def accept(self, cluster_state: ElasticsearchState) -> Sequence[str]:
            # metastore should exist on all cirrussearch clusters
            try:
                yield cluster_state.aliases['mw_cirrus_metastore']
            except KeyError:
    Severity: Minor
    Found in scripts/check_indices.py - About 45 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 build_config has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

    def build_config(parallelism: int) -> Sequence[ClusterToCheck]:
        with ThreadPoolExecutor(max_workers=parallelism) as executor:
            wiki_state = list(make_all_wiki_state(executor))
    
        accept_all = [
    Severity: Minor
    Found in scripts/check_indices.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

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

    def validate_clusters(clusters: Sequence[ClusterToCheck]) -> Sequence[Problem]:
        clusters = list(clusters)
        es_states = {
            cluster.key: make_elasticsearch_state(cluster)
            for cluster in clusters}
    Severity: Minor
    Found in scripts/check_indices.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

    Avoid too many return statements within this function.
    Open

                return "Index on wrong cluster of replica, expected in " + ', '.join(
    Severity: Major
    Found in scripts/check_indices.py - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

                  return (
      Severity: Major
      Found in scripts/check_indices.py - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                return (
        Severity: Major
        Found in scripts/check_indices.py - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                      return 'Duplicate of live index ' + live_index + '. ' + reason
          Severity: Major
          Found in scripts/check_indices.py - About 30 mins to fix

            There are no issues that match your filters.

            Category
            Status