mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-07-28 18:02:00 +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>
115 lines
3.2 KiB
Go
115 lines
3.2 KiB
Go
package impltracefunnel
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/SigNoz/signoz/pkg/errors"
|
|
"github.com/SigNoz/signoz/pkg/sqlstore"
|
|
traceFunnels "github.com/SigNoz/signoz/pkg/types/tracefunneltypes"
|
|
"github.com/SigNoz/signoz/pkg/valuer"
|
|
)
|
|
|
|
type store struct {
|
|
sqlstore sqlstore.SQLStore
|
|
}
|
|
|
|
func NewStore(sqlstore sqlstore.SQLStore) traceFunnels.FunnelStore {
|
|
return &store{sqlstore: sqlstore}
|
|
}
|
|
|
|
func (store *store) Create(ctx context.Context, funnel *traceFunnels.StorableFunnel) error {
|
|
// Check if a funnel with the same name already exists in the organization
|
|
exists, err := store.
|
|
sqlstore.
|
|
BunDB().
|
|
NewSelect().
|
|
Model(new(traceFunnels.StorableFunnel)).
|
|
Where("name = ? AND org_id = ?", funnel.Name, funnel.OrgID.String()).
|
|
Exists(ctx)
|
|
if err != nil {
|
|
return errors.Wrapf(err, errors.TypeInternal, errors.CodeInternal, "failed to check for existing funnelr")
|
|
}
|
|
if exists {
|
|
return store.sqlstore.WrapAlreadyExistsErrf(nil, traceFunnels.ErrFunnelAlreadyExists, "a funnel with name '%s' already exists in this organization", funnel.Name)
|
|
}
|
|
|
|
_, err = store.
|
|
sqlstore.
|
|
BunDB().
|
|
NewInsert().
|
|
Model(funnel).
|
|
Exec(ctx)
|
|
if err != nil {
|
|
return errors.Wrapf(err, errors.TypeInternal, errors.CodeInternal, "failed to create funnels")
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// Get retrieves a funnel by ID
|
|
func (store *store) Get(ctx context.Context, uuid valuer.UUID, orgID valuer.UUID) (*traceFunnels.StorableFunnel, error) {
|
|
funnel := &traceFunnels.StorableFunnel{}
|
|
err := store.
|
|
sqlstore.
|
|
BunDB().
|
|
NewSelect().
|
|
Model(funnel).
|
|
Relation("CreatedByUser").
|
|
Where("?TableAlias.id = ? AND ?TableAlias.org_id = ?", uuid.String(), orgID.String()).
|
|
Scan(ctx)
|
|
if err != nil {
|
|
return nil, errors.Wrapf(err, errors.TypeInternal, errors.CodeInternal, "failed to get funnels")
|
|
}
|
|
return funnel, nil
|
|
}
|
|
|
|
// Update updates an existing funnel
|
|
func (store *store) Update(ctx context.Context, funnel *traceFunnels.StorableFunnel) error {
|
|
funnel.UpdatedAt = time.Now()
|
|
|
|
_, err := store.
|
|
sqlstore.
|
|
BunDB().
|
|
NewUpdate().
|
|
Model(funnel).
|
|
WherePK().
|
|
Exec(ctx)
|
|
if err != nil {
|
|
return store.sqlstore.WrapAlreadyExistsErrf(err, traceFunnels.ErrFunnelAlreadyExists, "a funnel with name '%s' already exists in this organization", funnel.Name)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// List retrieves all funnels for a given organization
|
|
func (store *store) List(ctx context.Context, orgID valuer.UUID) ([]*traceFunnels.StorableFunnel, error) {
|
|
var funnels []*traceFunnels.StorableFunnel
|
|
err := store.
|
|
sqlstore.
|
|
BunDB().
|
|
NewSelect().
|
|
Model(&funnels).
|
|
Relation("CreatedByUser").
|
|
Where("?TableAlias.org_id = ?", orgID.String()).
|
|
Scan(ctx)
|
|
if err != nil {
|
|
return nil, errors.Wrapf(err, errors.TypeInternal, errors.CodeInternal, "failed to list funnels")
|
|
}
|
|
return funnels, nil
|
|
}
|
|
|
|
// Delete removes a funnel by ID
|
|
func (store *store) Delete(ctx context.Context, funnelID valuer.UUID, orgID valuer.UUID) error {
|
|
_, err := store.
|
|
sqlstore.
|
|
BunDB().
|
|
NewDelete().
|
|
Model(new(traceFunnels.StorableFunnel)).
|
|
Where("id = ? AND org_id = ?", funnelID.String(), orgID.String()).
|
|
Exec(ctx)
|
|
if err != nil {
|
|
return errors.Wrapf(err, errors.TypeInternal, errors.CodeInternal, "failed to delete funnel")
|
|
}
|
|
return nil
|
|
}
|