diff --git a/server/go/api_api.go b/server/go/api_api.go index c665842454..dbe99ca9a0 100644 --- a/server/go/api_api.go +++ b/server/go/api_api.go @@ -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 } @@ -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"), @@ -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() @@ -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 { @@ -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 { @@ -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 { @@ -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) @@ -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 { diff --git a/server/go/api_api_service.go b/server/go/api_api_service.go index d6f8288e9a..79d088a559 100644 --- a/server/go/api_api_service.go +++ b/server/go/api_api_service.go @@ -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) @@ -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) @@ -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, diff --git a/server/go/helpers.go b/server/go/helpers.go index fbe8e92f16..35e4a3ff0e 100644 --- a/server/go/helpers.go +++ b/server/go/helpers.go @@ -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, } diff --git a/server/go/model_assertion.go b/server/go/model_assertion.go index e2a2bd244e..c299268672 100644 --- a/server/go/model_assertion.go +++ b/server/go/model_assertion.go @@ -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"` diff --git a/server/go/routers.go b/server/go/routers.go index 5693d78af4..0cc1a734c7 100644 --- a/server/go/routers.go +++ b/server/go/routers.go @@ -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 } @@ -214,4 +214,4 @@ func parseInt32ArrayParameter(param, delim string, required bool) ([]int32, erro } return ints, nil -} \ No newline at end of file +} diff --git a/server/go/tracedb/tempodb/tempodb.go b/server/go/tracedb/tempodb/tempodb.go index a97b0603a6..8c7d379880 100644 --- a/server/go/tracedb/tempodb/tempodb.go +++ b/server/go/tracedb/tempodb/tempodb.go @@ -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 diff --git a/server/go/utils.go b/server/go/utils.go index 4991cb330f..cf06da713c 100644 --- a/server/go/utils.go +++ b/server/go/utils.go @@ -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" @@ -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) +}