Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement cache update deduplication per fetch cycle #5509

Merged
merged 36 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
208d1cf
Intial work on backoff algorithm.
edwbuck Sep 17, 2024
c6d23aa
Push after refactoring registration entry event tracking.
edwbuck Sep 18, 2024
b4d2de9
Final refactoring done. Need to fix unit tests.
edwbuck Sep 18, 2024
bf6ad3c
Reworked some of the unit tests to the refactored algorithm.
edwbuck Sep 24, 2024
f81942f
Saving work off so I can switch machines.
edwbuck Sep 25, 2024
4118679
Fix compliation.
edwbuck Sep 26, 2024
791b503
Unit test fixes and restoration of authorized_entryfetcher.go.
edwbuck Sep 27, 2024
aad7444
Add in boundary builder unit tests.
edwbuck Sep 27, 2024
806ebf7
Add unit tests for updating the node cache from the database.
edwbuck Sep 29, 2024
8ab4d68
Added loadCache testing for authorized entries registered entry.
edwbuck Oct 1, 2024
b5a068a
Add in updates to fakedatastore.
edwbuck Oct 1, 2024
a43e9ef
Add unit test for authorized entryfetcher registration entries.
edwbuck Oct 1, 2024
2eb66d1
Add poll entries testing to authorized entryfetcher registration entr…
edwbuck Oct 1, 2024
7c645c4
Add in new entry unit tests for auth entry fetcher registraiton entries.
edwbuck Oct 1, 2024
9278f36
Update cache unit test for authorized entryfetcher registration entries.
edwbuck Oct 1, 2024
673a480
Fix datastore wrapper_test.
edwbuck Oct 1, 2024
9d0986b
Fix unit tests.
edwbuck Oct 1, 2024
978fbab
Fix some linting issues.
edwbuck Oct 1, 2024
a0a2d49
Fix linting issues.
edwbuck Oct 1, 2024
0a21834
Fix grammar in func calls / structs.
edwbuck Oct 1, 2024
6036b1c
Merge branch 'main' into backoff
edwbuck Oct 1, 2024
61feaa4
Fix spelling items in comments for code review.
edwbuck Oct 1, 2024
c5457cd
Better commentary around BoundaryBuilder.
edwbuck Oct 2, 2024
d4225bf
Fix update of poll count when an item is polled.
edwbuck Oct 7, 2024
55f8254
Fix eventTracker for multiple boundaries.
edwbuck Oct 7, 2024
9a9a942
Removed inner loop assignment as capture problem fixed in language.
edwbuck Oct 8, 2024
9205427
Merge branch 'main' into backoff
edwbuck Oct 8, 2024
24e772e
Merge branch 'main' into backoff
edwbuck Oct 9, 2024
ee1ba09
Fixed small typos and style choices for code review.
edwbuck Oct 9, 2024
8fc09e3
Fixed export of metrics selector name sets in unit tests.
edwbuck Oct 9, 2024
ac075b8
Add in sync.Pool semantics to avoid memory trashing / overallocation.
edwbuck Oct 9, 2024
59f2b7a
Remove backoff polling.
edwbuck Oct 15, 2024
de28e0d
Add in buffer resetting for eventTracker, remove TODO items.
edwbuck Oct 16, 2024
28bd44d
Fixes for freeing the shared buffer between eventTracker and its users.
edwbuck Oct 17, 2024
889cc29
Merge branch 'main' into backoff
edwbuck Oct 17, 2024
f0cbc4b
fix pool usage to satisfy linter
azdagron Oct 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions pkg/common/telemetry/server/datastore/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import (
"github.com/spiffe/spire/pkg/common/telemetry"
)

