Skip to content

chore: add CLI invokation telemetry #7589

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 8 commits into from
May 24, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Better comments
  • Loading branch information
ammario committed May 17, 2023
commit 586130d73ed47d67f6d66a161586850208765fcf
12 changes: 6 additions & 6 deletions coderd/httpmw/telemetry.go → coderd/httpmw/clitelemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import (
)

func ReportCLITelemetry(log slog.Logger, rep telemetry.Reporter) func(http.Handler) http.Handler {
var mu sync.Mutex

var (
mu sync.Mutex

// We send telemetry at most once per minute.
limiter = rate.NewLimiter(rate.Every(time.Minute), 1)
queue []telemetry.CLIInvocation
Expand All @@ -27,12 +27,10 @@ func ReportCLITelemetry(log slog.Logger, rep telemetry.Reporter) func(http.Handl

return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
// No matter what, we proceed with the request.
defer next.ServeHTTP(rw, r)
payload := r.Header.Get(codersdk.CLITelemetryHeader)

// We do simple checks and processing outside of the goroutine
// to avoid the overhead of an additional goroutine on every
// request.
payload := r.Header.Get(codersdk.CLITelemetryHeader)
if payload == "" {
return
}
Expand All @@ -58,6 +56,8 @@ func ReportCLITelemetry(log slog.Logger, rep telemetry.Reporter) func(http.Handl
return
}

// We do expensive work in a goroutine so we don't block the
// request.
go func() {
mu.Lock()
defer mu.Unlock()
Expand Down