Skip to content

feat: Add active users prometheus metric - #3406

Merged
kylecarbs merged 1 commit into
mainfrom
usermetrics
Aug 8, 2022
Merged

kylecarbs merged 1 commit into
mainfrom
usermetrics

Conversation

@kylecarbs

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown

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 done
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