Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

fix: signoz shouldn't panic with postgres provider (#7138)

Nityananda Gohaineba2049a4d08
diff --git a/ee/query-service/app/api/cloudIntegrations.go b/ee/query-service/app/api/cloudIntegrations.go
index 8f7568480b..da1f482688 100644
--- a/ee/query-service/app/api/cloudIntegrations.go
+++ b/ee/query-service/app/api/cloudIntegrations.go
@@ -183,7 +183,7 @@ func (ah *APIHandler) getOrCreateCloudIntegrationUser(
if apiErr != nil {
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())
if err != nil {
diff --git a/ee/query-service/app/server.go b/ee/query-service/app/server.go
index 8ed5c83d75..99bb42df70 100644
--- a/ee/query-service/app/server.go
+++ b/ee/query-service/app/server.go
@@ -105,7 +105,7 @@ func (s Server) HealthCheckStatus() chan healthcheck.Status {
// NewServer creates and initializes Server
func NewServer(serverOptions *ServerOptions) (*Server, error) {
- modelDao, err := dao.InitDao(serverOptions.SigNoz.SQLStore.SQLxDB())
+ modelDao, err := dao.InitDao(serverOptions.SigNoz.SQLStore)
if err != nil {
return nil, err
}
@@ -128,7 +128,7 @@ func NewServer(serverOptions *ServerOptions) (*Server, error) {
}
// 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 {
return nil, err
}
@@ -197,14 +197,14 @@ func NewServer(serverOptions *ServerOptions) (*Server, error) {
return nil, err
}
- integrationsController, err := integrations.NewController(serverOptions.SigNoz.SQLStore.SQLxDB())
+ integrationsController, err := integrations.NewController(serverOptions.SigNoz.SQLStore)
if err != nil {
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 {
return nil, fmt.Errorf(
"couldn't create cloud provider integrations controller: %w", err,
diff --git a/ee/query-service/auth/auth.go b/ee/query-service/auth/auth.go
index ebaefa700d..11fdb5a7da 100644
--- a/ee/query-service/auth/auth.go
+++ b/ee/query-service/auth/auth.go
@@ -40,7 +40,7 @@ func GetUserFromRequestContext(ctx context.Context, apiHandler *api.APIHandler)
}
telemetry.GetInstance().SetPatTokenUser()
dao.UpdatePATLastUsed(ctx, patToken, time.Now().Unix())
- user.User.GroupId = group.Id
+ user.User.GroupId = group.ID
user.User.Id = pat.Id
return &basemodel.UserPayload{
User: user.User,
diff --git a/ee/query-service/dao/factory.go b/ee/query-service/dao/factory.go
index 2db8404bd1..3da11bad0c 100644
--- a/ee/query-service/dao/factory.go
+++ b/ee/query-service/dao/factory.go
@@ -1,10 +1,10 @@
package dao
import (
- "github.com/jmoiron/sqlx"
"go.signoz.io/signoz/ee/query-service/dao/sqlite"
+ "go.signoz.io/signoz/pkg/sqlstore"
)
-func InitDao(inputDB *sqlx.DB) (ModelDao, error) {
- return sqlite.InitDB(inputDB)
+func InitDao(sqlStore sqlstore.SQLStore) (ModelDao, error) {
+ return sqlite.InitDB(sqlStore)
}
diff --git a/ee/query-service/dao/sqlite/auth.go b/ee/query-service/dao/sqlite/auth.go
index f97a6736be..ca7df0fd14 100644
--- a/ee/query-service/dao/sqlite/auth.go
+++ b/ee/query-service/dao/sqlite/auth.go
@@ -49,7 +49,7 @@ func (m *modelDao) createUserForSAMLRequest(ctx context.Context, email string) (
Password: hash,
CreatedAt: time.Now().Unix(),
ProfilePictureURL: "", // Currently unused
- GroupId: group.Id,
+ GroupId: group.ID,
OrgId: domain.OrgId,
}
diff --git a/ee/query-service/dao/sqlite/modelDao.go b/ee/query-service/dao/sqlite/modelDao.go
index 43b1088248..64064ef01b 100644
--- a/ee/query-service/dao/sqlite/modelDao.go
+++ b/ee/query-service/dao/sqlite/modelDao.go
@@ -7,6 +7,7 @@ import (
basedao "go.signoz.io/signoz/pkg/query-service/dao"
basedsql "go.signoz.io/signoz/pkg/query-service/dao/sqlite"
baseint "go.signoz.io/signoz/pkg/query-service/interfaces"
+ "go.signoz.io/signoz/pkg/sqlstore"
)
type modelDao struct {
@@ -29,8 +30,8 @@ func (m *modelDao) checkFeature(key string) error {
}
// InitDB creates and extends base model DB repository
-func InitDB(inputDB *sqlx.DB) (*modelDao, error) {
- dao, err := basedsql.InitDB(inputDB)
+func InitDB(sqlStore sqlstore.SQLStore) (*modelDao, error) {
+ dao, err := basedsql.InitDB(sqlStore)
if err != nil {
return nil, err
}
diff --git a/ee/query-service/license/db.go b/ee/query-service/license/db.go
index cd60e163e0..021dc2b676 100644
--- a/ee/query-service/license/db.go
+++ b/ee/query-service/license/db.go
@@ -9,21 +9,25 @@ import (
"github.com/jmoiron/sqlx"
"github.com/mattn/go-sqlite3"
+ "github.com/uptrace/bun"
"go.signoz.io/signoz/ee/query-service/model"
basemodel "go.signoz.io/signoz/pkg/query-service/model"
+ "go.signoz.io/signoz/pkg/types"
"go.uber.org/zap"
)
// Repo is license repo. stores license keys in a secured DB
type Repo struct {
- db *sqlx.DB
+ db *sqlx.DB
+ bundb *bun.DB
}
// NewLicenseRepo initiates a new license repo
-func NewLicenseRepo(db *sqlx.DB) Repo {
+func NewLicenseRepo(db *sqlx.DB, bundb *bun.DB) 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
}
-func (r *Repo) CreateFeature(req *basemodel.Feature) *basemodel.ApiError {
+func (r *Repo) CreateFeature(req *types.FeatureStatus) *basemodel.ApiError {
- _, err := r.db.Exec(
- `INSERT INTO feature_status (name, active, usage, usage_limit, route)
- VALUES (?, ?, ?, ?, ?);`,
- req.Name, req.Active, req.Usage, req.UsageLimit, req.Route)
+ _, err := r.bundb.NewInsert().
+ Model(req).
+ Exec(context.Background())
if err != nil {
return &basemodel.ApiError{Typ: basemodel.ErrorInternal, Err: err}
}
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 {
return feature, err
}
@@ -205,18 +210,19 @@ func (r *Repo) GetAllFeatures() ([]basemodel.Feature, error) {
return feature, nil
}
-func (r *Repo) UpdateFeature(req basemodel.Feature) error {
+func (r *Repo) UpdateFeature(req types.FeatureStatus) error {
- _, err := r.db.Exec(
- `UPDATE feature_status SET active = ?, usage = ?, usage_limit = ?, route = ? WHERE name = ?;`,
- req.Active, req.Usage, req.UsageLimit, req.Route, req.Name)
+ _, err := r.bundb.NewUpdate().
+ Model(&req).
+ Where("name = ?", req.Name).
+ Exec(context.Background())
if err != nil {
return err
}
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.
for _, feature := range req {
currentFeature, err := r.GetFeature(feature.Name)
@@ -229,7 +235,7 @@ func (r *Repo) InitFeatures(req basemodel.FeatureSet) error {
} else if err != nil {
return err
}
- feature.Usage = currentFeature.Usage
+ feature.Usage = int(currentFeature.Usage)
if feature.Usage >= feature.UsageLimit && feature.UsageLimit != -1 {
feature.Active = false
}
diff --git a/ee/query-service/license/manager.go b/ee/query-service/license/manager.go
index 992490e644..6ba862a1f6 100644
--- a/ee/query-service/license/manager.go
+++ b/ee/query-service/license/manager.go
@@ -7,10 +7,12 @@ import (
"github.com/jmoiron/sqlx"
"github.com/pkg/errors"
+ "github.com/uptrace/bun"
"sync"
baseconstants "go.signoz.io/signoz/pkg/query-service/constants"
+ "go.signoz.io/signoz/pkg/types"
"go.signoz.io/signoz/pkg/types/authtypes"
validate "go.signoz.io/signoz/ee/query-service/integrations/signozio"
@@ -43,12 +45,12 @@ type Manager struct {
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 {
return LM, nil
}
- repo := NewLicenseRepo(db)
+ repo := NewLicenseRepo(db, bundb)
m := &Manager{
repo: &repo,
}
@@ -282,15 +284,41 @@ func (lm *Manager) GetFeatureFlags() (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 {
- 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) {
- 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
diff --git a/pkg/query-service/app/cloudintegrations/controller.go b/pkg/query-service/app/cloudintegrations/controller.go
index 3647a74774..5260cda54e 100644
--- a/pkg/query-service/app/cloudintegrations/controller.go
+++ b/pkg/query-service/app/cloudintegrations/controller.go
@@ -8,9 +8,9 @@ import (
"strings"
"time"
- "github.com/jmoiron/sqlx"
"go.signoz.io/signoz/pkg/query-service/app/dashboards"
"go.signoz.io/signoz/pkg/query-service/model"
+ "go.signoz.io/signoz/pkg/sqlstore"
"golang.org/x/exp/maps"
)
@@ -30,15 +30,15 @@ type Controller struct {
serviceConfigRepo serviceConfigRepository
}
-func NewController(db *sqlx.DB) (
+func NewController(sqlStore sqlstore.SQLStore) (
*Controller, error,
) {
- accountsRepo, err := newCloudProviderAccountsRepository(db)
+ accountsRepo, err := newCloudProviderAccountsRepository(sqlStore.SQLxDB())
if err != nil {
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 {
return nil, fmt.Errorf("couldn't create cloud provider service config repo: %w", err)
}
diff --git a/pkg/query-service/app/cloudintegrations/controller_test.go b/pkg/query-service/app/cloudintegrations/controller_test.go
index 70673f457d..8bf4e73680 100644
--- a/pkg/query-service/app/cloudintegrations/controller_test.go
+++ b/pkg/query-service/app/cloudintegrations/controller_test.go
@@ -12,8 +12,8 @@ import (
func TestRegenerateConnectionUrlWithUpdatedConfig(t *testing.T) {
require := require.New(t)
- testDB, _ := utils.NewTestSqliteDB(t)
- controller, err := NewController(testDB)
+ sqlStore, _ := utils.NewTestSqliteDB(t)
+ controller, err := NewController(sqlStore)
require.NoError(err)
// should be able to generate connection url for
@@ -56,8 +56,8 @@ func TestRegenerateConnectionUrlWithUpdatedConfig(t *testing.T) {
func TestAgentCheckIns(t *testing.T) {
require := require.New(t)
- testDB, _ := utils.NewTestSqliteDB(t)
- controller, err := NewController(testDB)
+ sqlStore, _ := utils.NewTestSqliteDB(t)
+ controller, err := NewController(sqlStore)
require.NoError(err)
// 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) {
require := require.New(t)
- testDB, _ := utils.NewTestSqliteDB(t)
- controller, err := NewController(testDB)
+ sqlStore, _ := utils.NewTestSqliteDB(t)
+ controller, err := NewController(sqlStore)
require.NoError(err)
// Attempting to disconnect a non-existent account should return error
@@ -154,8 +154,8 @@ func TestCantDisconnectNonExistentAccount(t *testing.T) {
func TestConfigureService(t *testing.T) {
require := require.New(t)
- testDB, _ := utils.NewTestSqliteDB(t)
- controller, err := NewController(testDB)
+ sqlStore, _ := utils.NewTestSqliteDB(t)
+ controller, err := NewController(sqlStore)
require.NoError(err)
testCloudAccountId := "546311234"
diff --git a/pkg/query-service/app/http_handler.go b/pkg/query-service/app/http_handler.go
index 9072b3a891..bc5593284c 100644
--- a/pkg/query-service/app/http_handler.go
+++ b/pkg/query-service/app/http_handler.go
@@ -2285,13 +2285,13 @@ func (aH *APIHandler) deleteUser(w http.ResponseWriter, r *http.Request) {
RespondError(w, apiErr, "Failed to get admin group")
return
}
- adminUsers, apiErr := dao.DB().GetUsersByGroup(ctx, adminGroup.Id)
+ adminUsers, apiErr := dao.DB().GetUsersByGroup(ctx, adminGroup.ID)
if apiErr != nil {
RespondError(w, apiErr, "Failed to get admin group users")
return
}
- if user.GroupId == adminGroup.Id && len(adminUsers) == 1 {
+ if user.GroupId == adminGroup.ID && len(adminUsers) == 1 {
RespondError(w, &model.ApiError{
Typ: model.ErrorInternal,
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 {
RespondError(w, apiErr, "Failed to add user to group")
return
diff --git a/pkg/query-service/app/integrations/controller.go b/pkg/query-service/app/integrations/controller.go
index 530bf40c3c..5bfee3eb2b 100644
--- a/pkg/query-service/app/integrations/controller.go
+++ b/pkg/query-service/app/integrations/controller.go
@@ -4,21 +4,21 @@ import (
"context"
"fmt"
- "github.com/jmoiron/sqlx"
"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/logparsingpipeline"
"go.signoz.io/signoz/pkg/query-service/model"
+ "go.signoz.io/signoz/pkg/sqlstore"
)
type Controller struct {
mgr *Manager
}
-func NewController(db *sqlx.DB) (
+func NewController(sqlStore sqlstore.SQLStore) (
*Controller, error,
) {
- mgr, err := NewManager(db)
+ mgr, err := NewManager(sqlStore.SQLxDB())
if err != nil {
return nil, fmt.Errorf("couldn't create integrations manager: %w", err)
}
diff --git a/pkg/query-service/app/integrations/test_utils.go b/pkg/query-service/app/integrations/test_utils.go
index adb667b96e..18fbf1c461 100644
--- a/pkg/query-service/app/integrations/test_utils.go
+++ b/pkg/query-service/app/integrations/test_utils.go
@@ -16,7 +16,7 @@ import (
func NewTestIntegrationsManager(t *testing.T) *Manager {
testDB := utils.NewQueryServiceDBForTests(t)
- installedIntegrationsRepo, err := NewInstalledIntegrationsSqliteRepo(testDB)
+ installedIntegrationsRepo, err := NewInstalledIntegrationsSqliteRepo(testDB.SQLxDB())
if err != nil {
t.Fatalf("could not init sqlite DB for installed integrations: %v", err)
}
diff --git a/pkg/query-service/app/opamp/config_provider_test.go b/pkg/query-service/app/opamp/config_provider_test.go
index 1a6efe122a..99b7b1c965 100644
--- a/pkg/query-service/app/opamp/config_provider_test.go
+++ b/pkg/query-service/app/opamp/config_provider_test.go
@@ -166,7 +166,7 @@ type testbed struct {
func newTestbed(t *testing.T) *testbed {
testDB := utils.NewQueryServiceDBForTests(t)
- _, err := model.InitDB(testDB)
+ _, err := model.InitDB(testDB.SQLxDB())
if err != nil {
t.Fatalf("could not init opamp model: %v", err)
}
diff --git a/pkg/query-service/app/server.go b/pkg/query-service/app/server.go
index 21549bdc9f..3101bf9306 100644
--- a/pkg/query-service/app/server.go
+++ b/pkg/query-service/app/server.go
@@ -91,7 +91,7 @@ func (s Server) HealthCheckStatus() chan healthcheck.Status {
// NewServer creates and initializes Server
func NewServer(serverOptions *ServerOptions) (*Server, 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
}
@@ -163,12 +163,12 @@ func NewServer(serverOptions *ServerOptions) (*Server, error) {
return nil, err
}
- integrationsController, err := integrations.NewController(serverOptions.SigNoz.SQLStore.SQLxDB())
+ integrationsController, err := integrations.NewController(serverOptions.SigNoz.SQLStore)
if err != nil {
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 {
return nil, fmt.Errorf("couldn't create cloud provider integrations controller: %w", err)
}
diff --git a/pkg/query-service/auth/auth.go b/pkg/query-service/auth/auth.go
index 708bf9585b..4ca00707ea 100644
--- a/pkg/query-service/auth/auth.go
+++ b/pkg/query-service/auth/auth.go
@@ -421,7 +421,7 @@ func RegisterFirstUser(ctx context.Context, req *RegisterRequest) (*model.User,
Password: hash,
CreatedAt: time.Now().Unix(),
ProfilePictureURL: "", // Currently unused
- GroupId: group.Id,
+ GroupId: group.ID,
OrgId: org.Id,
}
@@ -499,7 +499,7 @@ func RegisterInvitedUser(ctx context.Context, req *RegisterRequest, nopassword b
Password: hash,
CreatedAt: time.Now().Unix(),
ProfilePictureURL: "", // Currently unused
- GroupId: group.Id,
+ GroupId: group.ID,
OrgId: invite.OrgId,
}
diff --git a/pkg/query-service/auth/rbac.go b/pkg/query-service/auth/rbac.go
index e5fe687b2c..9575c0d7f9 100644
--- a/pkg/query-service/auth/rbac.go
+++ b/pkg/query-service/auth/rbac.go
@@ -31,7 +31,7 @@ func InitAuthCache(ctx context.Context) error {
if err != nil {
return errors.Wrapf(err.Err, "failed to get group %s", groupName)
}
- *dest = group.Id
+ *dest = group.ID
return nil
}
diff --git a/pkg/query-service/dao/factory.go b/pkg/query-service/dao/factory.go
index 02d50158fd..c403c4f1ea 100644
--- a/pkg/query-service/dao/factory.go
+++ b/pkg/query-service/dao/factory.go
@@ -1,15 +1,15 @@
package dao
import (
- "github.com/jmoiron/sqlx"
"go.signoz.io/signoz/pkg/query-service/dao/sqlite"
+ "go.signoz.io/signoz/pkg/sqlstore"
)
var db ModelDao
-func InitDao(inputDB *sqlx.DB) error {
+func InitDao(sqlStore sqlstore.SQLStore) error {
var err error
- db, err = sqlite.InitDB(inputDB)
+ db, err = sqlite.InitDB(sqlStore)
if err != nil {
return err
}
diff --git a/pkg/query-service/dao/interface.go b/pkg/query-service/dao/interface.go
index 9f99d67c74..68fdfb0088 100644
--- a/pkg/query-service/dao/interface.go
+++ b/pkg/query-service/dao/interface.go
@@ -4,6 +4,7 @@ import (
"context"
"go.signoz.io/signoz/pkg/query-service/model"
+ "go.signoz.io/signoz/pkg/types"
)
type ModelDao interface {
@@ -22,7 +23,7 @@ type Queries interface {
GetUsersWithOpts(ctx context.Context, limit int) ([]model.UserPayload, *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)
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)
- 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
CreateOrg(ctx context.Context, org *model.Organization) (*model.Organization, *model.ApiError)
diff --git a/pkg/query-service/dao/sqlite/connection.go b/pkg/query-service/dao/sqlite/connection.go
index 40b24f097b..697b1b3797 100644
--- a/pkg/query-service/dao/sqlite/connection.go
+++ b/pkg/query-service/dao/sqlite/connection.go
@@ -5,19 +5,23 @@ import (
"github.com/jmoiron/sqlx"
"github.com/pkg/errors"
+ "github.com/uptrace/bun"
"go.signoz.io/signoz/pkg/query-service/constants"
"go.signoz.io/signoz/pkg/query-service/model"
"go.signoz.io/signoz/pkg/query-service/telemetry"
+ "go.signoz.io/signoz/pkg/sqlstore"
+ "go.signoz.io/signoz/pkg/types"
"go.uber.org/zap"
)
type ModelDaoSqlite struct {
- db *sqlx.DB
+ db *sqlx.DB
+ bundb *bun.DB
}
// InitDB sets up setting up the connection pool global variable.
-func InitDB(db *sqlx.DB) (*ModelDaoSqlite, error) {
- mds := &ModelDaoSqlite{db: db}
+func InitDB(sqlStore sqlstore.SQLStore) (*ModelDaoSqlite, error) {
+ mds := &ModelDaoSqlite{db: sqlStore.SQLxDB(), bundb: sqlStore.BunDB()}
ctx := context.Background()
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,
- name string) (*model.Group, error) {
+ name string) (*types.Group, error) {
group, err := mds.GetGroupByName(ctx, name)
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))
- group, cErr := mds.CreateGroup(ctx, &model.Group{Name: name})
+ group, cErr := mds.CreateGroup(ctx, &types.Group{Name: name})
if cErr != nil {
return nil, cErr.Err
}
diff --git a/pkg/query-service/dao/sqlite/rbac.go b/pkg/query-service/dao/sqlite/rbac.go
index 7eaabed214..799baffa2c 100644
--- a/pkg/query-service/dao/sqlite/rbac.go
+++ b/pkg/query-service/dao/sqlite/rbac.go
@@ -10,6 +10,7 @@ import (
"github.com/pkg/errors"
"go.signoz.io/signoz/pkg/query-service/model"
"go.signoz.io/signoz/pkg/query-service/telemetry"
+ "go.signoz.io/signoz/pkg/types"
)
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,
- 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.db.ExecContext(ctx, q, group.Id, group.Name); err != nil {
+ if _, err := mds.bundb.NewInsert().
+ Model(group).
+ Exec(ctx); err != nil {
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,
- name string) (*model.Group, *model.ApiError) {
+ name string) (*types.Group, *model.ApiError) {
- groups := []model.Group{}
- if err := mds.db.Select(&groups, `SELECT id, name FROM groups WHERE name=?`, name); err != nil {
+ groups := []types.Group{}
+ err := mds.bundb.NewSelect().
+ Model(&groups).
+ Where("name = ?", name).
+ Scan(ctx)
+ if err != nil {
return nil, &model.ApiError{Typ: model.ErrorInternal, Err: err}
}
diff --git a/pkg/query-service/tests/integration/filter_suggestions_test.go b/pkg/query-service/tests/integration/filter_suggestions_test.go
index 4fa9dff51e..3fd05afa0b 100644
--- a/pkg/query-service/tests/integration/filter_suggestions_test.go
+++ b/pkg/query-service/tests/integration/filter_suggestions_test.go
@@ -293,7 +293,7 @@ func NewFilterSuggestionsTestBed(t *testing.T) *FilterSuggestionsTestBed {
testDB := utils.NewQueryServiceDBForTests(t)
fm := featureManager.StartManager()
- reader, mockClickhouse := NewMockClickhouseReader(t, testDB, fm)
+ reader, mockClickhouse := NewMockClickhouseReader(t, testDB.SQLxDB(), fm)
mockClickhouse.MatchExpectationsInOrder(false)
apiHandler, err := app.NewAPIHandler(app.APIHandlerOpts{
diff --git a/pkg/query-service/tests/integration/logparsingpipeline_test.go b/pkg/query-service/tests/integration/logparsingpipeline_test.go
index 7c0b218168..e7b588a9c8 100644
--- a/pkg/query-service/tests/integration/logparsingpipeline_test.go
+++ b/pkg/query-service/tests/integration/logparsingpipeline_test.go
@@ -11,7 +11,6 @@ import (
"github.com/google/uuid"
"github.com/gorilla/mux"
- "github.com/jmoiron/sqlx"
"github.com/knadh/koanf/parsers/yaml"
"github.com/open-telemetry/opamp-go/protobufs"
"github.com/pkg/errors"
@@ -28,6 +27,7 @@ import (
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/utils"
+ "go.signoz.io/signoz/pkg/sqlstore"
"golang.org/x/exp/maps"
"golang.org/x/exp/slices"
)
@@ -449,18 +449,18 @@ type LogPipelinesTestBed struct {
}
// testDB can be injected for sharing a DB across multiple integration testbeds.
-func NewTestbedWithoutOpamp(t *testing.T, testDB *sqlx.DB) *LogPipelinesTestBed {
- if testDB == nil {
- testDB = utils.NewQueryServiceDBForTests(t)
+func NewTestbedWithoutOpamp(t *testing.T, sqlStore sqlstore.SQLStore) *LogPipelinesTestBed {
+ if sqlStore == nil {
+ sqlStore = utils.NewQueryServiceDBForTests(t)
}
- ic, err := integrations.NewController(testDB)
+ ic, err := integrations.NewController(sqlStore)
if err != nil {
t.Fatalf("could not create integrations controller: %v", err)
}
controller, err := logparsingpipeline.NewLogParsingPipelinesController(
- testDB, ic.GetPipelinesForInstalledIntegrations,
+ sqlStore.SQLxDB(), ic.GetPipelinesForInstalledIntegrations,
)
if err != nil {
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
- testDB, err = opampModel.InitDB(testDB)
+ testDB, err := opampModel.InitDB(sqlStore.SQLxDB())
require.Nil(t, err, "failed to init opamp model")
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)
opampServer := opamp.InitializeServer(nil, testbed.agentConfMgr)
diff --git a/pkg/query-service/tests/integration/signoz_cloud_integrations_test.go b/pkg/query-service/tests/integration/signoz_cloud_integrations_test.go
index 7de502a563..7bc22e0d68 100644
--- a/pkg/query-service/tests/integration/signoz_cloud_integrations_test.go
+++ b/pkg/query-service/tests/integration/signoz_cloud_integrations_test.go
@@ -9,7 +9,6 @@ import (
"time"
"github.com/google/uuid"
- "github.com/jmoiron/sqlx"
mockhouse "github.com/srikanthccv/ClickHouse-go-mock"
"github.com/stretchr/testify/require"
"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/model"
"go.signoz.io/signoz/pkg/query-service/utils"
+ "go.signoz.io/signoz/pkg/sqlstore"
"go.uber.org/zap"
)
@@ -344,7 +344,7 @@ type CloudIntegrationsTestBed struct {
}
// 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 {
testDB = utils.NewQueryServiceDBForTests(t)
}
@@ -355,7 +355,7 @@ func NewCloudIntegrationsTestBed(t *testing.T, testDB *sqlx.DB) *CloudIntegratio
}
fm := featureManager.StartManager()
- reader, mockClickhouse := NewMockClickhouseReader(t, testDB, fm)
+ reader, mockClickhouse := NewMockClickhouseReader(t, testDB.SQLxDB(), fm)
mockClickhouse.MatchExpectationsInOrder(false)
apiHandler, err := app.NewAPIHandler(app.APIHandlerOpts{
diff --git a/pkg/query-service/tests/integration/signoz_integrations_test.go b/pkg/query-service/tests/integration/signoz_integrations_test.go
index 92308aafc5..f70797d8ef 100644
--- a/pkg/query-service/tests/integration/signoz_integrations_test.go
+++ b/pkg/query-service/tests/integration/signoz_integrations_test.go
@@ -8,7 +8,6 @@ import (
"testing"
"time"
- "github.com/jmoiron/sqlx"
mockhouse "github.com/srikanthccv/ClickHouse-go-mock"
"github.com/stretchr/testify/require"
"go.signoz.io/signoz/pkg/http/middleware"
@@ -23,6 +22,7 @@ import (
"go.signoz.io/signoz/pkg/query-service/model"
v3 "go.signoz.io/signoz/pkg/query-service/model/v3"
"go.signoz.io/signoz/pkg/query-service/utils"
+ "go.signoz.io/signoz/pkg/sqlstore"
"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.
-func NewIntegrationsTestBed(t *testing.T, testDB *sqlx.DB) *IntegrationsTestBed {
+func NewIntegrationsTestBed(t *testing.T, testDB sqlstore.SQLStore) *IntegrationsTestBed {
if testDB == nil {
testDB = utils.NewQueryServiceDBForTests(t)
}
@@ -557,7 +557,7 @@ func NewIntegrationsTestBed(t *testing.T, testDB *sqlx.DB) *IntegrationsTestBed
}
fm := featureManager.StartManager()
- reader, mockClickhouse := NewMockClickhouseReader(t, testDB, fm)
+ reader, mockClickhouse := NewMockClickhouseReader(t, testDB.SQLxDB(), fm)
mockClickhouse.MatchExpectationsInOrder(false)
cloudIntegrationsController, err := cloudintegrations.NewController(testDB)
diff --git a/pkg/query-service/tests/integration/test_utils.go b/pkg/query-service/tests/integration/test_utils.go
index 8e0fbf6480..af68e41047 100644
--- a/pkg/query-service/tests/integration/test_utils.go
+++ b/pkg/query-service/tests/integration/test_utils.go
@@ -176,7 +176,7 @@ func createTestUser() (*model.User, *model.ApiError) {
Email: userId[:8] + "[email protected]",
Password: "test",
OrgId: org.Id,
- GroupId: group.Id,
+ GroupId: group.ID,
},
true,
)
diff --git a/pkg/query-service/utils/testutils.go b/pkg/query-service/utils/testutils.go
index e0833dd4b1..4c008e3b85 100644
--- a/pkg/query-service/utils/testutils.go
+++ b/pkg/query-service/utils/testutils.go
@@ -5,7 +5,6 @@ import (
"os"
"testing"
- "github.com/jmoiron/sqlx"
_ "github.com/mattn/go-sqlite3"
"go.signoz.io/signoz/pkg/factory"
"go.signoz.io/signoz/pkg/factory/providertest"
@@ -17,7 +16,7 @@ import (
"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-*")
if err != nil {
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) })
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 {
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)
}
- 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 {
t.Fatalf("could not migrate test db sql migrations: %v", err)
}
- testDB = sqlstore.SQLxDB()
-
- return testDB, testDBFilePath
+ return sqlStore, testDBFilePath
}
-func NewQueryServiceDBForTests(t *testing.T) *sqlx.DB {
- testDB, _ := NewTestSqliteDB(t)
+func NewQueryServiceDBForTests(t *testing.T) sqlstore.SQLStore {
+ sqlStore, _ := NewTestSqliteDB(t)
- // TODO(Raj): This should not require passing in the DB file path
- dao.InitDao(testDB)
- dashboards.InitDB(testDB)
+ dao.InitDao(sqlStore)
+ dashboards.InitDB(sqlStore.SQLxDB())
- return testDB
+ return sqlStore
}
diff --git a/pkg/signoz/provider.go b/pkg/signoz/provider.go
index d23833415b..04bff4b738 100644
--- a/pkg/signoz/provider.go
+++ b/pkg/signoz/provider.go
@@ -7,6 +7,7 @@ import (
"go.signoz.io/signoz/pkg/factory"
"go.signoz.io/signoz/pkg/sqlmigration"
"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/sqlstorehook"
"go.signoz.io/signoz/pkg/telemetrystore"
@@ -46,7 +47,7 @@ func NewProviderConfig() ProviderConfig {
),
SQLStoreProviderFactories: factory.MustNewNamedMap(
sqlitesqlstore.NewFactory(sqlstorehook.NewLoggingFactory()),
- // postgressqlstore.NewFactory(),
+ postgressqlstore.NewFactory(sqlstorehook.NewLoggingFactory()),
),
SQLMigrationProviderFactories: factory.MustNewNamedMap(
sqlmigration.NewAddDataMigrationsFactory(),
diff --git a/pkg/types/license.go b/pkg/types/license.go
index ddeadedfdb..fb9fd7e6d0 100644
--- a/pkg/types/license.go
+++ b/pkg/types/license.go
@@ -30,11 +30,11 @@ type Site struct {
type FeatureStatus struct {
bun.BaseModel `bun:"table:feature_status"`
- Name string `bun:"name,pk,type:text"`
- Active bool `bun:"active"`
- Usage int `bun:"usage,default:0"`
- UsageLimit int `bun:"usage_limit,default:0"`
- Route string `bun:"route,type:text"`
+ Name string `bun:"name,pk,type:text" json:"name"`
+ Active bool `bun:"active" json:"active"`
+ Usage int `bun:"usage,default:0" json:"usage"`
+ UsageLimit int `bun:"usage_limit,default:0" json:"usage_limit"`
+ Route string `bun:"route,type:text" json:"route"`
}
type LicenseV3 struct {
diff --git a/pkg/types/organization.go b/pkg/types/organization.go
index 51a87bbb45..32da1a2601 100644
--- a/pkg/types/organization.go
+++ b/pkg/types/organization.go
@@ -31,8 +31,8 @@ type Invite struct {
type Group struct {
bun.BaseModel `bun:"table:groups"`
- ID string `bun:"id,pk,type:text"`
- Name string `bun:"name,type:text,notnull,unique"`
+ ID string `bun:"id,pk,type:text" json:"id"`
+ Name string `bun:"name,type:text,notnull,unique" json:"name"`
}
type User struct {