Skip to content

Commit 076457b

Browse files
committed
feat: Add incidents statistics endpoint and frontend chart
- Implemented GetIncidentsCountByDateRange method in SQLiteStorage to retrieve incident counts by date range. - Added GetIncidentsCountByDateRange to the Storage interface. - Created handleAPIGetIncidentsStats handler to process requests for incident statistics by date range. - Developed ChartIncidentsStats component in the frontend to visualize incident statistics using Recharts. - Introduced new types for API parameters and response data related to incident statistics. - Enhanced the UI with select options for different time ranges and chart types.
1 parent 7a29c44 commit 076457b

19 files changed

Lines changed: 4704 additions & 5696 deletions

File tree

docs/docsv1/docs.go

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,60 @@ const docTemplate = `{
108108
}
109109
}
110110
},
111+
"/incidents/stats": {
112+
"get": {
113+
"description": "Returns the stats of incidents by date range",
114+
"consumes": [
115+
"application/json"
116+
],
117+
"produces": [
118+
"application/json"
119+
],
120+
"tags": [
121+
"incidents"
122+
],
123+
"summary": "Get incidents stats by date range",
124+
"parameters": [
125+
{
126+
"type": "string",
127+
"description": "Start time (RFC3339 format)",
128+
"name": "start_time",
129+
"in": "query",
130+
"required": true
131+
},
132+
{
133+
"type": "string",
134+
"description": "End time (RFC3339 format)",
135+
"name": "end_time",
136+
"in": "query",
137+
"required": true
138+
}
139+
],
140+
"responses": {
141+
"200": {
142+
"description": "Incidents stats by date range",
143+
"schema": {
144+
"type": "array",
145+
"items": {
146+
"$ref": "#/definitions/web.getIncidentsStatsItem"
147+
}
148+
}
149+
},
150+
"400": {
151+
"description": "Bad request",
152+
"schema": {
153+
"$ref": "#/definitions/web.ErrorResponse"
154+
}
155+
},
156+
"500": {
157+
"description": "Internal server error",
158+
"schema": {
159+
"$ref": "#/definitions/web.ErrorResponse"
160+
}
161+
}
162+
}
163+
}
164+
},
111165
"/server/health": {
112166
"get": {
113167
"description": "Checks the health of the server",
@@ -1299,6 +1353,23 @@ const docTemplate = `{
12991353
}
13001354
}
13011355
},
1356+
"web.getIncidentsStatsItem": {
1357+
"type": "object",
1358+
"properties": {
1359+
"avg_duration": {
1360+
"type": "integer"
1361+
},
1362+
"avg_duration_human": {
1363+
"type": "string"
1364+
},
1365+
"count": {
1366+
"type": "integer"
1367+
},
1368+
"date": {
1369+
"type": "string"
1370+
}
1371+
}
1372+
},
13021373
"web.healthCheckResponse": {
13031374
"type": "object",
13041375
"properties": {

docs/docsv1/swagger.json

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,60 @@
101101
}
102102
}
103103
},
104+
"/incidents/stats": {
105+
"get": {
106+
"description": "Returns the stats of incidents by date range",
107+
"consumes": [
108+
"application/json"
109+
],
110+
"produces": [
111+
"application/json"
112+
],
113+
"tags": [
114+
"incidents"
115+
],
116+
"summary": "Get incidents stats by date range",
117+
"parameters": [
118+
{
119+
"type": "string",
120+
"description": "Start time (RFC3339 format)",
121+
"name": "start_time",
122+
"in": "query",
123+
"required": true
124+
},
125+
{
126+
"type": "string",
127+
"description": "End time (RFC3339 format)",
128+
"name": "end_time",
129+
"in": "query",
130+
"required": true
131+
}
132+
],
133+
"responses": {
134+
"200": {
135+
"description": "Incidents stats by date range",
136+
"schema": {
137+
"type": "array",
138+
"items": {
139+
"$ref": "#/definitions/web.getIncidentsStatsItem"
140+
}
141+
}
142+
},
143+
"400": {
144+
"description": "Bad request",
145+
"schema": {
146+
"$ref": "#/definitions/web.ErrorResponse"
147+
}
148+
},
149+
"500": {
150+
"description": "Internal server error",
151+
"schema": {
152+
"$ref": "#/definitions/web.ErrorResponse"
153+
}
154+
}
155+
}
156+
}
157+
},
104158
"/server/health": {
105159
"get": {
106160
"description": "Checks the health of the server",
@@ -1292,6 +1346,23 @@
12921346
}
12931347
}
12941348
},
1349+
"web.getIncidentsStatsItem": {
1350+
"type": "object",
1351+
"properties": {
1352+
"avg_duration": {
1353+
"type": "integer"
1354+
},
1355+
"avg_duration_human": {
1356+
"type": "string"
1357+
},
1358+
"count": {
1359+
"type": "integer"
1360+
},
1361+
"date": {
1362+
"type": "string"
1363+
}
1364+
}
1365+
},
12951366
"web.healthCheckResponse": {
12961367
"type": "object",
12971368
"properties": {

docs/docsv1/swagger.yaml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,17 @@ definitions:
351351
example: Operation completed successfully
352352
type: string
353353
type: object
354+
web.getIncidentsStatsItem:
355+
properties:
356+
avg_duration:
357+
type: integer
358+
avg_duration_human:
359+
type: string
360+
count:
361+
type: integer
362+
date:
363+
type: string
364+
type: object
354365
web.healthCheckResponse:
355366
properties:
356367
status:
@@ -425,6 +436,42 @@ paths:
425436
summary: Get recent incidents
426437
tags:
427438
- incidents
439+
/incidents/stats:
440+
get:
441+
consumes:
442+
- application/json
443+
description: Returns the stats of incidents by date range
444+
parameters:
445+
- description: Start time (RFC3339 format)
446+
in: query
447+
name: start_time
448+
required: true
449+
type: string
450+
- description: End time (RFC3339 format)
451+
in: query
452+
name: end_time
453+
required: true
454+
type: string
455+
produces:
456+
- application/json
457+
responses:
458+
"200":
459+
description: Incidents stats by date range
460+
schema:
461+
items:
462+
$ref: '#/definitions/web.getIncidentsStatsItem'
463+
type: array
464+
"400":
465+
description: Bad request
466+
schema:
467+
$ref: '#/definitions/web.ErrorResponse'
468+
"500":
469+
description: Internal server error
470+
schema:
471+
$ref: '#/definitions/web.ErrorResponse'
472+
summary: Get incidents stats by date range
473+
tags:
474+
- incidents
428475
/server/health:
429476
get:
430477
consumes:

frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"react-markdown": "^10.1.0",
2929
"react-router": "^7.7.1",
3030
"react-use-websocket": "^4.13.0",
31+
"recharts": "^2.15.4",
3132
"remark-gfm": "^4.0.1",
3233
"sonner": "^2.0.6",
3334
"tailwind-merge": "^3.3.1",

0 commit comments

Comments
 (0)