Skip to content

Commit

Permalink
feat: add endpoint to list events from a test run (#2276)
Browse files Browse the repository at this point in the history
add endpoint to list events from a test run
  • Loading branch information
mathnogueira committed Mar 29, 2023
1 parent 132814b commit b907493
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 17 deletions.
2 changes: 1 addition & 1 deletion api/openapi.yaml
Expand Up @@ -863,7 +863,7 @@ paths:
- in: path
name: runId
schema:
type: string
type: integer
required: true
summary: "get events from a test run"
description: "get events from a test run"
Expand Down
2 changes: 1 addition & 1 deletion api/testEvents.yaml
Expand Up @@ -22,7 +22,7 @@ components:
testId:
type: string
runId:
type: string
type: integer
dataStoreConnection:
$ref: "./config.yaml#/components/schemas/ConnectionResult"
polling:
Expand Down
4 changes: 2 additions & 2 deletions cli/openapi/api_api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions cli/openapi/model_test_run_event.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions server/http/controller.go
Expand Up @@ -184,8 +184,13 @@ func (c *controller) GetTestRun(ctx context.Context, testID, runID string) (open
return openapi.Response(200, c.mappers.Out.Run(&run)), nil
}

func (*controller) GetTestRunEvents(context.Context, string, string) (openapi.ImplResponse, error) {
return openapi.Response(http.StatusOK, []openapi.TestRunEvent{}), nil
func (c *controller) GetTestRunEvents(ctx context.Context, testID string, runID int32) (openapi.ImplResponse, error) {
events, err := c.testDB.GetTestRunEvents(ctx, id.ID(testID), int(runID))
if err != nil {
return openapi.Response(http.StatusInternalServerError, nil), err
}

return openapi.Response(http.StatusOK, c.mappers.Out.TestRunEvents(events)), nil
}

func (c *controller) DeleteTestRun(ctx context.Context, testID, runID string) (openapi.ImplResponse, error) {
Expand Down
64 changes: 64 additions & 0 deletions server/http/mappings/test_run_events.go
@@ -0,0 +1,64 @@
package mappings

import (
"github.com/kubeshop/tracetest/server/model"
"github.com/kubeshop/tracetest/server/openapi"
)

func (m OpenAPI) TestRunEvents(in []model.TestRunEvent) []openapi.TestRunEvent {
out := make([]openapi.TestRunEvent, 0, len(in))
for _, event := range in {
out = append(out, m.TestRunEvent(event))
}

return out
}

func (m OpenAPI) TestRunEvent(in model.TestRunEvent) openapi.TestRunEvent {
return openapi.TestRunEvent{
Type: in.Type,
Stage: string(in.Stage),
Description: in.Description,
CreatedAt: in.CreatedAt,
TestId: string(in.TestID),
RunId: int32(in.RunID),
DataStoreConnection: m.ConnectionTestResult(in.DataStoreConnection),
Polling: m.PollingInfo(in.Polling),
Outputs: m.OutputsInfo(in.Outputs),
}
}

func (m OpenAPI) PollingInfo(in model.PollingInfo) openapi.PollingInfo {
return openapi.PollingInfo{
Type: string(in.Type),
ReasonNextIteration: in.ReasonNextIteration,
IsComplete: in.IsComplete,
Periodic: m.PeriodicPollingInfo(in.Periodic),
}
}

func (m OpenAPI) PeriodicPollingInfo(in *model.PeriodicPollingConfig) openapi.PollingInfoPeriodic {
if in == nil {
return openapi.PollingInfoPeriodic{}
}

return openapi.PollingInfoPeriodic{
NumberSpans: int32(in.NumberSpans),
NumberIterations: int32(in.NumberIterations),
}
}

func (m OpenAPI) OutputsInfo(in []model.OutputInfo) []openapi.OutputInfo {
out := make([]openapi.OutputInfo, 0, len(in))
for _, output := range in {
newOutput := openapi.OutputInfo{
LogLevel: string(output.LogLevel),
Message: output.Message,
OutputName: output.OutputName,
}

out = append(out, newOutput)
}

return out
}
2 changes: 1 addition & 1 deletion server/openapi/api.go
Expand Up @@ -116,7 +116,7 @@ type ApiApiServicer interface {
GetTest(context.Context, string) (ImplResponse, error)
GetTestResultSelectedSpans(context.Context, string, string, string) (ImplResponse, error)
GetTestRun(context.Context, string, string) (ImplResponse, error)
GetTestRunEvents(context.Context, string, string) (ImplResponse, error)
GetTestRunEvents(context.Context, string, int32) (ImplResponse, error)
GetTestRuns(context.Context, string, int32, int32) (ImplResponse, error)
GetTestSpecs(context.Context, string) (ImplResponse, error)
GetTestVersion(context.Context, string, int32) (ImplResponse, error)
Expand Down
6 changes: 5 additions & 1 deletion server/openapi/api_api.go
Expand Up @@ -858,7 +858,11 @@ func (c *ApiApiController) GetTestRunEvents(w http.ResponseWriter, r *http.Reque
params := mux.Vars(r)
testIdParam := params["testId"]

runIdParam := params["runId"]
runIdParam, err := parseInt32Parameter(params["runId"], true)
if err != nil {
c.errorHandler(w, r, &ParsingError{Err: err}, nil)
return
}

result, err := c.service.GetTestRunEvents(r.Context(), testIdParam, runIdParam)
// If an error occurred, encode the error with the status code
Expand Down
2 changes: 1 addition & 1 deletion server/openapi/model_test_run_event.go
Expand Up @@ -26,7 +26,7 @@ type TestRunEvent struct {

TestId string `json:"testId,omitempty"`

RunId string `json:"runId,omitempty"`
RunId int32 `json:"runId,omitempty"`

DataStoreConnection ConnectionResult `json:"dataStoreConnection,omitempty"`

Expand Down
4 changes: 2 additions & 2 deletions web/src/types/Generated.types.ts
Expand Up @@ -818,7 +818,7 @@ export interface operations {
parameters: {
path: {
testId: string;
runId: string;
runId: number;
};
};
responses: {
Expand Down Expand Up @@ -1802,7 +1802,7 @@ export interface external {
/** Format: date-time */
createdAt?: string;
testId?: string;
runId?: string;
runId?: number;
dataStoreConnection?: external["config.yaml"]["components"]["schemas"]["ConnectionResult"];
polling?: external["testEvents.yaml"]["components"]["schemas"]["PollingInfo"];
outputs?: external["testEvents.yaml"]["components"]["schemas"]["OutputInfo"][];
Expand Down

0 comments on commit b907493

Please sign in to comment.