// StartListRegistrationEntriesEventsCall return metric
// StartListRegistrationEntryEventsCall return metric
// for server's datastore, on listing registration entry events.
func StartListRegistrationEntriesEventsCall(m telemetry.Metrics) *telemetry.CallCounter {
func StartListRegistrationEntryEventsCall(m telemetry.Metrics) *telemetry.CallCounter {
return telemetry.StartCall(m, telemetry.Datastore, telemetry.RegistrationEntryEvent, telemetry.List)
}

// StartPruneRegistrationEntriesEventsCall return metric
// StartPruneRegistrationEntryEventsCall return metric
// for server's datastore, on pruning registration entry events.
func StartPruneRegistrationEntriesEventsCall(m telemetry.Metrics) *telemetry.CallCounter {
func StartPruneRegistrationEntryEventsCall(m telemetry.Metrics) *telemetry.CallCounter {
return telemetry.StartCall(m, telemetry.Datastore, telemetry.RegistrationEntryEvent, telemetry.Prune)
}

Expand All @@ -34,15 +34,15 @@ func StartFetchRegistrationEntryEventCall(m telemetry.Metrics) *telemetry.CallCo
return telemetry.StartCall(m, telemetry.Datastore, telemetry.RegistrationEntryEvent, telemetry.Fetch)
}

// StartListAttestedNodesEventsCall return metric
// StartListAttestedNodeEventsCall return metric
// for server's datastore, on listing attested node events.
func StartListAttestedNodesEventsCall(m telemetry.Metrics) *telemetry.CallCounter {
func StartListAttestedNodeEventsCall(m telemetry.Metrics) *telemetry.CallCounter {
return telemetry.StartCall(m, telemetry.Datastore, telemetry.NodeEvent, telemetry.List)
}

// StartPruneAttestedNodesEventsCall return metric
// StartPruneAttestedNodeEventsCall return metric
// for server's datastore, on pruning attested node events.
func StartPruneAttestedNodesEventsCall(m telemetry.Metrics) *telemetry.CallCounter {
func StartPruneAttestedNodeEventsCall(m telemetry.Metrics) *telemetry.CallCounter {
return telemetry.StartCall(m, telemetry.Datastore, telemetry.NodeEvent, telemetry.Prune)
}

Expand Down
24 changes: 12 additions & 12 deletions pkg/common/telemetry/server/datastore/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,10 @@ func (w metricsWrapper) ListAttestedNodes(ctx context.Context, req *datastore.Li
return w.ds.ListAttestedNodes(ctx, req)
}

func (w metricsWrapper) ListAttestedNodesEvents(ctx context.Context, req *datastore.ListAttestedNodesEventsRequest) (_ *datastore.ListAttestedNodesEventsResponse, err error) {
callCounter := StartListAttestedNodesEventsCall(w.m)
func (w metricsWrapper) ListAttestedNodeEvents(ctx context.Context, req *datastore.ListAttestedNodeEventsRequest) (_ *datastore.ListAttestedNodeEventsResponse, err error) {
callCounter := StartListAttestedNodeEventsCall(w.m)
defer callCounter.Done(&err)
return w.ds.ListAttestedNodesEvents(ctx, req)
return w.ds.ListAttestedNodeEvents(ctx, req)
}

func (w metricsWrapper) ListBundles(ctx context.Context, req *datastore.ListBundlesRequest) (_ *datastore.ListBundlesResponse, err error) {
Expand All @@ -203,10 +203,10 @@ func (w metricsWrapper) ListRegistrationEntries(ctx context.Context, req *datast
return w.ds.ListRegistrationEntries(ctx, req)
}

func (w metricsWrapper) ListRegistrationEntriesEvents(ctx context.Context, req *datastore.ListRegistrationEntriesEventsRequest) (_ *datastore.ListRegistrationEntriesEventsResponse, err error) {
callCounter := StartListRegistrationEntriesEventsCall(w.m)
func (w metricsWrapper) ListRegistrationEntryEvents(ctx context.Context, req *datastore.ListRegistrationEntryEventsRequest) (_ *datastore.ListRegistrationEntryEventsResponse, err error) {
callCounter := StartListRegistrationEntryEventsCall(w.m)
defer callCounter.Done(&err)
return w.ds.ListRegistrationEntriesEvents(ctx, req)
return w.ds.ListRegistrationEntryEvents(ctx, req)
}

func (w metricsWrapper) CountAttestedNodes(ctx context.Context, req *datastore.CountAttestedNodesRequest) (_ int32, err error) {
Expand All @@ -227,10 +227,10 @@ func (w metricsWrapper) CountRegistrationEntries(ctx context.Context, req *datas
return w.ds.CountRegistrationEntries(ctx, req)
}

func (w metricsWrapper) PruneAttestedNodesEvents(ctx context.Context, olderThan time.Duration) (err error) {
callCounter := StartPruneAttestedNodesEventsCall(w.m)
func (w metricsWrapper) PruneAttestedNodeEvents(ctx context.Context, olderThan time.Duration) (err error) {
callCounter := StartPruneAttestedNodeEventsCall(w.m)
defer callCounter.Done(&err)
return w.ds.PruneAttestedNodesEvents(ctx, olderThan)
return w.ds.PruneAttestedNodeEvents(ctx, olderThan)
}

func (w metricsWrapper) PruneBundle(ctx context.Context, trustDomainID string, expiresBefore time.Time) (_ bool, err error) {
Expand All @@ -251,10 +251,10 @@ func (w metricsWrapper) PruneRegistrationEntries(ctx context.Context, expiresBef
return w.ds.PruneRegistrationEntries(ctx, expiresBefore)
}

func (w metricsWrapper) PruneRegistrationEntriesEvents(ctx context.Context, olderThan time.Duration) (err error) {
callCounter := StartPruneRegistrationEntriesEventsCall(w.m)
func (w metricsWrapper) PruneRegistrationEntryEvents(ctx context.Context, olderThan time.Duration) (err error) {
callCounter := StartPruneRegistrationEntryEventsCall(w.m)
defer callCounter.Done(&err)
return w.ds.PruneRegistrationEntriesEvents(ctx, olderThan)
return w.ds.PruneRegistrationEntryEvents(ctx, olderThan)
}

func (w metricsWrapper) SetBundle(ctx context.Context, bundle *common.Bundle) (_ *common.Bundle, err error) {
Expand Down
20 changes: 10 additions & 10 deletions pkg/common/telemetry/server/datastore/wrapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func TestWithMetrics(t *testing.T) {
},
{
key: "datastore.node_event.list",
methodName: "ListAttestedNodesEvents",
methodName: "ListAttestedNodeEvents",
},
{
key: "datastore.bundle.list",
Expand All @@ -167,15 +167,15 @@ func TestWithMetrics(t *testing.T) {
},
{
key: "datastore.registration_entry_event.list",
methodName: "ListRegistrationEntriesEvents",
methodName: "ListRegistrationEntryEvents",
},
{
key: "datastore.federation_relationship.list",
methodName: "ListFederationRelationships",
},
{
key: "datastore.node_event.prune",
methodName: "PruneAttestedNodesEvents",
methodName: "PruneAttestedNodeEvents",
},
{
key: "datastore.bundle.prune",
Expand All @@ -191,7 +191,7 @@ func TestWithMetrics(t *testing.T) {
},
{
key: "datastore.registration_entry_event.prune",
methodName: "PruneRegistrationEntriesEvents",
methodName: "PruneRegistrationEntryEvents",
},
{
key: "datastore.bundle.set",
Expand Down Expand Up @@ -445,8 +445,8 @@ func (ds *fakeDataStore) ListAttestedNodes(context.Context, *datastore.ListAttes
return &datastore.ListAttestedNodesResponse{}, ds.err
}

func (ds *fakeDataStore) ListAttestedNodesEvents(context.Context, *datastore.ListAttestedNodesEventsRequest) (*datastore.ListAttestedNodesEventsResponse, error) {
return &datastore.ListAttestedNodesEventsResponse{}, ds.err
func (ds *fakeDataStore) ListAttestedNodeEvents(context.Context, *datastore.ListAttestedNodeEventsRequest) (*datastore.ListAttestedNodeEventsResponse, error) {
return &datastore.ListAttestedNodeEventsResponse{}, ds.err
}

func (ds *fakeDataStore) ListBundles(context.Context, *datastore.ListBundlesRequest) (*datastore.ListBundlesResponse, error) {
Expand All @@ -461,11 +461,11 @@ func (ds *fakeDataStore) ListRegistrationEntries(context.Context, *datastore.Lis
return &datastore.ListRegistrationEntriesResponse{}, ds.err
}

func (ds *fakeDataStore) ListRegistrationEntriesEvents(context.Context, *datastore.ListRegistrationEntriesEventsRequest) (*datastore.ListRegistrationEntriesEventsResponse, error) {
return &datastore.ListRegistrationEntriesEventsResponse{}, ds.err
func (ds *fakeDataStore) ListRegistrationEntryEvents(context.Context, *datastore.ListRegistrationEntryEventsRequest) (*datastore.ListRegistrationEntryEventsResponse, error) {
return &datastore.ListRegistrationEntryEventsResponse{}, ds.err
}

func (ds *fakeDataStore) PruneAttestedNodesEvents(context.Context, time.Duration) error {
func (ds *fakeDataStore) PruneAttestedNodeEvents(context.Context, time.Duration) error {
return ds.err
}

Expand All @@ -481,7 +481,7 @@ func (ds *fakeDataStore) PruneRegistrationEntries(context.Context, time.Time) er
return ds.err
}

func (ds *fakeDataStore) PruneRegistrationEntriesEvents(context.Context, time.Duration) error {
func (ds *fakeDataStore) PruneRegistrationEntryEvents(context.Context, time.Duration) error {
return ds.err
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/server/authorizedentries/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,8 @@ func (c *Cache) removeEntry(entryID string) {
}
}

func (c *Cache) Stats() cacheStats {
return cacheStats{
func (c *Cache) Stats() CacheStats {
return CacheStats{
AgentsByID: c.agentsByID.Len(),
AgentsByExpiresAt: c.agentsByExpiresAt.Len(),
AliasesByEntryID: c.aliasesByEntryID.Len(),
Expand All @@ -286,7 +286,7 @@ func isNodeAlias(e *types.Entry) bool {
return e.ParentId.Path == idutil.ServerIDPath
}

type cacheStats struct {
type CacheStats struct {
AgentsByID int
AgentsByExpiresAt int
AliasesByEntryID int
Expand Down
16 changes: 8 additions & 8 deletions pkg/server/authorizedentries/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,27 +186,27 @@ func TestCacheInternalStats(t *testing.T) {

cache := NewCache(clk)
cache.UpdateEntry(entry1)
require.Equal(t, cacheStats{
require.Equal(t, CacheStats{
EntriesByEntryID: 1,
EntriesByParentID: 1,
}, cache.Stats())

cache.UpdateEntry(entry2a)
require.Equal(t, cacheStats{
require.Equal(t, CacheStats{
EntriesByEntryID: 2,
EntriesByParentID: 2,
}, cache.Stats())

cache.UpdateEntry(entry2b)
require.Equal(t, cacheStats{
require.Equal(t, CacheStats{
EntriesByEntryID: 1,
EntriesByParentID: 1,
AliasesByEntryID: 2, // one for each selector
AliasesBySelector: 2, // one for each selector
}, cache.Stats())

cache.RemoveEntry(entry1.Id)
require.Equal(t, cacheStats{
require.Equal(t, CacheStats{
AliasesByEntryID: 2, // one for each selector
AliasesBySelector: 2, // one for each selector
}, cache.Stats())
Expand All @@ -222,25 +222,25 @@ func TestCacheInternalStats(t *testing.T) {
t.Run("agents", func(t *testing.T) {
cache := NewCache(clk)
cache.UpdateAgent(agent1.String(), now.Add(time.Hour), []*types.Selector{sel1})
require.Equal(t, cacheStats{
require.Equal(t, CacheStats{
AgentsByID: 1,
AgentsByExpiresAt: 1,
}, cache.Stats())

cache.UpdateAgent(agent2.String(), now.Add(time.Hour*2), []*types.Selector{sel2})
require.Equal(t, cacheStats{
require.Equal(t, CacheStats{
AgentsByID: 2,
AgentsByExpiresAt: 2,
}, cache.Stats())

cache.UpdateAgent(agent2.String(), now.Add(time.Hour*3), []*types.Selector{sel2})
require.Equal(t, cacheStats{
require.Equal(t, CacheStats{
AgentsByID: 2,
AgentsByExpiresAt: 2,
}, cache.Stats())

cache.RemoveAgent(agent1.String())
require.Equal(t, cacheStats{
require.Equal(t, CacheStats{
AgentsByID: 1,
AgentsByExpiresAt: 1,
}, cache.Stats())
Expand Down
16 changes: 8 additions & 8 deletions pkg/server/datastore/datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ type DataStore interface {
UpdateRegistrationEntry(context.Context, *common.RegistrationEntry, *common.RegistrationEntryMask) (*common.RegistrationEntry, error)

// Entries Events
ListRegistrationEntriesEvents(ctx context.Context, req *ListRegistrationEntriesEventsRequest) (*ListRegistrationEntriesEventsResponse, error)
PruneRegistrationEntriesEvents(ctx context.Context, olderThan time.Duration) error
ListRegistrationEntryEvents(ctx context.Context, req *ListRegistrationEntryEventsRequest) (*ListRegistrationEntryEventsResponse, error)
PruneRegistrationEntryEvents(ctx context.Context, olderThan time.Duration) error
FetchRegistrationEntryEvent(ctx context.Context, eventID uint) (*RegistrationEntryEvent, error)
CreateRegistrationEntryEventForTesting(ctx context.Context, event *RegistrationEntryEvent) error
DeleteRegistrationEntryEventForTesting(ctx context.Context, eventID uint) error
Expand All @@ -55,8 +55,8 @@ type DataStore interface {
UpdateAttestedNode(context.Context, *common.AttestedNode, *common.AttestedNodeMask) (*common.AttestedNode, error)

// Nodes Events
ListAttestedNodesEvents(ctx context.Context, req *ListAttestedNodesEventsRequest) (*ListAttestedNodesEventsResponse, error)
PruneAttestedNodesEvents(ctx context.Context, olderThan time.Duration) error
ListAttestedNodeEvents(ctx context.Context, req *ListAttestedNodeEventsRequest) (*ListAttestedNodeEventsResponse, error)
PruneAttestedNodeEvents(ctx context.Context, olderThan time.Duration) error
FetchAttestedNodeEvent(ctx context.Context, eventID uint) (*AttestedNodeEvent, error)
CreateAttestedNodeEventForTesting(ctx context.Context, event *AttestedNodeEvent) error
DeleteAttestedNodeEventForTesting(ctx context.Context, eventID uint) error
Expand Down Expand Up @@ -169,7 +169,7 @@ type ListAttestedNodesResponse struct {
Pagination *Pagination
}

type ListAttestedNodesEventsRequest struct {
type ListAttestedNodeEventsRequest struct {
GreaterThanEventID uint
LessThanEventID uint
}
Expand All @@ -179,7 +179,7 @@ type AttestedNodeEvent struct {
SpiffeID string
}

type ListAttestedNodesEventsResponse struct {
type ListAttestedNodeEventsResponse struct {
Events []AttestedNodeEvent
}

Expand Down Expand Up @@ -223,7 +223,7 @@ type ListRegistrationEntriesResponse struct {
Pagination *Pagination
}

type ListRegistrationEntriesEventsRequest struct {
type ListRegistrationEntryEventsRequest struct {
GreaterThanEventID uint
LessThanEventID uint
}
Expand All @@ -233,7 +233,7 @@ type RegistrationEntryEvent struct {
EntryID string
}

type ListRegistrationEntriesEventsResponse struct {
type ListRegistrationEntryEventsResponse struct {
Events []RegistrationEntryEvent
}

Expand Down
Loading
Loading