Nityananda Gohain 2d73f91380
Fix: Multitenancy support for ORG (#7155)
* fix: support multitenancy in org

* fix: register and login working now

* fix: changes to migration

* fix: migrations run both on sqlite and postgres

* fix: remove user flags from fe and be

* fix: remove ingestion keys from update

* fix: multitenancy support for apdex settings

* fix: render ts for users correctly

* fix: fix migration to run for new tenants

* fix: clean up migrations

* fix: address comments

* Update pkg/sqlmigration/013_update_organization.go

Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>

* fix: fix build

* fix: force invites with org id

* Update pkg/query-service/auth/auth.go

Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>

* fix: address comments

* fix: address comments

* fix: provier with their own dialect

* fix: update dialects

* fix: remove unwanted change

* Update pkg/query-service/app/http_handler.go

Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>

* fix: different files for types

---------

Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>
2025-03-06 15:39:45 +05:30

66 lines
1.5 KiB
Go

package sqlite
import (
"context"
"github.com/uptrace/bun"
"go.signoz.io/signoz/pkg/query-service/model"
"go.signoz.io/signoz/pkg/types"
)
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
_, 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
}