mirror of
https://github.com/SigNoz/signoz.git
synced 2026-09-21 02:40:40 +01:00
## Summary
- Handle malformed selectedFields in the extradata in the migration and
new migration to fix in the already migrated cases.
- Restructure saved-view create/update/get payloads so
`schemaVersion`/`spec` are top-level (unwrapping the old `data`
nesting), matching how dashboards and rules shape their wire types.
- Publish `schemaVersion` as an `enum: [v2]`
- Make `display` and `selectedFields` optional in the OpenAPI schema
- Declare `409` on `CreateSavedView`
- Require `minItems: 1` on `queries`
New API contract in [below
comment](https://github.com/SigNoz/signoz/pull/12477#issuecomment-5230041074),
follow up on https://github.com/SigNoz/signoz/pull/12342
Closes https://github.com/SigNoz/engineering-pod/issues/4651
Notes to reviewer:
- Please pay attention to the last case in above linked comment for
partial display field updates.
- Still assuming that [migration
046](6372af75a6/pkg/sqlmigration/046_update_dashboard_alert_and_saved_view_v5.go (L233))
has already migrated all the views to v5 QB format and don't need to do
that now.
- Breaking change: queries are not validated in the v1 APIs as well, so
any incorrect query will be rejected
---------
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
74 lines
2.3 KiB
Go
74 lines
2.3 KiB
Go
package implsavedview
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/SigNoz/signoz/pkg/errors"
|
|
"github.com/SigNoz/signoz/pkg/modules/savedview"
|
|
"github.com/SigNoz/signoz/pkg/types/authtypes"
|
|
"github.com/SigNoz/signoz/pkg/types/savedviewtypes"
|
|
"github.com/SigNoz/signoz/pkg/valuer"
|
|
)
|
|
|
|
type module struct {
|
|
store savedviewtypes.Store
|
|
}
|
|
|
|
func NewModule(store savedviewtypes.Store) savedview.Module {
|
|
return &module{store: store}
|
|
}
|
|
|
|
func (module *module) GetViewsForFilters(ctx context.Context, orgID string, source savedviewtypes.Source, name string) ([]*savedviewtypes.SavedView, error) {
|
|
storables, err := module.store.List(ctx, orgID, source, name)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return savedviewtypes.NewSavedViewsFromStorableSavedViews(storables), nil
|
|
}
|
|
|
|
func (module *module) CreateView(ctx context.Context, orgID string, view savedviewtypes.PostableSavedView) (valuer.UUID, error) {
|
|
claims, err := authtypes.ClaimsFromContext(ctx)
|
|
if err != nil {
|
|
return valuer.UUID{}, errors.NewInternalf(errors.CodeInternal, "error in getting email from context")
|
|
}
|
|
|
|
dbView := view.ToSavedView(orgID, claims.Email)
|
|
|
|
if err := module.store.Create(ctx, savedviewtypes.NewStorableSavedView(dbView)); err != nil {
|
|
return valuer.UUID{}, err
|
|
}
|
|
return dbView.ID, nil
|
|
}
|
|
|
|
func (module *module) GetView(ctx context.Context, orgID string, uuid valuer.UUID) (*savedviewtypes.SavedView, error) {
|
|
storable, err := module.store.Get(ctx, orgID, uuid)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return storable.ToSavedView(), nil
|
|
}
|
|
|
|
func (module *module) UpdateView(ctx context.Context, orgID string, uuid valuer.UUID, view savedviewtypes.UpdatableSavedView) error {
|
|
claims, err := authtypes.ClaimsFromContext(ctx)
|
|
if err != nil {
|
|
return errors.NewInternalf(errors.CodeInternal, "error in getting email from context")
|
|
}
|
|
|
|
dbView := view.ToSavedView(uuid, orgID, claims.Email)
|
|
return module.store.Update(ctx, savedviewtypes.NewStorableSavedView(dbView))
|
|
}
|
|
|
|
func (module *module) DeleteView(ctx context.Context, orgID string, uuid valuer.UUID) error {
|
|
return module.store.Delete(ctx, orgID, uuid)
|
|
}
|
|
|
|
func (module *module) Collect(ctx context.Context, orgID valuer.UUID) (map[string]any, error) {
|
|
storables, err := module.store.List(ctx, orgID.StringValue(), savedviewtypes.Source{}, "")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return savedviewtypes.NewStatsFromStorableSavedViews(storables), nil
|
|
}
|