Skip to content

Commit

Permalink
fix: Rename ids of plugins to match remote (#28014)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjackwhite authored Jan 29, 2025
1 parent e3f66e3 commit c9b50f2
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ exports[`CdpCyclotronWorkerPlugins onEvent should handle and collect errors 3`]
"level": "debug",
"log_source": "hog_function",
"log_source_id": "<REPLACED-UUID-2>",
"message": "Executing plugin intercom",
"message": "Executing plugin posthog-intercom-plugin",
"team_id": 2,
"timestamp": "2025-01-01 00:00:00.000",
},
Expand All @@ -44,11 +44,11 @@ exports[`CdpCyclotronWorkerPlugins onEvent should handle and collect errors 3`]
]
`;

exports[`CdpCyclotronWorkerPlugins smoke tests should run the plugin: { name: 'customer-io', plugin: [Object] } 1`] = `
exports[`CdpCyclotronWorkerPlugins smoke tests should run the plugin: { name: 'customerio-plugin', plugin: [Object] } 1`] = `
[
{
"level": "debug",
"message": "Executing plugin customer-io",
"message": "Executing plugin customerio-plugin",
},
{
"level": "info",
Expand All @@ -73,11 +73,11 @@ exports[`CdpCyclotronWorkerPlugins smoke tests should run the plugin: { name: 'c
]
`;

exports[`CdpCyclotronWorkerPlugins smoke tests should run the plugin: { name: 'intercom', plugin: [Object] } 1`] = `
exports[`CdpCyclotronWorkerPlugins smoke tests should run the plugin: { name: 'posthog-intercom-plugin', plugin: [Object] } 1`] = `
[
{
"level": "debug",
"message": "Executing plugin intercom",
"message": "Executing plugin posthog-intercom-plugin",
},
{
"level": "info",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ describe('CdpCyclotronWorkerPlugins', () => {
return item
}

const intercomPlugin = PLUGINS_BY_ID['posthog-intercom-plugin']

beforeEach(async () => {
await resetTestDatabase()
hub = await createHub()
Expand Down Expand Up @@ -64,7 +66,7 @@ describe('CdpCyclotronWorkerPlugins', () => {

fn = await insertHogFunction({
name: 'Plugin test',
template_id: 'plugin-intercom',
template_id: 'plugin-posthog-intercom-plugin',
})
globals = {
...createHogExecutionGlobals({
Expand Down Expand Up @@ -105,7 +107,7 @@ describe('CdpCyclotronWorkerPlugins', () => {

describe('setupPlugin', () => {
it('should setup a plugin on first call', async () => {
jest.spyOn(PLUGINS_BY_ID['intercom'] as any, 'setupPlugin')
jest.spyOn(intercomPlugin, 'setupPlugin')

const results = processor.processBatch([
createInvocation(fn, globals),
Expand All @@ -115,8 +117,8 @@ describe('CdpCyclotronWorkerPlugins', () => {

expect(await results).toMatchObject([{ finished: true }, { finished: true }, { finished: true }])

expect(PLUGINS_BY_ID['intercom'].setupPlugin).toHaveBeenCalledTimes(1)
expect(jest.mocked(PLUGINS_BY_ID['intercom'].setupPlugin!).mock.calls[0][0]).toMatchInlineSnapshot(`
expect(intercomPlugin.setupPlugin).toHaveBeenCalledTimes(1)
expect(jest.mocked(intercomPlugin.setupPlugin!).mock.calls[0][0]).toMatchInlineSnapshot(`
{
"config": {
"ignoredEmailDomains": "dev.posthog.com",
Expand All @@ -139,7 +141,7 @@ describe('CdpCyclotronWorkerPlugins', () => {

describe('onEvent', () => {
it('should call the plugin onEvent method', async () => {
jest.spyOn(PLUGINS_BY_ID['intercom'] as any, 'onEvent')
jest.spyOn(intercomPlugin, 'onEvent')

const invocation = createInvocation(fn, globals)
invocation.globals.event.event = 'mycustomevent'
Expand All @@ -154,9 +156,8 @@ describe('CdpCyclotronWorkerPlugins', () => {

await processor.processBatch([invocation])

expect(PLUGINS_BY_ID['intercom'].onEvent).toHaveBeenCalledTimes(1)
expect(forSnapshot(jest.mocked(PLUGINS_BY_ID['intercom'].onEvent!).mock.calls[0][0]))
.toMatchInlineSnapshot(`
expect(intercomPlugin.onEvent).toHaveBeenCalledTimes(1)
expect(forSnapshot(jest.mocked(intercomPlugin.onEvent!).mock.calls[0][0])).toMatchInlineSnapshot(`
{
"distinct_id": "distinct_id",
"event": "mycustomevent",
Expand Down Expand Up @@ -219,7 +220,7 @@ describe('CdpCyclotronWorkerPlugins', () => {
})

it('should mock out fetch if it is a test function', async () => {
jest.spyOn(PLUGINS_BY_ID['intercom'] as any, 'onEvent')
jest.spyOn(intercomPlugin, 'onEvent')

const invocation = createInvocation(fn, globals)
invocation.hogFunction.name = 'My function [CDP-TEST-HIDDEN]'
Expand All @@ -232,12 +233,12 @@ describe('CdpCyclotronWorkerPlugins', () => {

expect(mockFetch).toHaveBeenCalledTimes(0)

expect(PLUGINS_BY_ID['intercom'].onEvent).toHaveBeenCalledTimes(1)
expect(intercomPlugin.onEvent).toHaveBeenCalledTimes(1)

expect(forSnapshot(getProducedKafkaMessagesForTopic('log_entries_test').map((m) => m.value.message)))
.toMatchInlineSnapshot(`
[
"Executing plugin intercom",
"Executing plugin posthog-intercom-plugin",
"Fetch called but mocked due to test function",
"Unable to search contact [email protected] in Intercom. Status Code: undefined. Error message: ",
"Execution successful",
Expand All @@ -246,7 +247,7 @@ describe('CdpCyclotronWorkerPlugins', () => {
})

it('should handle and collect errors', async () => {
jest.spyOn(PLUGINS_BY_ID['intercom'] as any, 'onEvent')
jest.spyOn(intercomPlugin, 'onEvent')

const invocation = createInvocation(fn, globals)
invocation.globals.event.event = 'mycustomevent'
Expand All @@ -258,7 +259,7 @@ describe('CdpCyclotronWorkerPlugins', () => {

const res = await processor.processBatch([invocation])

expect(PLUGINS_BY_ID['intercom'].onEvent).toHaveBeenCalledTimes(1)
expect(intercomPlugin.onEvent).toHaveBeenCalledTimes(1)

expect(res[0].error).toBeInstanceOf(Error)
expect(forSnapshot(res[0].logs)).toMatchInlineSnapshot(`[]`)
Expand Down
2 changes: 1 addition & 1 deletion plugin-server/src/cdp/legacy-plugins/customerio/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ function getEmailFromEvent(event: ProcessedPluginEvent): string | null {
}

export const customerioPlugin: LegacyPlugin = {
id: 'customer-io',
id: 'customerio-plugin',
metadata: metadata as any,
setupPlugin: setupPlugin as any,
onEvent,
Expand Down
2 changes: 1 addition & 1 deletion plugin-server/src/cdp/legacy-plugins/intercom/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ function getTimestamp(meta: IntercomMeta, event: ProcessedPluginEvent): number {
}

export const intercomPlugin: LegacyPlugin = {
id: 'intercom',
id: 'posthog-intercom-plugin',
metadata: metadata as any,
onEvent,
setupPlugin: () => Promise.resolve(),
Expand Down
5 changes: 5 additions & 0 deletions posthog/cdp/migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ def migrate_legacy_plugins(dry_run=True, team_ids=None, test_mode=True):
team = teams_by_id[plugin_config["team_id"]]
serializer_context = {"team": team, "get_team": (lambda t=team: t)}

icon_url = plugin_config["plugin__icon"]

if not icon_url:
icon_url = f"https://raw.githubusercontent.com/PostHog/{plugin_id}/main/logo.png"

data = {
"template_id": f"plugin-{plugin_id}",
"type": "destination",
Expand Down

0 comments on commit c9b50f2

Please sign in to comment.