mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-07-29 23:31:59 +08:00

* feat(sqlmigration): update the alertmanager tables * feat(sqlmigration): update the alertmanager tables * feat(sqlmigration): make the preference package multi tenant * feat(preference): address nit pick comments * feat(preference): added the cascade delete for preferences * feat(sqlmigration): update apdex and TTL status tables (#7481) * feat(sqlmigration): update the apdex and ttl tables * feat(sqlmigration): register the new migration and rename table * feat(sqlmigration): fix the ttl queries * feat(sqlmigration): update the TTL and apdex tables * feat(sqlmigration): update the TTL and apdex tables
68 lines
1.6 KiB
Go
68 lines
1.6 KiB
Go
package sqlite
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/SigNoz/signoz/pkg/query-service/model"
|
|
"github.com/SigNoz/signoz/pkg/types"
|
|
"github.com/SigNoz/signoz/pkg/valuer"
|
|
"github.com/uptrace/bun"
|
|
)
|
|
|
|
const defaultApdexThreshold = 0.5
|
|
|
|
func (mds *ModelDaoSqlite) GetApdexSettings(ctx context.Context, orgID string, services []string) ([]types.ApdexSettings, *model.ApiError) {
|
|
var apdexSettings []types.ApdexSettings
|
|
|
|
err := mds.bundb.NewSelect().
|
|
Model(&apdexSettings).
|
|
Where("org_id = ?", orgID).
|
|
Where("service_name IN (?)", bun.In(services)).
|
|
Scan(ctx)
|
|
if err != nil {
|
|
return nil, &model.ApiError{
|
|
Err: err,
|
|
}
|
|
}
|
|
|
|
// add default apdex settings for services that don't have any
|
|
for _, service := range services {
|
|
var found bool
|
|
for _, apdexSetting := range apdexSettings {
|
|
if apdexSetting.ServiceName == service {
|
|
found = true
|
|
break
|
|
}
|
|
}
|
|
|
|
if !found {
|
|
apdexSettings = append(apdexSettings, types.ApdexSettings{
|
|
ServiceName: service,
|
|
Threshold: defaultApdexThreshold,
|
|
})
|
|
}
|
|
}
|
|
|
|
return apdexSettings, nil
|
|
}
|
|
|
|
func (mds *ModelDaoSqlite) SetApdexSettings(ctx context.Context, orgID string, apdexSettings *types.ApdexSettings) *model.ApiError {
|
|
// Set the org_id from the parameter since it's required for the foreign key constraint
|
|
apdexSettings.OrgID = orgID
|
|
apdexSettings.Identifiable.ID = valuer.GenerateUUID()
|
|
|
|
_, err := mds.bundb.NewInsert().
|
|
Model(apdexSettings).
|
|
On("CONFLICT (org_id, service_name) DO UPDATE").
|
|
Set("threshold = EXCLUDED.threshold").
|
|
Set("exclude_status_codes = EXCLUDED.exclude_status_codes").
|
|
Exec(ctx)
|
|
if err != nil {
|
|
return &model.ApiError{
|
|
Err: err,
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|