-
Notifications
You must be signed in to change notification settings - Fork 25
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
feat: preserve alerts, update to 40sdk #97
base: main
Are you sure you want to change the base?
Conversation
Python Tests 2 files - 6 56 suites - 168 0s ⏱️ -4s For more details on these failures and errors, see this check. Results for commit 809234e. ± Comparison against base commit 3065a4f. This pull request removes 86 and adds 22 tests. Note that renamed tests count towards both.
|
Python Tests 6 files ± 0 168 suites ±0 5s ⏱️ +3s For more details on these failures and errors, see this check. Results for commit 82d18a9. ± Comparison against base commit 1d080c2. This pull request removes 40 and adds 11 tests. Note that renamed tests count towards both.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me know what changes you want to handle and which I can handle. Thanks!
@@ -303,6 +359,8 @@ def main(args): | |||
args.target_base = 'Shared' | |||
|
|||
sdk = get_client(args.ini, args.env) | |||
global enabled_alerts | |||
enabled_alerts = sdk.search_alerts(disabled="false") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe you need sdk.search_alerts(disabled=False, all_owners=True)
to ensure all alerts for all users are pulled in (same with schedules)
existing_dash_alerts = [] | ||
existing_elements_w_alerts = [] | ||
|
||
if content_type == "dashboard": ## only run for dashboards, looks can't have alerts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to move this into a separate function that is called from here to allow for unit tests?
if is_new_dash == "false": ## if it's an existing dashboard, save the alerts and elements | ||
for element in existing_dash[0]['dashboard_elements']: | ||
start = len(existing_dash_alerts) | ||
alerts = list(filter(lambda alert: alert['dashboard_element_id'] == element['id'], enabled_alerts)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To get this to work I needed to do the following str(alert['dashboard_element_id']) == str(element['id'])
I think the alert ID might be a number 🤦 this allowed for the alert to be found
updated_dash = sdk.search_dashboards(title=json_dash['title'],folder_id=space_id) | ||
old_to_new_ids = {} | ||
for element in existing_elements_w_alerts: ## match old element ids to new element ids | ||
updated_dash_element = list(filter(lambda item: item['title'] == element['title'] and item['query_id'] == element['query_id'], updated_dash[0]['dashboard_elements'])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay so we're comparing title of the element and the query ID. What happens when the query ID changes? It's okay this break the alert as well? I also could not get this work when I tried to unit test it, didn't delve too deep into why. On 22.16 it's unsetting my alert from the dashboard but I'm also not getting it disabled either.
for key in alert.keys(): | ||
new_alert[key] = alert[key] | ||
if alert['dashboard_element_id'] in old_to_new_ids.keys(): | ||
logger.debug("creating alert", extra={"old_element_id": alert['dashboard_element_id'], "new_element_id": old_to_new_ids[alert['dashboard_element_id']]}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we get an logger.info line that summarizes what is happening that specifies the dashboard element ID and alert being updated.
disabled_alerts = sdk.search_alerts(disabled="true") | ||
for alert in disabled_alerts: | ||
if alert['disabled_reason'] == "Dashboard element has been removed.": | ||
sdk.delete_alert(alert['id']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we actually just disable the alert via update_alert, you can take the body and then change the is_disabled to false and add a disabled reason
disabled_alerts = sdk.search_alerts(disabled="true") | ||
for alert in disabled_alerts: | ||
if alert['disabled_reason'] == "Dashboard element has been removed.": | ||
sdk.delete_alert(alert['id']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also logger.info for any time we do delete or updating so people can see which IDs changed
@@ -303,6 +359,8 @@ def main(args): | |||
args.target_base = 'Shared' | |||
|
|||
sdk = get_client(args.ini, args.env) | |||
global enabled_alerts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we can get an update to the readme about this new functionality
looker_deployer/utils/get_client.py
Outdated
auth_session.AuthSession(settings, transport, serialize.deserialize31, "3.1"), | ||
serialize.deserialize31, | ||
serialize.serialize31, | ||
return methods.Looker40SDK( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add this to the readme as well that we are moving as a whole to API 4.0
for alert in disabled_alerts: | ||
if alert['disabled_reason'] == "Dashboard element has been removed.": | ||
sdk.delete_alert(alert['id']) | ||
|
||
|
||
def get_space_ids_from_name(space_name, parent_id, sdk): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we update any functions from space to folder and variables? Also tests will need to be updated for this change. Just don't change the actual looker commands (which already referred to things as folders). I'm pretty sure space to folder find & replace should fix 95% of use cases.
Python Tests 6 files ± 0 168 suites ±0 5s ⏱️ +3s For more details on these failures and errors, see this check. Results for commit 4d772c4. ± Comparison against base commit 1d080c2. This pull request removes 40 and adds 11 tests. Note that renamed tests count towards both.
|
Python Tests 6 files ± 0 168 suites ±0 5s ⏱️ +3s For more details on these failures and errors, see this check. Results for commit b2d7955. ± Comparison against base commit 1d080c2. This pull request removes 40 and adds 11 tests. Note that renamed tests count towards both.
|
Python Tests 4 files - 2 112 suites - 56 3s ⏱️ -1s For more details on these failures and errors, see this check. Results for commit 17c4d4a. ± Comparison against base commit 1d080c2. This pull request removes 40 and adds 10 tests. Note that renamed tests count towards both.
|
Python Tests 6 files ± 0 168 suites ±0 5s ⏱️ +3s For more details on these failures and errors, see this check. Results for commit 66a69a6. ± Comparison against base commit 1d080c2. This pull request removes 40 and adds 10 tests. Note that renamed tests count towards both.
|
@@ -13,7 +13,7 @@ | |||
# limitations under the License. | |||
|
|||
import logging | |||
from looker_sdk import models | |||
from looker_sdk import models40 as models |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will be good until the python SDK is updated after 3.1 is removed. Then models40 will probably be called models
. We should discuss/research how much code this would break ... or maybe we alias models for models40. Worth thinking about @christelilaka @drstrangelooker et al
Python Tests 6 files ± 0 168 suites ±0 5s ⏱️ +3s For more details on these failures and errors, see this check. Results for commit af83654. ± Comparison against base commit 1d080c2. This pull request removes 40 and adds 10 tests. Note that renamed tests count towards both.
|
Python Tests 6 files ± 0 168 suites ±0 5s ⏱️ +3s For more details on these failures and errors, see this check. Results for commit 532f33e. ± Comparison against base commit 1d080c2. This pull request removes 40 and adds 10 tests. Note that renamed tests count towards both.
|
Python Tests 5 files - 1 167 suites - 1 2s ⏱️ -1s For more details on these failures and errors, see this check. Results for commit 7135a21. ± Comparison against base commit 7323c77. This pull request removes 42 and adds 10 tests. Note that renamed tests count towards both.
|
The changes here preserve alerts when importing dashboards.
Dashboard elements don't have slugs and the element id is updated when a dashboard is overwritten, which breaks original alerts.
The dashboard element id for an alert can't be updated, even though it is not listed in the docs as a readonly attribute.
In order to preserve alerts, we first get all of the existing alerts. Then as we import each dashboard, we save all of the element ids that have existing alerts. After import, we map those old element ids to the new ids, based on title and query_id. Finally we create new alerts using the new element ids.
Alerts will still break if there are title or query changes between the old and the updated dashboard, as there isn't a convenient way to match the element ids.
In order to use the alerts API, I also had to update deployer to use the 40 sdk.