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

Function getGetEventMetricsHandler

internal/server/web/admin/reporting.go:52–137  ·  view source on GitHub ↗
(m KeyReportingManager, prod bool)

Source from the content-addressed store, hash-verified

50}
51
52func getGetEventMetricsHandler(m KeyReportingManager, prod bool) gin.HandlerFunc {
53 return func(c *gin.Context) {
54 log := util.GetLogFromCtx(c)
55 telemetry.Incr("bricksllm.admin.get_get_event_metrics.requests", nil, 1)
56
57 start := time.Now()
58 defer func() {
59 dur := time.Since(start)
60 telemetry.Timing("bricksllm.admin.get_get_event_metrics.latency", dur, nil, 1)
61 }()
62
63 path := "/api/reporting/events"
64
65 if c == nil || c.Request == nil {
66 c.JSON(http.StatusInternalServerError, &ErrorResponse{
67 Type: "/errors/empty-context",
68 Title: "context is empty error",
69 Status: http.StatusInternalServerError,
70 Detail: "gin context is empty",
71 Instance: path,
72 })
73 return
74 }
75
76 data, err := io.ReadAll(c.Request.Body)
77 if err != nil {
78 logError(log, "error when reading event reporting request body", prod, err)
79 c.JSON(http.StatusInternalServerError, &ErrorResponse{
80 Type: "/errors/request-body-read",
81 Title: "request body reader error",
82 Status: http.StatusInternalServerError,
83 Detail: err.Error(),
84 Instance: path,
85 })
86 return
87 }
88
89 request := &event.ReportingRequest{}
90 err = json.Unmarshal(data, request)
91 if err != nil {
92 logError(log, "error when unmarshalling event reporting request body", prod, err)
93 c.JSON(http.StatusInternalServerError, &ErrorResponse{
94 Type: "/errors/json-unmarshal",
95 Title: "json unmarshaller error",
96 Status: http.StatusInternalServerError,
97 Detail: err.Error(),
98 Instance: path,
99 })
100 return
101 }
102
103 if !validateEventReportingRequest(request) {
104 telemetry.Incr("bricksllm.admin.get_get_event_metrics.request_not_valid", nil, 1)
105
106 err = fmt.Errorf("event reporting request %+v is not valid", request)
107 logError(log, "invalid reporting request", prod, err)
108 c.JSON(http.StatusInternalServerError, &ErrorResponse{
109 Type: "/errors/invalid-reporting-request",

Callers 1

NewAdminServerFunction · 0.85

Calls 7

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

Tested by

no test coverage detected