id
stringlengths
2
7
text
stringlengths
17
51.2k
title
stringclasses
1 value
c173000
!strings.Contains(s.flags, "s_down") }
c173001
}) if err != nil { return nil, err } return res.([]*Slave), nil }
c173002
(interface{}, error) { return queryForSentinels(c, s.MasterName) }) if err != nil { return nil, err } return res.([]string), nil }
c173003
s.mu.Unlock() return nil }
c173004
:= net.ResolveTCPAddr("tcp", server) if err != nil { return nil, err } addrs[i] = NewAddr(tcpaddr) } } return &ServerList{addrs: addrs}, nil }
c173005
make(map[string]chan *conn), bufPool: make(chan []byte, poolSize()), } }
c173006
= nil c.maxIdlePerAddr = 0 return nil }
c173007
{ return nil, err } return c.parseItemResponse(key, cn, true) }
c173008
if err = c.sendConnCommand(cn, "", cmdNoop, nil, 0, nil); err != nil { return } var item *Item for { item, err = c.parseItemResponse("", cn, false) if item == nil || item.Key == "" { // Noop response break } ch <- item } }(addr, keys, ch) } m := make(map[string]*Item) for _, ch := range chs { for item := range ch { m[item.Key] = item } } return m, nil }
c173009
c.populateOne(cmdSet, item, 0) }
c173010
c.populateOne(cmdAdd, item, 0) }
c173011
c.populateOne(cmdSet, item, item.casid) }
c173012
_, _, err = c.parseResponse(key, cn) c.condRelease(cn, &err) return err }
c173013
{ return c.incrDecr(cmdIncr, key, delta) }
c173014
var buf bytes.Buffer buf.WriteString("failed to flush some servers: ") for ii, addr := range failed { if ii > 0 { buf.WriteString(", ") } buf.WriteString(addr.String()) buf.WriteString(": ") buf.WriteString(errs[ii].Error()) } return errors.New(buf.String()) } return nil }
c173015
pl.Lock() child := pl.child pl.Unlock() if child == nil { // already closed? memory optimization. return closedCh } return child.Closing() }
c173016
done: p.Closing(), which: closing, } }
c173017
done: p.Closed(), which: closed, } }
c173018
limit; i++ { limitch <- struct{}{} } return limitch }
c173019
q := newProcess(nil) parent.AddChild(q) return q }
c173020
:= goprocess.WithTeardown(tf) CloseAfterContext(p, ctx) return p }
c173021
if p.teardown != nil { panic("cannot SetTeardown twice") } p.teardown = tf select { case <-p.Closed(): p.closeErr = tf() default: } p.Unlock() }
c173022
p.Lock() w.ParentClear() } } if p.teardown != nil { p.closeErr = p.teardown() // actually run the close logic (ok safe to teardown) } close(p.closed) // signal that we're shut down (Closed) // go remove all the parents from the process links. optimization. go func(waiters []*processLink) { for _, pl := range waiters { pl.ClearChild() pr, ok := pl.Parent().(*process) if !ok { // parent has already been called to close continue } pr.Lock() delete(pr.waitfors, pl) delete(pr.children, pl) pr.Unlock() } }(p.waiters) // pass in so p.waiters = nil // clear them. release memory. }
c173023
return nil } // wait for all processes we're waiting for are closed. // the semantics here are simple: we will _only_ close // if there are no processes currently waiting for. for next := nextToWaitFor(); next != nil; next = nextToWaitFor() { <-next.Closed() } // YAY! we're done. close return p.Close() }
c173024
gp.Go(callOnTicker(ticker, procfunc)) }
c173025
gp.Go(goCallOnTicker(ticker, procfunc)) }
c173026
return err } else if status != 200 { return &CustomerIOError{status, c.customerURL(customerID), responseBody} } return nil }
c173027
:= c.request("POST", c.eventURL(customerID), j) if err != nil { return err } else if status != 200 { return &CustomerIOError{status, c.eventURL(customerID), responseBody} } return nil }
c173028
:= c.request("POST", c.anonURL(), j) if err != nil { return err } else if status != 200 { return &CustomerIOError{status, c.anonURL(), responseBody} } return nil }
c173029
200 { return &CustomerIOError{status, c.customerURL(customerID), responseBody} } return nil }
c173030
if err != nil { return err } status, responseBody, err := c.request("PUT", c.deviceURL(customerID), j) if err != nil { return err } else if status != 200 { return &CustomerIOError{status, c.deviceURL(customerID), responseBody} } return nil }
c173031
!= 200 { return &CustomerIOError{status, c.deleteDeviceURL(customerID, deviceID), responseBody} } return nil }
c173032
data } else { locale = path.Join(opt.Directory, fname) } err := i18n.SetMessageWithDesc(lang, opt.Names[i], locale, custom...) if err != nil && err != i18n.ErrLangAlreadyExist { panic(fmt.Errorf("fail to set message file(%s): %v", lang, err)) } } return language.NewMatcher(tags) }
c173033
langs := i18n.ListLangs() names := i18n.ListLangDescs() for i, v := range langs { if lang != v { restLangs = append(restLangs, LangType{v, names[i]}) } else { curLang.Name = names[i] } } // Set language properties. locale := Locale{i18n.Locale{lang}} ctx.Map(locale) ctx.Locale = locale ctx.Data[opt.TmplName] = locale ctx.Data["Tr"] = i18n.Tr ctx.Data["Lang"] = locale.Lang ctx.Data["LangName"] = curLang.Name ctx.Data["AllLangs"] = append([]LangType{curLang}, restLangs...) ctx.Data["RestLangs"] = restLangs if opt.Redirect && isNeedRedir { ctx.Redirect(opt.SubURL + ctx.Req.RequestURI[:strings.Index(ctx.Req.RequestURI, "?")]) } } }
c173034
return nil, err } if a.Debug { a.Log.Printf("[DEBUG] fetch check, received JSON: %s", string(result)) } check := new(Check) if err := json.Unmarshal(result, check); err != nil { return nil, err } return check, nil }
c173035
json.Unmarshal(result, &checks); err != nil { return nil, err } return &checks, nil }
c173036
apiURL, key: key, app: app, accountID: acctID, caCert: ac.CACert, tlsConfig: ac.TLSConfig, Debug: ac.Debug, Log: ac.Log, useExponentialBackoff: false, } a.Debug = ac.Debug a.Log = ac.Log if a.Debug && a.Log == nil { a.Log = log.New(os.Stderr, "", log.LstdFlags) } if a.Log == nil { a.Log = log.New(ioutil.Discard, "", log.LstdFlags) } return a, nil }
c173037
a.apiRequest("GET", reqPath, nil) }
c173038
return a.apiRequest("POST", reqPath, data) }
c173039
if err != nil { if !a.useExponentialBackoff { break } if strings.Contains(err.Error(), "code 403") { break } } if !success { var wait float64 if attempts >= len(backoffs) { wait = backoff(backoffs[len(backoffs)-1]) } else { wait = backoff(backoffs[attempts]) } attempts++ a.Log.Printf("[WARN] API call failed %s, retrying in %d seconds.\n", err.Error(), uint(wait)) time.Sleep(time.Duration(wait) * time.Second) } } return result, err }
c173040
return nil, err } if a.Debug { a.Log.Printf("[DEBUG] fetch graph, received JSON: %s", string(result)) } graph := new(Graph) if err := json.Unmarshal(result, graph); err != nil { return nil, err } return graph, nil }
c173041
json.Unmarshal(result, &graphs); err != nil { return nil, err } return &graphs, nil }
c173042
update graph, sending JSON: %s", string(jsonCfg)) } result, err := a.Put(graphCID, jsonCfg) if err != nil { return nil, err } graph := &Graph{} if err := json.Unmarshal(result, graph); err != nil { return nil, err } return graph, nil }
c173043
result, err := a.Post(config.GraphPrefix, jsonCfg) if err != nil { return nil, err } graph := &Graph{} if err := json.Unmarshal(result, graph); err != nil { return nil, err } return graph, nil }
c173044
graph config [nil]") } return a.DeleteGraphByCID(CIDType(&cfg.CID)) }
c173045
if !matched { return false, fmt.Errorf("Invalid graph CID [%s]", graphCID) } _, err = a.Delete(graphCID) if err != nil { return false, err } return true, nil }
c173046
return nil, err } if a.Debug { a.Log.Printf("[DEBUG] fetch check bundle, received JSON: %s", string(result)) } checkBundle := &CheckBundle{} if err := json.Unmarshal(result, checkBundle); err != nil { return nil, err } return checkBundle, nil }
c173047
json.Unmarshal(result, &checkBundles); err != nil { return nil, err } return &checkBundles, nil }
c173048
{ a.Log.Printf("[DEBUG] update check bundle, sending JSON: %s", string(jsonCfg)) } result, err := a.Put(bundleCID, jsonCfg) if err != nil { return nil, err } checkBundle := &CheckBundle{} if err := json.Unmarshal(result, checkBundle); err != nil { return nil, err } return checkBundle, nil }
c173049
return false, fmt.Errorf("Invalid check bundle config [nil]") } return a.DeleteCheckBundleByCID(CIDType(&cfg.CID)) }
c173050
if !matched { return false, fmt.Errorf("Invalid check bundle CID [%v]", bundleCID) } _, err = a.Delete(bundleCID) if err != nil { return false, err } return true, nil }
c173051
string, val interface{}) { m.SetGauge(metric, val) }
c173052
defer m.gm.Unlock() m.gauges[metric] = val }
c173053
uint8: m.gauges[metric] = v.(uint8) + val.(uint8) case uint16: m.gauges[metric] = v.(uint16) + val.(uint16) case uint32: m.gauges[metric] = v.(uint32) + val.(uint32) case uint64: m.gauges[metric] = v.(uint64) + val.(uint64) case float32: m.gauges[metric] = v.(float32) + val.(float32) case float64: m.gauges[metric] = v.(float64) + val.(float64) } }
c173054
defer m.gm.Unlock() delete(m.gauges, metric) }
c173055
defer m.gfm.Unlock() delete(m.gaugeFuncs, metric) }
c173056
mt = "i" case int32: mt = "i" case uint: mt = "I" case uint8: mt = "I" case uint16: mt = "I" case uint32: mt = "I" case int64: mt = "l" case uint64: mt = "L" } return mt }
c173057
err != nil { return nil, err } if a.Debug { a.Log.Printf("[DEBUG] fetch check bundle metrics, received JSON: %s", string(result)) } metrics := &CheckBundleMetrics{} if err := json.Unmarshal(result, metrics); err != nil { return nil, err } return metrics, nil }
c173058
} if a.Debug { a.Log.Printf("[DEBUG] update check bundle metrics, sending JSON: %s", string(jsonCfg)) } result, err := a.Put(metricsCID, jsonCfg) if err != nil { return nil, err } metrics := &CheckBundleMetrics{} if err := json.Unmarshal(result, metrics); err != nil { return nil, err } return metrics, nil }
c173059
broker.Name) } return broker, nil } broker, err := cm.selectBroker() if err != nil { return nil, fmt.Errorf("[ERROR] Unable to fetch suitable broker %s", err) } return broker, nil }
c173060
if *detail.IP == host { cn = detail.CN break } } if cn == "" { return "", fmt.Errorf("[ERROR] Unable to match URL host (%s) to Broker", u.Host) } return cn, nil }
c173061
{ if v.Type != enterpriseType { delete(validBrokers, k) } } } if len(validBrokers) == 0 { return nil, fmt.Errorf("found %d broker(s), zero are valid", len(*brokerList)) } validBrokerKeys := reflect.ValueOf(validBrokers).MapKeys() selectedBroker := validBrokers[validBrokerKeys[rand.Intn(len(validBrokerKeys))].String()] if cm.Debug { cm.Log.Printf("[DEBUG] Selected broker '%s'\n", selectedBroker.Name) } return &selectedBroker, nil }
c173062
if module == baseType { return true } } if idx := strings.Index(baseType, ":"); idx > 0 { baseType = baseType[0:idx] } for _, module := range details.Modules { if module == baseType { return true } } return false }
c173063
reqURL := url.URL{ Path: clusterCID, } extra := "" switch extras { case "metrics": extra = "_matching_metrics" case "uuids": extra = "_matching_uuid_metrics" } if extra != "" { q := url.Values{} q.Set("extra", extra) reqURL.RawQuery = q.Encode() } result, err := a.Get(reqURL.String()) if err != nil { return nil, err } if a.Debug { a.Log.Printf("[DEBUG] fetch metric cluster, received JSON: %s", string(result)) } cluster := &MetricCluster{} if err := json.Unmarshal(result, cluster); err != nil { return nil, err } return cluster, nil }
c173064
} if extra != "" { q := url.Values{} q.Set("extra", extra) reqURL.RawQuery = q.Encode() } result, err := a.Get(reqURL.String()) if err != nil { return nil, err } var clusters []MetricCluster if err := json.Unmarshal(result, &clusters); err != nil { return nil, err } return &clusters, nil }
c173065
a.Debug { a.Log.Printf("[DEBUG] update metric cluster, sending JSON: %s", string(jsonCfg)) } result, err := a.Put(clusterCID, jsonCfg) if err != nil { return nil, err } cluster := &MetricCluster{} if err := json.Unmarshal(result, cluster); err != nil { return nil, err } return cluster, nil }
c173066
} result, err := a.Post(config.MetricClusterPrefix, jsonCfg) if err != nil { return nil, err } cluster := &MetricCluster{} if err := json.Unmarshal(result, cluster); err != nil { return nil, err } return cluster, nil }
c173067
[nil]") } return a.DeleteMetricClusterByCID(CIDType(&cfg.CID)) }
c173068
if !matched { return false, fmt.Errorf("Invalid metric cluster CID [%s]", clusterCID) } _, err = a.Delete(clusterCID) if err != nil { return false, err } return true, nil }
c173069
being managed. cert, err = cm.fetchCert() if err != nil { return err } } if cert == nil { cert = circonusCA } cm.certPool.AppendCertsFromPEM(cert) return nil }
c173070
{ return nil, err } cadata := new(CACert) if err := json.Unmarshal(response, cadata); err != nil { return nil, err } if cadata.Contents == "" { return nil, fmt.Errorf("[ERROR] Unable to find ca cert %+v", cadata) } return []byte(cadata.Contents), nil }
c173071
json.Unmarshal(result, &accounts); err != nil { return nil, err } return &accounts, nil }
c173072
a.Log.Printf("[DEBUG] account update, sending JSON: %s", string(jsonCfg)) } result, err := a.Put(accountCID, jsonCfg) if err != nil { return nil, err } account := &Account{} if err := json.Unmarshal(result, account); err != nil { return nil, err } return account, nil }
c173073
return nil, err } if a.Debug { a.Log.Printf("[DEBUG] fetch annotation, received JSON: %s", string(result)) } annotation := &Annotation{} if err := json.Unmarshal(result, annotation); err != nil { return nil, err } return annotation, nil }
c173074
json.Unmarshal(result, &annotations); err != nil { return nil, err } return &annotations, nil }
c173075
a.Log.Printf("[DEBUG] update annotation, sending JSON: %s", string(jsonCfg)) } result, err := a.Put(annotationCID, jsonCfg) if err != nil { return nil, err } annotation := &Annotation{} if err := json.Unmarshal(result, annotation); err != nil { return nil, err } return annotation, nil }
c173076
result, err := a.Post(config.AnnotationPrefix, jsonCfg) if err != nil { return nil, err } annotation := &Annotation{} if err := json.Unmarshal(result, annotation); err != nil { return nil, err } return annotation, nil }
c173077
return false, fmt.Errorf("Invalid annotation config [nil]") } return a.DeleteAnnotationByCID(CIDType(&cfg.CID)) }
c173078
if !matched { return false, fmt.Errorf("Invalid annotation CID [%s]", annotationCID) } _, err = a.Delete(annotationCID) if err != nil { return false, err } return true, nil }
c173079
nil { return nil, err } if a.Debug { a.Log.Printf("[DEBUG] fetch outlier report, received JSON: %s", string(result)) } report := &OutlierReport{} if err := json.Unmarshal(result, report); err != nil { return nil, err } return report, nil }
c173080
if err := json.Unmarshal(result, &reports); err != nil { return nil, err } return &reports, nil }
c173081
a.Debug { a.Log.Printf("[DEBUG] update outlier report, sending JSON: %s", string(jsonCfg)) } result, err := a.Put(reportCID, jsonCfg) if err != nil { return nil, err } report := &OutlierReport{} if err := json.Unmarshal(result, report); err != nil { return nil, err } return report, nil }
c173082
} result, err := a.Post(config.OutlierReportPrefix, jsonCfg) if err != nil { return nil, err } report := &OutlierReport{} if err := json.Unmarshal(result, report); err != nil { return nil, err } return report, nil }
c173083
[nil]") } return a.DeleteOutlierReportByCID(CIDType(&cfg.CID)) }
c173084
if !matched { return false, fmt.Errorf("Invalid outlier report CID [%s]", reportCID) } _, err = a.Delete(reportCID) if err != nil { return false, err } return true, nil }
c173085
json.Unmarshal(result, &users); err != nil { return nil, err } return &users, nil }
c173086
user, sending JSON: %s", string(jsonCfg)) } result, err := a.Put(userCID, jsonCfg) if err != nil { return nil, err } user := &User{} if err := json.Unmarshal(result, user); err != nil { return nil, err } return user, nil }
c173087
return m.check.AddMetricTags(name, tags, false) }
c173088
return m.check.AddMetricTags(name, tags, true) }
c173089
return nil, err } if a.Debug { a.Log.Printf("[DEBUG] fetch metric, received JSON: %s", string(result)) } metric := &Metric{} if err := json.Unmarshal(result, metric); err != nil { return nil, err } return metric, nil }
c173090
json.Unmarshal(result, &metrics); err != nil { return nil, err } return &metrics, nil }
c173091
a.Log.Printf("[DEBUG] update metric, sending JSON: %s", string(jsonCfg)) } result, err := a.Put(metricCID, jsonCfg) if err != nil { return nil, err } metric := &Metric{} if err := json.Unmarshal(result, metric); err != nil { return nil, err } return metric, nil }
c173092
return nil, err } if a.Debug { a.Log.Printf("[DEBUG] acknowledgement fetch, received JSON: %s", string(result)) } acknowledgement := &Acknowledgement{} if err := json.Unmarshal(result, acknowledgement); err != nil { return nil, err } return acknowledgement, nil }
c173093
json.Unmarshal(result, &acknowledgements); err != nil { return nil, err } return &acknowledgements, nil }
c173094
a.Log.Printf("[DEBUG] acknowledgement update, sending JSON: %s", string(jsonCfg)) } result, err := a.Put(acknowledgementCID, jsonCfg) if err != nil { return nil, err } acknowledgement := &Acknowledgement{} if err := json.Unmarshal(result, acknowledgement); err != nil { return nil, err } return acknowledgement, nil }
c173095
result, err := a.Post(config.AcknowledgementPrefix, jsonCfg) if err != nil { return nil, err } if a.Debug { a.Log.Printf("[DEBUG] acknowledgement create, sending JSON: %s", string(jsonCfg)) } acknowledgement := &Acknowledgement{} if err := json.Unmarshal(result, acknowledgement); err != nil { return nil, err } return acknowledgement, nil }
c173096
m.gauges = make(map[string]interface{}) m.gaugeFuncs = make(map[string]func() int64) m.histograms = make(map[string]*Histogram) m.text = make(map[string]string) m.textFuncs = make(map[string]func() string) }
c173097
t map[string]string) { c = m.snapCounters() g = m.snapGauges() h = m.snapHistograms() t = m.snapText() return }
c173098
m.SetHistogramValue(metric, val) }
c173099
m.SetHistogramValue(metric, val) }