Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
proto: add network stats
Browse files Browse the repository at this point in the history
So that agent can transfer network stats to runtime

Fixes: #535

Signed-off-by: ZeroMagic <[email protected]>
  • Loading branch information
ZeroMagic committed Apr 19, 2019
1 parent e3967e7 commit d9aa453
Show file tree
Hide file tree
Showing 4 changed files with 714 additions and 202 deletions.
18 changes: 15 additions & 3 deletions grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -1182,18 +1182,30 @@ func (a *agentGRPC) StatsContainer(ctx context.Context, req *pb.StatsContainerRe
return nil, err
}

data, err := json.Marshal(stats.CgroupStats)
cgroupData, err := json.Marshal(stats.CgroupStats)
if err != nil {
return nil, err
}

netData, err := json.Marshal(stats.Interfaces)
if err != nil {
return nil, err
}

var cgroupStats pb.CgroupStats
err = json.Unmarshal(data, &cgroupStats)
networkStats := make([]*pb.NetworkStats, 0)

err = json.Unmarshal(cgroupData, &cgroupStats)
if err != nil {
return nil, err
}
err = json.Unmarshal(netData, &networkStats)
if err != nil {
return nil, err
}
resp := &pb.StatsContainerResponse{
CgroupStats: &cgroupStats,
CgroupStats: &cgroupStats,
NetworkStats: networkStats,
}

return resp, nil
Expand Down
11 changes: 11 additions & 0 deletions grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

pb "github.com/kata-containers/agent/protocols/grpc"
"github.com/opencontainers/runc/libcontainer"
"github.com/opencontainers/runc/libcontainer/cgroups"
"github.com/opencontainers/runc/libcontainer/configs"
"github.com/opencontainers/runc/libcontainer/seccomp"
"github.com/opencontainers/runtime-spec/specs-go"
Expand Down Expand Up @@ -516,16 +517,26 @@ func TestStatsContainer(t *testing.T) {
assert.Error(err)
assert.Nil(r)

network := &libcontainer.NetworkInterface{}
interfaces := make([]*libcontainer.NetworkInterface, 0)
interfaces = append(interfaces, network)

a.sandbox.containers[containerID] = &container{
container: &mockContainer{
id: containerID,
stats: libcontainer.Stats{
CgroupStats: &cgroups.Stats{},
Interfaces: interfaces,
},
},
}

r, err = a.StatsContainer(context.TODO(), req)
assert.NoError(err)
assert.NotNil(r)

assert.NotNil(r.CgroupStats)
assert.NotNil(r.NetworkStats)
}

func TestPauseContainer(t *testing.T) {
Expand Down
Loading

0 comments on commit d9aa453

Please sign in to comment.