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

automod: add removing of labels from accounts and records #950

Merged
merged 7 commits into from
Feb 25, 2025

Conversation

haileyok
Copy link
Contributor

i haven't tested this yet - and took me a little to understand what we were doing here so might still be a little off - but this should let us remove existing labels from accounts/records

@haileyok
Copy link
Contributor Author

haileyok commented Feb 20, 2025

one thing that might be weird here is if one rule adds a label and then another negates the label, need to think that through as i think it could get wonky with the current logic here in the pr....

early and still not fully caffeinated, but i think i got some decent logic here. imagine a scenario like:

  • Rule 1 executes and decides to AddLabel("sexual")
  • Rule 2 executes and decides to RemoveLabel("sexual")

Here, we'd keep the sexual label in the new labels to add (assuming it wasn't already added on the account/record).

  • Rule 1 executes and decides to RemoveLabel("sexual")
  • There is no sexual label on the account/record

Here we'd remove the sexual label from the rmdLabels, since there's no point in negating it.

  • Rule 1 executes and decides to RemoveLabel("sexual")
  • There is already a negated sexual label on the account/record

Here we'd remove the sexual label from the rmdLabels, since again in negating it.

@haileyok haileyok requested a review from bnewbold February 21, 2025 16:19
Copy link
Collaborator

@bnewbold bnewbold left a comment

Choose a reason for hiding this comment

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

one little typo, but otherwise looks good!

func (e *Effects) RemoveAccountLabel(val string) {
e.mu.Lock()
defer e.mu.Unlock()
for _, v := range e.RemovedRecordLabels {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Record / Account swapped here (sorry this code is so duplicative)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oop nice catch ty

@@ -42,6 +43,15 @@ func (eng *Engine) persistAccountModActions(c *AccountContext) error {

// de-dupe actions
newLabels := dedupeLabelActions(c.effects.AccountLabels, c.Account.AccountLabels, c.Account.AccountNegatedLabels)
var rmdLabels []string
Copy link
Collaborator

Choose a reason for hiding this comment

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

embarrassing idiomatic golang question: should this be:

rmdLabels := []string{}

specifically b/c it gets len() called on it, and passed to NegateLabelVals below. probably fine/same either way. "is zero/nil of an array of strings same as empty array"

Copy link
Contributor Author

@haileyok haileyok Feb 25, 2025

Choose a reason for hiding this comment

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

it would be fine for the len() case. good point though with getting passed to NegateLabelVals. i'm not sure if the api would be happy with a null (or omitted? didnt look closely) value after marshaling, so yea let's just initialize the empty array

@haileyok haileyok merged commit 464ab8d into main Feb 25, 2025
9 checks passed
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.

2 participants