Compare commits

..

12 Commits

Author SHA1 Message Date
Naman Verma
19418d6d36 feat: get dashboard api handler with todo 2026-04-07 16:59:13 +05:30
Naman Verma
fc9ba6aac0 Merge branch 'nv/4172' into nv/4310 2026-04-07 15:54:46 +05:30
Naman Verma
c88c59c83b feat: patch APIs to update name, desc, tags 2026-04-07 15:53:22 +05:30
Naman Verma
312b2fa38d Merge branch 'nv/4172' into nv/4310 2026-04-07 15:52:53 +05:30
Naman Verma
a7a4b2f2a1 feat: lock/unlock api in v2 2026-04-07 13:42:17 +05:30
Naman Verma
10ca8c38e1 Merge branch 'nv/4172' into nv/4310 2026-04-07 11:36:59 +05:30
Naman Verma
cf4f73dda0 feat: delete api for dashboard v2 2026-04-07 10:02:12 +05:30
Naman Verma
a6e4294665 Merge branch 'nv/4172' into nv/4310 2026-04-06 22:18:48 +05:30
Naman Verma
66582e528f feat: update v2 dashboard handler 2026-04-06 22:17:18 +05:30
Naman Verma
9c3e8ce15d fix: remove err catch from call to NewDashboardV2 method 2026-04-06 21:25:37 +05:30
Naman Verma
50e96fc450 Merge branch 'nv/4172' into nv/4310 2026-04-06 21:19:41 +05:30
Naman Verma
a7f0df61d1 feat: create v2 dashboard handler 2026-04-06 18:21:43 +05:30
4 changed files with 760 additions and 0 deletions

View File

@@ -0,0 +1,60 @@
package dashboardv2
import (
"context"
"net/http"
"github.com/SigNoz/signoz/pkg/types/dashboardtypes"
"github.com/SigNoz/signoz/pkg/valuer"
)
// IntegrationDashboardProvider abstracts access to integration-managed dashboards
// (cloud integrations and installed integrations) so that the module does not
// depend on pkg/query-service/app. The wiring layer adapts the concrete
// controllers to this interface.
//
// TODO: wire this in the wiring layer by adapting CloudIntegrationsController
// and IntegrationsController to this interface.
type IntegrationDashboardProvider interface {
IsCloudIntegrationDashboard(id string) bool
GetCloudIntegrationDashboard(ctx context.Context, orgID valuer.UUID, id string) (*dashboardtypes.DashboardV2, error)
IsInstalledIntegrationDashboard(id string) bool
GetInstalledIntegrationDashboard(ctx context.Context, orgID valuer.UUID, id string) (*dashboardtypes.DashboardV2, error)
}
type Module interface {
Create(ctx context.Context, orgID valuer.UUID, createdBy string, creator valuer.UUID, data dashboardtypes.PostableDashboardV2) (*dashboardtypes.DashboardV2, error)
Get(ctx context.Context, orgID valuer.UUID, id valuer.UUID) (*dashboardtypes.DashboardV2, error)
Update(ctx context.Context, orgID valuer.UUID, id valuer.UUID, updatedBy string, data dashboardtypes.UpdatableDashboardV2, diff int) (*dashboardtypes.DashboardV2, error)
Delete(ctx context.Context, orgID valuer.UUID, id valuer.UUID) error
LockUnlock(ctx context.Context, orgID valuer.UUID, id valuer.UUID, updatedBy string, isAdmin bool, lock bool) (*dashboardtypes.DashboardV2, error)
UpdateName(ctx context.Context, orgID valuer.UUID, id valuer.UUID, updatedBy string, name string) (*dashboardtypes.DashboardV2, error)
UpdateDescription(ctx context.Context, orgID valuer.UUID, id valuer.UUID, updatedBy string, description string) (*dashboardtypes.DashboardV2, error)
UpdateTags(ctx context.Context, orgID valuer.UUID, id valuer.UUID, updatedBy string, tags []string) (*dashboardtypes.DashboardV2, error)
}
type Handler interface {
Create(http.ResponseWriter, *http.Request)
Get(http.ResponseWriter, *http.Request)
Update(http.ResponseWriter, *http.Request)
Delete(http.ResponseWriter, *http.Request)
LockUnlock(http.ResponseWriter, *http.Request)
UpdateName(http.ResponseWriter, *http.Request)
UpdateDescription(http.ResponseWriter, *http.Request)
UpdateTags(http.ResponseWriter, *http.Request)
}

