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

High level overview for building your own plugin #1467

Merged
merged 17 commits into from
Jun 17, 2021
Merged

Conversation

neilkakkar
Copy link
Contributor

Changes

Did a first pass through this, capturing feedback before I polish this further.

FigJam for the images: GeoIP - https://www.figma.com/file/luaMsTScYN1fMoYliEfjrq/Plugin-Events?node-id=0%3A1

And S3 - https://www.figma.com/file/rr8QlwmSceKRaUq3Cg5vs1/Plugin-Events-External

Not sure if worth getting these made better via the great @lottiecoxon ^

Checklist

@neilkakkar neilkakkar requested a review from timgl June 10, 2021 15:45
@Twixes Twixes self-requested a review June 14, 2021 13:49
@neilkakkar neilkakkar marked this pull request as ready for review June 14, 2021 13:50

1. Every plugin acts on a single event coming in.

2. Plugins act on events before they are stored.
Copy link
Collaborator

Choose a reason for hiding this comment

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

There's just one problem with this line in that it's not technically true. I'm not sure if this is written like this for simplicity or just in error. However some plugins act on events before they are stored. Some plugins act on events at the same time that the event is being stored.

Basically:

event = await getNextEvent()
event = await processEvent1(event)
event = await processEvent2(event)
await Promise.all([
    storeEventInDatabase(event),
    onEvent1(event),
    onEvent2(event),
])

This means also that the figure for the GeoIP plugin example is correct, but the one for the S3 plugin is not. It goes into S3 and our db at the same time, two parallel arrows.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, that's right! I wanted to emphasise how some special functions mutate and others don't.

I think it's a technical detail that doesn't add extra information from the user's perspective? (i.e., I don't think knowing this will help them make better plugins? / understand plugins?)

I could do a footnote saying how this isn't exactly true?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess a footnote would suffice. The only technically important thing to clarify here is that even if an onEvent fails, the event still ends up in the database (as they are running in parallel). Otherwise people might get the wrong idea, and believe that a failure here will block the event.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, makes sense, that's the crux: there's no data loss. I'll highlight that here, and skip the footnote about the extra technical details.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually, we might need to explain this quite clearly for everything to click in place.

Inside events we have three special properties: $plugins_deferred, $plugins_failed, $plugins_succeeded:

image

The "deferred" literally implies that these plugins were run after (ingestion).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've made a note to add this bit in the developer reference, but not in the high level overview.

Copy link
Contributor

@yakkomajuri yakkomajuri left a comment

Choose a reason for hiding this comment

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

This is great! I like the structure and love how this takes me on a journey from the very basics.

Left a bunch of minor inline comments, but nothing particularly major.

One thing I'm not a fan of are the images. First, they're not transparent nor a neutral color that works in both light and dark mode. Second, I can't read what's going on. Third, they're not particularly beautiful (in comparison to our website images as a whole). Could be worth getting @lottiecoxon to quickly give this a look? I'm also happy to help

contents/docs/plugins/build/overview.md Outdated Show resolved Hide resolved
contents/docs/plugins/build/overview.md Outdated Show resolved Hide resolved

For example, you can send an event to AWS S3 whenever you see it in PostHog. Indeed, the [S3 plugin](https://posthog.com/plugins/s3-export) does exactly that. In this case, it doesn't matter if the S3 export succeeds or not, the event will always be stored.

![S3 Plugin Example](../../../images/plugins/s3-plugin-example.png)
Copy link
Contributor

Choose a reason for hiding this comment

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

this image is a bit wrong, as it gives me processEvent vibes. I'd personally prefer 2 arrows coming out of the event, one going via the plugin to S3, and the other to the DB

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmmmm, as a reader I feel that to be more confusing: how/why did the event go to both places?

I think if I remove the second event from the diagram, it feels closer to onEvent ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image

I really do think this raises more questions than it answers.

Disregarding how things actually happen, a good model helps people reason about the system without knowing exactly what's happening in the system. And I think all people need to know is that it's like processEvent, but the return value doesn't matter, so they can do all sorts of "side stuff" with onEvent.

contents/docs/plugins/build/overview.md Outdated Show resolved Hide resolved
contents/docs/plugins/build/overview.md Outdated Show resolved Hide resolved
contents/docs/plugins/build/tutorial.md Outdated Show resolved Hide resolved
contents/docs/plugins/build/tutorial.md Outdated Show resolved Hide resolved
contents/docs/plugins/build/tutorial.md Outdated Show resolved Hide resolved

#### Plugin Naming Conventions

When creating your repository, follow the naming convention of `posthog-<plugin-name>-plugin`. For example, the hello world plugin repository would be called `posthog-hello-world-plugin`.
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder how people will feel given a lot of our plugins don't follow this

Copy link
Contributor

Choose a reason for hiding this comment

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

Should be fine still, just wondering

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Precisely why I want to have this section, so that atleast starting from now all plugins follow this convention

contents/docs/plugins/build/tutorial.md Show resolved Hide resolved
@neilkakkar
Copy link
Contributor Author

Regarding the images, (1) and (3) make sense. For (2) - I'd expect people to click on the image to see the high res one with all details. Did this not feel obvious?

@neilkakkar
Copy link
Contributor Author

Hiya! Are there any remaining concerns which stop us from publishing these changes?

I'll put in a design request to polish the images.

Regarding what the images should have: @mariusandra @yakkomajuri - does this comment help alleviate concerns? #1467 (comment)

Copy link
Contributor

@yakkomajuri yakkomajuri left a comment

Choose a reason for hiding this comment

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

I'm happy to get this in the name of iteration.

It's great stuff, I'd just like the images to at least be transparent (plus a few other tweaks mentioned above)

@neilkakkar
Copy link
Contributor Author

Sounds good! I should've gotten to all the tweaks, except for the images, in aff2114

@neilkakkar neilkakkar merged commit 91d516a into master Jun 17, 2021
@neilkakkar neilkakkar deleted the plugindocs branch June 17, 2021 11:49
@corywatilo corywatilo added this to In Progress in Design 🎨 Jun 21, 2021
@corywatilo corywatilo moved this from In Progress to Done in Design 🎨 Jun 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

4 participants