Repository navigation
feat(resource_monitor): manage triggers, several notify users, and non-ACCOUNTADMIN owners - #86
Conversation
…n-ACCOUNTADMIN owners
A live resource monitor could not be declared and planned to zero changes:
- The class had no field for TRIGGERS, so notify and suspend thresholds
could not be declared or read back.
- The fetch returned the SHOW notify_users string ("A, B") instead of a
list, so a monitor with several notify users failed to plan.
- The spec refused any owner except ACCOUNTADMIN, although ACCOUNTADMIN can
hand a monitor to another role, and after that only that role can alter
or drop it.
Add a `triggers` field (threshold + NOTIFY / SUSPEND / SUSPEND_IMMEDIATE)
rendered and parsed by TriggersProp, read it back from notify_at /
suspend_at / suspend_immediately_at, and sort triggers and notify users so
order never diffs. Updates emit SET props followed by the TRIGGERS clause.
Create runs as ACCOUNTADMIN and transfers to a declared owner; update and
drop run as the owning role.
|
Reviewed this PR (10 files). Checked out the head, read every hunk against the surrounding code ( Five findings.
Checked and cleared, for the record: |
|
@GClunies checking in, quiet since my Oct 18 review. Open from my side are the two mediums: finding 1, the owner split breaking the ordering assumption in One scheduling note: #93 and #97 merged today and #93 touched Are you planning to pick these up? |
… users - Apply runs each level's ownership transfers after its other changes. An update runs as the current owner and shares a level with the transfer of the same resource, so a transfer that ran first made the ALTER fail with 003001. The old loop failed 5 of 10 hash seeds in the new unit test. - notify_users are named as Snowflake stores them: an unquoted name is uppercased, a quoted name keeps its case. Snowflake matches the NOTIFY_USERS string exactly, so `$$alice$$` failed with 090268. - Triggers with a missing or extra key, a bool threshold, or a negative threshold raise ValueError. A threshold of 0 is valid in Snowflake. - The class docstring fields are one line each, so the docs generator parses the class again. docs/resources/resource_monitor.md documents triggers and owner and drops the ACCOUNTADMIN-only note. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011dXsGMQktcy3n6S92p5Cmv
|
@noel Thanks for the review. All five findings are addressed in 419712f. I merged
|
Rerun live_audit.py on every object at snowcap 6ce5c12, so FINDINGS.md reflects current main, as the review asked. main changed three things that the inventory had to follow: - RESOURCE MONITOR: triggers is a field now (datacoves#86). The truth query joins SHOW's notify_at, suspend_at, and suspend_immediately_at columns, and the row has samples. It passes L2 to L5. - SECURITY INTEGRATION:saml2: SAML2SecurityIntegration models it now. The object has create_args, truth queries, and samples for 11 rows. The rows without a sample say why. The x509 samples are self-signed test certificates with no private key. - EXTERNAL FUNCTION: fqn now carries the argument signature (datacoves#90), so the DESCRIBE in the truth query doubled it and failed. The query names the function without a signature now. NOTEBOOK now fails L2, because Snowflake disabled new Legacy Notebooks on the test account (BCR: no Legacy Notebook activity in the 60 days before November 1, 2026). snowcap's Notebook renders only the legacy CREATE NOTEBOOK, so the finding is correct for current snowcap. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011dXsGLBEG2amgh6CdUmCP5
What
Snowcap can now manage a real resource monitor: its triggers, a list of notify users, and an owner other than
ACCOUNTADMIN. A live monitor declared in YAML plans to zero changes, and changes to it apply.ResourceMonitorhad no field forTRIGGERS. Notify and suspend thresholds could not be declared or read back.triggersfield: a list of{threshold, action}with actionNOTIFY,SUSPEND, orSUSPEND_IMMEDIATE. The fetch reads it back fromnotify_at,suspend_at, andsuspend_immediately_at.SHOWstring"A, B", so the plan rejected the monitor it read.ResourceMonitors can only be created by ACCOUNTADMINfor any other owner.ACCOUNTADMINand transfers ownership to the declared owner. Update and drop run as the owning role.ALTERfail with 003001.notify_users: [alice]rendered$$alice$$, which Snowflake rejects with 090268.Why
We tested each Snowflake behavior against a live account before we wrote the code.
ALTER RESOURCE MONITOR X SET CREDIT_QUOTA = 7 TRIGGERS ON ...TRIGGERSreplaces every trigger.update_resource_monitorrendersSETprops, then the fullTRIGGERSclause.ALTER RESOURCE MONITOR X SET TRIGGERS ON ...TRIGGERSis not aSETproperty.update__defaultcannot render it, so the resource has its own update function.UNSET TRIGGERS, a bareTRIGGERS,SET TRIGGERS = (),NOTRIGGERStriggers: []raisesValueError. Omittriggersto leave them unmanaged.TRIGGERS ON 75.5 PERCENT DO NOTIFYValueError.TRIGGERS ON 0 PERCENT DO NOTIFY,TRIGGERS ON -5 PERCENT DO NOTIFY0accepted.-5is syntax error 001003.boolthreshold, or a trigger with a missing or extra key, raisesValueError.ALTER RESOURCE MONITOR X TRIGGERS ON ..., with noSETACCOUNTADMINand as a custom owner.SHOW RESOURCE MONITORSnotify_at'50%,75%'. One production account reports'100%,50%,75%,90%', which is not numeric order.SHOW RESOURCE MONITORSnotify_users''or'A, B, C'.SET NOTIFY_USERS = ($$snowcap_admin$$)for userSNOWCAP_ADMINALTERorDROPon a monitor owned by another role, run asACCOUNTADMINGRANT OWNERSHIP ON RESOURCE MONITOR X TO ROLE RasACCOUNTADMINACCOUNTADMINhierarchy.ACCOUNTADMINwith an ownership transfer when the owner differs. A later transfer also runs asACCOUNTADMIN.Tested
TestResourceMonitorPlanningintests/test_blueprint.pycovers theSHOWround-trip with zero changes, a trigger-only change, a quota plus trigger change, create plus transfer, lowercase and quoted notify users, and an apply that alters before it transfers.tests/test_resource_types.pycovers the rejected trigger lists. The SQL and JSON fixtures carry triggers.PYTHONHASHSEEDvalues (1, 2, 5, 8, 9) and passes on the new loop for all 10.make lint,make typecheck, andpytest --ignore=tests/integration: 2335 passed, 1 skipped, 1 xfailed.tests/integration/data_provider/test_fetch_resource_simple.py --snowflake -k ResourceMonitorpasses against a live account.USE ROLE ACCOUNTADMIN,CREATE RESOURCE MONITOR E2E_RM CREDIT_QUOTA = 5 TRIGGERS ON 75 PERCENT DO NOTIFY ON 100 PERCENT DO SUSPEND,GRANT OWNERSHIP ... TO ROLE PROBE_RM_OWNER COPY CURRENT GRANTSUSE ROLE PROBE_RM_OWNER,ALTER RESOURCE MONITOR E2E_RM SET CREDIT_QUOTA = 7 TRIGGERS ON 50 PERCENT DO NOTIFY ON 90 PERCENT DO SUSPEND ON 110 PERCENT DO SUSPEND_IMMEDIATEsync_resourcesUSE ROLE PROBE_RM_OWNER,DROP RESOURCE MONITOR IF EXISTS E2E_RMA second live run used
Blueprint.applywiththreads=8underPYTHONHASHSEED1, 2, and 5. The owner roles were outside theACCOUNTADMINhierarchy, and the config named the notify user in lowercase (snowcap_admin).PROBE86_ACreateResourceSHOWreportsnotify_users: SNOWCAP_ADMIN.PROBE86_BUpdateResource {triggers}+TransferOwnershipPROBE86_B,notify_at: 50%,suspend_at: 90%.Known gap, not changed here
CREATE RESOURCE MONITOR ... FREQUENCY = MONTHLYwithoutSTART_TIMESTAMPfails with error 090259, "Must specify frequency and start time together." A monitor that declaresfrequencymust also declarestart_timestamp. This behavior predates this PR.Fixes #102