View File

@@ -0,0 +1,412 @@
package impldashboard
import (
"context"
"encoding/json"
"io"
"net/http"
"time"
"github.com/SigNoz/signoz/pkg/authz"
"github.com/SigNoz/signoz/pkg/errors"
"github.com/SigNoz/signoz/pkg/http/render"
"github.com/SigNoz/signoz/pkg/modules/dashboardv2"
"github.com/SigNoz/signoz/pkg/types/authtypes"
"github.com/SigNoz/signoz/pkg/types/dashboardtypes"
"github.com/SigNoz/signoz/pkg/valuer"
"github.com/gorilla/mux"
)
type handler struct {
module dashboardv2.Module
authz authz.AuthZ
integrations dashboardv2.IntegrationDashboardProvider
}
func NewHandler(module dashboardv2.Module, authz authz.AuthZ, integrations dashboardv2.IntegrationDashboardProvider) dashboardv2.Handler {
return &handler{module: module, authz: authz, integrations: integrations}
}
func (handler *handler) Create(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
}
body, err := io.ReadAll(r.Body)
if err != nil {
render.Error(rw, err)
return
}
req, err := dashboardtypes.UnmarshalAndValidateDashboardV2JSON(body)
if err != nil {
render.Error(rw, err)
return
}
dashboard, err := handler.module.Create(ctx, orgID, claims.Email, valuer.MustNewUUID(claims.IdentityID()), *req)
if err != nil {
render.Error(rw, err)
return
}
gettable, err := dashboardtypes.NewGettableDashboardV2FromDashboard(dashboard)
if err != nil {
render.Error(rw, err)
return
}
render.Success(rw, http.StatusCreated, gettable)
}
func (handler *handler) Get(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 := mux.Vars(r)["id"]
if id == "" {
render.Error(rw, errors.Newf(errors.TypeInvalidInput, errors.CodeInvalidInput, "id is missing in the path"))
return
}
if handler.integrations.IsCloudIntegrationDashboard(id) {
dashboard, err := handler.integrations.GetCloudIntegrationDashboard(ctx, orgID, id)
if err != nil {
render.Error(rw, err)
return
}
render.Success(rw, http.StatusOK, dashboard)
return
}
if handler.integrations.IsInstalledIntegrationDashboard(id) {
dashboard, err := handler.integrations.GetInstalledIntegrationDashboard(ctx, orgID, id)
if err != nil {
render.Error(rw, err)
return
}
render.Success(rw, http.StatusOK, dashboard)
return
}
dashboardID, err := valuer.NewUUID(id)
if err != nil {
render.Error(rw, err)
return
}
dashboard, err := handler.module.Get(ctx, orgID, dashboardID)
if err != nil {
render.Error(rw, err)
return
}
render.Success(rw, http.StatusOK, dashboard)
}
func (handler *handler) Update(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
}
// TODO: reject cloud integration and installed integration dashboard IDs
// (prefixed with "cloud-integration--" and "integration--") with an explicit error,
// since those dashboards are read-only and cannot be updated.
id := mux.Vars(r)["id"]
if id == "" {
render.Error(rw, errors.Newf(errors.TypeInvalidInput, errors.CodeInvalidInput, "id is missing in the path"))
return
}
dashboardID, err := valuer.NewUUID(id)
if err != nil {
render.Error(rw, err)
return
}
body, err := io.ReadAll(r.Body)
if err != nil {
render.Error(rw, err)
return
}
req, err := dashboardtypes.UnmarshalAndValidateDashboardV2JSON(body)
if err != nil {
render.Error(rw, err)
return
}
diff := 0
// Allow multiple deletions for API key requests; enforce for others
if claims.IdentNProvider == authtypes.IdentNProviderTokenizer {
diff = 1
}
dashboard, err := handler.module.Update(ctx, orgID, dashboardID, claims.Email, *req, diff)
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()
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 := mux.Vars(r)["id"]
if id == "" {
render.Error(rw, errors.Newf(errors.TypeInvalidInput, errors.CodeInvalidInput, "id is missing in the path"))
return
}
dashboardID, err := valuer.NewUUID(id)
if err != nil {
render.Error(rw, err)
return
}
err = handler.module.Delete(ctx, orgID, dashboardID)
if err != nil {
render.Error(rw, err)
return
}
render.Success(rw, http.StatusNoContent, nil)
}
func (handler *handler) LockUnlock(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 := mux.Vars(r)["id"]
if id == "" {
render.Error(rw, errors.Newf(errors.TypeInvalidInput, errors.CodeInvalidInput, "id is missing in the path"))
return
}
dashboardID, err := valuer.NewUUID(id)
if err != nil {
render.Error(rw, err)
return
}
req := new(dashboardtypes.LockUnlockDashboard)
if err := json.NewDecoder(r.Body).Decode(req); err != nil {
render.Error(rw, err)
return
}
isAdmin := false
selectors := []authtypes.Selector{
authtypes.MustNewSelector(authtypes.TypeRole, authtypes.SigNozAdminRoleName),
}
err = handler.authz.CheckWithTupleCreation(
ctx,
claims,
valuer.MustNewUUID(claims.OrgID),
authtypes.RelationAssignee,
authtypes.TypeableRole,
selectors,
selectors,
)
if err == nil {
isAdmin = true
}
dashboard, err := handler.module.LockUnlock(ctx, orgID, dashboardID, claims.Email, isAdmin, *req.Locked)
if err != nil {
render.Error(rw, err)
return
}
render.Success(rw, http.StatusOK, dashboard)
}
func (handler *handler) UpdateName(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 := mux.Vars(r)["id"]
if id == "" {
render.Error(rw, errors.Newf(errors.TypeInvalidInput, errors.CodeInvalidInput, "id is missing in the path"))
return
}
dashboardID, err := valuer.NewUUID(id)
if err != nil {
render.Error(rw, err)
return
}
var req struct {
Name string `json:"name"`
}
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
render.Error(rw, err)
return
}
dashboard, err := handler.module.UpdateName(ctx, orgID, dashboardID, claims.Email, req.Name)
if err != nil {
render.Error(rw, err)
return
}
render.Success(rw, http.StatusOK, dashboard)
}
func (handler *handler) UpdateDescription(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 := mux.Vars(r)["id"]
if id == "" {
render.Error(rw, errors.Newf(errors.TypeInvalidInput, errors.CodeInvalidInput, "id is missing in the path"))
return
}
dashboardID, err := valuer.NewUUID(id)
if err != nil {
render.Error(rw, err)
return
}
var req struct {
Description string `json:"description"`
}
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
render.Error(rw, err)
return
}
dashboard, err := handler.module.UpdateDescription(ctx, orgID, dashboardID, claims.Email, req.Description)
if err != nil {
render.Error(rw, err)
return
}
render.Success(rw, http.StatusOK, dashboard)
}
func (handler *handler) UpdateTags(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 := mux.Vars(r)["id"]
if id == "" {
render.Error(rw, errors.Newf(errors.TypeInvalidInput, errors.CodeInvalidInput, "id is missing in the path"))
return
}
dashboardID, err := valuer.NewUUID(id)
if err != nil {
render.Error(rw, err)
return
}
var req struct {
Tags []string `json:"tags"`
}
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
render.Error(rw, err)
return
}
dashboard, err := handler.module.UpdateTags(ctx, orgID, dashboardID, claims.Email, req.Tags)
if err != nil {
render.Error(rw, err)
return
}
render.Success(rw, http.StatusOK, dashboard)
}

