本文整理汇总了Golang中github.com/dgryski/carbonzipper/carbonzipperpb.GlobResponse.Marshal方法的典型用法代码示例。如果您正苦于以下问题:Golang GlobResponse.Marshal方法的具体用法?Golang GlobResponse.Marshal怎么用?Golang GlobResponse.Marshal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/dgryski/carbonzipper/carbonzipperpb.GlobResponse
的用法示例。
在下文中一共展示了GlobResponse.Marshal方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: findHandler
func findHandler(w http.ResponseWriter, req *http.Request) {
logger.Debugln("request: ", req.URL.RequestURI())
Metrics.FindRequests.Add(1)
rewrite, _ := url.ParseRequestURI(req.URL.RequestURI())
v := rewrite.Query()
format := req.FormValue("format")
v.Set("format", "protobuf")
rewrite.RawQuery = v.Encode()
query := req.FormValue("query")
var tld string
if i := strings.IndexByte(query, '.'); i > 0 {
tld = query[:i]
}
// lookup tld in our map of where they live to reduce the set of
// servers we bug with our find
var backends []string
var ok bool
if backends, ok = Config.pathCache.get(tld); !ok || backends == nil || len(backends) == 0 {
backends = Config.Backends
}
responses := multiGet(backends, rewrite.RequestURI())
if responses == nil || len(responses) == 0 {
logger.Logln("find: error querying backends for: ", rewrite.RequestURI())
http.Error(w, "find: error querying backends", http.StatusInternalServerError)
return
}
metrics, paths := findHandlerPB(w, req, responses)
// update our cache of which servers have which metrics
for k, v := range paths {
Config.pathCache.set(k, v)
}
switch format {
case "protobuf":
w.Header().Set("Content-Type", "application/protobuf")
var result pb.GlobResponse
query := req.FormValue("query")
result.Name = &query
result.Matches = metrics
b, _ := result.Marshal()
w.Write(b)
case "json":
w.Header().Set("Content-Type", "application/json")
jEnc := json.NewEncoder(w)
jEnc.Encode(metrics)
case "", "pickle":
w.Header().Set("Content-Type", "application/pickle")
var result []map[string]interface{}
for _, metric := range metrics {
mm := map[string]interface{}{
"metric_path": *metric.Path,
"isLeaf": *metric.IsLeaf,
}
result = append(result, mm)
}
pEnc := pickle.NewEncoder(w)
pEnc.Encode(result)
}
}
示例2: renderHandler
//.........这里部分代码省略.........
http.Error(w, msg, http.StatusBadRequest)
return
}
for _, m := range exp.Metrics() {
mfetch := m
mfetch.From += from32
mfetch.Until += until32
if _, ok := metricMap[mfetch]; ok {
// already fetched this metric for this request
continue
}
var glob pb.GlobResponse
var haveCacheData bool
if response, ok := findCache.get(m.Metric); useCache && ok {
Metrics.FindCacheHits.Add(1)
err := glob.Unmarshal(response)
haveCacheData = err == nil
}
if !haveCacheData {
var err error
Metrics.FindRequests.Add(1)
stats.zipperRequests++
glob, err = Zipper.Find(m.Metric)
if err != nil {
logger.Logf("Find: %v: %v", m.Metric, err)
continue
}
b, err := glob.Marshal()
if err == nil {
findCache.set(m.Metric, b, 5*60)
}
}
// For each metric returned in the Find response, query Render
// This is a conscious decision to *not* cache render data
rch := make(chan *expr.MetricData, len(glob.GetMatches()))
leaves := 0
for _, m := range glob.GetMatches() {
if !m.GetIsLeaf() {
continue
}
Metrics.RenderRequests.Add(1)
leaves++
Limiter.enter()
stats.zipperRequests++
go func(m *pb.GlobMatch, from, until int32) {
var rptr *expr.MetricData
r, err := Zipper.Render(m.GetPath(), from, until)
if err == nil {
rptr = &r
} else {
logger.Logf("Render: %v: %v", m.GetPath(), err)
}
rch <- rptr
Limiter.leave()
}(m, mfetch.From, mfetch.Until)
}
for i := 0; i < leaves; i++ {
r := <-rch