From 86d69f74f3ce98cce5176402142256d484bf6224 Mon Sep 17 00:00:00 2001 From: Shivanshu Raj Shrivastava Date: Thu, 29 May 2025 15:13:41 +0530 Subject: [PATCH] chore: remove save API endpoint Signed-off-by: Shivanshu Raj Shrivastava --- .../tracefunnel/impltracefunnel/handler.go | 73 ------------------- .../impltracefunnel/handler_test.go | 68 +---------------- pkg/modules/tracefunnel/tracefunnel.go | 2 - pkg/query-service/app/http_handler.go | 3 - pkg/sqlmigration/040_add_trace_funnels.go | 23 +++--- pkg/types/tracefunneltypes/tracefunnel.go | 3 - 6 files changed, 14 insertions(+), 158 deletions(-) diff --git a/pkg/modules/tracefunnel/impltracefunnel/handler.go b/pkg/modules/tracefunnel/impltracefunnel/handler.go index 2bee100409..09f4dfe269 100644 --- a/pkg/modules/tracefunnel/impltracefunnel/handler.go +++ b/pkg/modules/tracefunnel/impltracefunnel/handler.go @@ -3,7 +3,6 @@ package impltracefunnel import ( "encoding/json" "net/http" - "time" "github.com/SigNoz/signoz/pkg/errors" "github.com/SigNoz/signoz/pkg/http/render" @@ -234,75 +233,3 @@ func (handler *handler) Delete(rw http.ResponseWriter, r *http.Request) { render.Success(rw, http.StatusOK, nil) } - -func (handler *handler) Save(rw http.ResponseWriter, r *http.Request) { - var req tf.PostableFunnel - if err := json.NewDecoder(r.Body).Decode(&req); err != nil { - render.Error(rw, errors.Newf(errors.TypeInvalidInput, - errors.CodeInvalidInput, - "invalid request: %v", err)) - return - } - - claims, err := authtypes.ClaimsFromContext(r.Context()) - if err != nil { - render.Error(rw, err) - return - } - - funnel, err := handler.module.Get(r.Context(), req.FunnelID, valuer.MustNewUUID(claims.OrgID)) - if err != nil { - render.Error(rw, errors.Newf(errors.TypeInvalidInput, - errors.CodeInvalidInput, - "funnel not found: %v", err)) - return - } - - updateTimestamp := req.Timestamp - if updateTimestamp == 0 { - updateTimestamp = time.Now().UnixMilli() - } else if !tf.ValidateTimestampIsMilliseconds(updateTimestamp) { - render.Error(rw, errors.Newf(errors.TypeInvalidInput, - errors.CodeInvalidInput, - "timestamp must be in milliseconds format (13 digits)")) - return - } - - updatedAt, err := tf.ValidateAndConvertTimestamp(updateTimestamp) - if err != nil { - render.Error(rw, err) - return - } - - funnel.UpdatedAt = updatedAt - funnel.UpdatedBy = claims.UserID - funnel.Description = req.Description - - if err := handler.module.Update(r.Context(), funnel, valuer.MustNewUUID(claims.OrgID)); err != nil { - render.Error(rw, errors.Newf(errors.TypeInvalidInput, - errors.CodeInvalidInput, - "failed to save funnel: %v", err)) - return - } - - createdAtMillis, updatedAtMillis, extraDataFromDB, err := handler.module.GetFunnelMetadata(r.Context(), funnel.ID, valuer.MustNewUUID(claims.OrgID)) - if err != nil { - render.Error(rw, errors.Newf(errors.TypeInvalidInput, - errors.CodeInvalidInput, - "failed to get funnel metadata: %v", err)) - return - } - - resp := tf.GettableFunnel{ - FunnelName: funnel.Name, - CreatedAt: createdAtMillis, - UpdatedAt: updatedAtMillis, - CreatedBy: funnel.CreatedBy, - UpdatedBy: funnel.UpdatedBy, - OrgID: funnel.OrgID.String(), - Description: extraDataFromDB, - UserEmail: claims.Email, - } - - render.Success(rw, http.StatusOK, resp) -} diff --git a/pkg/modules/tracefunnel/impltracefunnel/handler_test.go b/pkg/modules/tracefunnel/impltracefunnel/handler_test.go index 1d74941304..2a622839ba 100644 --- a/pkg/modules/tracefunnel/impltracefunnel/handler_test.go +++ b/pkg/modules/tracefunnel/impltracefunnel/handler_test.go @@ -1,14 +1,8 @@ package impltracefunnel import ( - "bytes" "context" "encoding/json" - "net/http" - "net/http/httptest" - "testing" - "time" - "github.com/SigNoz/signoz/pkg/types" "github.com/SigNoz/signoz/pkg/types/authtypes" traceFunnels "github.com/SigNoz/signoz/pkg/types/tracefunneltypes" @@ -16,6 +10,9 @@ import ( "github.com/gorilla/mux" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" + "net/http" + "net/http/httptest" + "testing" ) type MockModule struct { @@ -173,62 +170,3 @@ func TestHandler_Delete(t *testing.T) { mockModule.AssertExpectations(t) } - -func TestHandler_Save(t *testing.T) { - mockModule := new(MockModule) - handler := NewHandler(mockModule) - - reqBody := traceFunnels.PostableFunnel{ - FunnelID: valuer.GenerateUUID(), - Description: "updated description", - Timestamp: time.Now().UnixMilli(), - UserID: "user-123", - } - - jsonBody, _ := json.Marshal(reqBody) - req := httptest.NewRequest(http.MethodPost, "/api/v1/trace-funnels/save", bytes.NewBuffer(jsonBody)) - req.Header.Set("Content-Type", "application/json") - - orgID := valuer.GenerateUUID() - userID := valuer.GenerateUUID() - claims := authtypes.Claims{ - UserID: userID.String(), - OrgID: orgID.String(), - } - req = req.WithContext(authtypes.NewContextWithClaims(req.Context(), claims)) - - rr := httptest.NewRecorder() - - existingFunnel := &traceFunnels.StorableFunnel{ - Identifiable: types.Identifiable{ - ID: reqBody.FunnelID, - }, - Name: "test-funnel", - OrgID: orgID, - } - - mockModule.On("Get", req.Context(), reqBody.FunnelID, orgID).Return(existingFunnel, nil) - mockModule.On("Update", req.Context(), mock.MatchedBy(func(f *traceFunnels.StorableFunnel) bool { - return f.ID.String() == reqBody.FunnelID.String() && - f.Name == existingFunnel.Name && - f.Description == reqBody.Description && - f.UpdatedBy == userID.String() && - f.OrgID.String() == orgID.String() - }), orgID).Return(nil) - mockModule.On("GetFunnelMetadata", req.Context(), reqBody.FunnelID, orgID).Return(int64(0), int64(0), reqBody.Description, nil) - - handler.Save(rr, req) - - assert.Equal(t, http.StatusOK, rr.Code) - - var response struct { - Status string `json:"status"` - Data traceFunnels.GettableFunnel `json:"data"` - } - err := json.Unmarshal(rr.Body.Bytes(), &response) - assert.NoError(t, err) - assert.Equal(t, "success", response.Status) - assert.Equal(t, reqBody.Description, response.Data.Description) - - mockModule.AssertExpectations(t) -} diff --git a/pkg/modules/tracefunnel/tracefunnel.go b/pkg/modules/tracefunnel/tracefunnel.go index e747c7a572..13401ee5a4 100644 --- a/pkg/modules/tracefunnel/tracefunnel.go +++ b/pkg/modules/tracefunnel/tracefunnel.go @@ -35,6 +35,4 @@ type Handler interface { Get(http.ResponseWriter, *http.Request) Delete(http.ResponseWriter, *http.Request) - - Save(http.ResponseWriter, *http.Request) } diff --git a/pkg/query-service/app/http_handler.go b/pkg/query-service/app/http_handler.go index 794f2fdc49..77085ae41e 100644 --- a/pkg/query-service/app/http_handler.go +++ b/pkg/query-service/app/http_handler.go @@ -5251,7 +5251,4 @@ func (aH *APIHandler) RegisterTraceFunnelsRoutes(router *mux.Router, am *middlew traceFunnelsRouter.HandleFunc("/{funnel_id}", am.ViewAccess(aH.Signoz.Handlers.TraceFunnel.UpdateFunnel)). Methods(http.MethodPut) - traceFunnelsRouter.HandleFunc("/save", - am.ViewAccess(aH.Signoz.Handlers.TraceFunnel.Save)). - Methods(http.MethodPost) } diff --git a/pkg/sqlmigration/040_add_trace_funnels.go b/pkg/sqlmigration/040_add_trace_funnels.go index 22cb7ae57c..355251dab4 100644 --- a/pkg/sqlmigration/040_add_trace_funnels.go +++ b/pkg/sqlmigration/040_add_trace_funnels.go @@ -5,7 +5,6 @@ import ( "fmt" "github.com/SigNoz/signoz/pkg/factory" - v3 "github.com/SigNoz/signoz/pkg/query-service/model/v3" "github.com/SigNoz/signoz/pkg/sqlstore" "github.com/SigNoz/signoz/pkg/types" "github.com/SigNoz/signoz/pkg/valuer" @@ -28,16 +27,16 @@ type Funnel struct { } type FunnelStep struct { - ID valuer.UUID `json:"id,omitempty"` - Name string `json:"name,omitempty"` // step name - Description string `json:"description,omitempty"` // step description - Order int64 `json:"step_order"` - ServiceName string `json:"service_name"` - SpanName string `json:"span_name"` - Filters *v3.FilterSet `json:"filters,omitempty"` - LatencyPointer string `json:"latency_pointer,omitempty"` - LatencyType string `json:"latency_type,omitempty"` - HasErrors bool `json:"has_errors"` + types.Identifiable + Name string `json:"name,omitempty"` // step name + Description string `json:"description,omitempty"` // step description + Order int64 `json:"step_order"` + ServiceName string `json:"service_name"` + SpanName string `json:"span_name"` + Filters string `json:"filters,omitempty"` + LatencyPointer string `json:"latency_pointer,omitempty"` + LatencyType string `json:"latency_type,omitempty"` + HasErrors bool `json:"has_errors"` } type addTraceFunnels struct { @@ -69,7 +68,7 @@ func (migration *addTraceFunnels) Up(ctx context.Context, db *bun.DB) error { defer tx.Rollback() _, err = tx.NewCreateTable(). - Model((*Funnel)(nil)). + Model(new(Funnel)). ForeignKey(`("org_id") REFERENCES "organizations" ("id") ON DELETE CASCADE`). IfNotExists(). Exec(ctx) diff --git a/pkg/types/tracefunneltypes/tracefunnel.go b/pkg/types/tracefunneltypes/tracefunnel.go index 3c6b664922..fdc51d943a 100644 --- a/pkg/types/tracefunneltypes/tracefunnel.go +++ b/pkg/types/tracefunneltypes/tracefunnel.go @@ -12,9 +12,6 @@ var ( ErrFunnelAlreadyExists = errors.MustNewCode("funnel_already_exists") ) -type BaseMetadata struct { -} - // StorableFunnel Core Data Structure (StorableFunnel and FunnelStep) type StorableFunnel struct { types.Identifiable