mirror of
https://github.com/coder/coder.git
synced 2025-07-09 11:45:56 +00:00
feat!: add sections
parameter to template insights (#10010)
This commit is contained in:
@ -38,6 +38,15 @@ const (
|
||||
InsightsReportIntervalWeek InsightsReportInterval = "week"
|
||||
)
|
||||
|
||||
// TemplateInsightsSection defines the section to be included in the template insights response.
|
||||
type TemplateInsightsSection string
|
||||
|
||||
// TemplateInsightsSection enums.
|
||||
const (
|
||||
TemplateInsightsSectionIntervalReports TemplateInsightsSection = "interval_reports"
|
||||
TemplateInsightsSectionReport TemplateInsightsSection = "report"
|
||||
)
|
||||
|
||||
// UserLatencyInsightsResponse is the response from the user latency insights
|
||||
// endpoint.
|
||||
type UserLatencyInsightsResponse struct {
|
||||
@ -158,8 +167,8 @@ func (c *Client) UserActivityInsights(ctx context.Context, req UserActivityInsig
|
||||
|
||||
// TemplateInsightsResponse is the response from the template insights endpoint.
|
||||
type TemplateInsightsResponse struct {
|
||||
Report TemplateInsightsReport `json:"report"`
|
||||
IntervalReports []TemplateInsightsIntervalReport `json:"interval_reports"`
|
||||
Report *TemplateInsightsReport `json:"report,omitempty"`
|
||||
IntervalReports []TemplateInsightsIntervalReport `json:"interval_reports,omitempty"`
|
||||
}
|
||||
|
||||
// TemplateInsightsReport is the report from the template insights endpoint.
|
||||
@ -221,10 +230,11 @@ type TemplateParameterValue struct {
|
||||
}
|
||||
|
||||
type TemplateInsightsRequest struct {
|
||||
StartTime time.Time `json:"start_time" format:"date-time"`
|
||||
EndTime time.Time `json:"end_time" format:"date-time"`
|
||||
TemplateIDs []uuid.UUID `json:"template_ids" format:"uuid"`
|
||||
Interval InsightsReportInterval `json:"interval" example:"day"`
|
||||
StartTime time.Time `json:"start_time" format:"date-time"`
|
||||
EndTime time.Time `json:"end_time" format:"date-time"`
|
||||
TemplateIDs []uuid.UUID `json:"template_ids" format:"uuid"`
|
||||
Interval InsightsReportInterval `json:"interval" example:"day"`
|
||||
Sections []TemplateInsightsSection `json:"sections" example:"report"`
|
||||
}
|
||||
|
||||
func (c *Client) TemplateInsights(ctx context.Context, req TemplateInsightsRequest) (TemplateInsightsResponse, error) {
|
||||
@ -241,6 +251,13 @@ func (c *Client) TemplateInsights(ctx context.Context, req TemplateInsightsReque
|
||||
if req.Interval != "" {
|
||||
qp.Add("interval", string(req.Interval))
|
||||
}
|
||||
if len(req.Sections) > 0 {
|
||||
var sections []string
|
||||
for _, sec := range req.Sections {
|
||||
sections = append(sections, string(sec))
|
||||
}
|
||||
qp.Add("sections", strings.Join(sections, ","))
|
||||
}
|
||||
|
||||
reqURL := fmt.Sprintf("/api/v2/insights/templates?%s", qp.Encode())
|
||||
resp, err := c.Request(ctx, http.MethodGet, reqURL, nil)
|
||||
|
Reference in New Issue
Block a user