Skip to content

Commit

Permalink
Handle inconsistent grafana.com dashboard revision API.
Browse files Browse the repository at this point in the history
  • Loading branch information
addreas committed Jun 7, 2022
1 parent 685f2ba commit af0b5c3
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions controllers/grafanadashboard/dashboard_pipeline.go
Expand Up @@ -380,12 +380,13 @@ func (r *DashboardPipelineImpl) getLatestRevisionForGrafanaComDashboard() (int,
// direction.
func (r *DashboardPipelineImpl) getMaximumRevisionFromListDashboardRevisionsResponse(resp *listDashboardRevisionsResponse) int {
if resp.OrderBy == "revision" {
if resp.Direction == "asc" {
return resp.Items[len(resp.Items)-1].Revision
}

if resp.Direction == "desc" {
return resp.Items[0].Revision
// resp.Direction seems to be inverted in the response (as of 2022-05-09), so let's ignore it and grab the bigger value
first := resp.Items[0].Revision
last := resp.Items[len(resp.Items)-1].Revision
if first > last {
return first
} else {
return last
}
}

Expand Down

0 comments on commit af0b5c3

Please sign in to comment.