-
Notifications
You must be signed in to change notification settings - Fork 368
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
Add nodelatencystats rest apis implementation. #6479
Conversation
481f49c
to
3e38af0
Compare
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.
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.
if targetIPLatencyCount == 1 { | ||
avgLatency = currentLatency | ||
} else { | ||
avgLatency += (currentLatency - avgLatency) / targetIPLatencyCount | ||
} |
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.
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
)
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.
Ok, I've changed it to simple accumulation.
{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)."}, |
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.
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.
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.
Ok, using a formatted timestamp string is a better choice.
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() |
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.
There is no need to create a cancellable context, you should just use ctx := context.Background()
same comment for other 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.
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) |
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.
assert.NoError(t, err) | |
require.NoError(t, err) |
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.
Ok.
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.
this one was not addressed
expectedErr bool | ||
err error |
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.
You don't need the boolean (expectedErr
). You can check err != nil
in the 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.
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) |
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.
assert.Nil(t, err) | |
require.NoError(t, err) |
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.
Ok, I've updated all of them.
defer cancel() | ||
|
||
_, err := r.Create(ctx, tt.summary, nil, nil) | ||
assert.NoError(t, err) |
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.
ditto
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.
Ok.
defer cancel() | ||
|
||
_, err := r.Create(ctx, summary, nil, nil) | ||
assert.Nil(t, err) |
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.
ditto
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.
Ok.
_, err := r.Create(ctx, summary, nil, nil) | ||
assert.Nil(t, err) | ||
objs, err := r.List(ctx, options) | ||
assert.NoError(t, err) |
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.
assert.NoError(t, err) | |
require.NoError(t, err) |
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.
Ok.
defer cancel() | ||
|
||
_, err := r.Create(ctx, summary, nil, nil) | ||
assert.Nil(t, err) |
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.
ditto
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.
Ok.
_, err := r.Create(ctx, summary, nil, nil) | ||
assert.Nil(t, err) | ||
obj, err := r.ConvertToTable(ctx, summary, nil) | ||
assert.NoError(t, err) |
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.
ditto
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.
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) |
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 don't think this test is doing anything
You need to populate PeerNodeLatencyStats
with some data and validate the actual rows.
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.
Ok, I populated PeerNodeLatencyStats
in this case.
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
obj, err := r.Create(ctx, summary, nil, nil) | ||
assert.NoError(t, err) |
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.
this one was not addressed
options := &internalversion.ListOptions{ | ||
Limit: 10, | ||
Continue: "", | ||
} |
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.
remove, we should use nil
as the list options in this test given that we don't support them yet
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.
Yes, it is be better to be removed.
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, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} |
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 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.
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.
Okay, the two parts are really the same and can be left out of the comparison.
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, | ||
}, | ||
}, | ||
}, | ||
}, |
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.
please add a second Node entry to this list, and use non-zero (and distinct) values for LastMeasuredRTTNanoseconds
, for higher-quality testing
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.
Ok.
Signed-off-by: Asklv <[email protected]>
Signed-off-by: Antonin Bas <[email protected]>
1d3a874
to
2d54451
Compare
/skip-all |
In last PR #6392, we have defined some rest apis for
nodelatencystats
.We have implemented the inner operations by
cache.Indexer
and support querynodelatencystats
by api.Example: