Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: add prometheus metric for tracking user statuses#15281

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
coadler merged 5 commits intomainfromcolin/user-prom
Oct 30, 2024

Conversation

coadler
Copy link
Contributor

Adds the ability to track total users in the platform by status. This can help for seeing how license seat usage is being used over time.

Closes#15278

@coadlercoadler self-assigned thisOct 30, 2024
Copy link
Contributor

@dannykoppingdannykopping left a comment

Choose a reason for hiding this comment

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

LGTM, a few nits.

@coadlercoadlerenabled auto-merge (squash)October 30, 2024 18:22
@coadlercoadler merged commit3de98c2 intomainOct 30, 2024
26 checks passed
@coadlercoadler deleted the colin/user-prom branchOctober 30, 2024 18:41
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsOct 30, 2024
}, testutil.WaitShort, testutil.IntervalSlow)
}

require.Eventually(t, checkFn, testutil.WaitShort, testutil.IntervalFast)
Copy link
Contributor

Choose a reason for hiding this comment

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

Hhmm, do we needrequire.Eventually with quartz now implemented (thank you for doing this!)?

Copy link
ContributorAuthor

@coadlercoadlerOct 30, 2024
edited
Loading

Choose a reason for hiding this comment

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

It was my assumption thatAdvanceNext().MustWait() only waits for the ticker to fire, then the actual gathering code runs async. I guess I could technically make it block until the end usingAfterFunc, but that felt kinda janky. My assumption could definitely be wrong tho, in my testing the metrics seemed to always be ready on the first try but I didn't want to risk it.

Comment on lines +97 to +122
ctx, cancelFunc := context.WithCancel(ctx)
done := make(chan struct{})
ticker := clk.NewTicker(duration)
go func() {
defer close(done)
defer ticker.Stop()
for {
select {
case <-ctx.Done():
return
case <-ticker.C:
}

gauge.Reset()
//nolint:gocritic // This is a system service that needs full access
//to the users table.
users, err := db.GetUsers(dbauthz.AsSystemRestricted(ctx), database.GetUsersParams{})
if err != nil {
logger.Error(ctx, "get all users for prometheus metrics", slog.Error(err))
continue
}

for _, user := range users {
gauge.WithLabelValues(string(user.Status)).Inc()
}
}
Copy link
Collaborator

@sreyasreyaOct 31, 2024
edited
Loading

Choose a reason for hiding this comment

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

Instead of doing this you can just useclock.TickerFunc, it removes any timing problems in the tests as well

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Ah, that makes more sense

Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@dannykoppingdannykoppingdannykopping approved these changes

@sreyasreyasreya left review comments

Assignees

@coadlercoadler

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Prometheus metric breaking down total users by status
3 participants
@coadler@dannykopping@sreya

[8]ページ先頭

©2009-2025 Movatter.jp