View File

@@ -0,0 +1,207 @@
package impldashboard
import (
"context"
"github.com/SigNoz/signoz/pkg/analytics"
"github.com/SigNoz/signoz/pkg/errors"
"github.com/SigNoz/signoz/pkg/factory"
"github.com/SigNoz/signoz/pkg/modules/dashboardv2"
"github.com/SigNoz/signoz/pkg/types"
"github.com/SigNoz/signoz/pkg/types/dashboardtypes"
"github.com/SigNoz/signoz/pkg/valuer"
"github.com/perses/common/set"
)
type module struct {
store *store
settings factory.ScopedProviderSettings
analytics analytics.Analytics
}
func NewModule(store *store, settings factory.ProviderSettings, analytics analytics.Analytics) dashboardv2.Module {
scopedProviderSettings := factory.NewScopedProviderSettings(settings, "github.com/SigNoz/signoz/pkg/modules/dashboardv2/impldashboard")
return &module{
store: store,
settings: scopedProviderSettings,
analytics: analytics,
}
}
func (module *module) Create(ctx context.Context, orgID valuer.UUID, createdBy string, creator valuer.UUID, data dashboardtypes.PostableDashboardV2) (*dashboardtypes.DashboardV2, error) {
dashboard := dashboardtypes.NewDashboardV2(orgID, createdBy, data)
storable, err := dashboardtypes.NewStorableDashboardV2FromDashboardV2(dashboard)
if err != nil {
return nil, err
}
err = module.store.Create(ctx, storable)
if err != nil {
return nil, err
}
module.analytics.TrackUser(ctx, orgID.String(), creator.String(), "Dashboard Created", dashboardtypes.NewStatsFromStorableDashboardsV2([]*dashboardtypes.StorableDashboardV2{storable}))
return dashboard, nil
}
func (module *module) Get(ctx context.Context, orgID valuer.UUID, id valuer.UUID) (*dashboardtypes.DashboardV2, error) {
storable, err := module.store.Get(ctx, orgID, id)
if err != nil {
return nil, err
}
return dashboardtypes.NewDashboardV2FromStorableDashboard(storable), nil
}
func (module *module) Update(ctx context.Context, orgID valuer.UUID, id valuer.UUID, updatedBy string, data dashboardtypes.UpdatableDashboardV2, diff int) (*dashboardtypes.DashboardV2, error) {
// Fetch current state to validate lock status and panel diff before updating.
// This lives in the module layer (not pushed into a conditional SQL update)
// to keep business logic out of the store.
storable, err := module.store.Get(ctx, orgID, id)
if err != nil {
return nil, err
}
dashboard := dashboardtypes.NewDashboardV2FromStorableDashboard(storable)
err = dashboard.Update(ctx, data, updatedBy, diff)
if err != nil {
return nil, err
}
updatedStorable, err := dashboardtypes.NewStorableDashboardV2FromDashboardV2(dashboard)
if err != nil {
return nil, err
}
err = module.store.Update(ctx, orgID, updatedStorable)
if err != nil {
return nil, err
}
return dashboard, nil
}
func (module *module) Delete(ctx context.Context, orgID valuer.UUID, id valuer.UUID) error {
storable, err := module.store.Get(ctx, orgID, id)
if err != nil {
return err
}
if storable.Data.Locked {
return errors.New(errors.TypeInvalidInput, errors.CodeInvalidInput, "dashboard is locked, please unlock the dashboard to delete it")
}
return module.store.Delete(ctx, orgID, id)
}
func (module *module) LockUnlock(ctx context.Context, orgID valuer.UUID, id valuer.UUID, updatedBy string, isAdmin bool, lock bool) (*dashboardtypes.DashboardV2, error) {
storable, err := module.store.Get(ctx, orgID, id)
if err != nil {
return nil, err
}
dashboard := dashboardtypes.NewDashboardV2FromStorableDashboard(storable)
role := types.RoleViewer
if isAdmin {
role = types.RoleAdmin
}
err = dashboard.LockUnlock(lock, role, updatedBy)
if err != nil {
return nil, err
}
updatedStorable, err := dashboardtypes.NewStorableDashboardV2FromDashboardV2(dashboard)
if err != nil {
return nil, err
}
err = module.store.Update(ctx, orgID, updatedStorable)
if err != nil {
return nil, err
}
return dashboard, nil
}
func (module *module) UpdateName(ctx context.Context, orgID valuer.UUID, id valuer.UUID, updatedBy string, name string) (*dashboardtypes.DashboardV2, error) {
storable, err := module.store.Get(ctx, orgID, id)
if err != nil {
return nil, err
}
dashboard := dashboardtypes.NewDashboardV2FromStorableDashboard(storable)
err = dashboard.UpdateName(name, updatedBy)
if err != nil {
return nil, err
}
updatedStorable, err := dashboardtypes.NewStorableDashboardV2FromDashboardV2(dashboard)
if err != nil {
return nil, err
}
err = module.store.Update(ctx, orgID, updatedStorable)
if err != nil {
return nil, err
}
return dashboard, nil
}
func (module *module) UpdateDescription(ctx context.Context, orgID valuer.UUID, id valuer.UUID, updatedBy string, description string) (*dashboardtypes.DashboardV2, error) {
storable, err := module.store.Get(ctx, orgID, id)
if err != nil {
return nil, err
}
dashboard := dashboardtypes.NewDashboardV2FromStorableDashboard(storable)
err = dashboard.UpdateDescription(description, updatedBy)
if err != nil {
return nil, err
}
updatedStorable, err := dashboardtypes.NewStorableDashboardV2FromDashboardV2(dashboard)
if err != nil {
return nil, err
}
err = module.store.Update(ctx, orgID, updatedStorable)
if err != nil {
return nil, err
}
return dashboard, nil
}
func (module *module) UpdateTags(ctx context.Context, orgID valuer.UUID, id valuer.UUID, updatedBy string, tags []string) (*dashboardtypes.DashboardV2, error) {
storable, err := module.store.Get(ctx, orgID, id)
if err != nil {
return nil, err
}
dashboard := dashboardtypes.NewDashboardV2FromStorableDashboard(storable)
err = dashboard.UpdateTags(set.New(tags...), updatedBy)
if err != nil {
return nil, err
}
updatedStorable, err := dashboardtypes.NewStorableDashboardV2FromDashboardV2(dashboard)
if err != nil {
return nil, err
}
err = module.store.Update(ctx, orgID, updatedStorable)
if err != nil {
return nil, err
}
return dashboard, nil
}

