feat(coderd): add coder_app usage stats (#9001)

Updates #8658
This commit is contained in:
Mathias Fredriksson
2023-08-16 15:22:00 +03:00
committed by GitHub
parent f3c707648c
commit 6fd9975aed
31 changed files with 1730 additions and 62 deletions

View File

@ -497,6 +497,36 @@ func (api *API) workspaceProxyIssueSignedAppToken(rw http.ResponseWriter, r *htt
})
}
// @Summary Report workspace app stats
// @ID report-workspace-app-stats
// @Security CoderSessionToken
// @Accept json
// @Tags Enterprise
// @Param request body wsproxysdk.ReportAppStatsRequest true "Report app stats request"
// @Success 204
// @Router /workspaceproxies/me/app-stats [post]
// @x-apidocgen {"skip": true}
func (api *API) workspaceProxyReportAppStats(rw http.ResponseWriter, r *http.Request) {
ctx := r.Context()
_ = httpmw.WorkspaceProxy(r) // Ensure the proxy is authenticated.
var req wsproxysdk.ReportAppStatsRequest
if !httpapi.Read(ctx, rw, r, &req) {
return
}
api.Logger.Debug(ctx, "report app stats", slog.F("stats", req.Stats))
reporter := api.WorkspaceAppsStatsCollectorOptions.Reporter
if err := reporter.Report(ctx, req.Stats); err != nil {
api.Logger.Error(ctx, "report app stats failed", slog.Error(err))
httpapi.InternalServerError(rw, err)
return
}
httpapi.Write(ctx, rw, http.StatusNoContent, nil)
}
// workspaceProxyRegister is used to register a new workspace proxy. When a proxy
// comes online, it will announce itself to this endpoint. This updates its values
// in the database and returns a signed token that can be used to authenticate