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

chore: App metrics no hub no promise manager #17581

Merged
merged 1 commit into from
Sep 25, 2023
Merged

Conversation

tiina303
Copy link
Contributor

@tiina303 tiina303 commented Sep 21, 2023

Problem

I want to use app metrics for webhooks, which don't have hub.

  1. We don't need a hub.
  2. We also don't want to use promiseManager (it makes things unpredictable and hard to debug).
  3. we weren't flushing the app metrics on app shutdown
  4. removed the no longer relevant isAvailable stuff (it's 100% enabled on cloud and also that was more for the self-hosted model)
  5. added logs to keep track of how long flushes are taking to make sure they aren't causing problems

Changes

  1. Added an ability to flush by key limit too - giving us more options to configure when flushes happen. Too big of a queue is a problem too, e.g. when we're getting lot's of errors as each of these is a separate row currently.

The guard for not flushing in tests is because of our tests not being properly set-up isolated, ideally we'd move the app metrics completely outside of the hub, but that's for the future.

👉 Stay up-to-date with PostHog coding conventions for a smoother review.

How did you test this code?

@PostHog PostHog deleted a comment from posthog-bot Sep 21, 2023
@tiina303 tiina303 requested a review from a team September 21, 2023 19:28
@@ -178,10 +166,11 @@ export class AppMetrics {
}),
}))

await this.hub.kafkaProducer.queueMessage({
await this.kafkaProducer.queueMessage({
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice, no hub 🥳

Copy link
Contributor

@tomasfarias tomasfarias left a comment

Choose a reason for hiding this comment

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

lgtm, happy to see less hub

Comment on lines +72 to +73
// For quick access to queueSize instead of using Object.keys(queuedData).length every time
queueSize: number
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: This adds an extra attribute that we have to keep track on with every method that manipulates the queue. Should be fine for now, but it could be bug-prone as it introduces a problem we didn't have: Forgetting to update the queueSize.

If this was Python I would suggest using a property that does the equivalent Object.keys(queuedData).length call, e.g.:

@property
def queue_size(self):
    return len(self.queuedData)

But with js I'm not sure if there's anything better.

The issue grows only if we add new methods that manipulate the queue, so when we do that we can tackle this too.

@tiina303 tiina303 merged commit bf1a80d into master Sep 25, 2023
@tiina303 tiina303 deleted the app-metrics-no-hub branch September 25, 2023 13:34
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