Skip to content

Conversation

@ronensc
Copy link
Collaborator

@ronensc ronensc commented Feb 27, 2022

This is a follow up to #95 as part of #61

@ronensc ronensc self-assigned this Feb 27, 2022
@ronensc ronensc changed the title Add a test for extract_aggregate [WIP] Add a test for extract_aggregate Feb 27, 2022
@codecov-commenter
Copy link

codecov-commenter commented Feb 27, 2022

Codecov Report

Merging #106 (7d74fce) into main (59852cf) will increase coverage by 1.25%.
The diff coverage is n/a.

Impacted file tree graph

@@            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     
Flag Coverage Δ
unittests 56.05% <ø> (+1.25%) ⬆️

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

Impacted Files Coverage Δ
pkg/pipeline/extract/extract.go 100.00% <0.00%> (ø)
pkg/api/encode_prom.go 100.00% <0.00%> (ø)
cmd/confgenerator/main.go 0.00% <0.00%> (ø)
pkg/pipeline/extract/extract_aggregate.go 56.25% <0.00%> (ø)
pkg/api/transform_network.go 100.00% <0.00%> (ø)
pkg/api/enum.go 68.00% <0.00%> (ø)
pkg/api/write_loki.go 55.55% <0.00%> (ø)
pkg/api/encode_kafka.go 100.00% <0.00%> (ø)
pkg/pipeline/write/write_loki.go 67.23% <0.00%> (+4.51%) ⬆️
pkg/pipeline/pipeline.go 74.35% <0.00%> (+10.25%) ⬆️
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 59852cf...7d74fce. Read the comment docs.

@ronensc ronensc requested review from KalmanMeth and eranra February 27, 2022 14:04
@ronensc ronensc changed the title [WIP] Add a test for extract_aggregate Add a test for extract_aggregate Feb 27, 2022
"count": "2",
},
{
"name": "bandwidth",
Copy link
Collaborator

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",
Copy link
Collaborator

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?

Copy link
Collaborator Author

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)

}
Copy link
Collaborator

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

Copy link
Collaborator Author

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.
Copy link
Collaborator

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 :-)

Copy link
Collaborator

@eranra eranra left a 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 ./...
Copy link
Collaborator Author

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},
Copy link
Collaborator

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?

Copy link
Collaborator Author

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",
Copy link
Collaborator

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".

Copy link
Collaborator Author

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...

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)
Copy link
Collaborator

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?

Copy link
Collaborator Author

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)

@eranra
Copy link
Collaborator

eranra commented Mar 1, 2022

@ronensc it looks very-very nice now :-) thanks for putting effort to create those tests :-)

@eranra eranra merged commit 510ca74 into netobserv:main Mar 1, 2022
@ronensc ronensc deleted the test-extract-agg branch March 1, 2022 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants