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

Feature/restart count delta #382

Merged
merged 5 commits into from
Mar 31, 2022
Merged

Feature/restart count delta #382

merged 5 commits into from
Mar 31, 2022

Conversation

sigilioso
Copy link
Contributor

@sigilioso sigilioso commented Mar 21, 2022

Closes #379

@CLAassistant
Copy link

CLAassistant commented Mar 21, 2022

CLA assistant check
All committers have signed the CLA.

@sigilioso sigilioso linked an issue Mar 21, 2022 that may be closed by this pull request
4 tasks
@sigilioso sigilioso requested a review from a team March 24, 2022 08:00
@sigilioso sigilioso marked this pull request as ready for review March 24, 2022 08:01
func TestRestartCountDeltaValues(t *testing.T) {
intgr, err := integration.New("test", "test", integration.InMemoryStore())
assert.NoError(t, err)
intgr.Clear()
Copy link
Member

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?

Copy link
Contributor Author

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!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed here: bc62e84

@@ -200,6 +233,40 @@ func TestPopulateK8s(t *testing.T) {
}
}

func TestRestartCountDeltaValues(t *testing.T) {
intgr, err := integration.New("test", "test", integration.InMemoryStore())
Copy link
Member

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

Copy link
Contributor

@roobre roobre Mar 24, 2022

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed here: bc62e84

}
for k, values := range valuesInTime {
if lenValues := len(values); lenValues > 0 {
metrics[k] = values[tg.groupCallsCount%lenValues]
Copy link
Member

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

@@ -200,6 +233,40 @@ func TestPopulateK8s(t *testing.T) {
}
}

func TestRestartCountDeltaValues(t *testing.T) {
intgr, err := integration.New("test", "test", integration.InMemoryStore())
Copy link
Member

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()?

Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added here: bc62e84

Copy link
Member

@paologallinaharbur paologallinaharbur left a 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)

@@ -144,18 +145,50 @@ var kubeletSpecs = definition.SpecGroups{
"container": metric.KubeletSpecs["container"],
}

type testGrouper struct{}
type testGrouper struct {
Copy link
Contributor

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

Copy link
Contributor Author

@sigilioso sigilioso Mar 24, 2022

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

Copy link
Contributor

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

Comment on lines 149 to 152
// 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{}
Copy link
Contributor

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.

Copy link
Contributor Author

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.

return groups, nil
}

func (tg *testGrouper) buildMetrics(
Copy link
Contributor

Choose a reason for hiding this comment

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

What does buildMetrics do?

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'm improving docs/naming because if you had to ask... it is not obvious enough ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done: 50c8a5a

@@ -200,6 +233,40 @@ func TestPopulateK8s(t *testing.T) {
}
}

func TestRestartCountDeltaValues(t *testing.T) {
intgr, err := integration.New("test", "test", integration.InMemoryStore())
Copy link
Contributor

@roobre roobre Mar 24, 2022

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

src/scrape/scrape_job_test.go Show resolved Hide resolved
@sigilioso sigilioso requested review from paologallinaharbur, roobre and a team March 29, 2022 07:17
Copy link
Contributor

@roobre roobre left a 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! ❤️

@sigilioso sigilioso merged commit 7f4c3b3 into main Mar 31, 2022
@sigilioso sigilioso deleted the feature/restartCountDelta branch March 31, 2022 11:12
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.

Add restartCountDelta metric
4 participants