View File

@@ -0,0 +1,81 @@
package impldashboard
import (
"context"
"github.com/SigNoz/signoz/pkg/errors"
"github.com/SigNoz/signoz/pkg/sqlstore"
"github.com/SigNoz/signoz/pkg/types/dashboardtypes"
"github.com/SigNoz/signoz/pkg/valuer"
)
type store struct {
sqlstore sqlstore.SQLStore
}
func NewStore(sqlstore sqlstore.SQLStore) *store {
return &store{sqlstore: sqlstore}
}
func (store *store) Create(ctx context.Context, storable *dashboardtypes.StorableDashboardV2) error {
_, err := store.
sqlstore.
BunDB().
NewInsert().
Model(storable).
Exec(ctx)
if err != nil {
return store.sqlstore.WrapAlreadyExistsErrf(err, errors.CodeAlreadyExists, "dashboard with id %s already exists", storable.ID)
}
return nil
}
func (store *store) Get(ctx context.Context, orgID valuer.UUID, id valuer.UUID) (*dashboardtypes.StorableDashboardV2, error) {
storable := new(dashboardtypes.StorableDashboardV2)
err := store.
sqlstore.
BunDB().
NewSelect().
Model(storable).
Where("id = ?", id).
Where("org_id = ?", orgID).
Scan(ctx)
if err != nil {
return nil, store.sqlstore.WrapNotFoundErrf(err, errors.CodeNotFound, "dashboard with id %s doesn't exist", id)
}
return storable, nil
}
func (store *store) Update(ctx context.Context, orgID valuer.UUID, storable *dashboardtypes.StorableDashboardV2) error {
_, err := store.
sqlstore.
BunDB().
NewUpdate().
Model(storable).
WherePK().
Where("org_id = ?", orgID).
Exec(ctx)
if err != nil {
return store.sqlstore.WrapNotFoundErrf(err, errors.CodeNotFound, "dashboard with id %s doesn't exist", storable.ID)
}
return nil
}
func (store *store) Delete(ctx context.Context, orgID valuer.UUID, id valuer.UUID) error {
_, err := store.
sqlstore.
BunDB().
NewDelete().
Model(new(dashboardtypes.StorableDashboardV2)).
Where("id = ?", id).
Where("org_id = ?", orgID).
Exec(ctx)
if err != nil {
return store.sqlstore.WrapNotFoundErrf(err, errors.CodeNotFound, "dashboard with id %s doesn't exist", id)
}
return nil
}