Compare commits

...

11 Commits

Author SHA1 Message Date
Pradeep Kumar
c2535f0ccf update reset as per discussion
ref: https://github.com/SigNoz/engineering-pod/issues/4501#issuecomment-4571186964

now reset uses {id} similar pattern to what existing apis have
and guarded by source system, means only system dashboards are
allowed for reset.
2026-05-29 16:27:15 +05:30
Pradeep Kumar
745222867b align system-dashboard with Source enums
assumption taken that system dashbard is just one which is going
tobe ai-o11y-overview page. (there is going to be a unique Name in
dashboard which would help us handle other system dashbaords)

no seeding code part present in this pr.
2026-05-29 16:15:33 +05:30
Pradeep Kumar
b0ddcbe9f1 change from QP to path param
address review comment to add source as path param instead of QP
and a little refactor
2026-05-29 16:14:11 +05:30
Pradeep Kumar
785c6233c7 address review comments after using existing paths.
fix migration number 78  to 79
drop id in reset path, and refactor
use locking for system dashboard as well.
2026-05-29 16:14:07 +05:30
Pradeep Kumar
97912f6c50 use existing dashboards path
as discussed on the pr conversations, we are now using existing
dashboards path and most of the existing methods.

- GET /api/v1/dashboards?source=<src>
- POST /api/v1/dashboards/{id}/reset
Update works same it just bypass the lock/unlock check

Behavior of seeding remains intact
2026-05-29 16:12:25 +05:30
Pradeep Kumar
849cae1a9c fix migration not by by FK toggle
used similar pattern as 029_drop_groups.

tested in local env with without data in both dashboard and
public_dashboard
2026-05-29 16:10:20 +05:30
Pradeep Kumar
92d40bf335 fix migration
after testing with data in public_dashboard migration failed.
fixed with Alter table.
2026-05-29 16:10:20 +05:30
Pradeep Kumar
78723f63bc add userid instead of empty string or 'system' & fix migration
comment out storing default value, only add column
2026-05-29 16:10:20 +05:30
Pradeep Kumar
f8d73af495 address review comments 2026-05-29 16:10:20 +05:30
Pradeep Kumar
6ba2049cfe removes ai_o11y_overview.json containing default value
this removes default values for dashbaord data for system source

only thing changed is removal of file and not storing anything
at seed time .
will handle this in diff pr.
2026-05-29 16:10:20 +05:30
Pradeep Kumar
bd1fc43376 address review comments 2026-05-29 16:10:18 +05:30
7 changed files with 73 additions and 7 deletions

View File

@@ -237,6 +237,10 @@ func (module *module) Update(ctx context.Context, orgID valuer.UUID, id valuer.U
return module.pkgDashboardModule.Update(ctx, orgID, id, updatedBy, data, diff)
}
func (module *module) ResetSystemDashboard(ctx context.Context, orgID valuer.UUID, id valuer.UUID, updatedBy string) (*dashboardtypes.Dashboard, error) {
return module.pkgDashboardModule.ResetSystemDashboard(ctx, orgID, id, updatedBy)
}
func (module *module) LockUnlock(ctx context.Context, orgID valuer.UUID, id valuer.UUID, updatedBy string, isAdmin bool, lock bool) error {
return module.pkgDashboardModule.LockUnlock(ctx, orgID, id, updatedBy, isAdmin, lock)
}

View File

