netdata/netdata

View on GitHub
src/web/gui/src/dashboard.js/registry.js

Summary

Maintainability
F
2 wks
Test Coverage

File registry.js has 256 lines of code (exceeds 250 allowed). Consider refactoring.
Open


// Registry of netdata hosts

NETDATA.registry = {
    server: null,         // the netdata registry server
Severity: Minor
Found in src/web/gui/src/dashboard.js/registry.js - About 2 hrs to fix

    Function access has 53 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        access: function (max_redirects, callback) {
            let name = NETDATA.registry.MASKED_DATA;
            let url = NETDATA.registry.MASKED_DATA;
    
            if (!NETDATA.registry.isUsingGlobalRegistry()) {
    Severity: Major
    Found in src/web/gui/src/dashboard.js/registry.js - About 2 hrs to fix

      Function init has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

          init: function () {
              if (netdataRegistry !== true) {
                  return;
              }
      
      
      Severity: Minor
      Found in src/web/gui/src/dashboard.js/registry.js - 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 parsePersonUrls has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          parsePersonUrls: function (person_urls) {
              NETDATA.registry.person_urls = person_urls;
      
              if (person_urls) {
                  NETDATA.registry.machines = {};
      Severity: Minor
      Found in src/web/gui/src/dashboard.js/registry.js - 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 parsePersonUrls has 34 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          parsePersonUrls: function (person_urls) {
              NETDATA.registry.person_urls = person_urls;
      
              if (person_urls) {
                  NETDATA.registry.machines = {};
      Severity: Minor
      Found in src/web/gui/src/dashboard.js/registry.js - About 1 hr to fix

        Function init has 31 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            init: function () {
                if (netdataRegistry !== true) {
                    return;
                }
        
        
        Severity: Minor
        Found in src/web/gui/src/dashboard.js/registry.js - About 1 hr to fix

          Function hello has 27 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              hello: function (host, callback) {
                  host = NETDATA.fixHost(host);
          
                  // send HELLO to a netdata server:
                  // 1. verifies the server is reachable
          Severity: Minor
          Found in src/web/gui/src/dashboard.js/registry.js - About 1 hr to fix

            Function switch has 26 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                switch: function (new_person_guid, callback) {
                    // impersonate
                    $.ajax({
                        url: NETDATA.registry.server + '/api/v1/registry?action=switch&machine=' + NETDATA.registry.machine_guid + '&name=' + encodeURIComponent(NETDATA.registry.hostname) + '&url=' + encodeURIComponent(NETDATA.serverDefault) + '&to=' + new_person_guid,
                        async: true,
            Severity: Minor
            Found in src/web/gui/src/dashboard.js/registry.js - About 1 hr to fix

              Function delete has 26 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  delete: function (delete_url, callback) {
                      // send DELETE to a netdata registry:
                      $.ajax({
                          url: NETDATA.registry.server + '/api/v1/registry?action=delete&machine=' + NETDATA.registry.machine_guid + '&name=' + encodeURIComponent(NETDATA.registry.hostname) + '&url=' + encodeURIComponent(NETDATA.serverDefault) + '&delete_url=' + encodeURIComponent(delete_url),
                          async: true,
              Severity: Minor
              Found in src/web/gui/src/dashboard.js/registry.js - About 1 hr to fix

                Function search has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    search: function (machine_guid, callback) {
                        // SEARCH for the URLs of a machine:
                        $.ajax({
                            url: NETDATA.registry.server + '/api/v1/registry?action=search&machine=' + NETDATA.registry.machine_guid + '&name=' + encodeURIComponent(NETDATA.registry.hostname) + '&url=' + encodeURIComponent(NETDATA.serverDefault) + '&for=' + machine_guid,
                            async: true,
                Severity: Minor
                Found in src/web/gui/src/dashboard.js/registry.js - About 1 hr to fix

                  Identical blocks of code found in 2 locations. Consider refactoring.
                  Open

                          $.ajax({
                              url: NETDATA.registry.server + '/api/v1/registry?action=access&machine=' + NETDATA.registry.machine_guid + '&name=' + encodeURIComponent(name) + '&url=' + encodeURIComponent(url), // + '&visible_url=' + encodeURIComponent(document.location),
                              async: true,
                              cache: false,
                              headers: {
                  Severity: Major
                  Found in src/web/gui/src/dashboard.js/registry.js and 1 other location - About 2 days to fix
                  src/web/gui/v1/dashboard.js on lines 10039..10089

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 496.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                      init: function () {
                          if (netdataRegistry !== true) {
                              return;
                          }
                  
                  
                  Severity: Major
                  Found in src/web/gui/src/dashboard.js/registry.js and 1 other location - About 2 days to fix
                  src/web/gui/v1/dashboard.js on lines 9956..9989

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 475.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Identical blocks of code found in 2 locations. Consider refactoring.
                  Open

                      parsePersonUrls: function (person_urls) {
                          NETDATA.registry.person_urls = person_urls;
                  
                          if (person_urls) {
                              NETDATA.registry.machines = {};
                  Severity: Major
                  Found in src/web/gui/src/dashboard.js/registry.js and 1 other location - About 2 days to fix
                  src/web/gui/v1/dashboard.js on lines 9911..9954

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 458.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Identical blocks of code found in 2 locations. Consider refactoring.
                  Open

                      delete: function (delete_url, callback) {
                          // send DELETE to a netdata registry:
                          $.ajax({
                              url: NETDATA.registry.server + '/api/v1/registry?action=delete&machine=' + NETDATA.registry.machine_guid + '&name=' + encodeURIComponent(NETDATA.registry.hostname) + '&url=' + encodeURIComponent(NETDATA.serverDefault) + '&delete_url=' + encodeURIComponent(delete_url),
                              async: true,
                  Severity: Major
                  Found in src/web/gui/src/dashboard.js/registry.js and 1 other location - About 1 day to fix
                  src/web/gui/v1/dashboard.js on lines 10092..10123

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 323.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 4 locations. Consider refactoring.
                  Open

                      switch: function (new_person_guid, callback) {
                          // impersonate
                          $.ajax({
                              url: NETDATA.registry.server + '/api/v1/registry?action=switch&machine=' + NETDATA.registry.machine_guid + '&name=' + encodeURIComponent(NETDATA.registry.hostname) + '&url=' + encodeURIComponent(NETDATA.serverDefault) + '&to=' + new_person_guid,
                              async: true,
                  Severity: Major
                  Found in src/web/gui/src/dashboard.js/registry.js and 3 other locations - About 1 day to fix
                  src/web/gui/src/dashboard.js/registry.js on lines 246..277
                  src/web/gui/v1/dashboard.js on lines 10125..10156
                  src/web/gui/v1/dashboard.js on lines 10158..10189

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 319.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 4 locations. Consider refactoring.
                  Open

                      search: function (machine_guid, callback) {
                          // SEARCH for the URLs of a machine:
                          $.ajax({
                              url: NETDATA.registry.server + '/api/v1/registry?action=search&machine=' + NETDATA.registry.machine_guid + '&name=' + encodeURIComponent(NETDATA.registry.hostname) + '&url=' + encodeURIComponent(NETDATA.serverDefault) + '&for=' + machine_guid,
                              async: true,
                  Severity: Major
                  Found in src/web/gui/src/dashboard.js/registry.js and 3 other locations - About 1 day to fix
                  src/web/gui/src/dashboard.js/registry.js on lines 279..310
                  src/web/gui/v1/dashboard.js on lines 10125..10156
                  src/web/gui/v1/dashboard.js on lines 10158..10189

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 319.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Identical blocks of code found in 2 locations. Consider refactoring.
                  Open

                      hello: function (host, callback) {
                          host = NETDATA.fixHost(host);
                  
                          // send HELLO to a netdata server:
                          // 1. verifies the server is reachable
                  Severity: Major
                  Found in src/web/gui/src/dashboard.js/registry.js and 1 other location - About 1 day to fix
                  src/web/gui/v1/dashboard.js on lines 9991..10026

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 260.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  There are no issues that match your filters.

                  Category
                  Status