From cd9211d71841a3d04c8b7b71ae4ea993b2b98546 Mon Sep 17 00:00:00 2001 From: swapnil-signoz Date: Tue, 17 Mar 2026 17:04:27 +0530 Subject: [PATCH] refactor: clean up types --- .../cloudintegration/cloudintegration.go | 71 +++++++------------ pkg/types/cloudintegrationtypes/account.go | 28 ++++---- .../cloudintegrationtypes/cloudintegration.go | 12 ++-- pkg/types/cloudintegrationtypes/connection.go | 1 + pkg/types/cloudintegrationtypes/regions.go | 4 +- pkg/types/cloudintegrationtypes/service.go | 27 +++---- pkg/types/cloudintegrationtypes/store.go | 2 +- 7 files changed, 63 insertions(+), 82 deletions(-) diff --git a/pkg/modules/cloudintegration/cloudintegration.go b/pkg/modules/cloudintegration/cloudintegration.go index 8f81fdd9f9..35f4731749 100644 --- a/pkg/modules/cloudintegration/cloudintegration.go +++ b/pkg/modules/cloudintegration/cloudintegration.go @@ -4,60 +4,43 @@ import ( "context" "net/http" - "github.com/SigNoz/signoz/pkg/types/cloudintegrationtypes" + citypes "github.com/SigNoz/signoz/pkg/types/cloudintegrationtypes" "github.com/SigNoz/signoz/pkg/types/dashboardtypes" "github.com/SigNoz/signoz/pkg/valuer" ) type Module interface { - // CreateConnectionArtifact generates cloud provider specific connection information, - // client side handles how this information is shown - CreateConnectionArtifact( - ctx context.Context, - orgID valuer.UUID, - provider cloudintegrationtypes.CloudProviderType, - request *cloudintegrationtypes.ConnectionArtifactRequest, - ) (*cloudintegrationtypes.ConnectionArtifact, error) + CreateAccount(ctx context.Context, account *citypes.Account) error - // GetAccountStatus returns agent connection status for a cloud integration account - GetAccountStatus(ctx context.Context, orgID, accountID valuer.UUID) (*cloudintegrationtypes.AccountStatus, error) + // GetAccount returns cloud integration account + GetAccount(ctx context.Context, orgID, accountID valuer.UUID) (*citypes.Account, error) - // ListConnectedAccounts lists accounts where agent is connected - ListConnectedAccounts(ctx context.Context, orgID valuer.UUID) (*cloudintegrationtypes.ConnectedAccounts, error) + // GetAccounts lists accounts where agent is connected + GetAccounts(ctx context.Context, orgID valuer.UUID) ([]*citypes.Account, error) + + // UpdateAccount updates the cloud integration account for a specific organization. + UpdateAccount(ctx context.Context, account *citypes.Account) error // DisconnectAccount soft deletes/removes a cloud integration account. DisconnectAccount(ctx context.Context, orgID, accountID valuer.UUID) error - // UpdateAccountConfig updates the configuration of an existing cloud account for a specific organization. - UpdateAccountConfig( - ctx context.Context, - orgID, - accountID valuer.UUID, - config *cloudintegrationtypes.UpdateAccountConfigRequest, - ) (*cloudintegrationtypes.Account, error) + // GetConnectionArtifact returns cloud provider specific connection information, + // client side handles how this information is shown + GetConnectionArtifact(ctx context.Context, account *citypes.Account, req *citypes.ConnectionArtifactRequest) (*citypes.ConnectionArtifact, error) - // ListServicesMetadata returns list of services metadata for a cloud provider attached with the integrationID. + // GetServicesMetadata returns list of services metadata for a cloud provider attached with the integrationID. // This just returns a summary of the service and not the whole service definition - ListServicesMetadata(ctx context.Context, orgID valuer.UUID, integrationID *valuer.UUID) (*cloudintegrationtypes.ServicesMetadata, error) + GetServicesMetadata(ctx context.Context, orgID valuer.UUID, integrationID *valuer.UUID) ([]*citypes.ServiceMetadata, error) - // GetService returns service definition details for a serviceID. This returns config and + // GetService returns service definition details for a serviceType. This returns config and // other details required to show in service details page on web client. - GetService(ctx context.Context, orgID valuer.UUID, integrationID *valuer.UUID, serviceID string) (*cloudintegrationtypes.Service, error) + GetService(ctx context.Context, orgID valuer.UUID, integrationID *valuer.UUID, serviceType string) (*citypes.Service, error) - // UpdateServiceConfig updates cloud integration service config - UpdateServiceConfig( - ctx context.Context, - orgID valuer.UUID, - serviceID string, - config *cloudintegrationtypes.UpdateServiceConfigRequest, - ) (*cloudintegrationtypes.UpdateServiceConfigResponse, error) + // UpdateService updates cloud integration service + UpdateService(ctx context.Context, orgID valuer.UUID, service *citypes.CloudIntegrationService) error // AgentCheckIn is called by agent to heartbeat and get latest config in response. - AgentCheckIn( - ctx context.Context, - orgID valuer.UUID, - req *cloudintegrationtypes.AgentCheckInRequest, - ) (*cloudintegrationtypes.AgentCheckInResponse, error) + AgentCheckIn(ctx context.Context, orgID valuer.UUID, req *citypes.AgentCheckInRequest) (*citypes.AgentCheckInResponse, error) // GetDashboardByID returns dashboard JSON for a given dashboard id. // this only returns the dashboard when the service (embedded in dashboard id) is enabled @@ -70,13 +53,13 @@ type Module interface { } type Handler interface { - AgentCheckIn(http.ResponseWriter, *http.Request) - GenerateConnectionArtifact(http.ResponseWriter, *http.Request) - ListConnectedAccounts(http.ResponseWriter, *http.Request) - GetAccountStatus(http.ResponseWriter, *http.Request) - ListServices(http.ResponseWriter, *http.Request) - GetServiceDetails(http.ResponseWriter, *http.Request) - UpdateAccountConfig(http.ResponseWriter, *http.Request) - UpdateServiceConfig(http.ResponseWriter, *http.Request) + GetConnectionArtifact(http.ResponseWriter, *http.Request) + GetAccounts(http.ResponseWriter, *http.Request) + GetAccount(http.ResponseWriter, *http.Request) + UpdateAccount(http.ResponseWriter, *http.Request) DisconnectAccount(http.ResponseWriter, *http.Request) + GetServicesMetadata(http.ResponseWriter, *http.Request) + GetService(http.ResponseWriter, *http.Request) + UpdateService(http.ResponseWriter, *http.Request) + AgentCheckIn(http.ResponseWriter, *http.Request) } diff --git a/pkg/types/cloudintegrationtypes/account.go b/pkg/types/cloudintegrationtypes/account.go index fb19ce253a..e842b6958c 100644 --- a/pkg/types/cloudintegrationtypes/account.go +++ b/pkg/types/cloudintegrationtypes/account.go @@ -3,35 +3,31 @@ package cloudintegrationtypes import ( "time" + "github.com/SigNoz/signoz/pkg/types" "github.com/SigNoz/signoz/pkg/valuer" ) -type ( - ConnectedAccounts struct { - Accounts []*Account `json:"accounts"` - } - - GettableConnectedAccounts = ConnectedAccounts - - UpdateAccountConfigRequest struct { - AWS *AWSAccountConfig `json:"aws"` - } - - UpdatableAccountConfig = UpdateAccountConfigRequest -) - type ( Account struct { - Id string `json:"id"` + types.Identifiable + types.TimeAuditable ProviderAccountId *string `json:"providerAccountID,omitempty"` Provider CloudProviderType `json:"provider"` RemovedAt *time.Time `json:"removedAt,omitempty"` AgentReport *AgentReport `json:"agentReport,omitempty"` OrgID valuer.UUID `json:"orgID"` - Config *AccountConfig `json:"accountConfig,omitempty"` + Config *AccountConfig `json:"config,omitempty"` + } + + GettableConnectedAccounts struct { + Accounts []*Account `json:"accounts"` } GettableAccount = Account + + UpdatableAccount struct { + Config *AccountConfig `json:"config"` + } ) // AgentReport represents heartbeats sent by the agent. diff --git a/pkg/types/cloudintegrationtypes/cloudintegration.go b/pkg/types/cloudintegrationtypes/cloudintegration.go index 6e15cdcff6..432b171cc6 100644 --- a/pkg/types/cloudintegrationtypes/cloudintegration.go +++ b/pkg/types/cloudintegrationtypes/cloudintegration.go @@ -26,10 +26,10 @@ type StorableCloudIntegration struct { Provider CloudProviderType `json:"provider" bun:"provider,type:text"` // Config is provider specific data in JSON string format Config string `json:"config" bun:"config,type:text"` - AccountID *string `json:"account_id" bun:"account_id,type:text"` - LastAgentReport *StorableAgentReport `json:"last_agent_report" bun:"last_agent_report,type:text"` - RemovedAt *time.Time `json:"removed_at" bun:"removed_at,type:timestamp,nullzero"` - OrgID valuer.UUID `bun:"org_id,type:text"` + AccountID *string `json:"accountID" bun:"account_id,type:text"` + LastAgentReport *StorableAgentReport `json:"lastAgentReport" bun:"last_agent_report,type:text"` + RemovedAt *time.Time `json:"removedAt" bun:"removed_at,type:timestamp,nullzero"` + OrgID valuer.UUID `json:"orgID" bun:"org_id,type:text"` } // StorableAgentReport represents the last heartbeat and arbitrary data sent by the agent @@ -45,10 +45,10 @@ type StorableCloudIntegrationService struct { types.Identifiable types.TimeAuditable - Type valuer.String `bun:"type,type:text,notnull,unique:cloud_integration_id_type"` + Type ServiceType `bun:"type,type:text,notnull,unique:cloud_integration_id_type"` // Config is cloud provider's service specific data in JSON string format Config string `bun:"config,type:text"` - CloudIntegrationID valuer.UUID `bun:"cloud_integration_id,type:text,notnull,unique:cloud_integration_id_type,references:cloud_integration(id),on_delete:cascade"` + CloudIntegrationID valuer.UUID `bun:"cloud_integration_id,type:text,notnull,unique:cloud_integration_id_type,on_delete:cascade"` } // Scan scans value from DB. diff --git a/pkg/types/cloudintegrationtypes/connection.go b/pkg/types/cloudintegrationtypes/connection.go index 8170193a3d..67c2ad0b07 100644 --- a/pkg/types/cloudintegrationtypes/connection.go +++ b/pkg/types/cloudintegrationtypes/connection.go @@ -62,6 +62,7 @@ type ( GettableAgentCheckInResponse struct { AgentCheckInResponse + // For backward compatibility CloudIntegrationId string `json:"cloud_integration_id"` AccountId string `json:"account_id"` } diff --git a/pkg/types/cloudintegrationtypes/regions.go b/pkg/types/cloudintegrationtypes/regions.go index 2568c91740..83ab0d8287 100644 --- a/pkg/types/cloudintegrationtypes/regions.go +++ b/pkg/types/cloudintegrationtypes/regions.go @@ -5,8 +5,8 @@ import ( ) var ( - CodeInvalidCloudRegion = errors.MustNewCode("invalid_cloud_region") - CodeMismatchCloudProvider = errors.MustNewCode("cloud_provider_mismatch") + ErrCodeInvalidCloudRegion = errors.MustNewCode("invalid_cloud_region") + ErrCodeMismatchCloudProvider = errors.MustNewCode("cloud_provider_mismatch") ) // List of all valid cloud regions on Amazon Web Services. diff --git a/pkg/types/cloudintegrationtypes/service.go b/pkg/types/cloudintegrationtypes/service.go index 0cc66ce934..b9be23b45b 100644 --- a/pkg/types/cloudintegrationtypes/service.go +++ b/pkg/types/cloudintegrationtypes/service.go @@ -11,9 +11,15 @@ import ( var S3Sync = valuer.NewString("s3sync") +type ServiceType struct{ valuer.String } + type ( - ServicesMetadata struct { - Services []*ServiceMetadata `json:"services"` + CloudIntegrationService struct { + types.Identifiable + types.TimeAuditable + Type ServiceType `json:"type"` + Config *ServiceConfig `json:"config"` + CloudIntegrationID valuer.UUID `json:"cloudIntegrationID"` } // ServiceMetadata helps to quickly list available services and whether it is enabled or not. @@ -25,7 +31,9 @@ type ( Enabled bool `json:"enabled"` } - GettableServicesMetadata = ServicesMetadata + GettableServicesMetadata struct { + Services []*ServiceMetadata `json:"services"` + } Service struct { ServiceDefinition @@ -34,15 +42,8 @@ type ( GettableService = Service - UpdateServiceConfigRequest struct { - CloudIntegrationId valuer.UUID `json:"cloudIntegrationId"` - ServiceConfig *ServiceConfig `json:"serviceConfig"` - } - - UpdateServiceConfigResponse struct { - Id string `json:"id"` // service id - CloudIntegrationId valuer.UUID `json:"cloudIntegrationId"` - ServiceConfig *ServiceConfig `json:"serviceConfig"` + UpdatableService struct { + Config *ServiceConfig `json:"config"` } ) @@ -66,7 +67,7 @@ type AWSServiceMetricsConfig struct { Enabled bool `json:"enabled"` } -// DefinitionMetadata represents service definition metadata. This is useful for showing service overview. +// ServiceDefinitionMetadata represents service definition metadata. This is useful for showing service tab in frontend. type ServiceDefinitionMetadata struct { Id string `json:"id"` Title string `json:"title"` diff --git a/pkg/types/cloudintegrationtypes/store.go b/pkg/types/cloudintegrationtypes/store.go index 5090432773..3a3f40760e 100644 --- a/pkg/types/cloudintegrationtypes/store.go +++ b/pkg/types/cloudintegrationtypes/store.go @@ -11,7 +11,7 @@ type Store interface { GetAccountByID(ctx context.Context, orgID, id valuer.UUID, provider CloudProviderType) (*StorableCloudIntegration, error) // CreateAccount creates a new cloud integration account - CreateAccount(ctx context.Context, orgID valuer.UUID, account *StorableCloudIntegration) (*StorableCloudIntegration, error) + CreateAccount(ctx context.Context, account *StorableCloudIntegration) (*StorableCloudIntegration, error) // UpdateAccount updates an existing cloud integration account UpdateAccount(ctx context.Context, account *StorableCloudIntegration) error