@@ -42,6 +42,8 @@ type Module interface {
Update(ctx context.Context, orgID valuer.UUID, id valuer.UUID, updatedBy string, data dashboardtypes.UpdatableDashboard, diff int) (*dashboardtypes.Dashboard, error)
ResetSystemDashboard(ctx context.Context, orgID valuer.UUID, id valuer.UUID, updatedBy string) (*dashboardtypes.Dashboard, error)
LockUnlock(ctx context.Context, orgID valuer.UUID, id valuer.UUID, updatedBy string, isAdmin bool, lock bool) error
Delete(ctx context.Context, orgID valuer.UUID, id valuer.UUID) error
@@ -89,4 +91,6 @@ type Handler interface {
CreateV2(http.ResponseWriter, *http.Request)
GetV2(http.ResponseWriter, *http.Request)
ResetSystemDashboard(http.ResponseWriter, *http.Request)
}

View File

@@ -185,6 +185,38 @@ func (handler *handler) LockUnlock(rw http.ResponseWriter, r *http.Request) {
}
// ResetSystemDashboard resets the dashboard identified by {id} to its default.
func (handler *handler) ResetSystemDashboard(rw http.ResponseWriter, r *http.Request) {
ctx, cancel := context.WithTimeout(r.Context(), 10*time.Second)
defer cancel()
claims, err := authtypes.ClaimsFromContext(ctx)
if err != nil {
render.Error(rw, err)
return
}
orgID, err := valuer.NewUUID(claims.OrgID)
if err != nil {
render.Error(rw, err)
return
}
id, err := valuer.NewUUID(mux.Vars(r)["id"])
if err != nil {
render.Error(rw, err)
return
}
dashboard, err := handler.module.ResetSystemDashboard(ctx, orgID, id, claims.Email)
if err != nil {
render.Error(rw, err)
return
}
render.Success(rw, http.StatusOK, dashboard)
}
func (handler *handler) Delete(rw http.ResponseWriter, r *http.Request) {
ctx, cancel := context.WithTimeout(r.Context(), 10*time.Second)
defer cancel()

View File

@@ -97,8 +97,7 @@ func (module *module) Update(ctx context.Context, orgID valuer.UUID, id valuer.U
return nil, err
}
err = dashboard.Update(ctx, updatableDashboard, updatedBy, diff)
if err != nil {
if err := dashboard.Update(ctx, updatableDashboard, updatedBy, diff); err != nil {
return nil, err
}
@@ -107,14 +106,31 @@ func (module *module) Update(ctx context.Context, orgID valuer.UUID, id valuer.U
return nil, err
}
err = module.store.Update(ctx, orgID, storableDashboard)
if err != nil {
if err := module.store.Update(ctx, orgID, storableDashboard); err != nil {
return nil, err
}
return dashboard, nil
}
func (module *module) ResetSystemDashboard(ctx context.Context, orgID valuer.UUID, id valuer.UUID, updatedBy string) (*dashboardtypes.Dashboard, error) {
dashboard, err := module.Get(ctx, orgID, id)
if err != nil {
return nil, err
}
if dashboard.Source != dashboardtypes.SourceSystem {
return nil, errors.Newf(errors.TypeInvalidInput, errors.CodeInvalidInput, "only system dashboards can be reset")
}
defaults, err := dashboardtypes.NewDefaultSystemDashboard(orgID)
if err != nil {
return nil, err
}
return module.Update(ctx, orgID, id, updatedBy, defaults.Data, 0)
}
func (module *module) LockUnlock(ctx context.Context, orgID valuer.UUID, id valuer.UUID, updatedBy string, isAdmin bool, lock bool) error {
dashboard, err := module.Get(ctx, orgID, id)
if err != nil {
@@ -156,8 +172,7 @@ func (module *module) Delete(ctx context.Context, orgID valuer.UUID, id valuer.U
return errors.New(errors.TypeInvalidInput, errors.CodeInvalidInput, "dashboard is locked, please unlock the dashboard to be delete it")
}
err = module.store.Delete(ctx, orgID, id)
if err != nil {
if err := module.store.Delete(ctx, orgID, id); err != nil {
return err
}

View File

@@ -153,7 +153,7 @@ func (store *store) ListPublic(ctx context.Context, orgID valuer.UUID) ([]*dashb
func (store *store) Update(ctx context.Context, orgID valuer.UUID, storableDashboard *dashboardtypes.StorableDashboard) error {
_, err := store.
sqlstore.
BunDB().
BunDBCtx(ctx).
NewUpdate().
Model(storableDashboard).
WherePK().

View File

@@ -502,6 +502,7 @@ func (aH *APIHandler) RegisterRoutes(router *mux.Router, am *middleware.AuthZ) {
router.HandleFunc("/api/v1/dashboards/{id}", am.EditAccess(aH.Signoz.Handlers.Dashboard.Update)).Methods(http.MethodPut)
router.HandleFunc("/api/v1/dashboards/{id}", am.EditAccess(aH.Signoz.Handlers.Dashboard.Delete)).Methods(http.MethodDelete)
router.HandleFunc("/api/v1/dashboards/{id}/lock", am.EditAccess(aH.Signoz.Handlers.Dashboard.LockUnlock)).Methods(http.MethodPut)
router.HandleFunc("/api/v1/dashboards/{id}/reset", am.AdminAccess(aH.Signoz.Handlers.Dashboard.ResetSystemDashboard)).Methods(http.MethodPut)
router.HandleFunc("/api/v2/variables/query", am.ViewAccess(aH.queryDashboardVarsV2)).Methods(http.MethodPost)
router.HandleFunc("/api/v1/explorer/views", am.ViewAccess(aH.Signoz.Handlers.SavedView.List)).Methods(http.MethodGet)

View File

@@ -0,0 +1,10 @@
package dashboardtypes
import (
"github.com/SigNoz/signoz/pkg/errors"
"github.com/SigNoz/signoz/pkg/valuer"
)
func NewDefaultSystemDashboard(orgID valuer.UUID) (*Dashboard, error) {
return nil, errors.Newf(errors.TypeInvalidInput, errors.CodeInvalidInput, "no defaults registered for system dashboard")
}