Skip to content

Improve payload format of DORA metrics API

Shinya Maeda requested to merge change-payload-format-for-dora-metrics into master

What does this MR do?

In a few weeks ago, we introduced DORA metrics API. At that moment, the payload format was decided to Array of Hash, that takes "date" as key and "Y-Axis (You can find more details of metric types in the doc)" as value. For example, [ { '2021-02-06' => 0 }, { '2021-02-07' => 1 } ].

However, as @nfriend pointed out, this format has the following problems:

  • It's hard to extend the data point structure because the Hash key/value pair is fixed.
  • It's hard to consume the data in client side (e.g. frontend, external service, etc) because each hash is in an array, meaning searching a value of a specific date requires O(N) iteration. (FYI, an array should be used to ensure the items are sorted by date ascending order)
  • It likely requires extra step to transform the data structure in client side, which is inconvenient.

This MR mitigates these problems by adding explicit date and value keys in the Hash, e.g. { "date": "<Date>", "value": "<Float>" }. This format is same with the Daily Code Coverage API. Please see that daily_build_group_report_results.json endpoint also serializes the data in the same format.

The unnecessary/duplicate { key => value } entry will be removed in 14.0. Please see #325931 (closed) for more information.

Sample payload

`curl -H "Private-token: [REDACTED]" 'http://local.gitlab.test:8181/api/v4/projects/35/dora/metrics?metric=deployment_frequency' | jq
[
  {
    "2021-02-06": 0,
    "date": "2021-02-06",
    "value": 0
  },
  {
    "2021-02-07": 0,
    "date": "2021-02-07",
    "value": 0
  },
  {
    "2021-02-08": 0,
    "date": "2021-02-08",
    "value": 0
  },
  {
    "2021-02-09": 0,
    "date": "2021-02-09",
    "value": 0
  },
  {
    "2021-02-10": 0,
    "date": "2021-02-10",
    "value": 0
  },
  {
    "2021-02-11": 0,
    "date": "2021-02-11",
    "value": 0
  },
  {
    "2021-02-12": 0,
    "date": "2021-02-12",
    "value": 0
  },
  {
    "2021-02-13": 0,
    "date": "2021-02-13",
    "value": 0
  },
  {
    "2021-02-14": 0,
    "date": "2021-02-14",
    "value": 0
  },
  {
    "2021-02-15": 0,
    "date": "2021-02-15",
    "value": 0
  },
  {
    "2021-02-16": 0,
    "date": "2021-02-16",
    "value": 0
  },
  {
    "2021-02-17": 0,
    "date": "2021-02-17",
    "value": 0
  },
  {
    "2021-02-18": 0,
    "date": "2021-02-18",
    "value": 0
  },
  {
    "2021-02-19": 0,
    "date": "2021-02-19",
    "value": 0
  },
  {
    "2021-02-20": 0,
    "date": "2021-02-20",
    "value": 0
  },
  {
    "2021-02-21": 0,
    "date": "2021-02-21",
    "value": 0
  },
  {
    "2021-02-22": 0,
    "date": "2021-02-22",
    "value": 0
  },
  {
    "2021-02-23": 0,
    "date": "2021-02-23",
    "value": 0
  },
  {
    "2021-02-24": 0,
    "date": "2021-02-24",
    "value": 0
  },
  {
    "2021-02-25": 0,
    "date": "2021-02-25",
    "value": 0
  },
  {
    "2021-02-26": 0,
    "date": "2021-02-26",
    "value": 0
  },
  {
    "2021-02-27": 0,
    "date": "2021-02-27",
    "value": 0
  },
  {
    "2021-02-28": 0,
    "date": "2021-02-28",
    "value": 0
  },
  {
    "2021-03-01": 3,
    "date": "2021-03-01",
    "value": 3
  },
  {
    "2021-03-02": 6,
    "date": "2021-03-02",
    "value": 6
  },
  {
    "2021-03-03": 0,
    "date": "2021-03-03",
    "value": 0
  },
  {
    "2021-03-04": 0,
    "date": "2021-03-04",
    "value": 0
  },
  {
    "2021-03-05": 0,
    "date": "2021-03-05",
    "value": 0
  },
  {
    "2021-03-06": 0,
    "date": "2021-03-06",
    "value": 0
  },
  {
    "2021-03-07": 0,
    "date": "2021-03-07",
    "value": 0
  },
  {
    "2021-03-08": 4,
    "date": "2021-03-08",
    "value": 4
  }
]
`curl -H "Private-token: [REDACTED]" 'http://local.gitlab.test:8181/api/v4/projects/35/dora/metrics?metric=deployment_frequency&interval=monthly' | jq`
[
  {
    "2021-02-01": 0,
    "date": "2021-02-01",
    "value": 0
  },
  {
    "2021-03-01": 13,
    "date": "2021-03-01",
    "value": 13
  }
]
`curl -H "Private-token: [REDACTED]" 'http://local.gitlab.test:8181/api/v4/projects/35/dora/metrics?metric=lead_time_for_changes&interval=monthly' | jq`
[
  {
    "2021-02-01": null,
    "date": "2021-02-01",
    "value": null
  },
  {
    "2021-03-01": 6,
    "date": "2021-03-01",
    "value": 6
  }
]

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team
Edited by Shinya Maeda

Merge request reports