ToLoadReport unmarshals a binary encoded [ORCA LoadReport] protobuf message from md and returns the corresponding struct. The load report is expected to be stored as the value for key "endpoint-load-metrics-bin". If no load report was found in the provided metadata, if multiple load reports are fou
(md metadata.MD)
| 56 | // |
| 57 | // [ORCA LoadReport]: (https://github.com/cncf/xds/blob/main/xds/data/orca/v3/orca_load_report.proto#L15) |
| 58 | func ToLoadReport(md metadata.MD) (*v3orcapb.OrcaLoadReport, error) { |
| 59 | vs := md.Get(TrailerMetadataKey) |
| 60 | if len(vs) == 0 { |
| 61 | return nil, nil |
| 62 | } |
| 63 | if len(vs) != 1 { |
| 64 | return nil, errors.New("multiple orca load reports found in provided metadata") |
| 65 | } |
| 66 | ret := new(v3orcapb.OrcaLoadReport) |
| 67 | if err := proto.Unmarshal([]byte(vs[0]), ret); err != nil { |
| 68 | return nil, fmt.Errorf("failed to unmarshal load report found in metadata: %v", err) |
| 69 | } |
| 70 | return ret, nil |
| 71 | } |