Commit b3a41f0d authored by James Fargher's avatar James Fargher

Merge branch 'remove-redundant-key-value-pair-from-DORA-metrics-payload' into 'master'

Remove redundant key/value pair from the payload of DORA metrics API

See merge request gitlab-org/gitlab!62875
parents f90a8af4 9064c0fb
...@@ -7,7 +7,8 @@ type: reference, api ...@@ -7,7 +7,8 @@ type: reference, api
# DevOps Research and Assessment (DORA) key metrics API **(ULTIMATE)** # DevOps Research and Assessment (DORA) key metrics API **(ULTIMATE)**
> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/279039) in [GitLab Ultimate](https://about.gitlab.com/pricing/) 13.10. > - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/279039) in [GitLab Ultimate](https://about.gitlab.com/pricing/) 13.10.
> - The legacy key/value pair `{ "<date>" => "<value>" }` was removed from the payload in GitLab 14.0.
All methods require [reporter permissions and above](../../user/permissions.md). All methods require [reporter permissions and above](../../user/permissions.md).
...@@ -38,14 +39,14 @@ Example response: ...@@ -38,14 +39,14 @@ Example response:
```json ```json
[ [
{ "2021-03-01": 3, "date": "2021-03-01", "value": 3 }, { "date": "2021-03-01", "value": 3 },
{ "2021-03-02": 6, "date": "2021-03-02", "value": 6 }, { "date": "2021-03-02", "value": 6 },
{ "2021-03-03": 0, "date": "2021-03-03", "value": 0 }, { "date": "2021-03-03", "value": 0 },
{ "2021-03-04": 0, "date": "2021-03-04", "value": 0 }, { "date": "2021-03-04", "value": 0 },
{ "2021-03-05": 0, "date": "2021-03-05", "value": 0 }, { "date": "2021-03-05", "value": 0 },
{ "2021-03-06": 0, "date": "2021-03-06", "value": 0 }, { "date": "2021-03-06", "value": 0 },
{ "2021-03-07": 0, "date": "2021-03-07", "value": 0 }, { "date": "2021-03-07", "value": 0 },
{ "2021-03-08": 4, "date": "2021-03-08", "value": 4 } { "date": "2021-03-08", "value": 4 }
] ]
``` ```
...@@ -78,14 +79,14 @@ Example response: ...@@ -78,14 +79,14 @@ Example response:
```json ```json
[ [
{ "2021-03-01": 3, "date": "2021-03-01", "value": 3 }, { "date": "2021-03-01", "value": 3 },
{ "2021-03-02": 6, "date": "2021-03-02", "value": 6 }, { "date": "2021-03-02", "value": 6 },
{ "2021-03-03": 0, "date": "2021-03-03", "value": 0 }, { "date": "2021-03-03", "value": 0 },
{ "2021-03-04": 0, "date": "2021-03-04", "value": 0 }, { "date": "2021-03-04", "value": 0 },
{ "2021-03-05": 0, "date": "2021-03-05", "value": 0 }, { "date": "2021-03-05", "value": 0 },
{ "2021-03-06": 0, "date": "2021-03-06", "value": 0 }, { "date": "2021-03-06", "value": 0 },
{ "2021-03-07": 0, "date": "2021-03-07", "value": 0 }, { "date": "2021-03-07", "value": 0 },
{ "2021-03-08": 4, "date": "2021-03-08", "value": 4 } { "date": "2021-03-08", "value": 4 }
] ]
``` ```
......
...@@ -57,8 +57,6 @@ module Dora ...@@ -57,8 +57,6 @@ module Dora
def aggregate_for!(metric, interval) def aggregate_for!(metric, interval)
data_query = data_query_for!(metric) data_query = data_query_for!(metric)
# NOTE: We would remove the `{ date => value }` entry in 14.0 in favor of the explicit `date` and `value` keys.
# See more https://gitlab.com/gitlab-org/gitlab/-/issues/325931
case interval case interval
when INTERVAL_ALL when INTERVAL_ALL
select(data_query).take.data select(data_query).take.data
...@@ -66,12 +64,12 @@ module Dora ...@@ -66,12 +64,12 @@ module Dora
select("DATE_TRUNC('month', date)::date AS month, #{data_query}") select("DATE_TRUNC('month', date)::date AS month, #{data_query}")
.group("DATE_TRUNC('month', date)") .group("DATE_TRUNC('month', date)")
.order('month ASC') .order('month ASC')
.map { |row| { row.month.to_s => row.data, 'date' => row.month.to_s, 'value' => row.data } } .map { |row| { 'date' => row.month.to_s, 'value' => row.data } }
when INTERVAL_DAILY when INTERVAL_DAILY
select("date, #{data_query}") select("date, #{data_query}")
.group('date') .group('date')
.order('date ASC') .order('date ASC')
.map { |row| { row.date.to_s => row.data, 'date' => row.date.to_s, 'value' => row.data } } .map { |row| { 'date' => row.date.to_s, 'value' => row.data } }
else else
raise ArgumentError, 'Unknown interval' raise ArgumentError, 'Unknown interval'
end end
......
...@@ -193,7 +193,7 @@ RSpec.describe Dora::DailyMetrics, type: :model do ...@@ -193,7 +193,7 @@ RSpec.describe Dora::DailyMetrics, type: :model do
let(:interval) { described_class::INTERVAL_MONTHLY } let(:interval) { described_class::INTERVAL_MONTHLY }
it 'aggregates the rows' do it 'aggregates the rows' do
is_expected.to eq([{ '2021-01-01' => 12, 'date' => '2021-01-01', 'value' => 12 }]) is_expected.to eq([{ 'date' => '2021-01-01', 'value' => 12 }])
end end
end end
...@@ -201,10 +201,10 @@ RSpec.describe Dora::DailyMetrics, type: :model do ...@@ -201,10 +201,10 @@ RSpec.describe Dora::DailyMetrics, type: :model do
let(:interval) { described_class::INTERVAL_DAILY } let(:interval) { described_class::INTERVAL_DAILY }
it 'aggregates the rows' do it 'aggregates the rows' do
is_expected.to eq([{ '2021-01-01' => 6, 'date' => '2021-01-01', 'value' => 6 }, is_expected.to eq([{ 'date' => '2021-01-01', 'value' => 6 },
{ '2021-01-02' => 4, 'date' => '2021-01-02', 'value' => 4 }, { 'date' => '2021-01-02', 'value' => 4 },
{ '2021-01-03' => 2, 'date' => '2021-01-03', 'value' => 2 }, { 'date' => '2021-01-03', 'value' => 2 },
{ '2021-01-04' => nil, 'date' => '2021-01-04', 'value' => nil }]) { 'date' => '2021-01-04', 'value' => nil }])
end end
end end
...@@ -240,7 +240,7 @@ RSpec.describe Dora::DailyMetrics, type: :model do ...@@ -240,7 +240,7 @@ RSpec.describe Dora::DailyMetrics, type: :model do
let(:interval) { described_class::INTERVAL_MONTHLY } let(:interval) { described_class::INTERVAL_MONTHLY }
it 'calculates the median' do it 'calculates the median' do
is_expected.to eq([{ '2021-01-01' => 75, 'date' => '2021-01-01', 'value' => 75 }]) is_expected.to eq([{ 'date' => '2021-01-01', 'value' => 75 }])
end end
end end
...@@ -248,10 +248,10 @@ RSpec.describe Dora::DailyMetrics, type: :model do ...@@ -248,10 +248,10 @@ RSpec.describe Dora::DailyMetrics, type: :model do
let(:interval) { described_class::INTERVAL_DAILY } let(:interval) { described_class::INTERVAL_DAILY }
it 'calculates the median' do it 'calculates the median' do
is_expected.to eq([{ '2021-01-01' => 95, 'date' => '2021-01-01', 'value' => 95 }, is_expected.to eq([{ 'date' => '2021-01-01', 'value' => 95 },
{ '2021-01-02' => 75, 'date' => '2021-01-02', 'value' => 75 }, { 'date' => '2021-01-02', 'value' => 75 },
{ '2021-01-03' => 55, 'date' => '2021-01-03', 'value' => 55 }, { 'date' => '2021-01-03', 'value' => 55 },
{ '2021-01-04' => nil, 'date' => '2021-01-04', 'value' => nil }]) { 'date' => '2021-01-04', 'value' => nil }])
end end
end end
......
...@@ -35,8 +35,8 @@ RSpec.describe API::Dora::Metrics do ...@@ -35,8 +35,8 @@ RSpec.describe API::Dora::Metrics do
subject subject
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
expect(json_response).to eq([{ '2021-01-01' => 1, 'date' => '2021-01-01', 'value' => 1 }, expect(json_response).to eq([{ 'date' => '2021-01-01', 'value' => 1 },
{ '2021-01-02' => 2, 'date' => '2021-01-02', 'value' => 2 }]) { 'date' => '2021-01-02', 'value' => 2 }])
end end
context 'when user is guest' do context 'when user is guest' do
...@@ -84,8 +84,8 @@ RSpec.describe API::Dora::Metrics do ...@@ -84,8 +84,8 @@ RSpec.describe API::Dora::Metrics do
subject subject
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
expect(json_response).to eq([{ 1.day.ago.to_date.to_s => 1, 'date' => 1.day.ago.to_date.to_s, 'value' => 1 }, expect(json_response).to eq([{ 'date' => 1.day.ago.to_date.to_s, 'value' => 1 },
{ Time.current.to_date.to_s => 2, 'date' => Time.current.to_date.to_s, 'value' => 2 }]) { 'date' => Time.current.to_date.to_s, 'value' => 2 }])
end end
context 'when user is guest' do context 'when user is guest' do
......
...@@ -115,7 +115,7 @@ RSpec.describe Dora::AggregateMetricsService do ...@@ -115,7 +115,7 @@ RSpec.describe Dora::AggregateMetricsService do
it 'returns the aggregated data' do it 'returns the aggregated data' do
expect(subject[:status]).to eq(:success) expect(subject[:status]).to eq(:success)
expect(subject[:data]).to eq([{ Time.current.to_date.to_s => 2, 'date' => Time.current.to_date.to_s, 'value' => 2 }]) expect(subject[:data]).to eq([{ 'date' => Time.current.to_date.to_s, 'value' => 2 }])
end end
context 'when interval is monthly' do context 'when interval is monthly' do
...@@ -123,7 +123,7 @@ RSpec.describe Dora::AggregateMetricsService do ...@@ -123,7 +123,7 @@ RSpec.describe Dora::AggregateMetricsService do
it 'returns the aggregated data' do it 'returns the aggregated data' do
expect(subject[:status]).to eq(:success) expect(subject[:status]).to eq(:success)
expect(subject[:data]).to eq([{ Time.current.beginning_of_month.to_date.to_s => 2, 'date' => Time.current.beginning_of_month.to_date.to_s, 'value' => 2 }]) expect(subject[:data]).to eq([{ 'date' => Time.current.beginning_of_month.to_date.to_s, 'value' => 2 }])
end end
end end
...@@ -141,7 +141,7 @@ RSpec.describe Dora::AggregateMetricsService do ...@@ -141,7 +141,7 @@ RSpec.describe Dora::AggregateMetricsService do
it 'returns the aggregated data' do it 'returns the aggregated data' do
expect(subject[:status]).to eq(:success) expect(subject[:status]).to eq(:success)
expect(subject[:data]).to eq([{ Time.current.to_date.to_s => 1, 'date' => Time.current.to_date.to_s, 'value' => 1 }]) expect(subject[:data]).to eq([{ 'date' => Time.current.to_date.to_s, 'value' => 1 }])
end end
end end
...@@ -185,7 +185,7 @@ RSpec.describe Dora::AggregateMetricsService do ...@@ -185,7 +185,7 @@ RSpec.describe Dora::AggregateMetricsService do
it 'returns the aggregated data' do it 'returns the aggregated data' do
expect(subject[:status]).to eq(:success) expect(subject[:status]).to eq(:success)
expect(subject[:data]).to eq([{ Time.current.to_date.to_s => 3, 'date' => Time.current.to_date.to_s, 'value' => 3 }]) expect(subject[:data]).to eq([{ 'date' => Time.current.to_date.to_s, 'value' => 3 }])
end end
context 'when interval is monthly' do context 'when interval is monthly' do
...@@ -193,7 +193,7 @@ RSpec.describe Dora::AggregateMetricsService do ...@@ -193,7 +193,7 @@ RSpec.describe Dora::AggregateMetricsService do
it 'returns the aggregated data' do it 'returns the aggregated data' do
expect(subject[:status]).to eq(:success) expect(subject[:status]).to eq(:success)
expect(subject[:data]).to eq([{ Time.current.beginning_of_month.to_date.to_s => 3, 'date' => Time.current.beginning_of_month.to_date.to_s, 'value' => 3 }]) expect(subject[:data]).to eq([{ 'date' => Time.current.beginning_of_month.to_date.to_s, 'value' => 3 }])
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment