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

Dual write rule instances to new and old tables #3486

Merged
merged 6 commits into from
Jun 5, 2024
Merged

Conversation

dmjb
Copy link
Member

@dmjb dmjb commented May 31, 2024

Relates to #3485

Any time a profile is created or updated, write the rule instances to both the new and old rule instance tables. Mark the entries in the old tables as migrated so that we skip over them when we run the migration process.

Summary

Provide a brief overview of the changes and the issue being addressed.
Explain the rationale and any background necessary for understanding the changes.
List dependencies required by this change, if any.

Fixes #(related issue)

Change Type

Mark the type of change your PR introduces:

  • Bug fix (resolves an issue without affecting existing features)
  • Feature (adds new functionality without breaking changes)
  • Breaking change (may impact existing functionalities or require documentation updates)
  • Documentation (updates or additions to documentation)
  • Refactoring or test improvements (no bug fixes or new functionality)

Testing

Outline how the changes were tested, including steps to reproduce and any relevant configurations.
Attach screenshots if helpful.

Review Checklist:

  • Reviewed my own code for quality and clarity.
  • Added comments to complex or tricky code sections.
  • Updated any affected documentation.
  • Included tests that validate the fix or feature.
  • Checked that related changes are merged.

@coveralls
Copy link

coveralls commented May 31, 2024

Coverage Status

coverage: 53.236% (+0.07%) from 53.165%
when pulling 035c705 on rule-instance-table
into b2aecdf on main.

@dmjb dmjb force-pushed the rule-instance-table branch 3 times, most recently from 763b0b4 to dbca1ab Compare June 4, 2024 10:30
@dmjb dmjb marked this pull request as ready for review June 4, 2024 10:31
@dmjb dmjb requested a review from a team as a code owner June 4, 2024 10:31
@@ -28,7 +28,7 @@ INSERT INTO entity_profiles (
$1,
$2,
sqlc.arg(contextual_rules)::jsonb,
FALSE
TRUE
Copy link
Member Author

Choose a reason for hiding this comment

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

At this point, any new or updated profiles will have rules in the new rule instance table, and thus can be considered migrated.

RuleTypeID: entityRuleTuple.RuleID,
Name: rule.Name,
EntityType: entityType,
Def: pqtype.NullRawMessage{
Copy link
Contributor

Choose a reason for hiding this comment

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

The PR looks good, the only question I have is how would we later instantiate the rule params and defs - right now the code seems to presume that they are non-nil:

result, err = r.ingester.Ingest(ctx, inf.Entity, params.GetRule().Params.AsMap())

so we'll have to check that we don't instantiate them as nil in this case.

jhrozek
jhrozek previously approved these changes Jun 5, 2024
Copy link
Contributor

@jhrozek jhrozek left a comment

Choose a reason for hiding this comment

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

Added one comment but overall looks good.

rdimitrov
rdimitrov previously approved these changes Jun 5, 2024
dmjb added 4 commits June 5, 2024 14:04
Relates to #3485

Any time a profile is created or updated, write the rule instances to
both the new and old rule instance tables. Mark the entries in the old
tables as migrated so that we skip over them when we run the migration
process.
@dmjb dmjb dismissed stale reviews from rdimitrov and jhrozek via 78ee85b June 5, 2024 13:12

BEGIN;

ALTER TABLE rule_instances ALTER COLUMN def DROP NOT NULL;
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we haven't written anything to the columns, this is safe to do.


id, err := qtx.UpsertRuleInstance(ctx, newInstance)
Def: def,
Params: params,
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume that if there's no params defined then json.Marshall returns {}? I wasn't sure about that since the previous code had an explicit params != nil check. But I guess we'd want to either store {} or make sure to on retrieval convert whatever value is stored to {} .

@dmjb dmjb merged commit f170622 into main Jun 5, 2024
22 checks passed
@dmjb dmjb deleted the rule-instance-table branch June 5, 2024 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants