@@ -941,3 +941,181 @@ kernelci-api | INFO: 127.0.0.1:35810 - "POST /publish/abc HTTP/1.1" 200 OK
941941kernelci-api | INFO: 127.0.0.1:35754 - "GET /listen/abc HTTP/1.1" 200 OK
942942kernelci-api | INFO: 127.0.0.1:36744 - "POST /unsubscribe/abc HTTP/1.1" 200 OK
943943```
944+
945+
946+ ## Events
947+
948+ The ` /events ` endpoint provides access to the event history stored in MongoDB.
949+ Events are generated when nodes are created or updated, and are stored for a
950+ configurable retention period (default 7 days).
951+
952+ ### Event Structure
953+
954+ Each event contains the following fields:
955+
956+ | Field | Type | Description |
957+ | -------| ------| -------------|
958+ | ` id ` | string | Unique event document ID |
959+ | ` timestamp ` | datetime | When the event was created |
960+ | ` sequence_id ` | integer | Sequential ID for ordering (used by pub/sub) |
961+ | ` channel ` | string | Pub/sub channel name (typically "node") |
962+ | ` owner ` | string | Username of the event publisher |
963+ | ` data ` | object | Event payload (see below) |
964+
965+ The ` data ` object contains node information:
966+
967+ | Field | Type | Description |
968+ | -------| ------| -------------|
969+ | ` op ` | string | Operation type: ` created ` or ` updated ` |
970+ | ` id ` | string | Node ID |
971+ | ` kind ` | string | Node kind (e.g., ` checkout ` , ` kbuild ` , ` job ` , ` test ` ) |
972+ | ` name ` | string | Node name |
973+ | ` path ` | array | Node path hierarchy |
974+ | ` group ` | string | Node group |
975+ | ` state ` | string | Node state: ` running ` , ` available ` , ` closing ` , ` done ` |
976+ | ` result ` | string | Node result: ` pass ` , ` fail ` , ` skip ` , ` incomplete ` , or ` null ` |
977+ | ` owner ` | string | Node owner (username) |
978+ | ` data ` | object | Node-specific data |
979+ | ` is_hierarchy ` | boolean | Whether this is a hierarchy update |
980+
981+ ### Query Parameters
982+
983+ The ` /events ` endpoint supports the following query parameters:
984+
985+ | Parameter | Type | Description | Example |
986+ | -----------| ------| -------------| ---------|
987+ | ` limit ` | integer | Maximum number of events to return | ` limit=100 ` |
988+ | ` from ` | datetime | Return events after this timestamp (ISO format or Unix epoch) | ` from=2025-01-01T00:00:00 ` |
989+ | ` kind ` | string | Filter by node kind | ` kind=job ` |
990+ | ` state ` | string | Filter by node state | ` state=done ` |
991+ | ` result ` | string | Filter by node result | ` result=pass ` |
992+ | ` op ` | string | Filter by operation type | ` op=created ` |
993+ | ` name ` | string | Filter by node name (exact match) | ` name=baseline-x86 ` |
994+ | ` path ` | string | Filter by node path (regex pattern) | ` path=.*mainline.* ` |
995+ | ` group ` | string | Filter by node group (exact match) | ` group=kunit-x86_64 ` |
996+ | ` owner ` | string | Filter by node owner (exact match) | ` owner=admin ` |
997+ | ` channel ` | string | Filter by pub/sub channel | ` channel=node ` |
998+ | ` id ` | string | Filter by event document ID | ` id=507f1f77bcf86cd799439011 ` |
999+ | ` ids ` | string | Filter by multiple event IDs (comma-separated) | ` ids=id1,id2,id3 ` |
1000+ | ` node_id ` | string | Filter by node ID (alias for ` data.id ` ) | ` node_id=507f1f77bcf86cd799439011 ` |
1001+ | ` recursive ` | boolean | Include full node data with each event | ` recursive=true ` |
1002+
1003+ > ** Note** : When using ` recursive=true ` , the ` limit ` parameter is required and must be <= 1000.
1004+
1005+ ### Examples
1006+
1007+ ** Get all events (limited to default pagination):**
1008+ ```
1009+ $ curl http://localhost:8001/latest/events
1010+ ```
1011+
1012+ ** Get events for completed jobs with passing results:**
1013+ ```
1014+ $ curl 'http://localhost:8001/latest/events?kind=job&state=done&result=pass'
1015+ ```
1016+
1017+ ** Get recently created events (last hour):**
1018+ ```
1019+ $ curl 'http://localhost:8001/latest/events?op=created&from=2025-01-10T12:00:00'
1020+ ```
1021+
1022+ ** Get events for a specific node path pattern (regex):**
1023+ ```
1024+ $ curl 'http://localhost:8001/latest/events?path=.*linux-next.*&limit=50'
1025+ ```
1026+
1027+ ** Get events for a specific group:**
1028+ ```
1029+ $ curl 'http://localhost:8001/latest/events?group=kunit-x86_64&state=done'
1030+ ```
1031+
1032+ ** Get events by owner:**
1033+ ```
1034+ $ curl 'http://localhost:8001/latest/events?owner=admin&kind=checkout'
1035+ ```
1036+
1037+ ** Get events with full node data:**
1038+ ```
1039+ $ curl 'http://localhost:8001/latest/events?state=done&result=fail&recursive=true&limit=10'
1040+ ```
1041+
1042+ ** Get events for a specific node ID:**
1043+ ```
1044+ $ curl 'http://localhost:8001/latest/events?node_id=65a1355ee98651d0fe81e412'
1045+ ```
1046+
1047+ ** Combine multiple filters:**
1048+ ```
1049+ $ curl 'http://localhost:8001/latest/events?kind=test&state=done&result=fail&group=kselftest&from=2025-01-01&limit=100'
1050+ ```
1051+
1052+ ### Sample Response
1053+
1054+ ``` json
1055+ [
1056+ {
1057+ "id" : " 65a1355ee98651d0fe81e500" ,
1058+ "timestamp" : " 2025-01-12T08:30:00.000000" ,
1059+ "sequence_id" : 12345 ,
1060+ "channel" : " node" ,
1061+ "owner" : " admin" ,
1062+ "data" : {
1063+ "op" : " updated" ,
1064+ "id" : " 65a1355ee98651d0fe81e412" ,
1065+ "kind" : " test" ,
1066+ "name" : " kselftest-cpufreq" ,
1067+ "path" : [" checkout" , " kbuild" , " test" , " kselftest-cpufreq" ],
1068+ "group" : " kselftest" ,
1069+ "state" : " done" ,
1070+ "result" : " pass" ,
1071+ "owner" : " admin" ,
1072+ "data" : {
1073+ "kernel_revision" : {
1074+ "tree" : " mainline" ,
1075+ "branch" : " master" ,
1076+ "commit" : " abc123..."
1077+ }
1078+ },
1079+ "is_hierarchy" : false
1080+ }
1081+ }
1082+ ]
1083+ ```
1084+
1085+ ### Response with recursive=true
1086+
1087+ When ` recursive=true ` is specified, each event includes a ` node ` field with the
1088+ full node object:
1089+
1090+ ``` json
1091+ [
1092+ {
1093+ "id" : " 65a1355ee98651d0fe81e500" ,
1094+ "timestamp" : " 2025-01-12T08:30:00.000000" ,
1095+ "data" : {
1096+ "op" : " updated" ,
1097+ "id" : " 65a1355ee98651d0fe81e412" ,
1098+ "kind" : " test" ,
1099+ "name" : " kselftest-cpufreq" ,
1100+ "state" : " done" ,
1101+ "result" : " pass"
1102+ },
1103+ "node" : {
1104+ "id" : " 65a1355ee98651d0fe81e412" ,
1105+ "kind" : " test" ,
1106+ "name" : " kselftest-cpufreq" ,
1107+ "path" : [" checkout" , " kbuild" , " test" , " kselftest-cpufreq" ],
1108+ "group" : " kselftest" ,
1109+ "parent" : " 65a1355ee98651d0fe81e400" ,
1110+ "state" : " done" ,
1111+ "result" : " pass" ,
1112+ "artifacts" : {... },
1113+ "data" : {... },
1114+ "created" : " 2025-01-12T08:00:00.000000" ,
1115+ "updated" : " 2025-01-12T08:30:00.000000" ,
1116+ "owner" : " admin" ,
1117+ "user_groups" : []
1118+ }
1119+ }
1120+ ]
1121+ ```
0 commit comments