fix: minor changes

This commit is contained in:
nityanandagohain
2025-03-26 22:34:52 +05:30
parent 25044875d9
commit 1120a97c81
10 changed files with 38 additions and 26 deletions

View File

@@ -199,7 +199,7 @@ func StartNewVersion(
) (*types.AgentConfigVersion, *model.ApiError) {
// create a new version
cfg := types.NewAgentConfigVersion(eleType)
cfg := types.NewAgentConfigVersion(orgId, eleType)
// insert new config and elements into database
err := m.insertConfig(ctx, orgId, userId, cfg, elementIds)

View File

@@ -3814,9 +3814,14 @@ func (aH *APIHandler) InstallIntegration(
RespondError(w, model.BadRequest(err), nil)
return
}
claims, ok := authtypes.ClaimsFromContext(r.Context())
if !ok {
RespondError(w, model.UnauthorizedError(errors.New("unauthorized")), nil)
return
}
integration, apiErr := aH.IntegrationsController.Install(
r.Context(), &req,
r.Context(), claims.OrgID, &req,
)
if apiErr != nil {
RespondError(w, apiErr, nil)
@@ -3836,8 +3841,13 @@ func (aH *APIHandler) UninstallIntegration(
RespondError(w, model.BadRequest(err), nil)
return
}
claims, ok := authtypes.ClaimsFromContext(r.Context())
if !ok {
RespondError(w, model.UnauthorizedError(errors.New("unauthorized")), nil)
return
}
apiErr := aH.IntegrationsController.Uninstall(r.Context(), &req)
apiErr := aH.IntegrationsController.Uninstall(r.Context(), claims.OrgID, &req)
if apiErr != nil {
RespondError(w, apiErr, nil)
return

View File

@@ -87,7 +87,7 @@ type InstallIntegrationRequest struct {
}
func (c *Controller) Install(
ctx context.Context, req *InstallIntegrationRequest,
ctx context.Context, orgId string, req *InstallIntegrationRequest,
) (*IntegrationsListItem, *model.ApiError) {
res, apiErr := c.mgr.InstallIntegration(
ctx, req.IntegrationId, req.Config,
@@ -104,7 +104,7 @@ type UninstallIntegrationRequest struct {
}
func (c *Controller) Uninstall(
ctx context.Context, req *UninstallIntegrationRequest,
ctx context.Context, orgId string, req *UninstallIntegrationRequest,
) *model.ApiError {
if len(req.IntegrationId) < 1 {
return model.BadRequest(fmt.Errorf(

View File

@@ -22,7 +22,7 @@ func TestOpAMPServerToAgentCommunicationWithConfigProvider(t *testing.T) {
tb := newTestbed(t)
orgID, err := utils.GetTestOrgId(t, tb.sqlStore)
orgID, err := utils.GetTestOrgId(tb.sqlStore)
require.Nil(err)
require.Equal(

View File

@@ -7,6 +7,7 @@ import (
"sync"
"time"
"github.com/SigNoz/signoz/pkg/sqlstore"
"github.com/SigNoz/signoz/pkg/types"
"go.uber.org/zap"
"google.golang.org/protobuf/proto"
@@ -29,14 +30,15 @@ type Agent struct {
conn opampTypes.Connection
connMutex sync.Mutex
mux sync.RWMutex
store sqlstore.SQLStore
}
// set in agent description when agent is capable of supporting
// lb exporter configuration. values: 1 (true) or 0 (false)
const lbExporterFlag = "capabilities.lbexporter"
func New(orgID string, ID string, conn opampTypes.Connection) *Agent {
return &Agent{StorableAgent: types.StorableAgent{OrgID: orgID, AgentID: ID, StartedAt: time.Now(), CurrentStatus: types.AgentStatusConnected}, conn: conn}
func New(store sqlstore.SQLStore, orgID string, ID string, conn opampTypes.Connection) *Agent {
return &Agent{StorableAgent: types.StorableAgent{OrgID: orgID, AgentID: ID, StartedAt: time.Now(), CurrentStatus: types.AgentStatusConnected}, conn: conn, store: store}
}
// Upsert inserts or updates the agent in the database.
@@ -44,7 +46,7 @@ func (agent *Agent) Upsert() error {
agent.mux.Lock()
defer agent.mux.Unlock()
_, err := store.BunDB().NewInsert().
_, err := agent.store.BunDB().NewInsert().
Model(&agent.StorableAgent).
On("CONFLICT (org_id, agent_id) DO UPDATE").
Set("started_at = EXCLUDED.started_at").

View File

@@ -13,8 +13,6 @@ import (
"go.uber.org/zap"
)
var store sqlstore.SQLStore
var AllAgents = Agents{
agentsById: map[string]*Agent{},
connections: map[types.Connection]map[string]bool{},
@@ -24,6 +22,7 @@ type Agents struct {
mux sync.RWMutex
agentsById map[string]*Agent
connections map[types.Connection]map[string]bool
store sqlstore.SQLStore
}
func (a *Agents) Count() int {
@@ -32,12 +31,12 @@ func (a *Agents) Count() int {
// Initialize the database and create schema if needed
func InitDB(sqlStore sqlstore.SQLStore) {
store = sqlStore
AllAgents = Agents{
agentsById: make(map[string]*Agent),
connections: make(map[types.Connection]map[string]bool),
mux: sync.RWMutex{},
store: sqlStore,
}
}
@@ -80,7 +79,7 @@ func (agents *Agents) FindOrCreateAgent(agentID string, conn types.Connection, o
return nil, false, errors.New("cannot create agent without orgId")
}
agent = New(orgId, agentID, conn)
agent = New(agents.store, orgId, agentID, conn)
err := agent.Upsert()
if err != nil {
return nil, false, err

View File

@@ -37,7 +37,7 @@ func TestLogPipelinesLifecycle(t *testing.T) {
testbed := NewLogPipelinesTestBed(t, nil)
require := require.New(t)
orgID, err := utils.GetTestOrgId(t, testbed.sqlStore)
orgID, err := utils.GetTestOrgId(testbed.sqlStore)
require.Nil(err)
getPipelinesResp := testbed.GetPipelinesFromQS()
@@ -454,18 +454,18 @@ type LogPipelinesTestBed struct {
}
// testDB can be injected for sharing a DB across multiple integration testbeds.
func NewTestbedWithoutOpamp(t *testing.T, sqlStore sqlstore.SQLStore) *LogPipelinesTestBed {
if sqlStore == nil {
sqlStore = utils.NewQueryServiceDBForTests(t)
func NewTestbedWithoutOpamp(t *testing.T, store sqlstore.SQLStore) *LogPipelinesTestBed {
if store == nil {
store = utils.NewQueryServiceDBForTests(t)
}
ic, err := integrations.NewController(sqlStore)
ic, err := integrations.NewController(store)
if err != nil {
t.Fatalf("could not create integrations controller: %v", err)
}
controller, err := logparsingpipeline.NewLogParsingPipelinesController(
sqlStore, ic.GetPipelinesForInstalledIntegrations,
store, ic.GetPipelinesForInstalledIntegrations,
)
if err != nil {
t.Fatalf("could not create a logparsingpipelines controller: %v", err)
@@ -490,7 +490,7 @@ func NewTestbedWithoutOpamp(t *testing.T, sqlStore sqlstore.SQLStore) *LogPipeli
require.Nil(t, err, "failed to init opamp model")
agentConfMgr, err := agentConf.Initiate(&agentConf.ManagerOptions{
Store: sqlStore,
Store: store,
AgentFeatures: []agentConf.AgentFeature{
apiHandler.LogsParsingPipelineController,
}})
@@ -501,14 +501,14 @@ func NewTestbedWithoutOpamp(t *testing.T, sqlStore sqlstore.SQLStore) *LogPipeli
testUser: user,
apiHandler: apiHandler,
agentConfMgr: agentConfMgr,
sqlStore: sqlStore,
sqlStore: store,
}
}
func NewLogPipelinesTestBed(t *testing.T, testDB sqlstore.SQLStore) *LogPipelinesTestBed {
testbed := NewTestbedWithoutOpamp(t, testDB)
orgID, err := utils.GetTestOrgId(t, testbed.sqlStore)
orgID, err := utils.GetTestOrgId(testbed.sqlStore)
require.Nil(t, err)
model.InitDB(testbed.sqlStore)

View File

@@ -120,7 +120,7 @@ func TestLogPipelinesForInstalledSignozIntegrations(t *testing.T) {
testDB := utils.NewQueryServiceDBForTests(t)
utils.CreateTestOrg(t, testDB)
orgID, err := utils.GetTestOrgId(t, testDB)
orgID, err := utils.GetTestOrgId(testDB)
require.Nil(err)
integrationsTB := NewIntegrationsTestBed(t, testDB)

View File

@@ -51,9 +51,9 @@ func NewTestSqliteDB(t *testing.T) (sqlStore sqlstore.SQLStore, testDBFilePath s
sqlmigration.NewModifyOrgDomainFactory(),
sqlmigration.NewUpdateOrganizationFactory(sqlStore),
sqlmigration.NewUpdateDashboardAndSavedViewsFactory(sqlStore),
sqlmigration.NewUpdateAgentsFactory(sqlStore),
sqlmigration.NewUpdatePatAndOrgDomainsFactory(sqlStore),
sqlmigration.NewUpdatePipelines(sqlStore),
sqlmigration.NewUpdateAgentsFactory(sqlStore),
),
)
if err != nil {
@@ -92,7 +92,7 @@ func CreateTestOrg(t *testing.T, store sqlstore.SQLStore) error {
return nil
}
func GetTestOrgId(t *testing.T, store sqlstore.SQLStore) (string, error) {
func GetTestOrgId(store sqlstore.SQLStore) (string, error) {
var orgID string
err := store.BunDB().NewSelect().
Model(&types.Organization{}).

View File

@@ -68,8 +68,9 @@ type AgentConfigVersion struct {
LastConfig string `json:"lastConfig" bun:"last_config,type:text"`
}
func NewAgentConfigVersion(typeDef ElementTypeDef) *AgentConfigVersion {
func NewAgentConfigVersion(orgId string, typeDef ElementTypeDef) *AgentConfigVersion {
return &AgentConfigVersion{
OrgID: orgId,
ID: uuid.NewString(),
ElementType: typeDef,
Active: false,