mirror of
https://github.com/SigNoz/signoz.git
synced 2025-12-17 15:36:48 +00:00
### Summary
Integrate the new implementations of the alertmanager along with changes to the ruler. This change can be broadly categoried into 3 parts:
#### Frontend
- The earlier `/api/v1/alerts` api was double encoding the response in json and sending it to the frontend. This PR fixes the json response object.
For instance, we have gone from the response `{
"status": "success",
"data": "{\"status\":\"success\",\"data\":[{\"labels\":{\"alertname\":\"[platform][consumer] consumer is above 100% memory utilization\",\"bu\":\"platform\",\"......
}` to the response `{"status":"success","data":[{"labels":{"alertname":"[Metrics] Pod CP......`
- `msteams` has been changed to `msteamsv2` wherever applicable
#### Ruler
The following changes have been done in the ruler component:
- Removal of the old alertmanager and notifier
- The RuleDB methods `Create`, `Edit` and `Delete` have been made transactional
- Introduction of a new `testPrepareNotifyFunc` for sending test notifications
- Integration with the new alertmanager
#### Alertmanager
Although a huge chunk of the alertmanagers have been merged in previous PRs (the list can be found at https://github.com/SigNoz/platform-pod/issues/404), this PR takes care of changes needed in order to incorporate it with the ruler
- Addition of ruleId based matching
- Support for marshalling the global configuration directly from the upstream alertmanager
- Addition of orgId to the legacy alertmanager
- Support for always adding defaults to both routes and receivers while creating them
- Migration to create the required alertmanager tables
- Migration for msteams to msteamsv2 has been added. We will start using msteamv2 config for the new alertmanager and keep using msteams for the old one.
#### Related Issues / PR's
Closes https://github.com/SigNoz/platform-pod/issues/404
Closes https://github.com/SigNoz/platform-pod/issues/176
159 lines
4.7 KiB
Go
159 lines
4.7 KiB
Go
package sqlmigration
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/uptrace/bun"
|
|
"github.com/uptrace/bun/migrate"
|
|
"go.signoz.io/signoz/pkg/factory"
|
|
)
|
|
|
|
type addOrganization struct{}
|
|
|
|
func NewAddOrganizationFactory() factory.ProviderFactory[SQLMigration, Config] {
|
|
return factory.NewProviderFactory(factory.MustNewName("add_organization"), newAddOrganization)
|
|
}
|
|
|
|
func newAddOrganization(_ context.Context, _ factory.ProviderSettings, _ Config) (SQLMigration, error) {
|
|
return &addOrganization{}, nil
|
|
}
|
|
|
|
func (migration *addOrganization) Register(migrations *migrate.Migrations) error {
|
|
if err := migrations.Register(migration.Up, migration.Down); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (migration *addOrganization) Up(ctx context.Context, db *bun.DB) error {
|
|
|
|
// table:organizations
|
|
if _, err := db.NewCreateTable().
|
|
Model(&struct {
|
|
bun.BaseModel `bun:"table:organizations"`
|
|
ID string `bun:"id,pk,type:text"`
|
|
Name string `bun:"name,type:text,notnull"`
|
|
CreatedAt int `bun:"created_at,notnull"`
|
|
IsAnonymous int `bun:"is_anonymous,notnull,default:0"`
|
|
HasOptedUpdates int `bun:"has_opted_updates,notnull,default:1"`
|
|
}{}).
|
|
IfNotExists().
|
|
Exec(ctx); err != nil {
|
|
return err
|
|
}
|
|
|
|
// table:groups
|
|
if _, err := db.NewCreateTable().
|
|
Model(&struct {
|
|
bun.BaseModel `bun:"table:groups"`
|
|
ID string `bun:"id,pk,type:text"`
|
|
Name string `bun:"name,type:text,notnull,unique"`
|
|
}{}).
|
|
IfNotExists().
|
|
Exec(ctx); err != nil {
|
|
return err
|
|
}
|
|
|
|
// table:users
|
|
if _, err := db.NewCreateTable().
|
|
Model(&struct {
|
|
bun.BaseModel `bun:"table:users"`
|
|
ID string `bun:"id,pk,type:text"`
|
|
Name string `bun:"name,type:text,notnull"`
|
|
Email string `bun:"email,type:text,notnull,unique"`
|
|
Password string `bun:"password,type:text,notnull"`
|
|
CreatedAt int `bun:"created_at,notnull"`
|
|
ProfilePictureURL string `bun:"profile_picture_url,type:text"`
|
|
GroupID string `bun:"group_id,type:text,notnull"`
|
|
OrgID string `bun:"org_id,type:text,notnull"`
|
|
}{}).
|
|
ForeignKey(`("org_id") REFERENCES "organizations" ("id")`).
|
|
ForeignKey(`("group_id") REFERENCES "groups" ("id")`).
|
|
IfNotExists().
|
|
Exec(ctx); err != nil {
|
|
return err
|
|
}
|
|
|
|
// table:invites
|
|
if _, err := db.NewCreateTable().
|
|
Model(&struct {
|
|
bun.BaseModel `bun:"table:invites"`
|
|
ID int `bun:"id,pk,autoincrement"`
|
|
Name string `bun:"name,type:text,notnull"`
|
|
Email string `bun:"email,type:text,notnull,unique"`
|
|
Token string `bun:"token,type:text,notnull"`
|
|
CreatedAt int `bun:"created_at,notnull"`
|
|
Role string `bun:"role,type:text,notnull"`
|
|
OrgID string `bun:"org_id,type:text,notnull"`
|
|
}{}).
|
|
ForeignKey(`("org_id") REFERENCES "organizations" ("id")`).
|
|
IfNotExists().
|
|
Exec(ctx); err != nil {
|
|
return err
|
|
}
|
|
|
|
// table:reset_password_request
|
|
if _, err := db.NewCreateTable().
|
|
Model(&struct {
|
|
bun.BaseModel `bun:"table:reset_password_request"`
|
|
ID int `bun:"id,pk,autoincrement"`
|
|
Token string `bun:"token,type:text,notnull"`
|
|
UserID string `bun:"user_id,type:text,notnull"`
|
|
}{}).
|
|
ForeignKey(`("user_id") REFERENCES "users" ("id")`).
|
|
IfNotExists().
|
|
Exec(ctx); err != nil {
|
|
return err
|
|
}
|
|
|
|
// table:user_flags
|
|
if _, err := db.NewCreateTable().
|
|
Model(&struct {
|
|
bun.BaseModel `bun:"table:user_flags"`
|
|
UserID string `bun:"user_id,pk,type:text,notnull"`
|
|
Flags string `bun:"flags,type:text"`
|
|
}{}).
|
|
ForeignKey(`("user_id") REFERENCES "users" ("id")`).
|
|
IfNotExists().
|
|
Exec(ctx); err != nil {
|
|
return err
|
|
}
|
|
|
|
// table:apdex_settings
|
|
if _, err := db.NewCreateTable().
|
|
Model(&struct {
|
|
bun.BaseModel `bun:"table:apdex_settings"`
|
|
ServiceName string `bun:"service_name,pk,type:text"`
|
|
Threshold float64 `bun:"threshold,type:float,notnull"`
|
|
ExcludeStatusCodes string `bun:"exclude_status_codes,type:text,notnull"`
|
|
}{}).
|
|
IfNotExists().
|
|
Exec(ctx); err != nil {
|
|
return err
|
|
}
|
|
|
|
// table:ingestion_keys
|
|
if _, err := db.NewCreateTable().
|
|
Model(&struct {
|
|
bun.BaseModel `bun:"table:ingestion_keys"`
|
|
KeyId string `bun:"key_id,pk,type:text"`
|
|
Name string `bun:"name,type:text"`
|
|
CreatedAt time.Time `bun:"created_at,default:current_timestamp"`
|
|
IngestionKey string `bun:"ingestion_key,type:text,notnull"`
|
|
IngestionURL string `bun:"ingestion_url,type:text,notnull"`
|
|
DataRegion string `bun:"data_region,type:text,notnull"`
|
|
}{}).
|
|
IfNotExists().
|
|
Exec(ctx); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (migration *addOrganization) Down(ctx context.Context, db *bun.DB) error {
|
|
return nil
|
|
}
|