-
Notifications
You must be signed in to change notification settings - Fork 33
Add a test for extract_aggregate #106
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
759c688 to
2b82192
Compare
Codecov Report
@@ Coverage Diff @@
## main #106 +/- ##
==========================================
+ Coverage 54.80% 56.05% +1.25%
==========================================
Files 37 45 +8
Lines 2332 2501 +169
==========================================
+ Hits 1278 1402 +124
- Misses 981 1016 +35
- Partials 73 83 +10
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
| "count": "2", | ||
| }, | ||
| { | ||
| "name": "bandwidth", |
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.
@ronensc what is the difference from the previous test? (do we need this test ?)
| "count": "2", | ||
| }, | ||
| { | ||
| "name": "bandwidth_count", |
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.
The same question seems that these tests again count. ...
BTW; maybe add also avg test?
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.
Added
| actualAggs2 := extractAggregate.Extract(input2) | ||
| require.ElementsMatch(t, expectedAggs2, actualAggs2) | ||
|
|
||
| } |
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.
@ronensc general remark, maybe put the use cases in some for loop and just run them all of them against extractAggregate --- this is very common for tests --- look here for an example b24be79#diff-168486be9e126a8de1f0588534a9bf2fd49261555cbdc3759a5be2b1d2825cd3R26
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.
@eranra The test tests extract_aggregate as a whole. It can be thought of as an integration test between extract_aggregate.go and aggregate.go and aggregates.go.
The test sends flows in 2 batches and verifies the extractor's output after each batch. The output of the 2nd batch depends on the 1st batch. I'll check if the referred pattern is suitable here as well.
| @@ -0,0 +1,172 @@ | |||
| /* | |||
| * Copyright (C) 2021 IBM, Inc. | |||
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.
we are in 2022 ... 2021 is history :-)
eranra
left a comment
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.
Looks good to me, some comments but this is good ... waiting for @KalmanMeth to review :-)
| .PHONY: test | ||
| test: validate_go ## Test | ||
| go test -p 1 -race -covermode=atomic -coverprofile=/tmp/coverage.out ./... | ||
| go test -p 1 -race -coverpkg=./... -covermode=atomic -coverprofile=/tmp/coverage.out ./... |
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.
@eranra please note that I added the -coverpkg flag.
I added it because I noticed that the code coverage didn't increase for aggregate.go although this PR tests execution paths that were not tested by the other tests. The reason is that the test in this PR is in a different go package from aggregate.go. Adding the flag solves this. The following repo helped me understand this:
https://github.com/yudai/go_cover
| input1 := []config.GenericMap{ | ||
| {"service": "http", "bytes": 10.0}, | ||
| {"service": "http", "bytes": 20.0}, | ||
| {"service": "tcp", "bytes": 1.0}, |
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.
Why are "bytes" floats and not integers?
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'll fix this
| "value": "30.000000", | ||
| "bandwidth_value": "30.000000", | ||
| "recentRawValues": []float64{10.0, 20.0}, | ||
| "count": "2", |
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.
We now handle integers and not just strings, so "count" should be an integer. Same for "value" and "bandwidth_value".
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 used strings because that's the format returned by: GetMetrics()
I admit that I don't understand why it's string...
flowlogs-pipeline/pkg/pipeline/extract/aggregate/aggregate.go
Lines 178 to 189 in 59852cf
| metrics = append(metrics, config.GenericMap{ | |
| "name": aggregate.Definition.Name, | |
| "operation": aggregate.Definition.Operation, | |
| "record_key": aggregate.Definition.RecordKey, | |
| "by": strings.Join(aggregate.Definition.By, ","), | |
| "aggregate": string(group.normalizedValues), | |
| "value": fmt.Sprintf("%f", group.value), | |
| "recentRawValues": group.RecentRawValues, | |
| "count": fmt.Sprintf("%d", group.count), | |
| aggregate.Definition.Name + "_value": fmt.Sprintf("%f", group.value), | |
| strings.Join(aggregate.Definition.By, "_"): string(group.normalizedValues), | |
| }) |
| ) | ||
|
|
||
| func createAgg(name, recordKey, by, agg, op string, value float64, count int, rrv []float64) config.GenericMap { | ||
| valueString := fmt.Sprintf("%f", value) |
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.
Why do we need these to be strings?
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.
Same reason as #106 (comment)
|
@ronensc it looks very-very nice now :-) thanks for putting effort to create those tests :-) |
This is a follow up to #95 as part of #61