mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: Fix Deployment DAUs to work with local timezones (#7647)
* chore: Add timezone param to DAU SQL query * Merge DAUs response * Pass time offsets to metricscache
This commit is contained in:
+15
-3
@@ -614,15 +614,27 @@ func (api *API) patchTemplateMeta(rw http.ResponseWriter, r *http.Request) {
|
||||
// @Produce json
|
||||
// @Tags Templates
|
||||
// @Param template path string true "Template ID" format(uuid)
|
||||
// @Success 200 {object} codersdk.TemplateDAUsResponse
|
||||
// @Success 200 {object} codersdk.DAUsResponse
|
||||
// @Router /templates/{template}/daus [get]
|
||||
func (api *API) templateDAUs(rw http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
template := httpmw.TemplateParam(r)
|
||||
|
||||
resp, _ := api.metricsCache.TemplateDAUs(template.ID)
|
||||
vals := r.URL.Query()
|
||||
p := httpapi.NewQueryParamParser()
|
||||
tzOffset := p.Int(vals, 0, "tz_offset")
|
||||
p.ErrorExcessParams(vals)
|
||||
if len(p.Errors) > 0 {
|
||||
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
|
||||
Message: "Query parameters have invalid values.",
|
||||
Validations: p.Errors,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
_, resp, _ := api.metricsCache.TemplateDAUs(template.ID, tzOffset)
|
||||
if resp == nil || resp.Entries == nil {
|
||||
httpapi.Write(ctx, rw, http.StatusOK, &codersdk.TemplateDAUsResponse{
|
||||
httpapi.Write(ctx, rw, http.StatusOK, &codersdk.DAUsResponse{
|
||||
Entries: []codersdk.DAUEntry{},
|
||||
})
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user