mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-07-28 17:31:58 +08:00

* feat: adds server and handler changes Signed-off-by: Shivanshu Raj Shrivastava <shivanshu1333@gmail.com> * feat: add tracefunnel module and handler Signed-off-by: Shivanshu Raj Shrivastava <shivanshu1333@gmail.com> * feat: add required types for tracefunnels Signed-off-by: Shivanshu Raj Shrivastava <shivanshu1333@gmail.com> * feat: db operations, module and handler implementation Signed-off-by: Shivanshu Raj Shrivastava <shivanshu1333@gmail.com> * feat: add db migrations Signed-off-by: Shivanshu Raj Shrivastava <shivanshu1333@gmail.com> * chore: add utility functions Signed-off-by: Shivanshu Raj Shrivastava <shivanshu1333@gmail.com> * test: add utility function tests Signed-off-by: Shivanshu Raj Shrivastava <shivanshu1333@gmail.com> * test: add handler tests Signed-off-by: Shivanshu Raj Shrivastava <shivanshu1333@gmail.com> * test: add trace funnel module tests Signed-off-by: Shivanshu Raj Shrivastava <shivanshu1333@gmail.com> * chore: refactor handler and utils Signed-off-by: Shivanshu Raj Shrivastava <shivanshu1333@gmail.com> * chore: add funnel validation while processing funnel steps Signed-off-by: Shivanshu Raj Shrivastava <shivanshu1333@gmail.com> * test: add more tests to utils Signed-off-by: Shivanshu Raj Shrivastava <shivanshu1333@gmail.com> * chore: fix package naming Signed-off-by: Shivanshu Raj Shrivastava <shivanshu1333@gmail.com> * chore: fix naming convention Signed-off-by: Shivanshu Raj Shrivastava <shivanshu1333@gmail.com> * chore: update normalize funnel steps Signed-off-by: Shivanshu Raj Shrivastava <shivanshu1333@gmail.com> * chore: added some improvements Signed-off-by: Shivanshu Raj Shrivastava <shivanshu1333@gmail.com> * fix: optimize funnel creation by combining insert and update operations Signed-off-by: Shivanshu Raj Shrivastava <shivanshu1333@gmail.com> * chore: fix error handling Signed-off-by: Shivanshu Raj Shrivastava <shivanshu1333@gmail.com> * feat: trace funnel state management Signed-off-by: Shivanshu Raj Shrivastava <shivanshu1333@gmail.com> * fix: updated unit tests and mocks Signed-off-by: Shivanshu Raj Shrivastava <shivanshu1333@gmail.com> * fix: review comments Signed-off-by: Shivanshu Raj Shrivastava <shivanshu1333@gmail.com> * fix: minor fixes Signed-off-by: Shivanshu Raj Shrivastava <shivanshu1333@gmail.com> * fix: update funnel migration number Signed-off-by: Shivanshu Raj Shrivastava <shivanshu1333@gmail.com> * fix: review comments and some changes Signed-off-by: Shivanshu Raj Shrivastava <shivanshu1333@gmail.com> * fix: update modules Signed-off-by: Shivanshu Raj Shrivastava <shivanshu1333@gmail.com> --------- Signed-off-by: Shivanshu Raj Shrivastava <shivanshu1333@gmail.com>
97 lines
2.6 KiB
Go
97 lines
2.6 KiB
Go
package impltracefunnel
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/SigNoz/signoz/pkg/modules/tracefunnel"
|
|
"github.com/SigNoz/signoz/pkg/types"
|
|
traceFunnels "github.com/SigNoz/signoz/pkg/types/tracefunneltypes"
|
|
"github.com/SigNoz/signoz/pkg/valuer"
|
|
)
|
|
|
|
type module struct {
|
|
store traceFunnels.FunnelStore
|
|
}
|
|
|
|
func NewModule(store traceFunnels.FunnelStore) tracefunnel.Module {
|
|
return &module{
|
|
store: store,
|
|
}
|
|
}
|
|
|
|
func (module *module) Create(ctx context.Context, timestamp int64, name string, userID valuer.UUID, orgID valuer.UUID) (*traceFunnels.StorableFunnel, error) {
|
|
funnel := &traceFunnels.StorableFunnel{
|
|
Name: name,
|
|
OrgID: orgID,
|
|
}
|
|
funnel.CreatedAt = time.Unix(0, timestamp*1000000) // Convert to nanoseconds
|
|
funnel.CreatedBy = userID.String()
|
|
|
|
// Set up the user relationship
|
|
funnel.CreatedByUser = &types.User{
|
|
Identifiable: types.Identifiable{
|
|
ID: userID,
|
|
},
|
|
}
|
|
|
|
if funnel.ID.IsZero() {
|
|
funnel.ID = valuer.GenerateUUID()
|
|
}
|
|
|
|
if funnel.CreatedAt.IsZero() {
|
|
funnel.CreatedAt = time.Now()
|
|
}
|
|
if funnel.UpdatedAt.IsZero() {
|
|
funnel.UpdatedAt = time.Now()
|
|
}
|
|
|
|
// Set created_by if CreatedByUser is present
|
|
if funnel.CreatedByUser != nil {
|
|
funnel.CreatedBy = funnel.CreatedByUser.Identifiable.ID.String()
|
|
}
|
|
|
|
if err := module.store.Create(ctx, funnel); err != nil {
|
|
return nil, fmt.Errorf("failed to create funnel: %v", err)
|
|
}
|
|
|
|
return funnel, nil
|
|
}
|
|
|
|
// Get gets a funnel by ID
|
|
func (module *module) Get(ctx context.Context, funnelID valuer.UUID, orgID valuer.UUID) (*traceFunnels.StorableFunnel, error) {
|
|
return module.store.Get(ctx, funnelID, orgID)
|
|
}
|
|
|
|
// Update updates a funnel
|
|
func (module *module) Update(ctx context.Context, funnel *traceFunnels.StorableFunnel, userID valuer.UUID) error {
|
|
funnel.UpdatedBy = userID.String()
|
|
return module.store.Update(ctx, funnel)
|
|
}
|
|
|
|
// List lists all funnels for an organization
|
|
func (module *module) List(ctx context.Context, orgID valuer.UUID) ([]*traceFunnels.StorableFunnel, error) {
|
|
funnels, err := module.store.List(ctx, orgID)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to list funnels: %v", err)
|
|
}
|
|
|
|
return funnels, nil
|
|
}
|
|
|
|
// Delete deletes a funnel
|
|
func (module *module) Delete(ctx context.Context, funnelID valuer.UUID, orgID valuer.UUID) error {
|
|
return module.store.Delete(ctx, funnelID, orgID)
|
|
}
|
|
|
|
// GetFunnelMetadata gets metadata for a funnel
|
|
func (module *module) GetFunnelMetadata(ctx context.Context, funnelID valuer.UUID, orgID valuer.UUID) (int64, int64, string, error) {
|
|
funnel, err := module.store.Get(ctx, funnelID, orgID)
|
|
if err != nil {
|
|
return 0, 0, "", err
|
|
}
|
|
|
|
return funnel.CreatedAt.UnixNano() / 1000000, funnel.UpdatedAt.UnixNano() / 1000000, funnel.Description, nil
|
|
}
|