cloudfoundry/stratos

View on GitHub
src/jetstream/plugins/metrics/main.go

Summary

Maintainability
D
1 day
Test Coverage

Method MetricsSpecification.getMetricsEndpoints has a Cognitive Complexity of 26 (exceeds 8 allowed). Consider refactoring.
Open

func (m *MetricsSpecification) getMetricsEndpoints(userGUID string, cnsiList []string) (map[string]EndpointMetricsRelation, error) {

    metricsProviders := make([]MetricsMetadata, 0)
    endpointsMap := make(map[string]*interfaces.ConnectedEndpoint)
    results := make(map[string]EndpointMetricsRelation)
Severity: Minor
Found in src/jetstream/plugins/metrics/main.go - About 3 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

Method MetricsSpecification.Connect has 80 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func (m *MetricsSpecification) Connect(ec echo.Context, cnsiRecord interfaces.CNSIRecord, userId string) (*interfaces.TokenRecord, bool, error) {
    log.Debug("Metrics Connect...")

    params := new(interfaces.LoginToCNSIParams)
    err := interfaces.BindOnce(params, ec)
Severity: Major
Found in src/jetstream/plugins/metrics/main.go - About 2 hrs to fix

    Method MetricsSpecification.UpdateMetadata has a Cognitive Complexity of 19 (exceeds 8 allowed). Consider refactoring.
    Open

    func (m *MetricsSpecification) UpdateMetadata(info *interfaces.Info, userGUID string, echoContext echo.Context) {
    
        metricsProviders := make([]MetricsMetadata, 0)
        // Go through the metrics endpoints and get the corresponding services from the token metadata
        if metrics, ok := info.Endpoints[EndpointType]; ok {
    Severity: Minor
    Found in src/jetstream/plugins/metrics/main.go - 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

    Method MetricsSpecification.Connect has a Cognitive Complexity of 17 (exceeds 8 allowed). Consider refactoring.
    Open

    func (m *MetricsSpecification) Connect(ec echo.Context, cnsiRecord interfaces.CNSIRecord, userId string) (*interfaces.TokenRecord, bool, error) {
        log.Debug("Metrics Connect...")
    
        params := new(interfaces.LoginToCNSIParams)
        err := interfaces.BindOnce(params, ec)
    Severity: Minor
    Found in src/jetstream/plugins/metrics/main.go - 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

    Method MetricsSpecification.getMetricsEndpoints has 65 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func (m *MetricsSpecification) getMetricsEndpoints(userGUID string, cnsiList []string) (map[string]EndpointMetricsRelation, error) {
    
        metricsProviders := make([]MetricsMetadata, 0)
        endpointsMap := make(map[string]*interfaces.ConnectedEndpoint)
        results := make(map[string]EndpointMetricsRelation)
    Severity: Minor
    Found in src/jetstream/plugins/metrics/main.go - About 1 hr to fix

      Method MetricsSpecification.createMetadata has 55 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func (m *MetricsSpecification) createMetadata(metricEndpoint *url.URL, httpClient http.Client, auth *MetricsAuth) (string, error) {
          basicMetricRequest := fmt.Sprintf("%s/api/v1/query?query=firehose_total_metrics_received", metricEndpoint)
          req, err := http.NewRequest("GET", basicMetricRequest, nil)
          if err != nil {
              msg := "Failed to create request for the Metrics Endpoint: %v"
      Severity: Minor
      Found in src/jetstream/plugins/metrics/main.go - About 1 hr to fix

        Method MetricsSpecification.Connect has 9 return statements (exceeds 4 allowed).
        Open

        func (m *MetricsSpecification) Connect(ec echo.Context, cnsiRecord interfaces.CNSIRecord, userId string) (*interfaces.TokenRecord, bool, error) {
            log.Debug("Metrics Connect...")
        
            params := new(interfaces.LoginToCNSIParams)
            err := interfaces.BindOnce(params, ec)
        Severity: Major
        Found in src/jetstream/plugins/metrics/main.go - About 55 mins to fix

          Method MetricsSpecification.createMetadata has 8 return statements (exceeds 4 allowed).
          Open

          func (m *MetricsSpecification) createMetadata(metricEndpoint *url.URL, httpClient http.Client, auth *MetricsAuth) (string, error) {
              basicMetricRequest := fmt.Sprintf("%s/api/v1/query?query=firehose_total_metrics_received", metricEndpoint)
              req, err := http.NewRequest("GET", basicMetricRequest, nil)
              if err != nil {
                  msg := "Failed to create request for the Metrics Endpoint: %v"
          Severity: Major
          Found in src/jetstream/plugins/metrics/main.go - About 50 mins to fix

            Method MetricsSpecification.createMetadata has a Cognitive Complexity of 10 (exceeds 8 allowed). Consider refactoring.
            Open

            func (m *MetricsSpecification) createMetadata(metricEndpoint *url.URL, httpClient http.Client, auth *MetricsAuth) (string, error) {
                basicMetricRequest := fmt.Sprintf("%s/api/v1/query?query=firehose_total_metrics_received", metricEndpoint)
                req, err := http.NewRequest("GET", basicMetricRequest, nil)
                if err != nil {
                    msg := "Failed to create request for the Metrics Endpoint: %v"
            Severity: Minor
            Found in src/jetstream/plugins/metrics/main.go - 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

            Method MetricsSpecification.getMetricsEndpoints has 5 return statements (exceeds 4 allowed).
            Open

            func (m *MetricsSpecification) getMetricsEndpoints(userGUID string, cnsiList []string) (map[string]EndpointMetricsRelation, error) {
            
                metricsProviders := make([]MetricsMetadata, 0)
                endpointsMap := make(map[string]*interfaces.ConnectedEndpoint)
                results := make(map[string]EndpointMetricsRelation)
            Severity: Major
            Found in src/jetstream/plugins/metrics/main.go - About 35 mins to fix

              There are no issues that match your filters.

              Category
              Status