Skip to content

feat: Add active users prometheus metric #3406

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

Merged
merged 1 commit into from
Aug 8, 2022
Merged

feat: Add active users prometheus metric #3406

merged 1 commit into from
Aug 8, 2022

Conversation

kylecarbs
Copy link
Member

This allows deployments using our Prometheus export t determine
the number of active users in the past hour.

The interval is an hour to align with API key last used refresh times.

SSH connections poll to check shutdown time, so this will be accurate
even on long-running connections without dashboard requests.

@kylecarbs kylecarbs requested a review from coadler August 8, 2022 14:10
@kylecarbs kylecarbs self-assigned this Aug 8, 2022
This  allows deployments using our Prometheus export t determine
the number of active users in the past hour.

The interval is an hour to align with API key last used refresh times.

SSH connections poll to check shutdown time, so this will be accurate
even on long-running connections without dashboard requests.
return
case <-ticker.C:
}
apiKeys, err := db.GetAPIKeysLastUsedAfter(ctx, database.Now().Add(-1*time.Hour))
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it'd be cleaner to do a SELECT COUNT(distinct user_id) within postgres instead of here, but this is fine as-is.

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree. Just figured this was cleaner for now. Once it's not performing well, we shall abstract it out!


func TestPrometheus(t *testing.T) {
t.Parallel()
t.Run("All", func(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the tests 😎

@kylecarbs kylecarbs merged commit 3279504 into main Aug 8, 2022
@kylecarbs kylecarbs deleted the usermetrics branch August 8, 2022 15:09
@OlgaKhmelevskaya
Copy link

Hello @kylecarbs , could you please add reference to the issue this pull request is related to?

@bpmct bpmct mentioned this pull request Aug 15, 2022
3 tasks
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.

3 participants