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 nodelatencystats rest apis implementation. #6479

Merged
merged 2 commits into from
Jul 25, 2024

Conversation

IRONICBo
Copy link
Contributor

@IRONICBo IRONICBo commented Jun 23, 2024

In last PR #6392, we have defined some rest apis for nodelatencystats.

We have implemented the inner operations by cache.Indexer and support query nodelatencystats by api.

Example:

$ kubectl get nodelatencystats
NODE NAME            NUM LATENCY ENTRIES   AVG LATENCY   MAX LATENCY
kind-control-plane   2                     7.110553ms    8.94447ms
kind-worker          2                     11.177585ms   11.508751ms
kind-worker2         2                     11.356675ms   15.265629ms

@IRONICBo IRONICBo requested review from antoninbas and tnqn July 2, 2024 00:49
@IRONICBo IRONICBo force-pushed the feat/impl-node-latency-query-api branch from 481f49c to 3e38af0 Compare July 2, 2024 08:23
@antoninbas antoninbas mentioned this pull request Jul 22, 2024
Copy link
Contributor

@antoninbas antoninbas left a comment

Choose a reason for hiding this comment

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

some of the comments in rest_test.go apply to all test cases, even though I only commented once. Please update all test cases as necessary.

@IRONICBo IRONICBo requested a review from antoninbas July 24, 2024 17:22
@antoninbas antoninbas added this to the Antrea v2.1 release milestone Jul 24, 2024
Comment on lines 138 to 142
if targetIPLatencyCount == 1 {
avgLatency = currentLatency
} else {
avgLatency += (currentLatency - avgLatency) / targetIPLatencyCount
}
Copy link
Contributor

Choose a reason for hiding this comment

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

you should do avgLatency += currentLatency here, and divide at the end to avoid rounding errors.
(not worried about an overflow given that this is an int64)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I've changed it to simple accumulation.

Comment on lines 104 to 105
{Name: "Max Latency", Type: "integer", Format: "int64", Description: "Name of the peer with the highest latency and the latency value(ns)."},
{Name: "Avg Latency", Type: "integer", Format: "int64", Description: "Average latency value across all peers(ns)."},
Copy link
Contributor

Choose a reason for hiding this comment

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

It may be more user-friendly to make this a string.
To convert from the integral latency value (in ns) to the string, you would use: time.Duration(latency).String()
This way the column will be displayed as a value with a user-friendly unit (e.g., 10ns, 10µs, 10ms).
With this change, you can remove the unit specification ((ns)) from the column description.

Copy link
Contributor Author

@IRONICBo IRONICBo Jul 25, 2024

Choose a reason for hiding this comment

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

Ok, using a formatted timestamp string is a better choice.

Comment on lines 49 to 50
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Copy link
Contributor

Choose a reason for hiding this comment

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

There is no need to create a cancellable context, you should just use ctx := context.Background()

same comment for other tests

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I've updated all of them.

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
obj, err := r.Create(ctx, summary, nil, nil)
assert.NoError(t, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
assert.NoError(t, err)
require.NoError(t, err)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok.

Copy link
Contributor

Choose a reason for hiding this comment

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

this one was not addressed

expectedErr bool
err error
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't need the boolean (expectedErr). You can check err != nil in the test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, expectedErr has been removed.

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
_, err := r.Create(ctx, tt.summary, nil, nil)
assert.Nil(t, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
assert.Nil(t, err)
require.NoError(t, err)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I've updated all of them.

defer cancel()

_, err := r.Create(ctx, tt.summary, nil, nil)
assert.NoError(t, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok.

defer cancel()

_, err := r.Create(ctx, summary, nil, nil)
assert.Nil(t, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok.

_, err := r.Create(ctx, summary, nil, nil)
assert.Nil(t, err)
objs, err := r.List(ctx, options)
assert.NoError(t, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
assert.NoError(t, err)
require.NoError(t, err)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok.

defer cancel()

_, err := r.Create(ctx, summary, nil, nil)
assert.Nil(t, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok.

_, err := r.Create(ctx, summary, nil, nil)
assert.Nil(t, err)
obj, err := r.ConvertToTable(ctx, summary, nil)
assert.NoError(t, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok.

assert.Nil(t, err)
obj, err := r.ConvertToTable(ctx, summary, nil)
assert.NoError(t, err)
assert.Equal(t, expectedObj, obj.Rows[0].Object.Object)
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this test is doing anything
You need to populate PeerNodeLatencyStats with some data and validate the actual rows.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I populated PeerNodeLatencyStats in this case.

@IRONICBo IRONICBo requested a review from antoninbas July 25, 2024 09:10
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
obj, err := r.Create(ctx, summary, nil, nil)
assert.NoError(t, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

this one was not addressed

Comment on lines 164 to 167
options := &internalversion.ListOptions{
Limit: 10,
Continue: "",
}
Copy link
Contributor

Choose a reason for hiding this comment

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

remove, we should use nil as the list options in this test given that we don't support them yet

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it is be better to be removed.

Comment on lines 205 to 210
expectedObj := &statsv1alpha1.NodeLatencyStats{
ObjectMeta: metav1.ObjectMeta{Name: "node1"},
PeerNodeLatencyStats: []statsv1alpha1.PeerNodeLatencyStats{
{
NodeName: "node2",
TargetIPLatencyStats: []statsv1alpha1.TargetIPLatencyStats{
{
TargetIP: "192.168.0.1",
LastSendTime: metav1.Time{Time: mockTime},
LastRecvTime: metav1.Time{Time: mockTime},
LastMeasuredRTTNanoseconds: 0,
},
},
},
},
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think defining this object is useful, and I don't think the assert.Equal(t, expectedObj, obj.Rows[0].Object.Object) is very useful either.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, the two parts are really the same and can be left out of the comparison.

Comment on lines 191 to 203
PeerNodeLatencyStats: []statsv1alpha1.PeerNodeLatencyStats{
{
NodeName: "node2",
TargetIPLatencyStats: []statsv1alpha1.TargetIPLatencyStats{
{
TargetIP: "192.168.0.1",
LastSendTime: metav1.Time{Time: mockTime},
LastRecvTime: metav1.Time{Time: mockTime},
LastMeasuredRTTNanoseconds: 0,
},
},
},
},
Copy link
Contributor

Choose a reason for hiding this comment

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

please add a second Node entry to this list, and use non-zero (and distinct) values for LastMeasuredRTTNanoseconds, for higher-quality testing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok.

IRONICBo and others added 2 commits July 25, 2024 13:53
Signed-off-by: Asklv <boironic@gmail.com>
Signed-off-by: Antonin Bas <antonin.bas@broadcom.com>
@antoninbas antoninbas force-pushed the feat/impl-node-latency-query-api branch from 1d3a874 to 2d54451 Compare July 25, 2024 21:01
@antoninbas
Copy link
Contributor

/skip-all

@antoninbas antoninbas merged commit 4d9953f into antrea-io:main Jul 25, 2024
58 of 61 checks passed
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.

3 participants