Skip to content

Commit

Permalink
DiscoveryConfig Status: update even when no resources are found (#49588
Browse files Browse the repository at this point in the history
…) (#50331)

* DiscoveryConfig Status: update even when no resources are found

The DiscoveryService was not updating the DiscoveryConfigStatus when its
matchers didn't discovered any resource.

This would lead the user to think that there the DiscoveryConfig was not
being processed, when in fact it was.

* rename to FilterMapUnique

* rename to DiscoveryConfigName and GetDiscoveryConfigName

* fix var name
  • Loading branch information
marcoandredinis authored Dec 17, 2024
1 parent 62e5df1 commit 5294336
Show file tree
Hide file tree
Showing 25 changed files with 502 additions and 294 deletions.
4 changes: 2 additions & 2 deletions lib/srv/discovery/common/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ type Fetcher interface {
// IntegrationName identifies the integration name whose credentials were used to fetch the resources.
// Might be empty when the fetcher is using ambient credentials.
IntegrationName() string
// DiscoveryConfigName is the name of the discovery config which originated the resource.
// GetDiscoveryConfigName is the name of the discovery config which originated the resource.
// Might be empty when the fetcher is using static matchers:
// ie teleport.yaml/discovery_service.<cloud>.<matcher>
DiscoveryConfigName() string
GetDiscoveryConfigName() string
// Cloud returns the cloud the fetcher is operating.
Cloud() string
}
4 changes: 2 additions & 2 deletions lib/srv/discovery/common/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ func (w *Watcher) fetchAndSend() {
// Add the integration name to the static labels for each resource.
fetcherLabels[types.TeleportInternalDiscoveryIntegrationName] = lFetcher.IntegrationName()
}
if lFetcher.DiscoveryConfigName() != "" {
if lFetcher.GetDiscoveryConfigName() != "" {
// Add the discovery config name to the static labels of each resource.
fetcherLabels[types.TeleportInternalDiscoveryConfigName] = lFetcher.DiscoveryConfigName()
fetcherLabels[types.TeleportInternalDiscoveryConfigName] = lFetcher.GetDiscoveryConfigName()
}

if w.cfg.DiscoveryGroup != "" {
Expand Down
2 changes: 1 addition & 1 deletion lib/srv/discovery/common/watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func (m *mockFetcher) IntegrationName() string {
return ""
}

func (m *mockFetcher) DiscoveryConfigName() string {
func (m *mockFetcher) GetDiscoveryConfigName() string {
return ""
}
func (m *mockFetcher) Cloud() string {
Expand Down
11 changes: 10 additions & 1 deletion lib/srv/discovery/database_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/gravitational/teleport/lib/services"
"github.com/gravitational/teleport/lib/srv/discovery/common"
"github.com/gravitational/teleport/lib/utils"
"github.com/gravitational/teleport/lib/utils/slices"
)

const databaseEventPrefix = "db/"
Expand Down Expand Up @@ -74,6 +75,14 @@ func (s *Server) startDatabaseWatchers() error {
Origin: types.OriginCloud,
Clock: s.clock,
PreFetchHookFn: func() {
discoveryConfigs := slices.FilterMapUnique(
s.getAllDatabaseFetchers(),
func(f common.Fetcher) (s string, include bool) {
return f.GetDiscoveryConfigName(), f.GetDiscoveryConfigName() != ""
},
)
s.updateDiscoveryConfigStatus(discoveryConfigs...)

s.awsRDSResourcesStatus.reset()
},
},
Expand All @@ -99,7 +108,7 @@ func (s *Server) startDatabaseWatchers() error {

resourceGroup := awsResourceGroupFromLabels(db.GetStaticLabels())
resourcesFoundByGroup[resourceGroup] += 1
discoveryConfigsChanged[resourceGroup.discoveryConfig] = struct{}{}
discoveryConfigsChanged[resourceGroup.discoveryConfigName] = struct{}{}

dbs = append(dbs, db)
}
Expand Down
Loading

0 comments on commit 5294336

Please sign in to comment.