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

Add new version with AppProtocol, defaulted to 0 with flow.Flow usage #20

Merged
merged 2 commits into from
May 17, 2023

Conversation

aaronfuj
Copy link
Contributor

@aaronfuj aaronfuj commented May 16, 2023

Updates the chf.CHF and flow.Flow structs to support passing in an App Protocol. An App Protocol can be used to specify the type of flow being sent (i.e. Flow, SNMP, Streaming Telemetry Interface Metrics, etc.).

This has been validated to at least avoid regression by internal services leveraging libkflow and upgrading (without changing/using AppProtocol).

By default, this will make all consumers of flow.Flow have an App Protocol of 0 instead of the previous default max uint32 value. Therefore this is not a backwards compatible change. For any users that want to retain the 'no value', they will need to manually set the App Protocol field to math.MaxUint32 or 1<<32 - 1 or decimal value 4294967295.

@aaronfuj aaronfuj self-assigned this May 16, 2023
@aaronfuj aaronfuj changed the title Add new version with AppProtocol Add new version with AppProtocol, defaulted to 0 with flow.Flow usage May 17, 2023
@aaronfuj aaronfuj marked this pull request as ready for review May 17, 2023 00:19
@aaronfuj aaronfuj requested a review from a team May 17, 2023 00:19
cleroux
cleroux previously approved these changes May 17, 2023
Copy link

@cleroux cleroux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code seems fine. I trust your judgement on the bigger picture.

flow/flow.go Outdated
@@ -82,6 +82,7 @@ type Flow struct {
Ipv6SrcRoutePrefix []byte
Ipv6DstRoutePrefix []byte
IsMetric bool
AppProtocol uint32
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This struct can be optimized to reduce memory usage by about 6% if my napkin math is correct. I only mention it because this seems like a struct we instantiate a lot. There are a couple gaps in this struct if we consider the 8-byte alignment.
I think you can add AppProtocol without increasing memory usage if you insert it immediately after TcpRetransmit uint32

Does the ordering of these fields matter to capn proto? If not we can optimize it further by grouping the bool and uint8 fields.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I completely forgot about struct padding and packing in this way. This is indeed something that is heavily used and instantiated a lot so I think this will be pretty beneficial, but is something I'd want to do a little bit more due diligence on and have its own PR to show some before/after. For now I'll put it by the TcpRetransmit as you recommended since I agree that makes sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created #21 as the issue to track the further improvement.

@aaronfuj
Copy link
Contributor Author

Re-verified via internal services and created #21 for the follow up improvement.

@aaronfuj aaronfuj merged commit 65fe2d1 into master May 17, 2023
@aaronfuj aaronfuj deleted the af-update-capnproto branch May 19, 2023 20:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants