MCPcopy Create free account
hub / github.com/bricks-cloud/BricksLLM / getGetEventsV2Handler

Function getGetEventsV2Handler

internal/server/web/admin/events.go:248–334  ·  view source on GitHub ↗
(m KeyReportingManager, prod bool)

Source from the content-addressed store, hash-verified

246}
247
248func getGetEventsV2Handler(m KeyReportingManager, prod bool) gin.HandlerFunc {
249 return func(c *gin.Context) {
250 log := util.GetLogFromCtx(c)
251 telemetry.Incr("bricksllm.admin.get_get_events_v2_handler.requests", nil, 1)
252
253 start := time.Now()
254 defer func() {
255 dur := time.Since(start)
256 telemetry.Timing("bricksllm.admin.get_get_events_v2_handler.latency", dur, nil, 1)
257 }()
258
259 path := "/api/v2/events"
260 if c == nil || c.Request == nil {
261 c.JSON(http.StatusInternalServerError, &ErrorResponse{
262 Type: "/errors/empty-context",
263 Title: "context is empty error",
264 Status: http.StatusInternalServerError,
265 Detail: "gin context is empty",
266 Instance: path,
267 })
268 return
269 }
270
271 data, err := io.ReadAll(c.Request.Body)
272 if err != nil {
273 logError(log, "error when reading get events request body", prod, err)
274 c.JSON(http.StatusInternalServerError, &ErrorResponse{
275 Type: "/errors/request-body-read",
276 Title: "get events request body reader error",
277 Status: http.StatusInternalServerError,
278 Detail: err.Error(),
279 Instance: path,
280 })
281 return
282 }
283
284 request := &event.EventRequest{}
285 err = json.Unmarshal(data, request)
286 if err != nil {
287 logError(log, "error when unmarshalling get events request body", prod, err)
288 c.JSON(http.StatusInternalServerError, &ErrorResponse{
289 Type: "/errors/json-unmarshal",
290 Title: "json unmarshaller error",
291 Status: http.StatusInternalServerError,
292 Detail: err.Error(),
293 Instance: path,
294 })
295 return
296 }
297
298 keys, err := m.GetEventsV2(request)
299 if err != nil {
300 errType := "internal"
301
302 defer func() {
303 telemetry.Incr("bricksllm.admin.get_get_events_v2_handler.get_events_v2_err", []string{
304 "error_type:" + errType,
305 }, 1)

Callers 1

NewAdminServerFunction · 0.85

Calls 6

GetLogFromCtxFunction · 0.92
IncrFunction · 0.92
TimingFunction · 0.92
logErrorFunction · 0.70
ErrorMethod · 0.65
GetEventsV2Method · 0.65

Tested by

no test coverage detected