Skip to content

Commit

Permalink
Remove instrument calls where we already have named metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
bretthoerner committed Dec 5, 2023
1 parent ab06ab1 commit 2d2b003
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 48 deletions.
44 changes: 4 additions & 40 deletions plugin-server/src/worker/plugins/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Summary } from 'prom-client'
import { Hub, PluginConfig, PluginTaskType, VMMethods } from '../../types'
import { processError } from '../../utils/db/error'
import { trackedFetch } from '../../utils/fetch'
import { instrument } from '../../utils/metrics'
import { status } from '../../utils/status'
import { IllegalOperationError } from '../../utils/utils'

Expand Down Expand Up @@ -68,16 +67,7 @@ export async function runOnEvent(hub: Hub, event: ProcessedPluginEvent): Promise
await Promise.all(
pluginMethodsToRun
.filter(([, method]) => !!method)
.map(([pluginConfig, onEvent]) =>
instrument(
{
metricName: 'plugin.runOnEvent',
key: 'plugin',
tag: pluginConfig.plugin?.name || '?',
},
() => runSingleTeamPluginOnEvent(hub, event, pluginConfig, onEvent)
)
)
.map(([pluginConfig, onEvent]) => runSingleTeamPluginOnEvent(hub, event, pluginConfig, onEvent))
)
}

Expand Down Expand Up @@ -174,14 +164,7 @@ export async function runComposeWebhook(hub: Hub, event: PostHogEvent): Promise<
pluginMethodsToRun
.filter(([, method]) => !!method)
.map(([pluginConfig, composeWebhook]) =>
instrument(
{
metricName: 'plugin.runComposeWebhook',
key: 'plugin',
tag: pluginConfig.plugin?.name || '?',
},
() => runSingleTeamPluginComposeWebhook(hub, event, pluginConfig, composeWebhook)
)
runSingleTeamPluginComposeWebhook(hub, event, pluginConfig, composeWebhook)
)
)
}
Expand All @@ -205,15 +188,7 @@ export async function runProcessEvent(hub: Hub, event: PluginEvent): Promise<Plu
}

try {
returnedEvent =
(await instrument(
{
metricName: 'plugin.processEvent',
key: 'plugin',
tag: pluginConfig.plugin?.name || '?',
},
() => processEvent(returnedEvent!)
)) || null
returnedEvent = (await processEvent(returnedEvent!)) || null
if (returnedEvent && returnedEvent.team_id !== teamId) {
returnedEvent.team_id = teamId
throw new IllegalOperationError('Plugin tried to change event.team_id')
Expand Down Expand Up @@ -302,18 +277,7 @@ export async function runPluginTask(
}

shouldQueueAppMetric = taskType === PluginTaskType.Schedule && !task.__ignoreForAppMetrics
response = await instrument(
{
metricName: 'plugin.runTask',
key: 'plugin',
tag: pluginConfig?.plugin?.name || '?',
data: {
taskName,
taskType,
},
},
() => (payload ? task?.exec(payload) : task?.exec())
)
response = await (payload ? task?.exec(payload) : task?.exec())

pluginActionMsSummary
.labels(String(pluginConfig?.plugin?.id), 'task', 'success')
Expand Down
9 changes: 1 addition & 8 deletions plugin-server/src/worker/vm/lazy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,14 +234,7 @@ export class LazyPluginVM {
throw Error('Only 1x replication is allowed')
}
}
await instrument(
{
metricName: 'plugin.setupPlugin',
key: 'plugin',
tag: this.pluginConfig.plugin?.name || '?',
},
() => vm?.run(`${this.vmResponseVariable}.methods.setupPlugin?.()`)
)
await vm?.run(`${this.vmResponseVariable}.methods.setupPlugin?.()`)
pluginSetupMsSummary
.labels({ plugin_id: pluginId, status: 'success' })
.observe(new Date().getTime() - timer.getTime())
Expand Down

0 comments on commit 2d2b003

Please sign in to comment.