mirror of
https://github.com/SigNoz/signoz.git
synced 2025-12-17 15:36:48 +00:00
* feat(organization): add hname and alias for organization * fix: boolean values are not shown in the list panel's column * fix: moved logic to component level * fix: added type * fix: added test cases * fix: added test cases * chore: update copy webpack plugin * Revert "fix: display same key with multiple data types in filter suggestions by enhancing the deduping logic (#7255)" This reverts commit 1e85981a17a8e715e948308d3e85072d976907d3. * fix: use query search v2 for traces data source to handle multiple data types for the same key * fix(QueryBuilderSearchV2): add user typed option if it doesn't exist in the payload * fix(QueryBuilderSearchV2): increase the height of search dropdown for non-logs data sources * fix: display span scope selector for trace data source * chore: remove the span scope selector from qb search v1 and move the component to search v2 * fix: write test to ensure that we display span scope selector for traces data source * fix: limit converting -> only to log data source * fix: don't display empty suggestion if only spaces are typed * chore: tests for span scope selector * chore: qb search flow (key, operator, value) test cases * refactor: fix the Maximum update depth reached issue while running tests * chore: overall improvements to span scope selector tests Resource attr filter: style fix and quick filter changes (#7691) * chore: resource attr filter init * chore: resource attr filter api integration * chore: operator config updated * chore: fliter show hide logic and styles * chore: add support for custom operator list to qb * chore: minor refactor * chore: minor code refactor * test: quick filters test suite added * test: quick filters test suite added * test: all errors test suite added * chore: style fix * test: all errors mock fix * chore: test case fix and mixpanel update * chore: color update * chore: minor refactor * chore: style fix * chore: set default query in exceptions tab * chore: style fix * chore: minor refactor * chore: minor refactor * chore: minor refactor * chore: test update * chore: fix filter header with no query name * fix: scroll fix * chore: add data source traces to quick filters * chore: replace div with fragment --------- Co-authored-by: Aditya Singh <adityasingh@Adityas-MacBook-Pro.local> fix: handle rate operators for table panel (#7695) * fix: handle rate operators for table panel chore: fix error rate (#7701) Signed-off-by: Shivanshu Raj Shrivastava <shivanshu1333@gmail.com> * feat(organization): minor cleanups * feat(organization): better naming for api and usecase * feat(organization): better packaging for modules * feat(organization): change hname to displayName * feat(organization): update the migration to use dialect * feat(organization): update the migration to use dialect * feat(organization): update the migration to use dialect * feat(organization): revert back to impl * feat(organization): remove DI from organization * feat(organization): address review comments * feat(organization): address review comments * feat(organization): address review comments --------- Signed-off-by: Shivanshu Raj Shrivastava <shivanshu1333@gmail.com>
118 lines
3.3 KiB
Go
118 lines
3.3 KiB
Go
package sqlite
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/SigNoz/signoz/pkg/query-service/constants"
|
|
"github.com/SigNoz/signoz/pkg/query-service/telemetry"
|
|
"github.com/SigNoz/signoz/pkg/sqlstore"
|
|
"github.com/SigNoz/signoz/pkg/types"
|
|
"github.com/pkg/errors"
|
|
"github.com/uptrace/bun"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
type ModelDaoSqlite struct {
|
|
bundb *bun.DB
|
|
}
|
|
|
|
// InitDB sets up setting up the connection pool global variable.
|
|
func InitDB(sqlStore sqlstore.SQLStore) (*ModelDaoSqlite, error) {
|
|
mds := &ModelDaoSqlite{bundb: sqlStore.BunDB()}
|
|
|
|
ctx := context.Background()
|
|
if err := mds.initializeOrgPreferences(ctx); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := mds.initializeRBAC(ctx); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
telemetry.GetInstance().SetUserCountCallback(mds.GetUserCount)
|
|
telemetry.GetInstance().SetUserRoleCallback(mds.GetUserRole)
|
|
telemetry.GetInstance().SetGetUsersCallback(mds.GetUsers)
|
|
|
|
return mds, nil
|
|
}
|
|
|
|
// DB returns database connection
|
|
func (mds *ModelDaoSqlite) DB() *bun.DB {
|
|
return mds.bundb
|
|
}
|
|
|
|
// initializeOrgPreferences initializes in-memory telemetry settings. It is planned to have
|
|
// multiple orgs in the system. In case of multiple orgs, there will be separate instance
|
|
// of in-memory telemetry for each of the org, having their own settings. As of now, we only
|
|
// have one org so this method relies on the settings of this org to initialize the telemetry etc.
|
|
// TODO(Ahsan): Make it multi-tenant when we move to a system with multiple orgs.
|
|
func (mds *ModelDaoSqlite) initializeOrgPreferences(ctx context.Context) error {
|
|
|
|
// set anonymous setting as default in case of any failures to fetch UserPreference in below section
|
|
telemetry.GetInstance().SetTelemetryAnonymous(constants.DEFAULT_TELEMETRY_ANONYMOUS)
|
|
|
|
orgs, apiError := mds.GetOrgs(ctx)
|
|
if apiError != nil {
|
|
return apiError.Err
|
|
}
|
|
|
|
if len(orgs) > 1 {
|
|
return errors.Errorf("Found %d organizations, expected one or none.", len(orgs))
|
|
}
|
|
|
|
var org types.Organization
|
|
if len(orgs) == 1 {
|
|
org = orgs[0]
|
|
}
|
|
|
|
// set telemetry fields from userPreferences
|
|
telemetry.GetInstance().SetDistinctId(org.ID.StringValue())
|
|
|
|
users, _ := mds.GetUsers(ctx)
|
|
countUsers := len(users)
|
|
if countUsers > 0 {
|
|
telemetry.GetInstance().SetCompanyDomain(users[countUsers-1].Email)
|
|
telemetry.GetInstance().SetUserEmail(users[countUsers-1].Email)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// initializeRBAC creates the ADMIN, EDITOR and VIEWER groups if they are not present.
|
|
func (mds *ModelDaoSqlite) initializeRBAC(ctx context.Context) error {
|
|
f := func(groupName string) error {
|
|
_, err := mds.createGroupIfNotPresent(ctx, groupName)
|
|
return errors.Wrap(err, "Failed to create group")
|
|
}
|
|
|
|
if err := f(constants.AdminGroup); err != nil {
|
|
return err
|
|
}
|
|
if err := f(constants.EditorGroup); err != nil {
|
|
return err
|
|
}
|
|
if err := f(constants.ViewerGroup); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (mds *ModelDaoSqlite) createGroupIfNotPresent(ctx context.Context,
|
|
name string) (*types.Group, error) {
|
|
|
|
group, err := mds.GetGroupByName(ctx, name)
|
|
if err != nil {
|
|
return nil, errors.Wrap(err.Err, "Failed to query for root group")
|
|
}
|
|
if group != nil {
|
|
return group, nil
|
|
}
|
|
|
|
zap.L().Debug("group is not found, creating it", zap.String("group_name", name))
|
|
group, cErr := mds.CreateGroup(ctx, &types.Group{Name: name})
|
|
if cErr != nil {
|
|
return nil, cErr.Err
|
|
}
|
|
return group, nil
|
|
}
|