-
Notifications
You must be signed in to change notification settings - Fork 522
Improve performance for fetching authorized entries #6034
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @sorindumitru for this, it looks great!
func (e *ReadOnlyEntry) GetX509SvidTtl() int32 { | ||
return e.entry.X509SvidTtl | ||
} | ||
|
||
func (e *ReadOnlyEntry) GetJwtSvidTtl() int32 { | ||
return e.entry.JwtSvidTtl | ||
} | ||
|
||
func (e *ReadOnlyEntry) GetDnsNames() []string { | ||
return slices.Clone(e.entry.DnsNames) | ||
} | ||
|
||
func (e *ReadOnlyEntry) GetRevisionNumber() int64 { | ||
return e.entry.RevisionNumber | ||
} | ||
|
||
func (e *ReadOnlyEntry) GetCreatedAt() int64 { | ||
return e.entry.CreatedAt | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't seem like we there is test coverage for this, could you add that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a test to verify that the getters return the expected value
9330dde
to
6b83d27
Compare
One thing I realized was that it's somewhat possible to switch the trust domain of a deployment. I've added some changes to filter the entries with the wrong trust domain from the cache and a test for that too. |
6b83d27
to
d73d8a7
Compare
|
||
// Manually clone the entry instead of using the protobuf helpers | ||
// since those are two times slower. | ||
func (e *ReadOnlyEntry) Clone(mask *types.EntryMask) *types.Entry { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit concerned about the potential for field skew here. If the types.Entry struct is updated in the future (e.g., new fields are added), the manual Clone implementation will also need to be updated. Otherwise, newly added fields won't be cloned, which could lead to subtle, hard-to-detect bugs.
It might be helpful to add a comment warning about this, or ideally, include a test (perhaps using reflection) that ensures all fields are properly cloned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a test for this, which indeed uses reflection to make sure all fields are cloned:
spire/pkg/server/api/entry_test.go
Line 727 in d73d8a7
func TestReadOnlyEntryClone(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I missed that, thanks!
This also improves performance slightly since we no longer clone some slices. Signed-off-by: Sorin Dumitru <[email protected]>
Will be used in cases where an entry returned from a cache should not be modified. Access to individual fields can copy/clone fields as needed. Signed-off-by: Sorin Dumitru <[email protected]>
This slightly speeds up the SVID signing operation since we no longer have to fully clone the entries the agent has requested SVIDs for. Signed-off-by: Sorin Dumitru <[email protected]>
Signed-off-by: Sorin Dumitru <[email protected]>
spiffeIDFromProto() takes about 20% of the time to lookup authorized entries, so it seems worthwhile removing it. The path component is sufficient to identify the entries since all entries are going to have the same trust domain. Signed-off-by: Sorin Dumitru <[email protected]>
Signed-off-by: Sorin Dumitru <[email protected]>
Signed-off-by: Sorin Dumitru <[email protected]>
d73d8a7
to
9ea2eaf
Compare
This does a bunch of speedups to authorized entries lookup (used for syncing agent entries but also for signing SVIDs):
Some of the benchmarks we have in the tests show good improvements. Seen improvements also while running this, although somewhat smaller than the benchmark since some of the work still needs to be done in other places. Before:
and after:
For the events based cache. Before:
and after: