Conversation
Contributor
|
Contributor
Contributor
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Contributor
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Contributor
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Contributor
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Pull request overview
This PR addresses folder/dashboard interactions (Issue #125) by shifting folder resolution toward UID-based APIs and making several endpoints more tolerant of newer Grafana response shapes/status handling, with accompanying unit/integration test and docs updates.
Changes:
- Add folder UID resolution (
get_folder_uid_by_dashboard_path) and migrate dashboard operations to use folder UID instead of folder ID. - Update several API methods to handle newer Grafana response formats and include HTTP status codes in responses (alerting, dashboard diff, playlist items, datasource fallbacks).
- Adjust unit/integration tests and documentation to reflect the new behaviors and signatures.
Reviewed changes
Copilot reviewed 20 out of 21 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/unittests/test_folder.py | Updates mocks/expectations for new folder UID+ID helper usage. |
| tests/unittests/test_dashboard.py | Switches to folder UID lookup mocking; adjusts dashboard diff behavior expectations. |
| tests/unittests/test_alerting.py | Updates mocked alerting responses to include status codes. |
| tests/integrationtest/test_user.py | Exercises new UID-based star/unstar capability. |
| tests/integrationtest/test_playlist.py | Makes playlist tests resilient by creating/cleaning baseline playlists and tracking created UID. |
| tests/integrationtest/test_folder.py | Loosens assertions and updates to new folder UID+ID listing helper. |
| tests/integrationtest/test_datasource.py | Adds debug output (should be removed). |
| tests/integrationtest/test_dashboard.py | Forces overwrite in diff tests to reduce flakiness. |
| tests/integrationtest/test_alerting.py | Makes delete-config test tolerant of provisioned-config behavior. |
| tests/integrationtest/test_alerting_provisioning.py | Adds cleanup for orphaned resources before provisioning tests. |
| grafana_api/user.py | Adds optional UID-based star/unstar endpoints while keeping legacy ID behavior. |
| grafana_api/playlist.py | Handles playlist item responses that return {"items": [...]} instead of a list. |
| grafana_api/folder.py | Introduces folder UID lookup and new helper to return folder id+uid+title (but query construction is currently broken). |
| grafana_api/datasource.py | Adds fallbacks for deprecated/unavailable ID-based datasource operations. |
| grafana_api/dashboard.py | Migrates dashboard create/search to folder UID usage; changes diff endpoint handling to return non-200 payloads. |
| grafana_api/alerting.py | Switches alertmanager config create/delete to status-code-based handling with warnings on 4xx. |
| grafana_api/alerting_provisioning.py | Fixes incorrect success-range checks for status codes. |
| docs/coverage.svg | Updates displayed coverage percentage. |
| docs/content/grafana_api/user.md | Documents new UID-based star/unstar parameters. |
| docs/content/grafana_api/folder.md | Documents new folder UID lookup and folder id+uid+title listing helper. |
| docs/content/grafana_api/datasource.md | Documents datasource fallback behavior for deprecated endpoints. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
439
to
441
| folders_raw: list = Api(self.grafana_api_model).call_the_api( | ||
| f"{APIEndpoints.SEARCH.value}?folderIds=0" | ||
| f"{APIEndpoints.SEARCH.value}?folderUIDs" | ||
| ) |
| dashboard_json_complete: dict = { | ||
| "dashboard": dashboard_json, | ||
| "folderId": folder_id, | ||
| "folderUID": folder_uid, |
Comment on lines
+204
to
210
| folder_query_parameter: str = f"folderUIDs={folder_uid}" | ||
| if folder_uid is None: | ||
| folder_query_parameter = "" | ||
|
|
||
| search_query: str = ( | ||
| f"{APIEndpoints.SEARCH.value}?folderIds={folder_id}&query={dashboard_name}" | ||
| f"{APIEndpoints.SEARCH.value}?{folder_query_parameter}&query={dashboard_name}" | ||
| ) |
Comment on lines
+570
to
+581
| @@ -567,13 +571,14 @@ def calculate_dashboard_diff( | |||
| f"{APIEndpoints.DASHBOARDS.value}/calculate-diff", | |||
| RequestsMethods.POST, | |||
| json.dumps(diff_object), | |||
| response_status_code=True, | |||
| ) | |||
|
|
|||
| if api_call.status_code != 200: | |||
| logging.error(f"Check the error: {api_call.text}.") | |||
| raise Exception | |||
| else: | |||
| return api_call.text | |||
| if api_call.get("status") != 200: | |||
| logging.warning( | |||
| f"Dashboard diff returned non-200 status (endpoint may be deprecated): {api_call}." | |||
| ) | |||
| return api_call.get("data") or api_call | |||
Comment on lines
485
to
507
| if dashboard_id != 0: | ||
| api_call: dict = Api(self.grafana_api_model).call_the_api( | ||
| f"{APIEndpoints.USER.value}/stars/dashboard/{dashboard_id}", | ||
| RequestsMethods.POST, | ||
| json.dumps(dict()), | ||
| ) | ||
| if dashboard_uid: | ||
| api_call: dict = Api(self.grafana_api_model).call_the_api( | ||
| f"{APIEndpoints.USER.value}/stars/dashboard/uid/{dashboard_uid}", | ||
| RequestsMethods.POST, | ||
| json.dumps(dict()), | ||
| ) | ||
| else: | ||
| api_call: dict = Api(self.grafana_api_model).call_the_api( | ||
| f"{APIEndpoints.USER.value}/stars/dashboard/{dashboard_id}", | ||
| RequestsMethods.POST, | ||
| json.dumps(dict()), | ||
| ) | ||
|
|
||
| if api_call.get("message") != "Dashboard starred!": | ||
| if api_call.get("message") not in ("Dashboard starred!", "") and api_call != dict(): | ||
| logging.error(f"Check the error: {api_call}.") | ||
| raise Exception | ||
| else: | ||
| logging.info("You successfully starred the corresponding dashboard.") | ||
| else: | ||
| logging.error("There is no org_id defined.") | ||
| logging.error("There is no dashboard_id defined.") | ||
| raise ValueError | ||
|
|
| def test_get_datasource_by_name(self): | ||
| data_source: dict = self.data_source.get_datasource_by_name("TestData DB") | ||
|
|
||
| print(data_source) |
Comment on lines
+317
to
+324
| if not (200 <= api_call.get("status") < 300): | ||
| if 400 <= api_call.get("status") < 500: | ||
| logging.warning( | ||
| f"Delete alertmanager config returned client error (e.g. provisioned config): {api_call}." | ||
| ) | ||
| else: | ||
| logging.error(f"Check the error: {api_call}.") | ||
| raise Exception |
Comment on lines
404
to
412
| if not (200 <= api_call.get("status") < 300): | ||
| if 400 <= api_call.get("status") < 500: | ||
| logging.warning( | ||
| f"Create/update alertmanager config returned client error (e.g. provisioned config): {api_call}." | ||
| ) | ||
| else: | ||
| logging.error(f"Check the error: {api_call}.") | ||
| raise Exception | ||
| else: |
Contributor
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Contributor
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Contributor
Coverage Report
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Contributor
Coverage Report
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Contributor
Coverage Report
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Contributor
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Contributor
|
Contributor
|
Contributor
Coverage Report
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Contributor
Coverage Report
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Contributor
Coverage Report
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Contributor
Coverage Report
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Contributor
Coverage Report
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Contributor
Coverage Report
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Contributor
Coverage Report
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Contributor
Coverage Report
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Contributor
Coverage Report
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Contributor
Coverage Report
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix: #125