Skip to content

feat(coderd): add user latency and template insights endpoints #8519

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
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
8a1d3ee
feat(coderd): add user latency and template insights endpoints
mafredri Jul 14, 2023
b31ec33
feat(coderd): implement user latency insights logic
mafredri Jul 18, 2023
aaadc6a
feat(coderd): implement template insights logic
mafredri Jul 19, 2023
b54b0aa
make start/endtime check more strict
mafredri Jul 19, 2023
5f2bfd4
move interval verification
mafredri Jul 19, 2023
4820c53
gen
mafredri Jul 20, 2023
6326643
allow endtime for today include the hour
mafredri Jul 20, 2023
2198c5f
prevent timetravel
mafredri Jul 20, 2023
2e51056
add test for latencies
mafredri Jul 20, 2023
ddc8606
add test for template insights
mafredri Jul 20, 2023
26e0f02
Merge branch 'main' into mafredri/feat-coderd-add-user-latency-and-in…
mafredri Jul 20, 2023
2c8e311
verify same timezone for start/end
mafredri Jul 20, 2023
917997b
fix typo in query comment and improve comments
mafredri Jul 21, 2023
e5b96d4
fix generic internal server error
mafredri Jul 21, 2023
87b1b90
s/greater/after/
mafredri Jul 21, 2023
bffc673
unexport insights time layout
mafredri Jul 21, 2023
056918e
remove interval none
mafredri Jul 21, 2023
d5a9865
remove mixed tz restrictions, test DST
mafredri Jul 21, 2023
088620e
fix lint
mafredri Jul 21, 2023
397cc7a
add fixmes to dbauthz
mafredri Jul 21, 2023
ebacfe1
improve comment about assert equality
mafredri Jul 21, 2023
cd07478
replace sleep with cat
mafredri Jul 21, 2023
040390d
add bad request tests
mafredri Jul 21, 2023
b1de87f
fix comment placement
mafredri Jul 21, 2023
5588e39
create convert function for builtin apps
mafredri Jul 21, 2023
dafbba1
move interval loop
mafredri Jul 21, 2023
fc2157d
remove all users, improve test comments
mafredri Jul 21, 2023
7fd13df
Merge branch 'main' into mafredri/feat-coderd-add-user-latency-and-in…
mafredri Jul 21, 2023
9e228f6
Merge branch 'main' into mafredri/feat-coderd-add-user-latency-and-in…
mafredri Jul 21, 2023
b03cc29
fix windows test?
mafredri Jul 21, 2023
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
unexport insights time layout
  • Loading branch information
mafredri committed Jul 21, 2023
commit bffc673151f1f5c59c99cb4b85fa81b5ff6059e8
7 changes: 5 additions & 2 deletions coderd/insights.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import (
"github.com/coder/coder/codersdk"
)

// Duplicated in codersdk.
const insightsTimeLayout = time.RFC3339

// @Summary Get deployment DAUs
// @ID get-deployment-daus
// @Security CoderSessionToken
Expand Down Expand Up @@ -324,14 +327,14 @@ func parseInsightsStartAndEndTime(ctx context.Context, rw http.ResponseWriter, s
{"start_time", startTimeString, &startTime},
{"end_time", endTimeString, &endTime},
} {
t, err := time.Parse(codersdk.InsightsTimeLayout, qp.value)
t, err := time.Parse(insightsTimeLayout, qp.value)
if err != nil {
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
Message: "Query parameter has invalid value.",
Validations: []codersdk.ValidationError{
{
Field: qp.name,
Detail: fmt.Sprintf("Query param %q must be a valid date format (%s): %s", qp.name, codersdk.InsightsTimeLayout, err.Error()),
Detail: fmt.Sprintf("Query param %q must be a valid date format (%s): %s", qp.name, insightsTimeLayout, err.Error()),
},
},
})
Expand Down
6 changes: 2 additions & 4 deletions coderd/insights_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/coder/coder/codersdk"
)

func Test_parseInsightsStartAndEndTime(t *testing.T) {
t.Parallel()

layout := codersdk.InsightsTimeLayout
layout := insightsTimeLayout
now := time.Now().UTC()
y, m, d := now.Date()
today := time.Date(y, m, d, 0, 0, 0, 0, time.UTC)
Expand Down Expand Up @@ -135,11 +133,11 @@ func Test_parseInsightsStartAndEndTime(t *testing.T) {

// assert.Equal is unable to test location equality, so we
// use assert.WithinDuration.
assert.Equal(t, tt.wantOk, gotOk)
assert.WithinDuration(t, tt.wantStartTime, gotStartTime, 0)
assert.True(t, tt.wantStartTime.Equal(gotStartTime))
assert.WithinDuration(t, tt.wantEndTime, gotEndTime, 0)
assert.True(t, tt.wantEndTime.Equal(gotEndTime))
assert.Equal(t, tt.wantOk, gotOk)
})
}
}
11 changes: 6 additions & 5 deletions codersdk/insights.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import (
"golang.org/x/xerrors"
)

const InsightsTimeLayout = time.RFC3339
// Duplicated in coderd.
const insightsTimeLayout = time.RFC3339

// InsightsReportInterval is the interval of time over which to generate a
// smaller insights report within a time range.
Expand Down Expand Up @@ -61,8 +62,8 @@ type UserLatencyInsightsRequest struct {

func (c *Client) UserLatencyInsights(ctx context.Context, req UserLatencyInsightsRequest) (UserLatencyInsightsResponse, error) {
var qp []string
qp = append(qp, fmt.Sprintf("start_time=%s", req.StartTime.Format(InsightsTimeLayout)))
qp = append(qp, fmt.Sprintf("end_time=%s", req.EndTime.Format(InsightsTimeLayout)))
qp = append(qp, fmt.Sprintf("start_time=%s", req.StartTime.Format(insightsTimeLayout)))
qp = append(qp, fmt.Sprintf("end_time=%s", req.EndTime.Format(insightsTimeLayout)))
if len(req.TemplateIDs) > 0 {
var templateIDs []string
for _, id := range req.TemplateIDs {
Expand Down Expand Up @@ -161,8 +162,8 @@ type TemplateInsightsRequest struct {

func (c *Client) TemplateInsights(ctx context.Context, req TemplateInsightsRequest) (TemplateInsightsResponse, error) {
var qp []string
qp = append(qp, fmt.Sprintf("start_time=%s", req.StartTime.Format(InsightsTimeLayout)))
qp = append(qp, fmt.Sprintf("end_time=%s", req.EndTime.Format(InsightsTimeLayout)))
qp = append(qp, fmt.Sprintf("start_time=%s", req.StartTime.Format(insightsTimeLayout)))
qp = append(qp, fmt.Sprintf("end_time=%s", req.EndTime.Format(insightsTimeLayout)))
if len(req.TemplateIDs) > 0 {
var templateIDs []string
for _, id := range req.TemplateIDs {
Expand Down