本文整理汇总了Golang中github.com/dgryski/carbonzipper/carbonzipperpb.MultiFetchResponse.Unmarshal方法的典型用法代码示例。如果您正苦于以下问题:Golang MultiFetchResponse.Unmarshal方法的具体用法?Golang MultiFetchResponse.Unmarshal怎么用?Golang MultiFetchResponse.Unmarshal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/dgryski/carbonzipper/carbonzipperpb.MultiFetchResponse
的用法示例。
在下文中一共展示了MultiFetchResponse.Unmarshal方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: handleRenderPB
func handleRenderPB(w http.ResponseWriter, req *http.Request, format string, responses []serverResponse) {
metrics := make(map[string][]pb.FetchResponse)
for _, r := range responses {
var d pb.MultiFetchResponse
err := d.Unmarshal(r.response)
if err != nil {
logger.Logf("error decoding protobuf response from server:%s: req:%s: err=%s", r.server, req.URL.RequestURI(), err)
logger.Traceln("\n" + hex.Dump(r.response))
Metrics.RenderErrors.Add(1)
continue
}
for _, m := range d.Metrics {
metrics[m.GetName()] = append(metrics[m.GetName()], *m)
}
}
var multi pb.MultiFetchResponse
if len(metrics) == 0 {
err := fmt.Sprintf("no decoded responses to merge for req: %s", req.URL.RequestURI())
logger.Logln(err)
http.Error(w, err, http.StatusInternalServerError)
Metrics.RenderErrors.Add(1)
return
}
for name, decoded := range metrics {
logger.Tracef("request: %s: %q %+v", req.URL.RequestURI(), name, decoded)
if len(decoded) == 1 {
logger.Debugf("only one decoded responses to merge for req: %q %s", name, req.URL.RequestURI())
m := decoded[0]
multi.Metrics = append(multi.Metrics, &m)
continue
}
// Use the metric with the highest resolution as our base
var highest int
for i, d := range decoded {
if d.GetStepTime() < decoded[highest].GetStepTime() {
highest = i
}
}
decoded[0], decoded[highest] = decoded[highest], decoded[0]
metric := decoded[0]
mergeValues(req, &metric, decoded)
multi.Metrics = append(multi.Metrics, &metric)
}
returnRender(w, format, multi)
}