Sonarqube API question - GET api/measures/component_tree > period

Sonarqube 8.9 Enterprise Edition

We are using the API to obtain a list of measures for group of projects and we need to know the analysis date of the given metrics.

The example response for the API method <GET api/measures/component_tree> shows the following information:
“period”: {
“mode”: “previous_version”,
“date”: “2016-01-11T10:49:50+0100”,
“parameter”: “1.0-SNAPSHOT”
}

Is this the analysis date in which we obtained the metrics given by the same API method?

Thanks

Hey there.

Can you give an full example of the API response?

Hello!

Here is the full example:

{
  "paging": {
    "pageIndex": 1,
    "pageSize": 100,
    "total": 3
  },
  "baseComponent": {
    "key": "MY_PROJECT",
    "name": "My Project",
    "qualifier": "TRK",
    "measures": [
      {
        "metric": "new_violations",
        "period": {
          "value": "255"
        }
      },
      {
        "metric": "complexity",
        "value": "42"
      },
      {
        "metric": "ncloc",
        "value": "1984"
      }
    ]
  },
  "components": [
    {
      "key": "com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown/impl/ElementImpl.java",
      "name": "ElementImpl.java",
      "qualifier": "FIL",
      "language": "java",
      "path": "src/main/java/com/sonarsource/markdown/impl/ElementImpl.java",
      "measures": [
        {
          "metric": "new_violations",
          "period": {
            "value": "25"
          }
        },
        {
          "metric": "complexity",
          "value": "12"
        },
        {
          "metric": "ncloc",
          "value": "114"
        }
      ]
    },
    {
      "key": "com.sonarsource:java-markdown:src/test/java/com/sonarsource/markdown/impl/ElementImplTest.java",
      "name": "ElementImplTest.java",
      "qualifier": "UTS",
      "language": "java",
      "path": "src/test/java/com/sonarsource/markdown/impl/ElementImplTest.java",
      "measures": [
        {
          "metric": "new_violations",
          "period": {
            "value": "0"
          }
        }
      ]
    },
    {
      "key": "com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown/impl",
      "name": "src/main/java/com/sonarsource/markdown/impl",
      "qualifier": "DIR",
      "path": "src/main/java/com/sonarsource/markdown/impl",
      "measures": [
        {
          "metric": "new_violations",
          "period": {
            "value": "25"
          }
        },
        {
          "metric": "complexity",
          "value": "35",
          "period": {
            "value": "0"
          }
        },
        {
          "metric": "ncloc",
          "value": "217",
          "period": {
            "value": "0"
          }
        }
      ]
    }
  ],
  "metrics": [
    {
      "key": "complexity",
      "name": "Complexity",
      "description": "Cyclomatic complexity",
      "domain": "Complexity",
      "type": "INT",
      "higherValuesAreBetter": false,
      "qualitative": false,
      "hidden": false,
      "custom": false
    },
    {
      "key": "ncloc",
      "name": "Lines of code",
      "description": "Non Commenting Lines of Code",
      "domain": "Size",
      "type": "INT",
      "higherValuesAreBetter": false,
      "qualitative": false,
      "hidden": false,
      "custom": false
    },
    {
      "key": "new_violations",
      "name": "New issues",
      "description": "New Issues",
      "domain": "Issues",
      "type": "INT",
      "higherValuesAreBetter": false,
      "qualitative": true,
      "hidden": false,
      "custom": false,
      "bestValue": "0"
    }
  ],
  "period": {
    "mode": "previous_version",
    "date": "2016-01-11T10:49:50+0100",
    "parameter": "1.0-SNAPSHOT"
  }
}

Thanks.

You’ll notice that the measures prefixed by new contain a period value – this is in reference to the New Code Period set for your project. This might not be (and is unlikely) to be the latest analysis. You can check what the New Code Period is on your project dashboard.

The other metrics without period (like complexity) are values for your overall codebase, without considering the new code period.

Thank you for your feedback.

But, what about the period in the response under the other metrics without period?

Is this a reference to the period in the metrics prefixed by new?

Yes. And it should match the new code period defined for your project here!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.