Skip to content

Adds option to reduce worker info response size #35

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

Merged
merged 1 commit into from
Apr 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion api/proto/worker.proto
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ message WorkerStatusResponse {
string msg = 1;
}

message WorkerInfoRequest {}
message WorkerInfoRequest {
bool includeVendorProducts = 1;
}
message WorkerInfoResponse {
reserved 4;
MemoryInfo memory = 1;
Expand Down
18 changes: 10 additions & 8 deletions cmd/worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (w *WorkerServer) Status(context.Context, *proto.WorkerStatusRequest) (*pro
}

//goland:noinspection GoBoolExpressions
func (w *WorkerServer) Info(_ context.Context, _ *proto.WorkerInfoRequest) (*proto.WorkerInfoResponse, error) {
func (w *WorkerServer) Info(_ context.Context, req *proto.WorkerInfoRequest) (*proto.WorkerInfoResponse, error) {
res := &proto.WorkerInfoResponse{}

// Memory
Expand Down Expand Up @@ -210,7 +210,7 @@ func (w *WorkerServer) Info(_ context.Context, _ *proto.WorkerInfoRequest) (*pro
info := &proto.PCIInfo{}

for _, device := range p.Devices {
dInfo := pciDeviceToProto(device)
dInfo := pciDeviceToProto(req, device)

info.Devices = append(info.Devices, dInfo)
}
Expand Down Expand Up @@ -250,7 +250,7 @@ func (w *WorkerServer) Info(_ context.Context, _ *proto.WorkerInfoRequest) (*pro
cardInfo := &proto.GPUInfo_Card{
Index: uint32(card.Index),
Address: card.Address,
Device: pciDeviceToProto(card.DeviceInfo),
Device: pciDeviceToProto(nil, card.DeviceInfo),
}

info.Card = append(info.Card, cardInfo)
Expand All @@ -263,9 +263,9 @@ func (w *WorkerServer) Info(_ context.Context, _ *proto.WorkerInfoRequest) (*pro
return res, nil
}

func pciDeviceToProto(device *pci.Device) *proto.PCIInfo_Device {
func pciDeviceToProto(req *proto.WorkerInfoRequest, device *pci.Device) *proto.PCIInfo_Device {
info := &proto.PCIInfo_Device{
Vendor: pciVendorToProto(device.Vendor),
Vendor: pciVendorToProto(req, device.Vendor),
Product: pciProductToProto(device.Product),
Subsystem: pciProductToProto(device.Subsystem),
Class: pciClassToProto(device.Class),
Expand All @@ -278,15 +278,17 @@ func pciDeviceToProto(device *pci.Device) *proto.PCIInfo_Device {
return info
}

func pciVendorToProto(vendor *pcidb.Vendor) *proto.PCIInfo_Vendor {
func pciVendorToProto(req *proto.WorkerInfoRequest, vendor *pcidb.Vendor) *proto.PCIInfo_Vendor {
info := &proto.PCIInfo_Vendor{
Id: vendor.ID,
Name: vendor.Name,
Products: nil,
}

for _, product := range vendor.Products {
info.Products = append(info.Products, pciProductToProto(product))
if req.IncludeVendorProducts {
for _, product := range vendor.Products {
info.Products = append(info.Products, pciProductToProto(product))
}
}

return info
Expand Down