stmcginnis / gofish

Gofish is a Golang client library for DMTF Redfish and SNIA Swordfish interaction.
BSD 3-Clause "New" or "Revised" License
213 stars 112 forks source link

Use the $expand parameter when querying collections #340

Open Arno500 opened 4 months ago

Arno500 commented 4 months ago

When querying subcollections, gofish is currently iterating manually 3 by 3 to get the data. This is painfully slow, especially when the collections are big and the server is far away.

I would propose to include support for the $expand OData parameter when supported (this needs to be checked when querying a collection for the first time on this entity). It would allow the device to answer once for all the sub elements when asked, making the query much faster and reducing the impact of latency.

My specific case was requesting a PDU with 48 plugs, that is pretty slow in Redfish already. Querying all of them individually is not exactly fun as you can guess :P

stmcginnis commented 4 months ago

Thanks for bringing this up. It is an interesting idea. The Redfish service can be a little slow responding, but that network latency of making multiple calls to get the elements is definitely the bigger bottleneck.

I haven't spent a ton of time on this, but what I had thought about doing was to set a flag if it's supported. Luckily, the ServiceRoot object that you get at the root of the object hierarchy should contain ServiceRoot.ProtocolFeaturesSupported.ExpandQuery.ExpandAll. So right away on connection it should be possible to determine if the service will support expanding collections or not.

The trickier part is probably including that in a uniform interface for the library consumer. But I think during the custom unmarshalling that we need to do, we could try to collect that array of sub-objects in a private property. Then the consumer would still call the same method as they would if expand wasn't being used (e.g. outlets, err := pdu.Outlets()). Then internally, if the expanded data is there we can just return the collection of objects. If it is not there, then we can use the existing method of getting the collection of objects the slower way.

I will try to get some time to try this out some time soon.