grafana/k6-cloud-grafana-datasource

View on GitHub
src/DataSource.ts

Summary

Maintainability
D
2 days
Test Coverage
F
0%

File DataSource.ts has 730 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import _ from 'lodash';
import Keyv from 'keyv';

import {
  DataQueryRequest,
Severity: Major
Found in src/DataSource.ts - About 1 day to fix

    Function query has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
    Open

      async query(options: DataQueryRequest<K6CloudQuery>): Promise<DataQueryResponse> {
        let data = { data: [] as MutableDataFrame[] };
    
        for (const target of options.targets) {
          if (target.hide) {
    Severity: Minor
    Found in src/DataSource.ts - 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

    DataSource has 22 functions (exceeds 20 allowed). Consider refactoring.
    Open

    export class DataSource extends DataSourceApi<K6CloudQuery, K6CloudDataSourceOptions> {
      url?: string;
      cache?: Keyv;
    
      constructor(instanceSettings: DataSourceInstanceSettings<K6CloudDataSourceOptions>) {
    Severity: Minor
    Found in src/DataSource.ts - About 2 hrs to fix

      Avoid deeply nested control flow statements.
      Open

              if (resolvedTestRunId) {
                const thresholdsList = await this.getThresholdsForTestRun(resolvedTestRunId);
                const fields = this.convertThresholdsToFields(thresholdsList);
                data.data.push(
                  new MutableDataFrame({
      Severity: Major
      Found in src/DataSource.ts - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

              } else if (qtype === K6QueryType.URLS) {
                if (resolvedTestRunId) {
                  const urlsList = await this.getURLsForTestRun(resolvedTestRunId);
                  const fields = this.convertURLsToFields(urlsList);
                  data.data.push(
        Severity: Major
        Found in src/DataSource.ts - About 45 mins to fix

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

            convertSeriesToFields(series: K6Series, metric: K6Metric, tags?: Map<string, string>, aggregation?: string) {
              const timeValues = _.map(series.values, (d) => {
                return dateTimeParse(d.timestamp).unix() * 1000;
              });
              const values = _.map(series.values, (d) => {
          Severity: Minor
          Found in src/DataSource.ts - 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 [];
          Severity: Major
          Found in src/DataSource.ts - About 30 mins to fix

            There are no issues that match your filters.

            Category
            Status