Skip to content
This repository has been archived by the owner on Nov 4, 2021. It is now read-only.

Add plugins audit log #327

Merged
merged 10 commits into from
Apr 26, 2021
Merged

Add plugins audit log #327

merged 10 commits into from
Apr 26, 2021

Conversation

yakkomajuri
Copy link
Contributor

Changes

Tackles #269

I guess $plugins_failed will need to evolve once we have retries, but we don't yet, so...

Checklist

  • Updated Settings section in README.md, if settings are affected
  • Jest tests

Copy link
Collaborator

@mariusandra mariusandra left a comment

Choose a reason for hiding this comment

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

Thanks for making progress on this! Some comments/suggestions in the review.

src/worker/plugins/run.ts Outdated Show resolved Hide resolved
src/worker/plugins/run.ts Outdated Show resolved Hide resolved
@yakkomajuri
Copy link
Contributor Author

Also renamed to $plugins_ran_successfully because plugins that failed did technically run

Comment on lines 34 to 42
if (!returnedEvent.properties) {
returnedEvent.properties = {}
}
if (pluginsRan.length > 0) {
returnedEvent.properties['$plugins_ran_successfully'] = pluginsRan
}
if (pluginsFailed.length > 0) {
returnedEvent.properties['$plugins_failed'] = pluginsFailed
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Some code feedback then :).

  1. There's no need to run if (!returnedEvent.properties) { returnedEvent.properties = {} } if we're not going to change anything (when lengths are 0 for both arrays)
  2. I think it's better that either both keys exist or none do, otherwise you'll end up second guessing yourself if the $plugins_failed array is just not there (instead of being empty, which tells you directly that nothing failed)

You could do something like:

    if (pluginsRan.length > 0 || pluginsFailed.length > 0) {
        event.properties = { 
            ...event.properties,
            '$plugins_ran_successfully': pluginsRan,
            '$plugins_failed': pluginsFailed,
        }
    }

Comment on lines 87 to 93
if (event) {
if (!event.properties) {
event.properties = {}
}
event.properties['$plugins_ran_successfully'] = pluginsRan
event.properties['$plugins_failed'] = pluginsFailed
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here that we should only add these props if any plugins actually ran.

Copy link
Collaborator

@mariusandra mariusandra left a comment

Choose a reason for hiding this comment

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

feedback left inline :)

@@ -66,6 +81,16 @@ export async function runPluginsOnBatch(server: PluginsServer, batch: PluginEven
}
}

for (const event of returnedEvents) {
if ((event && pluginsRan.length > 0) || pluginsFailed.length > 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this if is looking funny... :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

huh formatter messed up there

Copy link
Collaborator

Choose a reason for hiding this comment

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

Did it now? :P
Or did you just forget the () and prettier just made the default operator precedence apparent? :)
Always when mixing && and || put as many brackets around the different parts of the query as possible to avoid any errors...

@mariusandra mariusandra added the bump patch Bump patch version when this PR gets merged label Apr 22, 2021
@mariusandra
Copy link
Collaborator

A flaky test that's not related to this PR is failing. So merging and will fix that later.

@mariusandra mariusandra enabled auto-merge (squash) April 22, 2021 14:45
@mariusandra
Copy link
Collaborator

Ah, no, I can't :D

image

Will re-run and hope for the best.

src/worker/plugins/run.ts Outdated Show resolved Hide resolved
fuziontech pushed a commit to PostHog/posthog that referenced this pull request Oct 12, 2021
* Add audit log of plugins ran and failed

* Add plugins audit log

* updates

* update tests

* address feedback

* update tests

* override formatter

* rename $plugins_ran_successfully to $plugins_succeeded

Co-authored-by: Marius Andra <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bump patch Bump patch version when this PR gets merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants