Skip to content

Commit

Permalink
Merge pull request #69 from kubeshop/add-debug
Browse files Browse the repository at this point in the history
bug fix: update execution result
  • Loading branch information
povilasv committed Mar 8, 2022
2 parents 59db719 + 433411a commit 00a4016
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 47 deletions.
46 changes: 14 additions & 32 deletions server/go/api_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

// ApiApiController binds http requests to an api service and writes the service results to the http response
type ApiApiController struct {
service ApiApiServicer
service ApiApiServicer
errorHandler ErrorHandler
}

Expand Down Expand Up @@ -49,7 +49,7 @@ func NewApiApiController(s ApiApiServicer, opts ...ApiApiOption) Router {

// Routes returns all of the api route for the ApiApiController
func (c *ApiApiController) Routes() Routes {
return Routes{
return Routes{
{
"CreateAssertion",
strings.ToUpper("Post"),
Expand Down Expand Up @@ -107,11 +107,11 @@ func (c *ApiApiController) Routes() Routes {
}
}

// CreateAssertion -
// CreateAssertion -
func (c *ApiApiController) CreateAssertion(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
idParam := params["id"]

assertionParam := Assertion{}
d := json.NewDecoder(r.Body)
d.DisallowUnknownFields()
Expand Down Expand Up @@ -158,11 +158,11 @@ func (c *ApiApiController) CreateTest(w http.ResponseWriter, r *http.Request) {

}

// GetAssertions -
// GetAssertions -
func (c *ApiApiController) GetAssertions(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
idParam := params["id"]

result, err := c.service.GetAssertions(r.Context(), idParam)
// If an error occurred, encode the error with the status code
if err != nil {
Expand All @@ -178,7 +178,7 @@ func (c *ApiApiController) GetAssertions(w http.ResponseWriter, r *http.Request)
func (c *ApiApiController) GetTest(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
testidParam := params["testid"]

result, err := c.service.GetTest(r.Context(), testidParam)
// If an error occurred, encode the error with the status code
if err != nil {
Expand All @@ -203,11 +203,11 @@ func (c *ApiApiController) GetTests(w http.ResponseWriter, r *http.Request) {

}

// TestsIdResultsGet -
// TestsIdResultsGet -
func (c *ApiApiController) TestsIdResultsGet(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
idParam := params["id"]

result, err := c.service.TestsIdResultsGet(r.Context(), idParam)
// If an error occurred, encode the error with the status code
if err != nil {
Expand All @@ -219,32 +219,14 @@ func (c *ApiApiController) TestsIdResultsGet(w http.ResponseWriter, r *http.Requ

}

// TestsTestidResultsIdGet -
// TestsTestidResultsIdGet -
func (c *ApiApiController) TestsTestidResultsIdGet(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
testidParam := params["testid"]

idParam := params["id"]

result, err := c.service.TestsTestidResultsIdGet(r.Context(), testidParam, idParam)
// If an error occurred, encode the error with the status code
if err != nil {
c.errorHandler(w, r, err, &result)
return
}
// If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, w)

}

// TestsTestidResultsIdTraceGet -
func (c *ApiApiController) TestsTestidResultsIdTraceGet(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
testidParam := params["testid"]

idParam := params["id"]
result, err := c.service.TestsTestidResultsIdTraceGet(r.Context(), testidParam, idParam)

result, err := c.service.TestsTestidResultsIdGet(r.Context(), testidParam, idParam)
// If an error occurred, encode the error with the status code
if err != nil {
c.errorHandler(w, r, err, &result)
Expand All @@ -255,11 +237,11 @@ func (c *ApiApiController) TestsTestidResultsIdTraceGet(w http.ResponseWriter, r

}

// TestsTestidRunPost -
// TestsTestidRunPost -
func (c *ApiApiController) TestsTestidRunPost(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
testidParam := params["testid"]

result, err := c.service.TestsTestidRunPost(r.Context(), testidParam)
// If an error occurred, encode the error with the status code
if err != nil {
Expand Down
17 changes: 9 additions & 8 deletions server/go/api_api_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ type TestDB interface {
GetTests(ctx context.Context) ([]Test, error)
GetTest(ctx context.Context, id string) (*Test, error)

CreateResult(ctx context.Context, testID string, run *Result) error
UpdateResult(ctx context.Context, run *Result) error
CreateResult(ctx context.Context, testID string, res *Result) error
UpdateResult(ctx context.Context, res *Result) error
GetResult(ctx context.Context, id string) (*Result, error)
GetResultsByTestID(ctx context.Context, testid string) ([]Result, error)

Expand Down Expand Up @@ -108,19 +108,19 @@ func (s *ApiApiService) TestsTestidRunPost(ctx context.Context, testid string) (
sid := trace.SpanID{}
s.rand.Read(sid[:])
fmt.Printf("gen span id: %v\n", sid)
run := &Result{
res := &Result{
Id: id,
CreatedAt: time.Now(),
Traceid: tid.String(),
Spanid: sid.String(),
}

err = s.testDB.CreateResult(ctx, testid, run)
err = s.testDB.CreateResult(ctx, testid, res)
if err != nil {
return Response(http.StatusInternalServerError, err.Error()), err
}

go func(t *Test, tid trace.TraceID, sid trace.SpanID) {
go func(t *Test, tid trace.TraceID, sid trace.SpanID, res *Result) {
ctx := context.Background()
fmt.Println("executing test")
resp, err := s.executor.Execute(t, tid, sid)
Expand All @@ -130,13 +130,14 @@ func (s *ApiApiService) TestsTestidRunPost(ctx context.Context, testid string) (
}
fmt.Println(resp)

run.CompletedAt = time.Now()
err = s.testDB.UpdateResult(ctx, run)
res.CompletedAt = time.Now()
err = s.testDB.UpdateResult(ctx, res)
if err != nil {
fmt.Printf("update result err: %s", err)
return
}
}(t, tid, sid)
fmt.Println("executed successfully")
}(t, tid, sid, res)

return Response(200, TestRun{
Id: id,
Expand Down
2 changes: 1 addition & 1 deletion server/go/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

// Response return a ImplResponse struct filled
func Response(code int, body interface{}) ImplResponse {
return ImplResponse {
return ImplResponse{
Code: code,
Body: body,
}
Expand Down
2 changes: 1 addition & 1 deletion server/go/model_assertion.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type Assertion struct {
// Defines the expected value of the property/ies
Comparable string `json:"comparable,omitempty"`

// Defines how the value of sought property/ies should be compared For example lt (less then), gt (greater then), eq (equals), in (contains)
// Defines how the value of sought property/ies should be compared For example lt (less then), gt (greater then), eq (equals), in (contains)
Operator string `json:"operator,omitempty"`

Successful bool `json:"successful,omitempty"`
Expand Down
8 changes: 4 additions & 4 deletions server/go/routers.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import (

// A Route defines the parameters for an api endpoint
type Route struct {
Name string
Method string
Pattern string
Name string
Method string
Pattern string
HandlerFunc http.HandlerFunc
}

Expand Down Expand Up @@ -214,4 +214,4 @@ func parseInt32ArrayParameter(param, delim string, required bool) ([]int32, erro
}

return ints, nil
}
}
2 changes: 1 addition & 1 deletion server/go/tracedb/tempodb/tempodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ func (ttd *TempoTraceDB) GetTraceByID(ctx context.Context, traceID string) (*v1.
return nil, fmt.Errorf("tempo err: %w", err)
}

fmt.Printf("tempo resp: %#v\n", resp.Trace.Batches)
if len(resp.Trace.Batches) == 0 {
return nil, tracedb.ErrTraceNotFound
}
fmt.Printf("tempo resp: %#v\n", resp.Trace.Batches)
return &v1.TracesData{
ResourceSpans: resp.GetTrace().GetBatches(),
}, nil
Expand Down
18 changes: 18 additions & 0 deletions server/go/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/gogo/protobuf/jsonpb"
"github.com/gogo/protobuf/proto"
"github.com/gorilla/mux"
v11 "go.opentelemetry.io/proto/otlp/common/v1"
res "go.opentelemetry.io/proto/otlp/resource/v1"
v1 "go.opentelemetry.io/proto/otlp/trace/v1"
Expand Down Expand Up @@ -70,3 +71,20 @@ func FixParent(tr *v1.TracesData, traceID, parentSpanID string) *v1.TracesData {

return tr
}

// TestsTestidResultsIdTraceGet -
func (c *ApiApiController) TestsTestidResultsIdTraceGet(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
testidParam := params["testid"]

idParam := params["id"]

result, err := c.service.TestsTestidResultsIdTraceGet(r.Context(), testidParam, idParam)
// If an error occurred, encode the error with the status code
if err != nil {
c.errorHandler(w, r, err, &result)
return
}
// If no error, encode the body and the result code
EncodeJSONPBResponse(result.Body, &result.Code, w)
}

0 comments on commit 00a4016

Please sign in to comment.