-
Notifications
You must be signed in to change notification settings - Fork 51
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
Feature/restart count delta #382
Conversation
src/scrape/scrape_job_test.go
Outdated
func TestRestartCountDeltaValues(t *testing.T) { | ||
intgr, err := integration.New("test", "test", integration.InMemoryStore()) | ||
assert.NoError(t, err) | ||
intgr.Clear() |
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 intgr.Clear()
is needed?
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.
As it is (or it should be) a brand new integration, I guess it is not needed. I'm digging into it in this and the populate-test we already had. Thanks!
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.
Removed here: bc62e84
src/scrape/scrape_job_test.go
Outdated
@@ -200,6 +233,40 @@ func TestPopulateK8s(t *testing.T) { | |||
} | |||
} | |||
|
|||
func TestRestartCountDeltaValues(t *testing.T) { | |||
intgr, err := integration.New("test", "test", integration.InMemoryStore()) |
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.
If I am not wrong two subsequent calls to integration.New() cause a panic (😢 )
If not really needed I would try to avoid using the integration in tests
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.
As integrations are stored globally, it would be advisable to have unique names for them. Otherwise, other test using "test", "test"
might cause race/concurrency issues. The Test integration helper does this for you :)
https://github.com/newrelic/nri-kubernetes/blob/main/internal/testutil/integration.go#L23
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.
Thanks! I didn't know. I will fix it here too.
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.
Fixed here: bc62e84
src/scrape/scrape_job_test.go
Outdated
} | ||
for k, values := range valuesInTime { | ||
if lenValues := len(values); lenValues > 0 { | ||
metrics[k] = values[tg.groupCallsCount%lenValues] |
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.
[nit] I would add a comment explaining this, maybe also moving the index calculation to a different line
src/scrape/scrape_job_test.go
Outdated
@@ -200,6 +233,40 @@ func TestPopulateK8s(t *testing.T) { | |||
} | |||
} | |||
|
|||
func TestRestartCountDeltaValues(t *testing.T) { | |||
intgr, err := integration.New("test", "test", integration.InMemoryStore()) |
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.
can we add t.parallel()?
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.
If you use t.Parallel
you'll need to wrap this with a mutex to avoid a race in the SDK. It's not particularly good, but the problem is already solved :)
https://github.com/newrelic/nri-kubernetes/blob/main/internal/testutil/integration.go#L18
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 here: bc62e84
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 like the approach, I added just some nits.
By the way after adding a new metric we need to update the spec file 😢 (I would really prefer the nrql being able to deal with cumulative counts in a better way)
src/scrape/scrape_job_test.go
Outdated
@@ -144,18 +145,50 @@ var kubeletSpecs = definition.SpecGroups{ | |||
"container": metric.KubeletSpecs["container"], | |||
} | |||
|
|||
type testGrouper struct{} | |||
type testGrouper struct { |
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 probably complaining about code that was already here (sorry!), but I'm finding hard to understand what testGrouper
is. Is it a helper? A mock? What does it do? I'd love to see a godoc comment explaining it :)
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 just extended the mock we had there... Anyway, you are right it was not obvious and now which it does more stuff it may be confusing. I'll improve naming and maybe include some godocs
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.
Yep, I don't think it needs to be exhaustive since it's unexported and for tests. Oneliners such as // testGrouper is an implementation of the Grouper interface that returns mocked metrics that might change in subsequent calls.
will be more than enough :)
src/scrape/scrape_job_test.go
Outdated
// PodValuesInTime allows to overwrite some metrics value in each Group execution. Ex: {"isReady": {0, 1, 2, 3}} | ||
PodValuesInTime map[string][]interface{} | ||
// ContainerValuesInTime allows to overwrite some metrics value in each Group execution. Ex: {"restartCount": {0, 1, 2, 3}} | ||
ContainerValuesInTime map[string][]interface{} |
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.
Is there a reason to have two identical fields for pod and container specifically? I wonder if we could do this differently so if we need to add values over time for another entity, e.g. Volume
, we don't need to add another VolumeValuesInTime
field.
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.
After this change 50c8a5a it is a bit more abstract.
We could go further and extract this mock and the corresponding specs to a testutils file and give them some parameters to make it easier to reduce fixtures as needed in different tests... I would include that change in a different PR.
src/scrape/scrape_job_test.go
Outdated
return groups, nil | ||
} | ||
|
||
func (tg *testGrouper) buildMetrics( |
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.
What does buildMetrics
do?
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 improving docs/naming because if you had to ask... it is not obvious enough ;)
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.
Done: 50c8a5a
src/scrape/scrape_job_test.go
Outdated
@@ -200,6 +233,40 @@ func TestPopulateK8s(t *testing.T) { | |||
} | |||
} | |||
|
|||
func TestRestartCountDeltaValues(t *testing.T) { | |||
intgr, err := integration.New("test", "test", integration.InMemoryStore()) |
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.
As integrations are stored globally, it would be advisable to have unique names for them. Otherwise, other test using "test", "test"
might cause race/concurrency issues. The Test integration helper does this for you :)
https://github.com/newrelic/nri-kubernetes/blob/main/internal/testutil/integration.go#L23
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.
Love the new approach, thanks for addressing the comments! ❤️
Closes #379