| 109 | } |
| 110 | |
| 111 | func (c *Client) UserLatencyInsights(ctx context.Context, req UserLatencyInsightsRequest) (UserLatencyInsightsResponse, error) { |
| 112 | qp := url.Values{} |
| 113 | qp.Add("start_time", req.StartTime.Format(insightsTimeLayout)) |
| 114 | qp.Add("end_time", req.EndTime.Format(insightsTimeLayout)) |
| 115 | if len(req.TemplateIDs) > 0 { |
| 116 | var templateIDs []string |
| 117 | for _, id := range req.TemplateIDs { |
| 118 | templateIDs = append(templateIDs, id.String()) |
| 119 | } |
| 120 | qp.Add("template_ids", strings.Join(templateIDs, ",")) |
| 121 | } |
| 122 | |
| 123 | reqURL := fmt.Sprintf("/api/v2/insights/user-latency?%s", qp.Encode()) |
| 124 | resp, err := c.Request(ctx, http.MethodGet, reqURL, nil) |
| 125 | if err != nil { |
| 126 | return UserLatencyInsightsResponse{}, xerrors.Errorf("make request: %w", err) |
| 127 | } |
| 128 | defer resp.Body.Close() |
| 129 | |
| 130 | if resp.StatusCode != http.StatusOK { |
| 131 | return UserLatencyInsightsResponse{}, ReadBodyAsError(resp) |
| 132 | } |
| 133 | var result UserLatencyInsightsResponse |
| 134 | return result, json.NewDecoder(resp.Body).Decode(&result) |
| 135 | } |
| 136 | |
| 137 | type UserActivityInsightsRequest struct { |
| 138 | StartTime time.Time `json:"start_time" format:"date-time"` |