From dff9837870d5bb5a978ef3fbaf7e00bdfb66f82d Mon Sep 17 00:00:00 2001 From: Matt Brock Date: Thu, 23 Jan 2025 22:46:08 -0600 Subject: [PATCH] Add godocs and correct a few comments --- lib/srv/discovery/access_graph_aws.go | 8 ++++---- lib/srv/discovery/access_graph_azure.go | 8 ++++---- lib/srv/discovery/access_graph_test.go | 8 ++++---- lib/srv/discovery/discovery.go | 4 ++-- lib/srv/discovery/status.go | 8 ++++---- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/srv/discovery/access_graph_aws.go b/lib/srv/discovery/access_graph_aws.go index 1fc62a793a8a9..ab5b185450174 100644 --- a/lib/srv/discovery/access_graph_aws.go +++ b/lib/srv/discovery/access_graph_aws.go @@ -83,9 +83,9 @@ func (s *Server) reconcileAccessGraph(ctx context.Context, currentTAGResources * } for _, fetcher := range allFetchers { - s.syncStatus.syncStarted(fetcher, s.clock.Now()) + s.tagSyncStatus.syncStarted(fetcher, s.clock.Now()) } - for _, discoveryConfigName := range s.syncStatus.discoveryConfigs() { + for _, discoveryConfigName := range s.tagSyncStatus.discoveryConfigs() { s.updateDiscoveryConfigStatus(discoveryConfigName) } @@ -129,9 +129,9 @@ func (s *Server) reconcileAccessGraph(ctx context.Context, currentTAGResources * pushErr := push(stream, upsert, toDel) for _, fetcher := range allFetchers { - s.syncStatus.syncFinished(fetcher, pushErr, s.clock.Now()) + s.tagSyncStatus.syncFinished(fetcher, pushErr, s.clock.Now()) } - for _, discoveryConfigName := range s.syncStatus.discoveryConfigs() { + for _, discoveryConfigName := range s.tagSyncStatus.discoveryConfigs() { s.updateDiscoveryConfigStatus(discoveryConfigName) } diff --git a/lib/srv/discovery/access_graph_azure.go b/lib/srv/discovery/access_graph_azure.go index dc3922f27c4ec..7f40956fdda89 100644 --- a/lib/srv/discovery/access_graph_azure.go +++ b/lib/srv/discovery/access_graph_azure.go @@ -67,9 +67,9 @@ func (s *Server) reconcileAccessGraphAzure( } for _, fetcher := range allFetchers { - s.syncStatus.syncStarted(fetcher, s.clock.Now()) + s.tagSyncStatus.syncStarted(fetcher, s.clock.Now()) } - for _, discoveryConfigName := range s.syncStatus.discoveryConfigs() { + for _, discoveryConfigName := range s.tagSyncStatus.discoveryConfigs() { s.updateDiscoveryConfigStatus(discoveryConfigName) } @@ -117,9 +117,9 @@ func (s *Server) reconcileAccessGraphAzure( pushErr := azurePush(stream, upsert, toDel) for _, fetcher := range allFetchers { - s.syncStatus.syncFinished(fetcher, pushErr, s.clock.Now()) + s.tagSyncStatus.syncFinished(fetcher, pushErr, s.clock.Now()) } - for _, discoveryConfigName := range s.syncStatus.discoveryConfigs() { + for _, discoveryConfigName := range s.tagSyncStatus.discoveryConfigs() { s.updateDiscoveryConfigStatus(discoveryConfigName) } diff --git a/lib/srv/discovery/access_graph_test.go b/lib/srv/discovery/access_graph_test.go index 283c21100f68b..c6efe1064cbfc 100644 --- a/lib/srv/discovery/access_graph_test.go +++ b/lib/srv/discovery/access_graph_test.go @@ -247,20 +247,20 @@ func TestServer_updateDiscoveryConfigStatus(t *testing.T) { AccessPoint: accessPoint, clock: clock, }, - syncStatus: newTagSyncStatus(), + tagSyncStatus: newTagSyncStatus(), } if tt.args.preRun { for _, fetcher := range tt.args.fetchers { - s.syncStatus.syncStarted(fetcher, s.clock.Now()) + s.tagSyncStatus.syncStarted(fetcher, s.clock.Now()) } } else { for _, fetcher := range tt.args.fetchers { - s.syncStatus.syncFinished(fetcher, tt.args.pushErr, s.clock.Now()) + s.tagSyncStatus.syncFinished(fetcher, tt.args.pushErr, s.clock.Now()) } } - for _, discoveryConfigName := range s.syncStatus.discoveryConfigs() { + for _, discoveryConfigName := range s.tagSyncStatus.discoveryConfigs() { s.updateDiscoveryConfigStatus(discoveryConfigName) } diff --git a/lib/srv/discovery/discovery.go b/lib/srv/discovery/discovery.go index 195c12d2df6cf..0f2617fb3f140 100644 --- a/lib/srv/discovery/discovery.go +++ b/lib/srv/discovery/discovery.go @@ -440,7 +440,7 @@ type Server struct { dynamicDiscoveryConfig map[string]*discoveryconfig.DiscoveryConfig - syncStatus *tagSyncStatus + tagSyncStatus *tagSyncStatus awsEC2ResourcesStatus awsResourcesStatus awsRDSResourcesStatus awsResourcesStatus awsEKSResourcesStatus awsResourcesStatus @@ -480,7 +480,7 @@ func New(ctx context.Context, cfg *Config) (*Server, error) { dynamicTAGAWSFetchers: make(map[string][]*aws_sync.Fetcher), dynamicTAGAzureFetchers: make(map[string][]*azure_sync.Fetcher), dynamicDiscoveryConfig: make(map[string]*discoveryconfig.DiscoveryConfig), - syncStatus: newTagSyncStatus(), + tagSyncStatus: newTagSyncStatus(), awsEC2ResourcesStatus: newAWSResourceStatusCollector(types.AWSMatcherEC2), awsRDSResourcesStatus: newAWSResourceStatusCollector(types.AWSMatcherRDS), awsEKSResourcesStatus: newAWSResourceStatusCollector(types.AWSMatcherEKS), diff --git a/lib/srv/discovery/status.go b/lib/srv/discovery/status.go index 3a8f20863efd5..4b25bff187540 100644 --- a/lib/srv/discovery/status.go +++ b/lib/srv/discovery/status.go @@ -38,6 +38,7 @@ import ( "github.com/gravitational/teleport/lib/srv/server" ) +// FetcherStatus defines an interface for fetchers to report status type FetcherStatus interface { // Status reports the last known status of the fetcher. Status() (uint64, error) @@ -67,10 +68,8 @@ func (s *Server) updateDiscoveryConfigStatus(discoveryConfigNames ...string) { IntegrationDiscoveredResources: make(map[string]*discoveryconfigv1.IntegrationDiscoveredSummary), } - // Merge AWS Sync (TAG) status - discoveryConfigStatus = s.syncStatus.mergeIntoGlobalStatus(discoveryConfigName, discoveryConfigStatus) - - // Merge Azure Sync (TAG) status + // Merge AWS or Azure Sync (TAG) status + discoveryConfigStatus = s.tagSyncStatus.mergeIntoGlobalStatus(discoveryConfigName, discoveryConfigStatus) // Merge AWS EC2 Instances (auto discovery) status discoveryConfigStatus = s.awsEC2ResourcesStatus.mergeIntoGlobalStatus(discoveryConfigName, discoveryConfigStatus) @@ -102,6 +101,7 @@ type tagSyncStatus struct { syncResults map[string][]tagSyncResult } +// newTagSyncStatus creates a new sync status object for storing results from the last fetch func newTagSyncStatus() *tagSyncStatus { return &tagSyncStatus{ syncResults: make(map[string][]tagSyncResult),