Skip to content

Commit

Permalink
Address latest round of review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Antonin Bas <[email protected]>
  • Loading branch information
antoninbas committed Jul 25, 2024
1 parent a7064c5 commit 2d54451
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 21 deletions.
4 changes: 2 additions & 2 deletions pkg/apiserver/registry/stats/nodelatencystats/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ func (r *REST) ConvertToTable(ctx context.Context, obj runtime.Object, tableOpti
ColumnDefinitions: []metav1.TableColumnDefinition{
{Name: "Node Name", Type: "string", Format: "name", Description: "Name of Node from which latency was measured."},
{Name: "Num Latency Entries", Type: "integer", Format: "int64", Description: "Number of peers for which latency measurements are available."},
{Name: "Max Latency", Type: "string", Format: "", Description: "Name of the peer with the highest latency and the latency value."},
{Name: "Avg Latency", Type: "string", Format: "", Description: "Average latency value across all peers."},
{Name: "Max Latency", Type: "string", Format: "", Description: "Largest latency value across all peers."},
},
}
if m, err := meta.ListAccessor(obj); err == nil {
Expand Down Expand Up @@ -146,7 +146,7 @@ func (r *REST) ConvertToTable(ctx context.Context, obj runtime.Object, tableOpti
avgLatency = avgLatency / targetIPLatencyCount
}

return []interface{}{name, peerNodeLatencyEntriesCount, time.Duration(maxLatency).String(), time.Duration(avgLatency).String()}, nil
return []interface{}{name, peerNodeLatencyEntriesCount, time.Duration(avgLatency).String(), time.Duration(maxLatency).String()}, nil
})
return table, err
}
Expand Down
27 changes: 8 additions & 19 deletions pkg/apiserver/registry/stats/nodelatencystats/rest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/apis/meta/internalversion"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"

Expand Down Expand Up @@ -50,7 +49,7 @@ func TestRESTCreate(t *testing.T) {
ctx := context.Background()

obj, err := r.Create(ctx, summary, nil, nil)
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, expectedObj, obj)
}

Expand Down Expand Up @@ -161,10 +160,6 @@ func TestRESTList(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{Name: "node1"},
PeerNodeLatencyStats: nil,
}
options := &internalversion.ListOptions{
Limit: 10,
Continue: "",
}
expectedObj := &statsv1alpha1.NodeLatencyStatsList{
Items: []statsv1alpha1.NodeLatencyStats{
{
Expand All @@ -179,7 +174,7 @@ func TestRESTList(t *testing.T) {

_, err := r.Create(ctx, summary, nil, nil)
require.NoError(t, err)
objs, err := r.List(ctx, options)
objs, err := r.List(ctx, nil)
require.NoError(t, err)
assert.Equal(t, expectedObj, objs)
}
Expand All @@ -193,32 +188,27 @@ func TestRESTConvertToTable(t *testing.T) {
NodeName: "node2",
TargetIPLatencyStats: []statsv1alpha1.TargetIPLatencyStats{
{
TargetIP: "192.168.0.1",
TargetIP: "192.168.0.2",
LastSendTime: metav1.Time{Time: mockTime},
LastRecvTime: metav1.Time{Time: mockTime},
LastMeasuredRTTNanoseconds: 0,
LastMeasuredRTTNanoseconds: 1000000,
},
},
},
},
}
expectedObj := &statsv1alpha1.NodeLatencyStats{
ObjectMeta: metav1.ObjectMeta{Name: "node1"},
PeerNodeLatencyStats: []statsv1alpha1.PeerNodeLatencyStats{
{
NodeName: "node2",
NodeName: "node3",
TargetIPLatencyStats: []statsv1alpha1.TargetIPLatencyStats{
{
TargetIP: "192.168.0.1",
TargetIP: "192.168.0.3",
LastSendTime: metav1.Time{Time: mockTime},
LastRecvTime: metav1.Time{Time: mockTime},
LastMeasuredRTTNanoseconds: 0,
LastMeasuredRTTNanoseconds: 2000000,
},
},
},
},
}
expectedCells := []interface{}{"node1", 1, "0s", "0s"}
expectedCells := []interface{}{"node1", 2, "1.5ms", "2ms"}

r := NewREST()
ctx := context.Background()
Expand All @@ -227,6 +217,5 @@ func TestRESTConvertToTable(t *testing.T) {
require.NoError(t, err)
obj, err := r.ConvertToTable(ctx, summary, nil)
require.NoError(t, err)
assert.Equal(t, expectedObj, obj.Rows[0].Object.Object)
assert.Equal(t, expectedCells, obj.Rows[0].Cells)
}

0 comments on commit 2d54451

Please sign in to comment.