Skip to content

Commit 2260ca4

Browse files
committed
Add enpoint for debug sessions
1 parent 6034185 commit 2260ca4

File tree

3 files changed

+257
-0
lines changed

3 files changed

+257
-0
lines changed

internal/dev_server/api/api.yaml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,34 @@ paths:
188188
$ref: "#/components/responses/ErrorResponse"
189189
400:
190190
$ref: "#/components/responses/ErrorResponse"
191+
/dev/debug-sessions:
192+
get:
193+
operationId: getDebugSessions
194+
summary: list all debug sessions with event counts
195+
parameters:
196+
- name: limit
197+
in: query
198+
description: limit the number of debug sessions returned
199+
required: false
200+
schema:
201+
type: integer
202+
default: 50
203+
- name: offset
204+
in: query
205+
description: offset for pagination
206+
required: false
207+
schema:
208+
type: integer
209+
default: 0
210+
responses:
211+
200:
212+
description: OK. List of debug sessions
213+
content:
214+
application/json:
215+
schema:
216+
$ref: "#/components/schemas/DebugSessionsPage"
217+
400:
218+
$ref: "#/components/responses/ErrorResponse"
191219
components:
192220
parameters:
193221
flagKey:
@@ -294,6 +322,45 @@ components:
294322
type: string
295323
name:
296324
type: string
325+
DebugSession:
326+
description: Debug session with event count
327+
type: object
328+
required:
329+
- key
330+
- written_at
331+
- event_count
332+
properties:
333+
key:
334+
type: string
335+
description: unique identifier for the debug session
336+
written_at:
337+
type: string
338+
format: date-time
339+
description: timestamp when the debug session was created
340+
event_count:
341+
type: integer
342+
format: int64
343+
description: number of events associated with this debug session
344+
DebugSessionsPage:
345+
description: Paginated response of debug sessions
346+
type: object
347+
required:
348+
- sessions
349+
- total_count
350+
- has_more
351+
properties:
352+
sessions:
353+
type: array
354+
items:
355+
$ref: "#/components/schemas/DebugSession"
356+
description: list of debug sessions
357+
total_count:
358+
type: integer
359+
format: int64
360+
description: total number of debug sessions available
361+
has_more:
362+
type: boolean
363+
description: whether there are more results available
297364
responses:
298365
FlagOverride:
299366
description: Flag override
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package api
2+
3+
import (
4+
"context"
5+
6+
"github.com/launchdarkly/ldcli/internal/dev_server/model"
7+
)
8+
9+
func (s server) GetDebugSessions(ctx context.Context, request GetDebugSessionsRequestObject) (GetDebugSessionsResponseObject, error) {
10+
eventStore := model.EventStoreFromContext(ctx)
11+
12+
// Set default values for pagination
13+
limit := 50
14+
offset := 0
15+
16+
if request.Params.Limit != nil {
17+
limit = *request.Params.Limit
18+
}
19+
if request.Params.Offset != nil {
20+
offset = *request.Params.Offset
21+
}
22+
23+
// Validate parameters
24+
if limit < 1 || limit > 1000 {
25+
return GetDebugSessions400JSONResponse{ErrorResponseJSONResponse{
26+
Code: "invalid_parameter",
27+
Message: "limit must be between 1 and 1000",
28+
}}, nil
29+
}
30+
31+
if offset < 0 {
32+
return GetDebugSessions400JSONResponse{ErrorResponseJSONResponse{
33+
Code: "invalid_parameter",
34+
Message: "offset must be non-negative",
35+
}}, nil
36+
}
37+
38+
// Query debug sessions from the event store
39+
page, err := eventStore.QueryDebugSessions(ctx, limit, offset)
40+
if err != nil {
41+
return nil, err
42+
}
43+
44+
// Convert model.DebugSession to API DebugSession
45+
var apiSessions []DebugSession
46+
for _, session := range page.Sessions {
47+
apiSessions = append(apiSessions, DebugSession{
48+
Key: session.Key,
49+
WrittenAt: session.WrittenAt,
50+
EventCount: session.EventCount,
51+
})
52+
}
53+
54+
response := DebugSessionsPage{
55+
Sessions: apiSessions,
56+
TotalCount: page.TotalCount,
57+
HasMore: page.HasMore,
58+
}
59+
60+
return GetDebugSessions200JSONResponse(response), nil
61+
}

internal/dev_server/api/server.gen.go

Lines changed: 129 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)