mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-13 16:59:04 +08:00
fix: signoz shouldn't panic with postgres provider (#7138)
All necessary changes so that whatever initalize SQL commans run, they are moved to bun so that it works with both sqlite and postgres.
This commit is contained in:
parent
2a939e813d
commit
eba2049a4d
@ -183,7 +183,7 @@ func (ah *APIHandler) getOrCreateCloudIntegrationUser(
|
|||||||
if apiErr != nil {
|
if apiErr != nil {
|
||||||
return nil, basemodel.WrapApiError(apiErr, "couldn't get viewer group for creating integration user")
|
return nil, basemodel.WrapApiError(apiErr, "couldn't get viewer group for creating integration user")
|
||||||
}
|
}
|
||||||
newUser.GroupId = viewerGroup.Id
|
newUser.GroupId = viewerGroup.ID
|
||||||
|
|
||||||
passwordHash, err := auth.PasswordHash(uuid.NewString())
|
passwordHash, err := auth.PasswordHash(uuid.NewString())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -105,7 +105,7 @@ func (s Server) HealthCheckStatus() chan healthcheck.Status {
|
|||||||
|
|
||||||
// NewServer creates and initializes Server
|
// NewServer creates and initializes Server
|
||||||
func NewServer(serverOptions *ServerOptions) (*Server, error) {
|
func NewServer(serverOptions *ServerOptions) (*Server, error) {
|
||||||
modelDao, err := dao.InitDao(serverOptions.SigNoz.SQLStore.SQLxDB())
|
modelDao, err := dao.InitDao(serverOptions.SigNoz.SQLStore)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -128,7 +128,7 @@ func NewServer(serverOptions *ServerOptions) (*Server, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// initiate license manager
|
// initiate license manager
|
||||||
lm, err := licensepkg.StartManager(serverOptions.SigNoz.SQLStore.SQLxDB())
|
lm, err := licensepkg.StartManager(serverOptions.SigNoz.SQLStore.SQLxDB(), serverOptions.SigNoz.SQLStore.BunDB())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -197,14 +197,14 @@ func NewServer(serverOptions *ServerOptions) (*Server, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
integrationsController, err := integrations.NewController(serverOptions.SigNoz.SQLStore.SQLxDB())
|
integrationsController, err := integrations.NewController(serverOptions.SigNoz.SQLStore)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf(
|
return nil, fmt.Errorf(
|
||||||
"couldn't create integrations controller: %w", err,
|
"couldn't create integrations controller: %w", err,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
cloudIntegrationsController, err := cloudintegrations.NewController(serverOptions.SigNoz.SQLStore.SQLxDB())
|
cloudIntegrationsController, err := cloudintegrations.NewController(serverOptions.SigNoz.SQLStore)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf(
|
return nil, fmt.Errorf(
|
||||||
"couldn't create cloud provider integrations controller: %w", err,
|
"couldn't create cloud provider integrations controller: %w", err,
|
||||||
|
@ -40,7 +40,7 @@ func GetUserFromRequestContext(ctx context.Context, apiHandler *api.APIHandler)
|
|||||||
}
|
}
|
||||||
telemetry.GetInstance().SetPatTokenUser()
|
telemetry.GetInstance().SetPatTokenUser()
|
||||||
dao.UpdatePATLastUsed(ctx, patToken, time.Now().Unix())
|
dao.UpdatePATLastUsed(ctx, patToken, time.Now().Unix())
|
||||||
user.User.GroupId = group.Id
|
user.User.GroupId = group.ID
|
||||||
user.User.Id = pat.Id
|
user.User.Id = pat.Id
|
||||||
return &basemodel.UserPayload{
|
return &basemodel.UserPayload{
|
||||||
User: user.User,
|
User: user.User,
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package dao
|
package dao
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/jmoiron/sqlx"
|
|
||||||
"go.signoz.io/signoz/ee/query-service/dao/sqlite"
|
"go.signoz.io/signoz/ee/query-service/dao/sqlite"
|
||||||
|
"go.signoz.io/signoz/pkg/sqlstore"
|
||||||
)
|
)
|
||||||
|
|
||||||
func InitDao(inputDB *sqlx.DB) (ModelDao, error) {
|
func InitDao(sqlStore sqlstore.SQLStore) (ModelDao, error) {
|
||||||
return sqlite.InitDB(inputDB)
|
return sqlite.InitDB(sqlStore)
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ func (m *modelDao) createUserForSAMLRequest(ctx context.Context, email string) (
|
|||||||
Password: hash,
|
Password: hash,
|
||||||
CreatedAt: time.Now().Unix(),
|
CreatedAt: time.Now().Unix(),
|
||||||
ProfilePictureURL: "", // Currently unused
|
ProfilePictureURL: "", // Currently unused
|
||||||
GroupId: group.Id,
|
GroupId: group.ID,
|
||||||
OrgId: domain.OrgId,
|
OrgId: domain.OrgId,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
basedao "go.signoz.io/signoz/pkg/query-service/dao"
|
basedao "go.signoz.io/signoz/pkg/query-service/dao"
|
||||||
basedsql "go.signoz.io/signoz/pkg/query-service/dao/sqlite"
|
basedsql "go.signoz.io/signoz/pkg/query-service/dao/sqlite"
|
||||||
baseint "go.signoz.io/signoz/pkg/query-service/interfaces"
|
baseint "go.signoz.io/signoz/pkg/query-service/interfaces"
|
||||||
|
"go.signoz.io/signoz/pkg/sqlstore"
|
||||||
)
|
)
|
||||||
|
|
||||||
type modelDao struct {
|
type modelDao struct {
|
||||||
@ -29,8 +30,8 @@ func (m *modelDao) checkFeature(key string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// InitDB creates and extends base model DB repository
|
// InitDB creates and extends base model DB repository
|
||||||
func InitDB(inputDB *sqlx.DB) (*modelDao, error) {
|
func InitDB(sqlStore sqlstore.SQLStore) (*modelDao, error) {
|
||||||
dao, err := basedsql.InitDB(inputDB)
|
dao, err := basedsql.InitDB(sqlStore)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -9,21 +9,25 @@ import (
|
|||||||
|
|
||||||
"github.com/jmoiron/sqlx"
|
"github.com/jmoiron/sqlx"
|
||||||
"github.com/mattn/go-sqlite3"
|
"github.com/mattn/go-sqlite3"
|
||||||
|
"github.com/uptrace/bun"
|
||||||
|
|
||||||
"go.signoz.io/signoz/ee/query-service/model"
|
"go.signoz.io/signoz/ee/query-service/model"
|
||||||
basemodel "go.signoz.io/signoz/pkg/query-service/model"
|
basemodel "go.signoz.io/signoz/pkg/query-service/model"
|
||||||
|
"go.signoz.io/signoz/pkg/types"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Repo is license repo. stores license keys in a secured DB
|
// Repo is license repo. stores license keys in a secured DB
|
||||||
type Repo struct {
|
type Repo struct {
|
||||||
db *sqlx.DB
|
db *sqlx.DB
|
||||||
|
bundb *bun.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewLicenseRepo initiates a new license repo
|
// NewLicenseRepo initiates a new license repo
|
||||||
func NewLicenseRepo(db *sqlx.DB) Repo {
|
func NewLicenseRepo(db *sqlx.DB, bundb *bun.DB) Repo {
|
||||||
return Repo{
|
return Repo{
|
||||||
db: db,
|
db: db,
|
||||||
|
bundb: bundb,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,24 +169,25 @@ func (r *Repo) UpdateLicenseV3(ctx context.Context, l *model.LicenseV3) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Repo) CreateFeature(req *basemodel.Feature) *basemodel.ApiError {
|
func (r *Repo) CreateFeature(req *types.FeatureStatus) *basemodel.ApiError {
|
||||||
|
|
||||||
_, err := r.db.Exec(
|
_, err := r.bundb.NewInsert().
|
||||||
`INSERT INTO feature_status (name, active, usage, usage_limit, route)
|
Model(req).
|
||||||
VALUES (?, ?, ?, ?, ?);`,
|
Exec(context.Background())
|
||||||
req.Name, req.Active, req.Usage, req.UsageLimit, req.Route)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &basemodel.ApiError{Typ: basemodel.ErrorInternal, Err: err}
|
return &basemodel.ApiError{Typ: basemodel.ErrorInternal, Err: err}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Repo) GetFeature(featureName string) (basemodel.Feature, error) {
|
func (r *Repo) GetFeature(featureName string) (types.FeatureStatus, error) {
|
||||||
|
var feature types.FeatureStatus
|
||||||
|
|
||||||
var feature basemodel.Feature
|
err := r.bundb.NewSelect().
|
||||||
|
Model(&feature).
|
||||||
|
Where("name = ?", featureName).
|
||||||
|
Scan(context.Background())
|
||||||
|
|
||||||
err := r.db.Get(&feature,
|
|
||||||
`SELECT * FROM feature_status WHERE name = ?;`, featureName)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return feature, err
|
return feature, err
|
||||||
}
|
}
|
||||||
@ -205,18 +210,19 @@ func (r *Repo) GetAllFeatures() ([]basemodel.Feature, error) {
|
|||||||
return feature, nil
|
return feature, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Repo) UpdateFeature(req basemodel.Feature) error {
|
func (r *Repo) UpdateFeature(req types.FeatureStatus) error {
|
||||||
|
|
||||||
_, err := r.db.Exec(
|
_, err := r.bundb.NewUpdate().
|
||||||
`UPDATE feature_status SET active = ?, usage = ?, usage_limit = ?, route = ? WHERE name = ?;`,
|
Model(&req).
|
||||||
req.Active, req.Usage, req.UsageLimit, req.Route, req.Name)
|
Where("name = ?", req.Name).
|
||||||
|
Exec(context.Background())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Repo) InitFeatures(req basemodel.FeatureSet) error {
|
func (r *Repo) InitFeatures(req []types.FeatureStatus) error {
|
||||||
// get a feature by name, if it doesn't exist, create it. If it does exist, update it.
|
// get a feature by name, if it doesn't exist, create it. If it does exist, update it.
|
||||||
for _, feature := range req {
|
for _, feature := range req {
|
||||||
currentFeature, err := r.GetFeature(feature.Name)
|
currentFeature, err := r.GetFeature(feature.Name)
|
||||||
@ -229,7 +235,7 @@ func (r *Repo) InitFeatures(req basemodel.FeatureSet) error {
|
|||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
feature.Usage = currentFeature.Usage
|
feature.Usage = int(currentFeature.Usage)
|
||||||
if feature.Usage >= feature.UsageLimit && feature.UsageLimit != -1 {
|
if feature.Usage >= feature.UsageLimit && feature.UsageLimit != -1 {
|
||||||
feature.Active = false
|
feature.Active = false
|
||||||
}
|
}
|
||||||
|
@ -7,10 +7,12 @@ import (
|
|||||||
|
|
||||||
"github.com/jmoiron/sqlx"
|
"github.com/jmoiron/sqlx"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"github.com/uptrace/bun"
|
||||||
|
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
baseconstants "go.signoz.io/signoz/pkg/query-service/constants"
|
baseconstants "go.signoz.io/signoz/pkg/query-service/constants"
|
||||||
|
"go.signoz.io/signoz/pkg/types"
|
||||||
"go.signoz.io/signoz/pkg/types/authtypes"
|
"go.signoz.io/signoz/pkg/types/authtypes"
|
||||||
|
|
||||||
validate "go.signoz.io/signoz/ee/query-service/integrations/signozio"
|
validate "go.signoz.io/signoz/ee/query-service/integrations/signozio"
|
||||||
@ -43,12 +45,12 @@ type Manager struct {
|
|||||||
activeFeatures basemodel.FeatureSet
|
activeFeatures basemodel.FeatureSet
|
||||||
}
|
}
|
||||||
|
|
||||||
func StartManager(db *sqlx.DB, features ...basemodel.Feature) (*Manager, error) {
|
func StartManager(db *sqlx.DB, bundb *bun.DB, features ...basemodel.Feature) (*Manager, error) {
|
||||||
if LM != nil {
|
if LM != nil {
|
||||||
return LM, nil
|
return LM, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
repo := NewLicenseRepo(db)
|
repo := NewLicenseRepo(db, bundb)
|
||||||
m := &Manager{
|
m := &Manager{
|
||||||
repo: &repo,
|
repo: &repo,
|
||||||
}
|
}
|
||||||
@ -282,15 +284,41 @@ func (lm *Manager) GetFeatureFlags() (basemodel.FeatureSet, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (lm *Manager) InitFeatures(features basemodel.FeatureSet) error {
|
func (lm *Manager) InitFeatures(features basemodel.FeatureSet) error {
|
||||||
return lm.repo.InitFeatures(features)
|
featureStatus := make([]types.FeatureStatus, len(features))
|
||||||
|
for i, f := range features {
|
||||||
|
featureStatus[i] = types.FeatureStatus{
|
||||||
|
Name: f.Name,
|
||||||
|
Active: f.Active,
|
||||||
|
Usage: int(f.Usage),
|
||||||
|
UsageLimit: int(f.UsageLimit),
|
||||||
|
Route: f.Route,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return lm.repo.InitFeatures(featureStatus)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (lm *Manager) UpdateFeatureFlag(feature basemodel.Feature) error {
|
func (lm *Manager) UpdateFeatureFlag(feature basemodel.Feature) error {
|
||||||
return lm.repo.UpdateFeature(feature)
|
return lm.repo.UpdateFeature(types.FeatureStatus{
|
||||||
|
Name: feature.Name,
|
||||||
|
Active: feature.Active,
|
||||||
|
Usage: int(feature.Usage),
|
||||||
|
UsageLimit: int(feature.UsageLimit),
|
||||||
|
Route: feature.Route,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (lm *Manager) GetFeatureFlag(key string) (basemodel.Feature, error) {
|
func (lm *Manager) GetFeatureFlag(key string) (basemodel.Feature, error) {
|
||||||
return lm.repo.GetFeature(key)
|
featureStatus, err := lm.repo.GetFeature(key)
|
||||||
|
if err != nil {
|
||||||
|
return basemodel.Feature{}, err
|
||||||
|
}
|
||||||
|
return basemodel.Feature{
|
||||||
|
Name: featureStatus.Name,
|
||||||
|
Active: featureStatus.Active,
|
||||||
|
Usage: int64(featureStatus.Usage),
|
||||||
|
UsageLimit: int64(featureStatus.UsageLimit),
|
||||||
|
Route: featureStatus.Route,
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetRepo return the license repo
|
// GetRepo return the license repo
|
||||||
|
@ -8,9 +8,9 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/jmoiron/sqlx"
|
|
||||||
"go.signoz.io/signoz/pkg/query-service/app/dashboards"
|
"go.signoz.io/signoz/pkg/query-service/app/dashboards"
|
||||||
"go.signoz.io/signoz/pkg/query-service/model"
|
"go.signoz.io/signoz/pkg/query-service/model"
|
||||||
|
"go.signoz.io/signoz/pkg/sqlstore"
|
||||||
"golang.org/x/exp/maps"
|
"golang.org/x/exp/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -30,15 +30,15 @@ type Controller struct {
|
|||||||
serviceConfigRepo serviceConfigRepository
|
serviceConfigRepo serviceConfigRepository
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewController(db *sqlx.DB) (
|
func NewController(sqlStore sqlstore.SQLStore) (
|
||||||
*Controller, error,
|
*Controller, error,
|
||||||
) {
|
) {
|
||||||
accountsRepo, err := newCloudProviderAccountsRepository(db)
|
accountsRepo, err := newCloudProviderAccountsRepository(sqlStore.SQLxDB())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("couldn't create cloud provider accounts repo: %w", err)
|
return nil, fmt.Errorf("couldn't create cloud provider accounts repo: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
serviceConfigRepo, err := newServiceConfigRepository(db)
|
serviceConfigRepo, err := newServiceConfigRepository(sqlStore.SQLxDB())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("couldn't create cloud provider service config repo: %w", err)
|
return nil, fmt.Errorf("couldn't create cloud provider service config repo: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -12,8 +12,8 @@ import (
|
|||||||
|
|
||||||
func TestRegenerateConnectionUrlWithUpdatedConfig(t *testing.T) {
|
func TestRegenerateConnectionUrlWithUpdatedConfig(t *testing.T) {
|
||||||
require := require.New(t)
|
require := require.New(t)
|
||||||
testDB, _ := utils.NewTestSqliteDB(t)
|
sqlStore, _ := utils.NewTestSqliteDB(t)
|
||||||
controller, err := NewController(testDB)
|
controller, err := NewController(sqlStore)
|
||||||
require.NoError(err)
|
require.NoError(err)
|
||||||
|
|
||||||
// should be able to generate connection url for
|
// should be able to generate connection url for
|
||||||
@ -56,8 +56,8 @@ func TestRegenerateConnectionUrlWithUpdatedConfig(t *testing.T) {
|
|||||||
|
|
||||||
func TestAgentCheckIns(t *testing.T) {
|
func TestAgentCheckIns(t *testing.T) {
|
||||||
require := require.New(t)
|
require := require.New(t)
|
||||||
testDB, _ := utils.NewTestSqliteDB(t)
|
sqlStore, _ := utils.NewTestSqliteDB(t)
|
||||||
controller, err := NewController(testDB)
|
controller, err := NewController(sqlStore)
|
||||||
require.NoError(err)
|
require.NoError(err)
|
||||||
|
|
||||||
// An agent should be able to check in from a cloud account even
|
// An agent should be able to check in from a cloud account even
|
||||||
@ -139,8 +139,8 @@ func TestAgentCheckIns(t *testing.T) {
|
|||||||
|
|
||||||
func TestCantDisconnectNonExistentAccount(t *testing.T) {
|
func TestCantDisconnectNonExistentAccount(t *testing.T) {
|
||||||
require := require.New(t)
|
require := require.New(t)
|
||||||
testDB, _ := utils.NewTestSqliteDB(t)
|
sqlStore, _ := utils.NewTestSqliteDB(t)
|
||||||
controller, err := NewController(testDB)
|
controller, err := NewController(sqlStore)
|
||||||
require.NoError(err)
|
require.NoError(err)
|
||||||
|
|
||||||
// Attempting to disconnect a non-existent account should return error
|
// Attempting to disconnect a non-existent account should return error
|
||||||
@ -154,8 +154,8 @@ func TestCantDisconnectNonExistentAccount(t *testing.T) {
|
|||||||
|
|
||||||
func TestConfigureService(t *testing.T) {
|
func TestConfigureService(t *testing.T) {
|
||||||
require := require.New(t)
|
require := require.New(t)
|
||||||
testDB, _ := utils.NewTestSqliteDB(t)
|
sqlStore, _ := utils.NewTestSqliteDB(t)
|
||||||
controller, err := NewController(testDB)
|
controller, err := NewController(sqlStore)
|
||||||
require.NoError(err)
|
require.NoError(err)
|
||||||
|
|
||||||
testCloudAccountId := "546311234"
|
testCloudAccountId := "546311234"
|
||||||
|
@ -2285,13 +2285,13 @@ func (aH *APIHandler) deleteUser(w http.ResponseWriter, r *http.Request) {
|
|||||||
RespondError(w, apiErr, "Failed to get admin group")
|
RespondError(w, apiErr, "Failed to get admin group")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
adminUsers, apiErr := dao.DB().GetUsersByGroup(ctx, adminGroup.Id)
|
adminUsers, apiErr := dao.DB().GetUsersByGroup(ctx, adminGroup.ID)
|
||||||
if apiErr != nil {
|
if apiErr != nil {
|
||||||
RespondError(w, apiErr, "Failed to get admin group users")
|
RespondError(w, apiErr, "Failed to get admin group users")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if user.GroupId == adminGroup.Id && len(adminUsers) == 1 {
|
if user.GroupId == adminGroup.ID && len(adminUsers) == 1 {
|
||||||
RespondError(w, &model.ApiError{
|
RespondError(w, &model.ApiError{
|
||||||
Typ: model.ErrorInternal,
|
Typ: model.ErrorInternal,
|
||||||
Err: errors.New("cannot delete the last admin user")}, nil)
|
Err: errors.New("cannot delete the last admin user")}, nil)
|
||||||
@ -2403,7 +2403,7 @@ func (aH *APIHandler) editRole(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
apiErr = dao.DB().UpdateUserGroup(context.Background(), user.Id, newGroup.Id)
|
apiErr = dao.DB().UpdateUserGroup(context.Background(), user.Id, newGroup.ID)
|
||||||
if apiErr != nil {
|
if apiErr != nil {
|
||||||
RespondError(w, apiErr, "Failed to add user to group")
|
RespondError(w, apiErr, "Failed to add user to group")
|
||||||
return
|
return
|
||||||
|
@ -4,21 +4,21 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/jmoiron/sqlx"
|
|
||||||
"go.signoz.io/signoz/pkg/query-service/agentConf"
|
"go.signoz.io/signoz/pkg/query-service/agentConf"
|
||||||
"go.signoz.io/signoz/pkg/query-service/app/dashboards"
|
"go.signoz.io/signoz/pkg/query-service/app/dashboards"
|
||||||
"go.signoz.io/signoz/pkg/query-service/app/logparsingpipeline"
|
"go.signoz.io/signoz/pkg/query-service/app/logparsingpipeline"
|
||||||
"go.signoz.io/signoz/pkg/query-service/model"
|
"go.signoz.io/signoz/pkg/query-service/model"
|
||||||
|
"go.signoz.io/signoz/pkg/sqlstore"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Controller struct {
|
type Controller struct {
|
||||||
mgr *Manager
|
mgr *Manager
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewController(db *sqlx.DB) (
|
func NewController(sqlStore sqlstore.SQLStore) (
|
||||||
*Controller, error,
|
*Controller, error,
|
||||||
) {
|
) {
|
||||||
mgr, err := NewManager(db)
|
mgr, err := NewManager(sqlStore.SQLxDB())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("couldn't create integrations manager: %w", err)
|
return nil, fmt.Errorf("couldn't create integrations manager: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ import (
|
|||||||
func NewTestIntegrationsManager(t *testing.T) *Manager {
|
func NewTestIntegrationsManager(t *testing.T) *Manager {
|
||||||
testDB := utils.NewQueryServiceDBForTests(t)
|
testDB := utils.NewQueryServiceDBForTests(t)
|
||||||
|
|
||||||
installedIntegrationsRepo, err := NewInstalledIntegrationsSqliteRepo(testDB)
|
installedIntegrationsRepo, err := NewInstalledIntegrationsSqliteRepo(testDB.SQLxDB())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("could not init sqlite DB for installed integrations: %v", err)
|
t.Fatalf("could not init sqlite DB for installed integrations: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -166,7 +166,7 @@ type testbed struct {
|
|||||||
|
|
||||||
func newTestbed(t *testing.T) *testbed {
|
func newTestbed(t *testing.T) *testbed {
|
||||||
testDB := utils.NewQueryServiceDBForTests(t)
|
testDB := utils.NewQueryServiceDBForTests(t)
|
||||||
_, err := model.InitDB(testDB)
|
_, err := model.InitDB(testDB.SQLxDB())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("could not init opamp model: %v", err)
|
t.Fatalf("could not init opamp model: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,7 @@ func (s Server) HealthCheckStatus() chan healthcheck.Status {
|
|||||||
// NewServer creates and initializes Server
|
// NewServer creates and initializes Server
|
||||||
func NewServer(serverOptions *ServerOptions) (*Server, error) {
|
func NewServer(serverOptions *ServerOptions) (*Server, error) {
|
||||||
var err error
|
var err error
|
||||||
if err := dao.InitDao(serverOptions.SigNoz.SQLStore.SQLxDB()); err != nil {
|
if err := dao.InitDao(serverOptions.SigNoz.SQLStore); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -163,12 +163,12 @@ func NewServer(serverOptions *ServerOptions) (*Server, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
integrationsController, err := integrations.NewController(serverOptions.SigNoz.SQLStore.SQLxDB())
|
integrationsController, err := integrations.NewController(serverOptions.SigNoz.SQLStore)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("couldn't create integrations controller: %w", err)
|
return nil, fmt.Errorf("couldn't create integrations controller: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
cloudIntegrationsController, err := cloudintegrations.NewController(serverOptions.SigNoz.SQLStore.SQLxDB())
|
cloudIntegrationsController, err := cloudintegrations.NewController(serverOptions.SigNoz.SQLStore)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("couldn't create cloud provider integrations controller: %w", err)
|
return nil, fmt.Errorf("couldn't create cloud provider integrations controller: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -421,7 +421,7 @@ func RegisterFirstUser(ctx context.Context, req *RegisterRequest) (*model.User,
|
|||||||
Password: hash,
|
Password: hash,
|
||||||
CreatedAt: time.Now().Unix(),
|
CreatedAt: time.Now().Unix(),
|
||||||
ProfilePictureURL: "", // Currently unused
|
ProfilePictureURL: "", // Currently unused
|
||||||
GroupId: group.Id,
|
GroupId: group.ID,
|
||||||
OrgId: org.Id,
|
OrgId: org.Id,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -499,7 +499,7 @@ func RegisterInvitedUser(ctx context.Context, req *RegisterRequest, nopassword b
|
|||||||
Password: hash,
|
Password: hash,
|
||||||
CreatedAt: time.Now().Unix(),
|
CreatedAt: time.Now().Unix(),
|
||||||
ProfilePictureURL: "", // Currently unused
|
ProfilePictureURL: "", // Currently unused
|
||||||
GroupId: group.Id,
|
GroupId: group.ID,
|
||||||
OrgId: invite.OrgId,
|
OrgId: invite.OrgId,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ func InitAuthCache(ctx context.Context) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err.Err, "failed to get group %s", groupName)
|
return errors.Wrapf(err.Err, "failed to get group %s", groupName)
|
||||||
}
|
}
|
||||||
*dest = group.Id
|
*dest = group.ID
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
package dao
|
package dao
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/jmoiron/sqlx"
|
|
||||||
"go.signoz.io/signoz/pkg/query-service/dao/sqlite"
|
"go.signoz.io/signoz/pkg/query-service/dao/sqlite"
|
||||||
|
"go.signoz.io/signoz/pkg/sqlstore"
|
||||||
)
|
)
|
||||||
|
|
||||||
var db ModelDao
|
var db ModelDao
|
||||||
|
|
||||||
func InitDao(inputDB *sqlx.DB) error {
|
func InitDao(sqlStore sqlstore.SQLStore) error {
|
||||||
var err error
|
var err error
|
||||||
db, err = sqlite.InitDB(inputDB)
|
db, err = sqlite.InitDB(sqlStore)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
|
|
||||||
"go.signoz.io/signoz/pkg/query-service/model"
|
"go.signoz.io/signoz/pkg/query-service/model"
|
||||||
|
"go.signoz.io/signoz/pkg/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ModelDao interface {
|
type ModelDao interface {
|
||||||
@ -22,7 +23,7 @@ type Queries interface {
|
|||||||
GetUsersWithOpts(ctx context.Context, limit int) ([]model.UserPayload, *model.ApiError)
|
GetUsersWithOpts(ctx context.Context, limit int) ([]model.UserPayload, *model.ApiError)
|
||||||
|
|
||||||
GetGroup(ctx context.Context, id string) (*model.Group, *model.ApiError)
|
GetGroup(ctx context.Context, id string) (*model.Group, *model.ApiError)
|
||||||
GetGroupByName(ctx context.Context, name string) (*model.Group, *model.ApiError)
|
GetGroupByName(ctx context.Context, name string) (*types.Group, *model.ApiError)
|
||||||
GetGroups(ctx context.Context) ([]model.Group, *model.ApiError)
|
GetGroups(ctx context.Context) ([]model.Group, *model.ApiError)
|
||||||
|
|
||||||
GetOrgs(ctx context.Context) ([]model.Organization, *model.ApiError)
|
GetOrgs(ctx context.Context) ([]model.Organization, *model.ApiError)
|
||||||
@ -50,7 +51,7 @@ type Mutations interface {
|
|||||||
|
|
||||||
UpdateUserFlags(ctx context.Context, userId string, flags map[string]string) (model.UserFlag, *model.ApiError)
|
UpdateUserFlags(ctx context.Context, userId string, flags map[string]string) (model.UserFlag, *model.ApiError)
|
||||||
|
|
||||||
CreateGroup(ctx context.Context, group *model.Group) (*model.Group, *model.ApiError)
|
CreateGroup(ctx context.Context, group *types.Group) (*types.Group, *model.ApiError)
|
||||||
DeleteGroup(ctx context.Context, id string) *model.ApiError
|
DeleteGroup(ctx context.Context, id string) *model.ApiError
|
||||||
|
|
||||||
CreateOrg(ctx context.Context, org *model.Organization) (*model.Organization, *model.ApiError)
|
CreateOrg(ctx context.Context, org *model.Organization) (*model.Organization, *model.ApiError)
|
||||||
|
@ -5,19 +5,23 @@ import (
|
|||||||
|
|
||||||
"github.com/jmoiron/sqlx"
|
"github.com/jmoiron/sqlx"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"github.com/uptrace/bun"
|
||||||
"go.signoz.io/signoz/pkg/query-service/constants"
|
"go.signoz.io/signoz/pkg/query-service/constants"
|
||||||
"go.signoz.io/signoz/pkg/query-service/model"
|
"go.signoz.io/signoz/pkg/query-service/model"
|
||||||
"go.signoz.io/signoz/pkg/query-service/telemetry"
|
"go.signoz.io/signoz/pkg/query-service/telemetry"
|
||||||
|
"go.signoz.io/signoz/pkg/sqlstore"
|
||||||
|
"go.signoz.io/signoz/pkg/types"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ModelDaoSqlite struct {
|
type ModelDaoSqlite struct {
|
||||||
db *sqlx.DB
|
db *sqlx.DB
|
||||||
|
bundb *bun.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
// InitDB sets up setting up the connection pool global variable.
|
// InitDB sets up setting up the connection pool global variable.
|
||||||
func InitDB(db *sqlx.DB) (*ModelDaoSqlite, error) {
|
func InitDB(sqlStore sqlstore.SQLStore) (*ModelDaoSqlite, error) {
|
||||||
mds := &ModelDaoSqlite{db: db}
|
mds := &ModelDaoSqlite{db: sqlStore.SQLxDB(), bundb: sqlStore.BunDB()}
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
if err := mds.initializeOrgPreferences(ctx); err != nil {
|
if err := mds.initializeOrgPreferences(ctx); err != nil {
|
||||||
@ -97,7 +101,7 @@ func (mds *ModelDaoSqlite) initializeRBAC(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (mds *ModelDaoSqlite) createGroupIfNotPresent(ctx context.Context,
|
func (mds *ModelDaoSqlite) createGroupIfNotPresent(ctx context.Context,
|
||||||
name string) (*model.Group, error) {
|
name string) (*types.Group, error) {
|
||||||
|
|
||||||
group, err := mds.GetGroupByName(ctx, name)
|
group, err := mds.GetGroupByName(ctx, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -108,7 +112,7 @@ func (mds *ModelDaoSqlite) createGroupIfNotPresent(ctx context.Context,
|
|||||||
}
|
}
|
||||||
|
|
||||||
zap.L().Debug("group is not found, creating it", zap.String("group_name", name))
|
zap.L().Debug("group is not found, creating it", zap.String("group_name", name))
|
||||||
group, cErr := mds.CreateGroup(ctx, &model.Group{Name: name})
|
group, cErr := mds.CreateGroup(ctx, &types.Group{Name: name})
|
||||||
if cErr != nil {
|
if cErr != nil {
|
||||||
return nil, cErr.Err
|
return nil, cErr.Err
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import (
|
|||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"go.signoz.io/signoz/pkg/query-service/model"
|
"go.signoz.io/signoz/pkg/query-service/model"
|
||||||
"go.signoz.io/signoz/pkg/query-service/telemetry"
|
"go.signoz.io/signoz/pkg/query-service/telemetry"
|
||||||
|
"go.signoz.io/signoz/pkg/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (mds *ModelDaoSqlite) CreateInviteEntry(ctx context.Context,
|
func (mds *ModelDaoSqlite) CreateInviteEntry(ctx context.Context,
|
||||||
@ -436,12 +437,13 @@ func (mds *ModelDaoSqlite) GetUsersByGroup(ctx context.Context,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (mds *ModelDaoSqlite) CreateGroup(ctx context.Context,
|
func (mds *ModelDaoSqlite) CreateGroup(ctx context.Context,
|
||||||
group *model.Group) (*model.Group, *model.ApiError) {
|
group *types.Group) (*types.Group, *model.ApiError) {
|
||||||
|
|
||||||
group.Id = uuid.NewString()
|
group.ID = uuid.NewString()
|
||||||
|
|
||||||
q := `INSERT INTO groups (id, name) VALUES (?, ?);`
|
if _, err := mds.bundb.NewInsert().
|
||||||
if _, err := mds.db.ExecContext(ctx, q, group.Id, group.Name); err != nil {
|
Model(group).
|
||||||
|
Exec(ctx); err != nil {
|
||||||
return nil, &model.ApiError{Typ: model.ErrorInternal, Err: err}
|
return nil, &model.ApiError{Typ: model.ErrorInternal, Err: err}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -478,10 +480,14 @@ func (mds *ModelDaoSqlite) GetGroup(ctx context.Context,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (mds *ModelDaoSqlite) GetGroupByName(ctx context.Context,
|
func (mds *ModelDaoSqlite) GetGroupByName(ctx context.Context,
|
||||||
name string) (*model.Group, *model.ApiError) {
|
name string) (*types.Group, *model.ApiError) {
|
||||||
|
|
||||||
groups := []model.Group{}
|
groups := []types.Group{}
|
||||||
if err := mds.db.Select(&groups, `SELECT id, name FROM groups WHERE name=?`, name); err != nil {
|
err := mds.bundb.NewSelect().
|
||||||
|
Model(&groups).
|
||||||
|
Where("name = ?", name).
|
||||||
|
Scan(ctx)
|
||||||
|
if err != nil {
|
||||||
return nil, &model.ApiError{Typ: model.ErrorInternal, Err: err}
|
return nil, &model.ApiError{Typ: model.ErrorInternal, Err: err}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -293,7 +293,7 @@ func NewFilterSuggestionsTestBed(t *testing.T) *FilterSuggestionsTestBed {
|
|||||||
testDB := utils.NewQueryServiceDBForTests(t)
|
testDB := utils.NewQueryServiceDBForTests(t)
|
||||||
|
|
||||||
fm := featureManager.StartManager()
|
fm := featureManager.StartManager()
|
||||||
reader, mockClickhouse := NewMockClickhouseReader(t, testDB, fm)
|
reader, mockClickhouse := NewMockClickhouseReader(t, testDB.SQLxDB(), fm)
|
||||||
mockClickhouse.MatchExpectationsInOrder(false)
|
mockClickhouse.MatchExpectationsInOrder(false)
|
||||||
|
|
||||||
apiHandler, err := app.NewAPIHandler(app.APIHandlerOpts{
|
apiHandler, err := app.NewAPIHandler(app.APIHandlerOpts{
|
||||||
|
@ -11,7 +11,6 @@ import (
|
|||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/jmoiron/sqlx"
|
|
||||||
"github.com/knadh/koanf/parsers/yaml"
|
"github.com/knadh/koanf/parsers/yaml"
|
||||||
"github.com/open-telemetry/opamp-go/protobufs"
|
"github.com/open-telemetry/opamp-go/protobufs"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@ -28,6 +27,7 @@ import (
|
|||||||
v3 "go.signoz.io/signoz/pkg/query-service/model/v3"
|
v3 "go.signoz.io/signoz/pkg/query-service/model/v3"
|
||||||
"go.signoz.io/signoz/pkg/query-service/queryBuilderToExpr"
|
"go.signoz.io/signoz/pkg/query-service/queryBuilderToExpr"
|
||||||
"go.signoz.io/signoz/pkg/query-service/utils"
|
"go.signoz.io/signoz/pkg/query-service/utils"
|
||||||
|
"go.signoz.io/signoz/pkg/sqlstore"
|
||||||
"golang.org/x/exp/maps"
|
"golang.org/x/exp/maps"
|
||||||
"golang.org/x/exp/slices"
|
"golang.org/x/exp/slices"
|
||||||
)
|
)
|
||||||
@ -449,18 +449,18 @@ type LogPipelinesTestBed struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// testDB can be injected for sharing a DB across multiple integration testbeds.
|
// testDB can be injected for sharing a DB across multiple integration testbeds.
|
||||||
func NewTestbedWithoutOpamp(t *testing.T, testDB *sqlx.DB) *LogPipelinesTestBed {
|
func NewTestbedWithoutOpamp(t *testing.T, sqlStore sqlstore.SQLStore) *LogPipelinesTestBed {
|
||||||
if testDB == nil {
|
if sqlStore == nil {
|
||||||
testDB = utils.NewQueryServiceDBForTests(t)
|
sqlStore = utils.NewQueryServiceDBForTests(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
ic, err := integrations.NewController(testDB)
|
ic, err := integrations.NewController(sqlStore)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("could not create integrations controller: %v", err)
|
t.Fatalf("could not create integrations controller: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
controller, err := logparsingpipeline.NewLogParsingPipelinesController(
|
controller, err := logparsingpipeline.NewLogParsingPipelinesController(
|
||||||
testDB, ic.GetPipelinesForInstalledIntegrations,
|
sqlStore.SQLxDB(), ic.GetPipelinesForInstalledIntegrations,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("could not create a logparsingpipelines controller: %v", err)
|
t.Fatalf("could not create a logparsingpipelines controller: %v", err)
|
||||||
@ -481,7 +481,7 @@ func NewTestbedWithoutOpamp(t *testing.T, testDB *sqlx.DB) *LogPipelinesTestBed
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Mock an available opamp agent
|
// Mock an available opamp agent
|
||||||
testDB, err = opampModel.InitDB(testDB)
|
testDB, err := opampModel.InitDB(sqlStore.SQLxDB())
|
||||||
require.Nil(t, err, "failed to init opamp model")
|
require.Nil(t, err, "failed to init opamp model")
|
||||||
|
|
||||||
agentConfMgr, err := agentConf.Initiate(&agentConf.ManagerOptions{
|
agentConfMgr, err := agentConf.Initiate(&agentConf.ManagerOptions{
|
||||||
@ -499,7 +499,7 @@ func NewTestbedWithoutOpamp(t *testing.T, testDB *sqlx.DB) *LogPipelinesTestBed
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewLogPipelinesTestBed(t *testing.T, testDB *sqlx.DB) *LogPipelinesTestBed {
|
func NewLogPipelinesTestBed(t *testing.T, testDB sqlstore.SQLStore) *LogPipelinesTestBed {
|
||||||
testbed := NewTestbedWithoutOpamp(t, testDB)
|
testbed := NewTestbedWithoutOpamp(t, testDB)
|
||||||
|
|
||||||
opampServer := opamp.InitializeServer(nil, testbed.agentConfMgr)
|
opampServer := opamp.InitializeServer(nil, testbed.agentConfMgr)
|
||||||
|
@ -9,7 +9,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/jmoiron/sqlx"
|
|
||||||
mockhouse "github.com/srikanthccv/ClickHouse-go-mock"
|
mockhouse "github.com/srikanthccv/ClickHouse-go-mock"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"go.signoz.io/signoz/pkg/http/middleware"
|
"go.signoz.io/signoz/pkg/http/middleware"
|
||||||
@ -20,6 +19,7 @@ import (
|
|||||||
"go.signoz.io/signoz/pkg/query-service/featureManager"
|
"go.signoz.io/signoz/pkg/query-service/featureManager"
|
||||||
"go.signoz.io/signoz/pkg/query-service/model"
|
"go.signoz.io/signoz/pkg/query-service/model"
|
||||||
"go.signoz.io/signoz/pkg/query-service/utils"
|
"go.signoz.io/signoz/pkg/query-service/utils"
|
||||||
|
"go.signoz.io/signoz/pkg/sqlstore"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -344,7 +344,7 @@ type CloudIntegrationsTestBed struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// testDB can be injected for sharing a DB across multiple integration testbeds.
|
// testDB can be injected for sharing a DB across multiple integration testbeds.
|
||||||
func NewCloudIntegrationsTestBed(t *testing.T, testDB *sqlx.DB) *CloudIntegrationsTestBed {
|
func NewCloudIntegrationsTestBed(t *testing.T, testDB sqlstore.SQLStore) *CloudIntegrationsTestBed {
|
||||||
if testDB == nil {
|
if testDB == nil {
|
||||||
testDB = utils.NewQueryServiceDBForTests(t)
|
testDB = utils.NewQueryServiceDBForTests(t)
|
||||||
}
|
}
|
||||||
@ -355,7 +355,7 @@ func NewCloudIntegrationsTestBed(t *testing.T, testDB *sqlx.DB) *CloudIntegratio
|
|||||||
}
|
}
|
||||||
|
|
||||||
fm := featureManager.StartManager()
|
fm := featureManager.StartManager()
|
||||||
reader, mockClickhouse := NewMockClickhouseReader(t, testDB, fm)
|
reader, mockClickhouse := NewMockClickhouseReader(t, testDB.SQLxDB(), fm)
|
||||||
mockClickhouse.MatchExpectationsInOrder(false)
|
mockClickhouse.MatchExpectationsInOrder(false)
|
||||||
|
|
||||||
apiHandler, err := app.NewAPIHandler(app.APIHandlerOpts{
|
apiHandler, err := app.NewAPIHandler(app.APIHandlerOpts{
|
||||||
|
@ -8,7 +8,6 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/jmoiron/sqlx"
|
|
||||||
mockhouse "github.com/srikanthccv/ClickHouse-go-mock"
|
mockhouse "github.com/srikanthccv/ClickHouse-go-mock"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"go.signoz.io/signoz/pkg/http/middleware"
|
"go.signoz.io/signoz/pkg/http/middleware"
|
||||||
@ -23,6 +22,7 @@ import (
|
|||||||
"go.signoz.io/signoz/pkg/query-service/model"
|
"go.signoz.io/signoz/pkg/query-service/model"
|
||||||
v3 "go.signoz.io/signoz/pkg/query-service/model/v3"
|
v3 "go.signoz.io/signoz/pkg/query-service/model/v3"
|
||||||
"go.signoz.io/signoz/pkg/query-service/utils"
|
"go.signoz.io/signoz/pkg/query-service/utils"
|
||||||
|
"go.signoz.io/signoz/pkg/sqlstore"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -546,7 +546,7 @@ func (tb *IntegrationsTestBed) mockMetricStatusQueryResponse(expectation *model.
|
|||||||
}
|
}
|
||||||
|
|
||||||
// testDB can be injected for sharing a DB across multiple integration testbeds.
|
// testDB can be injected for sharing a DB across multiple integration testbeds.
|
||||||
func NewIntegrationsTestBed(t *testing.T, testDB *sqlx.DB) *IntegrationsTestBed {
|
func NewIntegrationsTestBed(t *testing.T, testDB sqlstore.SQLStore) *IntegrationsTestBed {
|
||||||
if testDB == nil {
|
if testDB == nil {
|
||||||
testDB = utils.NewQueryServiceDBForTests(t)
|
testDB = utils.NewQueryServiceDBForTests(t)
|
||||||
}
|
}
|
||||||
@ -557,7 +557,7 @@ func NewIntegrationsTestBed(t *testing.T, testDB *sqlx.DB) *IntegrationsTestBed
|
|||||||
}
|
}
|
||||||
|
|
||||||
fm := featureManager.StartManager()
|
fm := featureManager.StartManager()
|
||||||
reader, mockClickhouse := NewMockClickhouseReader(t, testDB, fm)
|
reader, mockClickhouse := NewMockClickhouseReader(t, testDB.SQLxDB(), fm)
|
||||||
mockClickhouse.MatchExpectationsInOrder(false)
|
mockClickhouse.MatchExpectationsInOrder(false)
|
||||||
|
|
||||||
cloudIntegrationsController, err := cloudintegrations.NewController(testDB)
|
cloudIntegrationsController, err := cloudintegrations.NewController(testDB)
|
||||||
|
@ -176,7 +176,7 @@ func createTestUser() (*model.User, *model.ApiError) {
|
|||||||
Email: userId[:8] + "test@test.com",
|
Email: userId[:8] + "test@test.com",
|
||||||
Password: "test",
|
Password: "test",
|
||||||
OrgId: org.Id,
|
OrgId: org.Id,
|
||||||
GroupId: group.Id,
|
GroupId: group.ID,
|
||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
)
|
)
|
||||||
|
@ -5,7 +5,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/jmoiron/sqlx"
|
|
||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
"go.signoz.io/signoz/pkg/factory"
|
"go.signoz.io/signoz/pkg/factory"
|
||||||
"go.signoz.io/signoz/pkg/factory/providertest"
|
"go.signoz.io/signoz/pkg/factory/providertest"
|
||||||
@ -17,7 +16,7 @@ import (
|
|||||||
"go.signoz.io/signoz/pkg/sqlstore/sqlitesqlstore"
|
"go.signoz.io/signoz/pkg/sqlstore/sqlitesqlstore"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewTestSqliteDB(t *testing.T) (testDB *sqlx.DB, testDBFilePath string) {
|
func NewTestSqliteDB(t *testing.T) (sqlStore sqlstore.SQLStore, testDBFilePath string) {
|
||||||
testDBFile, err := os.CreateTemp("", "test-signoz-db-*")
|
testDBFile, err := os.CreateTemp("", "test-signoz-db-*")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("could not create temp file for test db: %v", err)
|
t.Fatalf("could not create temp file for test db: %v", err)
|
||||||
@ -26,7 +25,7 @@ func NewTestSqliteDB(t *testing.T) (testDB *sqlx.DB, testDBFilePath string) {
|
|||||||
t.Cleanup(func() { os.Remove(testDBFilePath) })
|
t.Cleanup(func() { os.Remove(testDBFilePath) })
|
||||||
testDBFile.Close()
|
testDBFile.Close()
|
||||||
|
|
||||||
sqlstore, err := sqlitesqlstore.New(context.Background(), providertest.NewSettings(), sqlstore.Config{Provider: "sqlite", Sqlite: sqlstore.SqliteConfig{Path: testDBFilePath}})
|
sqlStore, err = sqlitesqlstore.New(context.Background(), providertest.NewSettings(), sqlstore.Config{Provider: "sqlite", Sqlite: sqlstore.SqliteConfig{Path: testDBFilePath}})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("could not create test db sqlite store: %v", err)
|
t.Fatalf("could not create test db sqlite store: %v", err)
|
||||||
}
|
}
|
||||||
@ -52,22 +51,19 @@ func NewTestSqliteDB(t *testing.T) (testDB *sqlx.DB, testDBFilePath string) {
|
|||||||
t.Fatalf("could not create test db sql migrations: %v", err)
|
t.Fatalf("could not create test db sql migrations: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = sqlmigrator.New(context.Background(), providertest.NewSettings(), sqlstore, sqlmigrations, sqlmigrator.Config{}).Migrate(context.Background())
|
err = sqlmigrator.New(context.Background(), providertest.NewSettings(), sqlStore, sqlmigrations, sqlmigrator.Config{}).Migrate(context.Background())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("could not migrate test db sql migrations: %v", err)
|
t.Fatalf("could not migrate test db sql migrations: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
testDB = sqlstore.SQLxDB()
|
return sqlStore, testDBFilePath
|
||||||
|
|
||||||
return testDB, testDBFilePath
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewQueryServiceDBForTests(t *testing.T) *sqlx.DB {
|
func NewQueryServiceDBForTests(t *testing.T) sqlstore.SQLStore {
|
||||||
testDB, _ := NewTestSqliteDB(t)
|
sqlStore, _ := NewTestSqliteDB(t)
|
||||||
|
|
||||||
// TODO(Raj): This should not require passing in the DB file path
|
dao.InitDao(sqlStore)
|
||||||
dao.InitDao(testDB)
|
dashboards.InitDB(sqlStore.SQLxDB())
|
||||||
dashboards.InitDB(testDB)
|
|
||||||
|
|
||||||
return testDB
|
return sqlStore
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"go.signoz.io/signoz/pkg/factory"
|
"go.signoz.io/signoz/pkg/factory"
|
||||||
"go.signoz.io/signoz/pkg/sqlmigration"
|
"go.signoz.io/signoz/pkg/sqlmigration"
|
||||||
"go.signoz.io/signoz/pkg/sqlstore"
|
"go.signoz.io/signoz/pkg/sqlstore"
|
||||||
|
"go.signoz.io/signoz/pkg/sqlstore/postgressqlstore"
|
||||||
"go.signoz.io/signoz/pkg/sqlstore/sqlitesqlstore"
|
"go.signoz.io/signoz/pkg/sqlstore/sqlitesqlstore"
|
||||||
"go.signoz.io/signoz/pkg/sqlstore/sqlstorehook"
|
"go.signoz.io/signoz/pkg/sqlstore/sqlstorehook"
|
||||||
"go.signoz.io/signoz/pkg/telemetrystore"
|
"go.signoz.io/signoz/pkg/telemetrystore"
|
||||||
@ -46,7 +47,7 @@ func NewProviderConfig() ProviderConfig {
|
|||||||
),
|
),
|
||||||
SQLStoreProviderFactories: factory.MustNewNamedMap(
|
SQLStoreProviderFactories: factory.MustNewNamedMap(
|
||||||
sqlitesqlstore.NewFactory(sqlstorehook.NewLoggingFactory()),
|
sqlitesqlstore.NewFactory(sqlstorehook.NewLoggingFactory()),
|
||||||
// postgressqlstore.NewFactory(),
|
postgressqlstore.NewFactory(sqlstorehook.NewLoggingFactory()),
|
||||||
),
|
),
|
||||||
SQLMigrationProviderFactories: factory.MustNewNamedMap(
|
SQLMigrationProviderFactories: factory.MustNewNamedMap(
|
||||||
sqlmigration.NewAddDataMigrationsFactory(),
|
sqlmigration.NewAddDataMigrationsFactory(),
|
||||||
|
@ -30,11 +30,11 @@ type Site struct {
|
|||||||
type FeatureStatus struct {
|
type FeatureStatus struct {
|
||||||
bun.BaseModel `bun:"table:feature_status"`
|
bun.BaseModel `bun:"table:feature_status"`
|
||||||
|
|
||||||
Name string `bun:"name,pk,type:text"`
|
Name string `bun:"name,pk,type:text" json:"name"`
|
||||||
Active bool `bun:"active"`
|
Active bool `bun:"active" json:"active"`
|
||||||
Usage int `bun:"usage,default:0"`
|
Usage int `bun:"usage,default:0" json:"usage"`
|
||||||
UsageLimit int `bun:"usage_limit,default:0"`
|
UsageLimit int `bun:"usage_limit,default:0" json:"usage_limit"`
|
||||||
Route string `bun:"route,type:text"`
|
Route string `bun:"route,type:text" json:"route"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type LicenseV3 struct {
|
type LicenseV3 struct {
|
||||||
|
@ -31,8 +31,8 @@ type Invite struct {
|
|||||||
|
|
||||||
type Group struct {
|
type Group struct {
|
||||||
bun.BaseModel `bun:"table:groups"`
|
bun.BaseModel `bun:"table:groups"`
|
||||||
ID string `bun:"id,pk,type:text"`
|
ID string `bun:"id,pk,type:text" json:"id"`
|
||||||
Name string `bun:"name,type:text,notnull,unique"`
|
Name string `bun:"name,type:text,notnull,unique" json:"name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user