Skip to content

feat: expose template insights as Prometheus metrics #10325

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 21 commits into from
Oct 19, 2023

Conversation

mtojek
Copy link
Member

@mtojek mtojek commented Oct 18, 2023

Related: #9983

part 1/3 - I decided to split this PR into 3 parts to simplify code reviews. Unfortunately, we need to implement 3 extra DB queries with matching dbfake implementation.

This PR exposes "active users" metric from Coder template insights.

@mtojek mtojek requested review from johnstcn and mafredri October 18, 2023 13:42
@mtojek mtojek marked this pull request as ready for review October 18, 2023 13:43
Copy link
Member

@mafredri mafredri left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Member

@johnstcn johnstcn left a comment

Choose a reason for hiding this comment

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

LGTM 👍

Comment on lines 96 to 106
templateNames := map[uuid.UUID]string{}
if len(templateIDs) > 0 {
templates, err := mc.database.GetTemplatesWithFilter(ctx, database.GetTemplatesWithFilterParams{
IDs: templateIDs,
})
if err != nil {
mc.logger.Error(ctx, "unable to fetch template details from database", slog.Error(err))
return
}
templateNames = onlyTemplateNames(templates)
}
Copy link
Member

Choose a reason for hiding this comment

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

non-blocking, potential improvement: cache template ID -> template name to avoid DB fetches

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for your suggestion. Honestly, I wouldn't cache it yet unless we face performance issues. We would have to define the cache expiry and call db when templates are gone. Loop iterations are scheduled every 5 minutes by default, so I hope it won't impact performance. For sure, insights calls are heavier.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed, just something to think about later!

@mtojek mtojek enabled auto-merge (squash) October 19, 2023 08:39
@mtojek mtojek merged commit c4f5905 into main Oct 19, 2023
@mtojek mtojek deleted the 9983-insights-metrics-only-template branch October 19, 2023 08:45
@github-actions github-actions bot locked and limited conversation to collaborators Oct 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants