Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

chore: create source field in dashboards (#11367)

Srikanth Chekuri9f60bdf54a3b
diff --git a/docs/api/openapi.yml b/docs/api/openapi.yml
index 551474b7d7..c019797991 100644
--- a/docs/api/openapi.yml
+++ b/docs/api/openapi.yml
@@ -2342,6 +2342,8 @@ components:
type: boolean
org_id:
type: string
+ source:
+ $ref: '#/components/schemas/DashboardtypesSource'
updatedAt:
format: date-time
type: string
@@ -2371,6 +2373,12 @@ components:
timeRangeEnabled:
type: boolean
type: object
+ DashboardtypesSource:
+ enum:
+ - user
+ - system
+ - integration
+ type: object
DashboardtypesStorableDashboardData:
additionalProperties: {}
type: object
diff --git a/ee/modules/dashboard/impldashboard/module.go b/ee/modules/dashboard/impldashboard/module.go
index 57a197063c..e64aacb0e5 100644
--- a/ee/modules/dashboard/impldashboard/module.go
+++ b/ee/modules/dashboard/impldashboard/module.go
@@ -49,6 +49,14 @@ func (module *module) CreatePublic(ctx context.Context, orgID valuer.UUID, publi
return errors.New(errors.TypeLicenseUnavailable, errors.CodeLicenseUnavailable, "a valid license is not available").WithAdditional("this feature requires a valid license").WithAdditional(err.Error())
}
+ dashboard, err := module.Get(ctx, orgID, publicDashboard.DashboardID)
+ if err != nil {
+ return err
+ }
+ if err := dashboard.ErrIfNotPublishable(); err != nil {
+ return err
+ }
+
storablePublicDashboard, err := module.store.GetPublic(ctx, publicDashboard.DashboardID.StringValue())
if err != nil && !errors.Ast(err, errors.TypeNotFound) {
return err
@@ -129,6 +137,14 @@ func (module *module) UpdatePublic(ctx context.Context, orgID valuer.UUID, publi
return errors.New(errors.TypeLicenseUnavailable, errors.CodeLicenseUnavailable, "a valid license is not available").WithAdditional("this feature requires a valid license").WithAdditional(err.Error())
}
+ dashboard, err := module.Get(ctx, orgID, publicDashboard.DashboardID)
+ if err != nil {
+ return err
+ }
+ if err := dashboard.ErrIfNotPublishable(); err != nil {
+ return err
+ }
+
return module.store.UpdatePublic(ctx, dashboardtypes.NewStorablePublicDashboardFromPublicDashboard(publicDashboard))
}
@@ -138,6 +154,10 @@ func (module *module) Delete(ctx context.Context, orgID valuer.UUID, id valuer.U
return err
}
+ if err := dashboard.ErrIfNotDeletable(); err != nil {
+ return err
+ }
+
if dashboard.Locked {
return errors.New(errors.TypeInvalidInput, errors.CodeInvalidInput, "dashboard is locked, please unlock the dashboard to be delete it")
}
@@ -168,6 +188,14 @@ func (module *module) DeletePublic(ctx context.Context, orgID valuer.UUID, dashb
return errors.New(errors.TypeLicenseUnavailable, errors.CodeLicenseUnavailable, "a valid license is not available").WithAdditional("this feature requires a valid license").WithAdditional(err.Error())
}
+ dashboard, err := module.Get(ctx, orgID, dashboardID)
+ if err != nil {
+ return err
+ }
+ if err := dashboard.ErrIfNotPublishable(); err != nil {
+ return err
+ }
+
err = module.store.DeletePublic(ctx, dashboardID.StringValue())
if err != nil {
return err
diff --git a/frontend/src/api/generated/services/sigNoz.schemas.ts b/frontend/src/api/generated/services/sigNoz.schemas.ts
index df3b076502..d6fe6dd117 100644
--- a/frontend/src/api/generated/services/sigNoz.schemas.ts
+++ b/frontend/src/api/generated/services/sigNoz.schemas.ts
@@ -2999,6 +2999,11 @@ export interface CoretypesPatchableObjectsDTO {
deletions: CoretypesObjectGroupDTO[] | null;
}
+export enum DashboardtypesSourceDTO {
+ user = 'user',
+ system = 'system',
+ integration = 'integration',
+}
export interface DashboardtypesDashboardDTO {
/**
* @type string
@@ -3022,6 +3027,7 @@ export interface DashboardtypesDashboardDTO {
* @type string
*/
org_id?: string;
+ source?: DashboardtypesSourceDTO;
/**
* @type string
* @format date-time
diff --git a/pkg/modules/dashboard/impldashboard/module.go b/pkg/modules/dashboard/impldashboard/module.go
index d626e9ec29..cda9a25411 100644
--- a/pkg/modules/dashboard/impldashboard/module.go
+++ b/pkg/modules/dashboard/impldashboard/module.go
@@ -38,7 +38,7 @@ func NewModule(store dashboardtypes.Store, settings factory.ProviderSettings, an
}
func (module *module) Create(ctx context.Context, orgID valuer.UUID, createdBy string, creator valuer.UUID, postableDashboard dashboardtypes.PostableDashboard) (*dashboardtypes.Dashboard, error) {
- dashboard, err := dashboardtypes.NewDashboard(orgID, createdBy, postableDashboard)
+ dashboard, err := dashboardtypes.NewDashboard(orgID, createdBy, dashboardtypes.SourceUser, postableDashboard)
if err != nil {
return nil, err
}
@@ -72,7 +72,16 @@ func (module *module) List(ctx context.Context, orgID valuer.UUID) ([]*dashboard
return nil, err
}
- return dashboardtypes.NewDashboardsFromStorableDashboards(storableDashboards), nil
+ // system dashboards are hidden from the listing endpoint but still gettable by id.
+ filtered := make([]*dashboardtypes.StorableDashboard, 0, len(storableDashboards))
+ for _, storable := range storableDashboards {
+ if storable.Source == dashboardtypes.SourceSystem {
+ continue
+ }
+ filtered = append(filtered, storable)
+ }
+
+ return dashboardtypes.NewDashboardsFromStorableDashboards(filtered), nil
}
func (module *module) Update(ctx context.Context, orgID valuer.UUID, id valuer.UUID, updatedBy string, updatableDashboard dashboardtypes.UpdatableDashboard, diff int) (*dashboardtypes.Dashboard, error) {
@@ -81,6 +90,10 @@ func (module *module) Update(ctx context.Context, orgID valuer.UUID, id valuer.U
return nil, err
}
+ if err := dashboard.ErrIfNotMutable(); err != nil {
+ return nil, err
+ }
+
err = dashboard.Update(ctx, updatableDashboard, updatedBy, diff)
if err != nil {
return nil, err
@@ -105,6 +118,10 @@ func (module *module) LockUnlock(ctx context.Context, orgID valuer.UUID, id valu
return err
}
+ if err := dashboard.ErrIfNotLockable(); err != nil {
+ return err
+ }
+
err = dashboard.LockUnlock(lock, isAdmin, updatedBy)
if err != nil {
return err
@@ -128,6 +145,10 @@ func (module *module) Delete(ctx context.Context, orgID valuer.UUID, id valuer.U
return err
}
+ if err := dashboard.ErrIfNotDeletable(); err != nil {
+ return err
+ }
+
if dashboard.Locked {
return errors.New(errors.TypeInvalidInput, errors.CodeInvalidInput, "dashboard is locked, please unlock the dashboard to be delete it")
}
diff --git a/pkg/query-service/app/integrations/manager.go b/pkg/query-service/app/integrations/manager.go
index bb73423010..07018d41d4 100644
--- a/pkg/query-service/app/integrations/manager.go
+++ b/pkg/query-service/app/integrations/manager.go
@@ -348,7 +348,8 @@ func (m *Manager) GetInstalledIntegrationDashboardById(
CreatedBy: author,
UpdatedBy: author,
},
- OrgID: orgId,
+ OrgID: orgId,
+ Source: dashboardtypes.SourceIntegration,
}, nil
}
}
@@ -387,7 +388,8 @@ func (m *Manager) GetDashboardsForInstalledIntegrations(
CreatedBy: author,
UpdatedBy: author,
},
- OrgID: orgId,
+ OrgID: orgId,
+ Source: dashboardtypes.SourceIntegration,
})
}
}
diff --git a/pkg/signoz/provider.go b/pkg/signoz/provider.go
index eed7eb6162..f22aceea7e 100644
--- a/pkg/signoz/provider.go
+++ b/pkg/signoz/provider.go
@@ -204,6 +204,7 @@ func NewSQLMigrationProviderFactories(
sqlmigration.NewAddTagsFactory(sqlstore, sqlschema),
sqlmigration.NewAddRoleCRUDTuplesFactory(sqlstore),
sqlmigration.NewAddIntegrationDashboardFactory(sqlstore, sqlschema),
+ sqlmigration.NewAddSourceToDashboardFactory(sqlstore, sqlschema),
)
}
diff --git a/pkg/sqlmigration/085_add_source_to_dashboard.go b/pkg/sqlmigration/085_add_source_to_dashboard.go
new file mode 100644
index 0000000000..6cbfba9a05
--- /dev/null
+++ b/pkg/sqlmigration/085_add_source_to_dashboard.go
@@ -0,0 +1,79 @@
+package sqlmigration
+
+import (
+ "context"
+
+ "github.com/SigNoz/signoz/pkg/factory"
+ "github.com/SigNoz/signoz/pkg/sqlschema"
+ "github.com/SigNoz/signoz/pkg/sqlstore"
+ "github.com/uptrace/bun"
+ "github.com/uptrace/bun/migrate"
+)
+
+type addSourceToDashboard struct {
+ sqlstore sqlstore.SQLStore
+ sqlschema sqlschema.SQLSchema
+}
+
+func NewAddSourceToDashboardFactory(sqlstore sqlstore.SQLStore, sqlschema sqlschema.SQLSchema) factory.ProviderFactory[SQLMigration, Config] {
+ return factory.NewProviderFactory(
+ factory.MustNewName("add_source_to_dashboard"),
+ func(ctx context.Context, ps factory.ProviderSettings, c Config) (SQLMigration, error) {
+ return &addSourceToDashboard{sqlstore: sqlstore, sqlschema: sqlschema}, nil
+ },
+ )
+}
+
+func (migration *addSourceToDashboard) Register(migrations *migrate.Migrations) error {
+ return migrations.Register(migration.Up, migration.Down)
+}
+
+func (migration *addSourceToDashboard) Up(ctx context.Context, db *bun.DB) error {
+ // dashboard is referenced by public_dashboard and integration_dashboard;
+ // FK enforcement must be off for the SQLite recreate-table fallback.
+ if err := migration.sqlschema.ToggleFKEnforcement(ctx, db, false); err != nil {
+ return err
+ }
+
+ tx, err := db.BeginTx(ctx, nil)
+ if err != nil {
+ return err
+ }
+ defer func() {
+ _ = tx.Rollback()
+ }()
+
+ table, uniqueConstraints, err := migration.sqlschema.GetTable(ctx, sqlschema.TableName("dashboard"))
+ if err != nil {
+ return err
+ }
+
+ sourceColumn := &sqlschema.Column{
+ Name: sqlschema.ColumnName("source"),
+ DataType: sqlschema.DataTypeText,
+ Nullable: false,
+ }
+
+ // backfill existing rows with 'user' before the NOT NULL flip.
+ sqls := migration.sqlschema.Operator().AddColumn(table, uniqueConstraints, sourceColumn, "user")
+
+ for _, sql := range sqls {
+ if _, err := tx.ExecContext(ctx, string(sql)); err != nil {
+ return err
+ }
+ }
+
+ if err := tx.Commit(); err != nil {
+ return err
+ }
+
+ if err := migration.sqlschema.ToggleFKEnforcement(ctx, db, true); err != nil {
+ return err
+ }
+
+ return nil
+}
+
+func (migration *addSourceToDashboard) Down(context.Context, *bun.DB) error {
+ return nil
+}
diff --git a/pkg/types/cloudintegrationtypes/service.go b/pkg/types/cloudintegrationtypes/service.go
index 62069311a7..3f8e2adb2c 100644
--- a/pkg/types/cloudintegrationtypes/service.go
+++ b/pkg/types/cloudintegrationtypes/service.go
@@ -366,6 +366,7 @@ func GetDashboardsFromAssets(
CreatedBy: author,
UpdatedBy: author,
},
+ Source: dashboardtypes.SourceIntegration,
})
}
diff --git a/pkg/types/dashboardtypes/dashboard.go b/pkg/types/dashboardtypes/dashboard.go
index e9c238c3a3..2a7253d2ba 100644
--- a/pkg/types/dashboardtypes/dashboard.go
+++ b/pkg/types/dashboardtypes/dashboard.go
@@ -19,6 +19,8 @@ var (
ErrCodeDashboardNotFound = errors.MustNewCode("dashboard_not_found")
ErrCodeDashboardInvalidData = errors.MustNewCode("dashboard_invalid_data")
ErrCodeDashboardInvalidWidgetQuery = errors.MustNewCode("dashboard_invalid_widget_query")
+ ErrCodeDashboardInvalidSource = errors.MustNewCode("dashboard_invalid_source")
+ ErrCodeDashboardImmutable = errors.MustNewCode("dashboard_immutable")
)
type StorableDashboard struct {
@@ -30,6 +32,7 @@ type StorableDashboard struct {
Data StorableDashboardData `bun:"data,type:text,notnull"`
Locked bool `bun:"locked,notnull,default:false"`
OrgID valuer.UUID `bun:"org_id,notnull"`
+ Source Source `bun:"source,type:text,notnull"`
}
type Dashboard struct {
@@ -40,6 +43,7 @@ type Dashboard struct {
Data StorableDashboardData `json:"data"`
Locked bool `json:"locked"`
OrgID valuer.UUID `json:"org_id"`
+ Source Source `json:"source"`
}
type LockUnlockDashboard struct {
@@ -64,6 +68,10 @@ func NewStorableDashboardFromDashboard(dashboard *Dashboard) (*StorableDashboard
return nil, errors.Wrapf(err, errors.TypeInvalidInput, errors.CodeInvalidInput, "id is not a valid uuid")
}
+ if !dashboard.Source.IsValid() {
+ return nil, errors.Newf(errors.TypeInvalidInput, ErrCodeDashboardInvalidSource, "invalid dashboard source %q, must be one of user, system, integration", dashboard.Source.StringValue())
+ }
+
return &StorableDashboard{
Identifiable: types.Identifiable{
ID: dashboardID,
@@ -79,10 +87,15 @@ func NewStorableDashboardFromDashboard(dashboard *Dashboard) (*StorableDashboard
OrgID: dashboard.OrgID,
Data: dashboard.Data,
Locked: dashboard.Locked,
+ Source: dashboard.Source,
}, nil
}
-func NewDashboard(orgID valuer.UUID, createdBy string, storableDashboardData StorableDashboardData) (*Dashboard, error) {
+func NewDashboard(orgID valuer.UUID, createdBy string, source Source, storableDashboardData StorableDashboardData) (*Dashboard, error) {
+ if !source.IsValid() {
+ return nil, errors.Newf(errors.TypeInvalidInput, ErrCodeDashboardInvalidSource, "invalid dashboard source %q, must be one of user, system, integration", source.StringValue())
+ }
+
currentTime := time.Now()
return &Dashboard{
@@ -98,6 +111,7 @@ func NewDashboard(orgID valuer.UUID, createdBy string, storableDashboardData Sto
OrgID: orgID,
Data: storableDashboardData,
Locked: false,
+ Source: source,
}, nil
}
@@ -115,6 +129,7 @@ func NewDashboardFromStorableDashboard(storableDashboard *StorableDashboard) *Da
OrgID: storableDashboard.OrgID,
Data: storableDashboard.Data,
Locked: storableDashboard.Locked,
+ Source: storableDashboard.Source,
}
}
@@ -147,6 +162,7 @@ func NewGettableDashboardFromDashboard(dashboard *Dashboard) (*GettableDashboard
OrgID: dashboard.OrgID,
Data: dashboard.Data,
Locked: dashboard.Locked,
+ Source: dashboard.Source,
}, nil
}
@@ -238,6 +254,43 @@ func (storableDashboardData *StorableDashboardData) GetWidgetIds() []string {
return widgetIds
}
+func (dashboard *Dashboard) ErrIfNotMutable() error {
+ if dashboard.Source == SourceIntegration {
+ return errors.Newf(errors.TypeInvalidInput, ErrCodeDashboardImmutable, "integration dashboards cannot be modified")
+ }
+ return nil
+}
+
+func (dashboard *Dashboard) ErrIfNotDeletable() error {
+ if err := dashboard.ErrIfNotMutable(); err != nil {
+ return err
+ }
+ if dashboard.Source == SourceSystem {
+ return errors.Newf(errors.TypeInvalidInput, ErrCodeDashboardImmutable, "system dashboards cannot be deleted")
+ }
+ return nil
+}
+
+func (dashboard *Dashboard) ErrIfNotLockable() error {
+ if err := dashboard.ErrIfNotMutable(); err != nil {
+ return err
+ }
+ if dashboard.Source == SourceSystem {
+ return errors.Newf(errors.TypeInvalidInput, ErrCodeDashboardImmutable, "system dashboards cannot be locked or unlocked")
+ }
+ return nil
+}
+
+func (dashboard *Dashboard) ErrIfNotPublishable() error {
+ if err := dashboard.ErrIfNotMutable(); err != nil {
+ return err
+ }
+ if dashboard.Source == SourceSystem {
+ return errors.Newf(errors.TypeInvalidInput, ErrCodeDashboardImmutable, "system dashboards cannot be made public")
+ }
+ return nil
+}
+
func (dashboard *Dashboard) CanUpdate(ctx context.Context, data StorableDashboardData, diff int) error {
if dashboard.Locked {
return errors.Newf(errors.TypeInvalidInput, errors.CodeInvalidInput, "cannot update a locked dashboard, please unlock the dashboard to update")
diff --git a/pkg/types/dashboardtypes/dashboard_test.go b/pkg/types/dashboardtypes/dashboard_test.go
index 0a584cf383..5c43d2d9d5 100644
--- a/pkg/types/dashboardtypes/dashboard_test.go
+++ b/pkg/types/dashboardtypes/dashboard_test.go
@@ -66,7 +66,7 @@ func TestCanUpdate_MultipleDeletions_ByDiff(t *testing.T) {
initial := StorableDashboardData{
"widgets": makeTestWidgets("a", "b", "c"),
}
- d, err := NewDashboard(orgID, "tester", initial)
+ d, err := NewDashboard(orgID, "tester", SourceUser, initial)
assert.NoError(t, err)
updated := StorableDashboardData{
diff --git a/pkg/types/dashboardtypes/source.go b/pkg/types/dashboardtypes/source.go
new file mode 100644
index 0000000000..64b632d29a
--- /dev/null
+++ b/pkg/types/dashboardtypes/source.go
@@ -0,0 +1,60 @@
+package dashboardtypes
+
+import (
+ "database/sql/driver"
+ "slices"
+
+ "github.com/SigNoz/signoz/pkg/errors"
+ "github.com/SigNoz/signoz/pkg/valuer"
+)
+
+type Source struct {
+ s valuer.String
+}
+
+var (
+ SourceUser = Source{s: valuer.NewString("user")}
+ SourceSystem = Source{s: valuer.NewString("system")}
+ SourceIntegration = Source{s: valuer.NewString("integration")}
+)
+
+func (Source) Enum() []any {
+ return []any{SourceUser, SourceSystem, SourceIntegration}
+}
+
+func (s Source) IsValid() bool {
+ return slices.ContainsFunc(s.Enum(), func(v any) bool { return v == s })
+}
+
+func (s Source) IsZero() bool { return s.s.IsZero() }
+
+func (s Source) String() string { return s.s.String() }
+
+func (s Source) StringValue() string { return s.s.StringValue() }
+
+func (s Source) Value() (driver.Value, error) {
+ if !s.IsValid() {
+ return nil, errors.Newf(errors.TypeInvalidInput, ErrCodeDashboardInvalidSource, "invalid dashboard source %q, must be one of user, system, integration", s.s.StringValue())
+ }
+ return s.s.Value()
+}
+
+func (s *Source) Scan(src any) error {
+ return s.s.Scan(src)
+}
+
+func (s Source) MarshalJSON() ([]byte, error) {
+ return s.s.MarshalJSON()
+}
+
+func (s *Source) UnmarshalJSON(data []byte) error {
+ return s.s.UnmarshalJSON(data)
+}
+
+func NewSource(source string) (Source, error) {
+ candidate := Source{s: valuer.NewString(source)}
+ if !candidate.IsValid() {
+ return Source{}, errors.Newf(errors.TypeInvalidInput, ErrCodeDashboardInvalidSource, "invalid dashboard source %q, must be one of user, system, integration", source)
+ }
+ return candidate, nil
+}
diff --git a/pkg/types/dashboardtypes/source_test.go b/pkg/types/dashboardtypes/source_test.go
new file mode 100644
index 0000000000..1458877447
--- /dev/null
+++ b/pkg/types/dashboardtypes/source_test.go
@@ -0,0 +1,71 @@
+package dashboardtypes
+
+import (
+ "testing"
+
+ "github.com/SigNoz/signoz/pkg/valuer"
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
+)
+
+func TestSourceEnum(t *testing.T) {
+ t.Run("valid sources round-trip through Value/Scan", func(t *testing.T) {
+ for _, src := range []Source{SourceUser, SourceSystem, SourceIntegration} {
+ val, err := src.Value()
+ require.NoError(t, err)
+
+ var got Source
+ require.NoError(t, got.Scan(val))
+ assert.Equal(t, src, got)
+ }
+ })
+
+ t.Run("invalid source is rejected by Value", func(t *testing.T) {
+ bogus := Source{s: valuer.NewString("hacker")}
+ _, err := bogus.Value()
+ assert.Error(t, err)
+ })
+
+ t.Run("Scan tolerates unknown strings, Value still rejects them", func(t *testing.T) {
+ var got Source
+ require.NoError(t, got.Scan("future_source"))
+ assert.Equal(t, "future_source", got.StringValue())
+ assert.False(t, got.IsValid())
+
+ _, err := got.Value()
+ assert.Error(t, err)
+ })
+
+ t.Run("NewSource validates input", func(t *testing.T) {
+ s, err := NewSource("USER")
+ require.NoError(t, err)
+ assert.Equal(t, SourceUser, s)
+
+ _, err = NewSource("nope")
+ assert.Error(t, err)
+ })
+}
+
+func TestErrIfNotMutable_BySource(t *testing.T) {
+ cases := []struct {
+ source Source
+ mutable bool
+ deletable bool
+ lockable bool
+ publishable bool
+ }{
+ {SourceUser, true, true, true, true},
+ {SourceSystem, true, false, false, false},
+ {SourceIntegration, false, false, false, false},
+ }
+
+ for _, tc := range cases {
+ t.Run(tc.source.StringValue(), func(t *testing.T) {
+ d := &Dashboard{Source: tc.source}
+ assert.Equal(t, tc.mutable, d.ErrIfNotMutable() == nil)
+ assert.Equal(t, tc.deletable, d.ErrIfNotDeletable() == nil)
+ assert.Equal(t, tc.lockable, d.ErrIfNotLockable() == nil)
+ assert.Equal(t, tc.publishable, d.ErrIfNotPublishable() == nil)
+ })
+ }
+}