Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API: Add by UID routes for data sources #29884

Merged
merged 19 commits into from Jan 13, 2021
Merged

API: Add by UID routes for data sources #29884

merged 19 commits into from Jan 13, 2021

Conversation

kylebrandt
Copy link
Contributor

@kylebrandt kylebrandt commented Dec 16, 2020

What this PR does / why we need it:
Adds the ability to get a data source by UID from SQL and via the datasource cache. This is so alerting ng will be able to store data sources by uid instead of id so it works with provisioning.

We may also switch the frontend to operate by UID, so this sets us up for that.

For requests by ID, an additional cache key to the datasource based on the UID is added. For requests by UID, the opposite is also true - an additional id cache key is added.

Also adds HTTP methods for getting + deleting via UID, and adds UID as a property to the response when listing datasources.

Which issue(s) this PR fixes:

Fixes #29852

Special notes for your reviewer:

  • WIP - still need to look at enterprise.
  • Also, not sure we want/need these API routes. If we do, I may need to also look at what update endpoint does with uids.

@kylebrandt kylebrandt changed the title Backend: Data source cache - add uid index and lookup by uid Backend: Data source UIDs, add cache datasource/uid api endpoints Dec 16, 2020
torkelo
torkelo previously requested changes Jan 7, 2021
Copy link
Member

@torkelo torkelo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall it looks good but I do feel that the amount of duplication is a bit too much. Would try to share the query operation (see GetDashboardQuery for reference it allows fetching dashboard by id, or uid or slug). And on the API handler it feels like we can also share more

@kylebrandt kylebrandt marked this pull request as ready for review January 8, 2021 14:12
@kylebrandt kylebrandt requested review from a team as code owners January 8, 2021 14:12
@kylebrandt kylebrandt requested review from sunker, jesusvazquez, oddlittlebird and achatterjee-grafana and removed request for a team January 8, 2021 14:12
@kylebrandt kylebrandt added this to In progress in Alerting frontend backlog via automation Jan 8, 2021
docs/sources/http_api/data_source.md Outdated Show resolved Hide resolved
docs/sources/http_api/data_source.md Outdated Show resolved Hide resolved
docs/sources/http_api/data_source.md Outdated Show resolved Hide resolved
Copy link
Member

@marefr marefr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great. One important change in cache service related to uid cache key. In addition some nits similar to Torkel's review.

pkg/services/datasources/cache.go Outdated Show resolved Hide resolved
pkg/api/datasources.go Outdated Show resolved Hide resolved
pkg/api/datasources.go Outdated Show resolved Hide resolved
Alerting frontend backlog automation moved this from In progress to Review in progress Jan 12, 2021
Copy link
Member

@torkelo torkelo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think this looks good, marcus found some good things

Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
@kylebrandt kylebrandt added this to the 7.4.0 milestone Jan 12, 2021
@kylebrandt kylebrandt changed the title Backend: Data source UIDs, add cache datasource/uid api endpoints Backend: Data source UIDs, add cache datasource/uid api endpoints, and Refactor Get/Delete ds calls Jan 12, 2021
Copy link
Member

@marefr marefr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great. LGTM. Added a couple nits, but no blocker

Comment on lines 130 to 139
ds, err := getRawDataSourceByUID(uid, c.OrgId)
if err != nil {
return Error(400, "Failed to delete datasource", nil)
}

if ds.ReadOnly {
return Error(403, "Cannot delete read-only data source", nil)
}

cmd := &models.DeleteDataSourceCommand{UID: uid, OrgID: c.OrgId}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit. This part and below could be reused by DeleteDataSourceByUID and DeleteDataSourceById if extracted to func deleteDataSource(cmd *models.DeleteDataSourceCommand) Response. But could be fixed later if you want to get this merged fast.

Nit. If the data source is not found in getRawDataSourceByUID that should probably return a 404 not found instead. Same applies to DeleteDataSourceById.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed for 404, will save other for possible future work. Seems we have mix of responses. May want to start returning the UID (which requires the getCmd results), so will save that for possible future work focusing on api consistency.

@kylebrandt kylebrandt dismissed torkelo’s stale review January 13, 2021 17:52

marefr is handling it

Alerting frontend backlog automation moved this from Review in progress to Reviewer approved Jan 13, 2021
@kylebrandt kylebrandt changed the title Backend: Data source UIDs, add cache datasource/uid api endpoints, and Refactor Get/Delete ds calls API: Add by UID routes for data sources Jan 13, 2021
@kylebrandt kylebrandt merged commit 1c1a800 into master Jan 13, 2021
Alerting frontend backlog automation moved this from Reviewer approved to Done Jan 13, 2021
@kylebrandt kylebrandt deleted the uidDSCache branch January 13, 2021 18:16
ryantxu pushed a commit that referenced this pull request Jan 13, 2021
- also add Get by UID+OrgID to datasource cache
- Refactor backend commands for Delete and Get to be unified
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

Backend data source cache: Make UID Version
4 participants