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 methods to Set Interface #139

Merged
merged 1 commit into from
Feb 17, 2021

Conversation

srikartati
Copy link
Contributor

Add PrepareSet and ResetSet methods to Set interface.
This is to avoid multiple allocations by the user, for example, when
exporting sets user could allocate the Set only once and re-use it
for exporting multiple records.

PS: In Antrea, the main user of go-ipfix library, this change enables to write better unit tests.

@codecov
Copy link

codecov bot commented Feb 16, 2021

Codecov Report

Merging #139 (9de6727) into release-0.4.0 (5de397a) will decrease coverage by 0.63%.
The diff coverage is 46.66%.

Impacted file tree graph

@@                Coverage Diff                @@
##           release-0.4.0     #139      +/-   ##
=================================================
- Coverage          78.63%   78.00%   -0.64%     
=================================================
  Files                 13       13              
  Lines               1807     1823      +16     
=================================================
+ Hits                1421     1422       +1     
- Misses               253      260       +7     
- Partials             133      141       +8     
Flag Coverage Δ
integration-tests 62.42% <28.57%> (-0.64%) ⬇️
unit-tests 76.90% <46.66%> (-0.63%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pkg/exporter/process.go 66.66% <33.33%> (-1.55%) ⬇️
pkg/collector/process.go 86.88% <37.50%> (-2.01%) ⬇️
pkg/entities/set.go 76.08% <56.25%> (-13.11%) ⬇️

Comment on lines +79 to 87
func (s *set) ResetSet() {
s.buffer.Reset()
s.setType = Undefined
s.records = s.records[:0]
}
Copy link
Contributor

@zyiou zyiou Feb 17, 2021

Choose a reason for hiding this comment

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

Since we will probably encounter Undefined for setType, we should check whether setType is Undefined in AddRecords function to avoid adding record to invalid set.

if !isDecoding {
}

func (s *set) PrepareSet(templateID uint16) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible that we PrepareSet after ResetSet? I think this is a valid use case for us to re-use the set. If so, we can consider moving the setType parameter to PrepareSet otherwise the setType will be Undefined

Copy link
Contributor Author

@srikartati srikartati Feb 17, 2021

Choose a reason for hiding this comment

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

Agreed it is good to have these checks. Yes, we can reuse the set for both data and template types instead of allocating again.
Added those checks.
Edit: still working on the change

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the problem is still there -- if we call ResetSet and then want to use PrepareSet, the setType will always be Undefined.

Copy link
Contributor

Choose a reason for hiding this comment

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

And it's better to add another check here so that Undefined setType will not go through this function.

@srikartati srikartati force-pushed the change_sets branch 2 times, most recently from 5993fb3 to 82ec754 Compare February 17, 2021 19:38
Add PrepareSet and ResetSet methods to Set interface.
This is to avoid multiple allocations by the user, for example, when
exporting sets user could allocate the Set only once and re-use it
for exporting multiple records.
@srikartati
Copy link
Contributor Author

Originally I was thinking of using separate sets for data and template, so did not take care of set type.
It makes sense to use one set and just have separate ones for encoding and decoding.

Made the changes accordingly and addressed comments too.
Thanks for the comments @zyiou

Copy link
Contributor

@zyiou zyiou left a comment

Choose a reason for hiding this comment

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

Thanks for addressing the comments. LGTM

@srikartati srikartati merged commit dcaba26 into vmware:release-0.4.0 Feb 17, 2021
@srikartati srikartati deleted the change_sets branch February 17, 2021 19:48
srikartati added a commit to srikartati/go-ipfix that referenced this pull request Feb 18, 2021
Add PrepareSet and ResetSet methods to Set interface.
This is to avoid multiple allocations by the user, for example, when
exporting sets user could allocate the Set only once and re-use it
for exporting multiple records.
srikartati added a commit to srikartati/go-ipfix that referenced this pull request Feb 19, 2021
Add PrepareSet and ResetSet methods to Set interface.
This is to avoid multiple allocations by the user, for example, when
exporting sets user could allocate the Set only once and re-use it
for exporting multiple records.
srikartati added a commit that referenced this pull request Feb 19, 2021
Add PrepareSet and ResetSet methods to Set interface.
This is to avoid multiple allocations by the user, for example, when
exporting sets user could allocate the Set only once and re-use it
for exporting multiple records.
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.

3 participants