_id
stringlengths
2
7
title
stringlengths
1
118
partition
stringclasses
3 values
text
stringlengths
52
85.5k
language
stringclasses
1 value
meta_information
dict
q167300
signatureFunc
validation
func (enh *EvalNodeHelper) signatureFunc(on bool, names ...string) func(labels.Labels) uint64 { if enh.sigf == nil { enh.sigf = make(map[uint64]uint64, len(enh.out)) } f := signatureFunc(on, names...) return func(l labels.Labels) uint64 { h := l.Hash() ret, ok := enh.sigf[h] if ok { return ret } ret ...
go
{ "resource": "" }
q167301
evalSubquery
validation
func (ev *evaluator) evalSubquery(subq *SubqueryExpr) *MatrixSelector { val := ev.eval(subq).(Matrix) ms := &MatrixSelector{ Range: subq.Range, Offset: subq.Offset, series: make([]storage.Series, 0, len(val)), } for _, s := range val { ms.series = append(ms.series, NewStorageSeries(s)) } return ms }
go
{ "resource": "" }
q167302
vectorSelectorSingle
validation
func (ev *evaluator) vectorSelectorSingle(it *storage.BufferedSeriesIterator, node *VectorSelector, ts int64) (int64, float64, bool) { refTime := ts - durationMilliseconds(node.Offset) var t int64 var v float64 ok := it.Seek(refTime) if !ok { if it.Err() != nil { ev.error(it.Err()) } } if ok { t, v = ...
go
{ "resource": "" }
q167303
signatureFunc
validation
func signatureFunc(on bool, names ...string) func(labels.Labels) uint64 { // TODO(fabxc): ensure names are sorted and then use that and sortedness // of labels by names to speed up the operations below. // Alternatively, inline the hashing and don't build new label sets. if on { return func(lset labels.Labels) ui...
go
{ "resource": "" }
q167304
VectorscalarBinop
validation
func (ev *evaluator) VectorscalarBinop(op ItemType, lhs Vector, rhs Scalar, swap, returnBool bool, enh *EvalNodeHelper) Vector { for _, lhsSample := range lhs { lv, rv := lhsSample.V, rhs.V // lhs always contains the Vector. If the original position was different // swap for calculating the value. if swap { ...
go
{ "resource": "" }
q167305
scalarBinop
validation
func scalarBinop(op ItemType, lhs, rhs float64) float64 { switch op { case ItemADD: return lhs + rhs case ItemSUB: return lhs - rhs case ItemMUL: return lhs * rhs case ItemDIV: return lhs / rhs case ItemPOW: return math.Pow(lhs, rhs) case ItemMOD: return math.Mod(lhs, rhs) case ItemEQL: return bto...
go
{ "resource": "" }
q167306
shouldDropMetricName
validation
func shouldDropMetricName(op ItemType) bool { switch op { case ItemADD, ItemSUB, ItemDIV, ItemMUL, ItemPOW, ItemMOD: return true default: return false } }
go
{ "resource": "" }
q167307
NewEndpoints
validation
func NewEndpoints(l log.Logger, svc, eps, pod cache.SharedInformer) *Endpoints { if l == nil { l = log.NewNopLogger() } e := &Endpoints{ logger: l, endpointsInf: eps, endpointsStore: eps.GetStore(), serviceInf: svc, serviceStore: svc.GetStore(), podInf: pod, podStore: po...
go
{ "resource": "" }
q167308
calcTrendValue
validation
func calcTrendValue(i int, sf, tf, s0, s1, b float64) float64 { if i == 0 { return b } x := tf * (s1 - s0) y := (1 - tf) * b return x + y }
go
{ "resource": "" }
q167309
linearRegression
validation
func linearRegression(samples []Point, interceptTime int64) (slope, intercept float64) { var ( n float64 sumX, sumY float64 sumXY, sumX2 float64 ) for _, sample := range samples { x := float64(sample.T-interceptTime) / 1e3 n += 1.0 sumY += sample.V sumX += x sumXY += x * sample.V sumX2...
go
{ "resource": "" }
q167310
dateWrapper
validation
func dateWrapper(vals []Value, enh *EvalNodeHelper, f func(time.Time) float64) Vector { if len(vals) == 0 { return append(enh.out, Sample{ Metric: labels.Labels{}, Point: Point{V: f(time.Unix(enh.ts/1000, 0).UTC())}, }) } for _, el := range vals[0].(Vector) { t := time.Unix(int64(el.V), 0).UTC() ...
go
{ "resource": "" }
q167311
getFunction
validation
func getFunction(name string) (*Function, bool) { function, ok := functions[name] return function, ok }
go
{ "resource": "" }
q167312
Validate
validation
func (c *ServiceDiscoveryConfig) Validate() error { for _, cfg := range c.AzureSDConfigs { if cfg == nil { return errors.New("empty or null section in azure_sd_configs") } } for _, cfg := range c.ConsulSDConfigs { if cfg == nil { return errors.New("empty or null section in consul_sd_configs") } } for...
go
{ "resource": "" }
q167313
Dedupe
validation
func Dedupe(next log.Logger, repeat time.Duration) *Deduper { d := &Deduper{ next: next, repeat: repeat, quit: make(chan struct{}), seen: map[string]time.Time{}, } go d.run() return d }
go
{ "resource": "" }
q167314
Log
validation
func (d *Deduper) Log(keyvals ...interface{}) error { line, err := encode(keyvals...) if err != nil { return err } d.mtx.RLock() last, ok := d.seen[line] d.mtx.RUnlock() if ok && time.Since(last) < d.repeat { return nil } d.mtx.Lock() if len(d.seen) < maxEntries { d.seen[line] = time.Now() } d.mtx....
go
{ "resource": "" }
q167315
Start
validation
func (g *Gate) Start(ctx context.Context) error { select { case <-ctx.Done(): return ctx.Err() case g.ch <- struct{}{}: return nil } }
go
{ "resource": "" }
q167316
New
validation
func New(logger log.Logger, conf *SDConfig) (*Discovery, error) { tls, err := config_util.NewTLSConfig(&conf.TLSConfig) if err != nil { return nil, err } transport := &http.Transport{ TLSClientConfig: tls, DialContext: conntrack.NewDialContextFunc( conntrack.DialWithTracing(), conntrack.DialWithName("t...
go
{ "resource": "" }
q167317
ApplyConfig
validation
func (h *Handler) ApplyConfig(conf *config.Config) error { h.mtx.Lock() defer h.mtx.Unlock() h.config = conf return nil }
go
{ "resource": "" }
q167318
isReady
validation
func (h *Handler) isReady() bool { ready := atomic.LoadUint32(&h.ready) return ready > 0 }
go
{ "resource": "" }
q167319
New
validation
func New(fs http.FileSystem, t time.Time) http.FileSystem { return &timefs{fs: fs, t: t} }
go
{ "resource": "" }
q167320
UnmarshalJSON
validation
func (tv *TagValue) UnmarshalJSON(json []byte) error { escapeLevel := 0 // How many bytes after '_'. var parsedByte byte // Might need fewer bytes, but let's avoid realloc. result := bytes.NewBuffer(make([]byte, 0, len(json)-2)) for i, b := range json { if i == 0 { if b != '"' { return errors.Errorf("ex...
go
{ "resource": "" }
q167321
Write
validation
func (c *Client) Write(samples model.Samples) error { points := make([]*influx.Point, 0, len(samples)) for _, s := range samples { v := float64(s.Value) if math.IsNaN(v) || math.IsInf(v, 0) { level.Debug(c.logger).Log("msg", "cannot send to InfluxDB, skipping sample", "value", v, "sample", s) c.ignoredSamp...
go
{ "resource": "" }
q167322
mergeSamples
validation
func mergeSamples(a, b []prompb.Sample) []prompb.Sample { result := make([]prompb.Sample, 0, len(a)+len(b)) i, j := 0, 0 for i < len(a) && j < len(b) { if a[i].Timestamp < b[j].Timestamp { result = append(result, a[i]) i++ } else if a[i].Timestamp > b[j].Timestamp { result = append(result, b[j]) j++ ...
go
{ "resource": "" }
q167323
Describe
validation
func (c *Client) Describe(ch chan<- *prometheus.Desc) { ch <- c.ignoredSamples.Desc() }
go
{ "resource": "" }
q167324
NewDiscovery
validation
func NewDiscovery(conf SDConfig, logger log.Logger) (*Discovery, error) { rt, err := config_util.NewRoundTripperFromConfig(conf.HTTPClientConfig, "marathon_sd") if err != nil { return nil, err } if len(conf.AuthToken) > 0 { rt, err = newAuthTokenRoundTripper(conf.AuthToken, rt) } else if len(conf.AuthTokenFil...
go
{ "resource": "" }
q167325
newAuthTokenRoundTripper
validation
func newAuthTokenRoundTripper(token config_util.Secret, rt http.RoundTripper) (http.RoundTripper, error) { return &authTokenRoundTripper{token, rt}, nil }
go
{ "resource": "" }
q167326
newAuthTokenFileRoundTripper
validation
func newAuthTokenFileRoundTripper(tokenFile string, rt http.RoundTripper) (http.RoundTripper, error) { // fail-fast if we can't read the file. _, err := ioutil.ReadFile(tokenFile) if err != nil { return nil, errors.Wrapf(err, "unable to read auth token file %s", tokenFile) } return &authTokenFileRoundTripper{tok...
go
{ "resource": "" }
q167327
isContainerNet
validation
func (app app) isContainerNet() bool { return len(app.Networks) > 0 && app.Networks[0].Mode == "container" }
go
{ "resource": "" }
q167328
fetchApps
validation
func fetchApps(ctx context.Context, client *http.Client, url string) (*appList, error) { request, err := http.NewRequest("GET", url, nil) if err != nil { return nil, err } request = request.WithContext(ctx) resp, err := client.Do(request) if err != nil { return nil, err } defer func() { io.Copy(ioutil.Di...
go
{ "resource": "" }
q167329
randomAppsURL
validation
func randomAppsURL(servers []string) string { // TODO: If possible update server list from Marathon at some point. server := servers[rand.Intn(len(servers))] return fmt.Sprintf("%s%s", server, appListPath) }
go
{ "resource": "" }
q167330
appsToTargetGroups
validation
func appsToTargetGroups(apps *appList) map[string]*targetgroup.Group { tgroups := map[string]*targetgroup.Group{} for _, a := range apps.Apps { group := createTargetGroup(&a) tgroups[group.Source] = group } return tgroups }
go
{ "resource": "" }
q167331
extractPortMapping
validation
func extractPortMapping(portMappings []portMapping, containerNet bool) ([]uint32, []map[string]string) { ports := make([]uint32, len(portMappings)) labels := make([]map[string]string, len(portMappings)) for i := 0; i < len(portMappings); i++ { labels[i] = portMappings[i].Labels if containerNet { // If the...
go
{ "resource": "" }
q167332
Load
validation
func Load(s string) (*Config, error) { cfg := &Config{} // If the entire config body is empty the UnmarshalYAML method is // never called. We thus have to set the DefaultConfig at the entry // point as well. *cfg = DefaultConfig err := yaml.UnmarshalStrict([]byte(s), cfg) if err != nil { return nil, err } c...
go
{ "resource": "" }
q167333
LoadFile
validation
func LoadFile(filename string) (*Config, error) { content, err := ioutil.ReadFile(filename) if err != nil { return nil, err } cfg, err := Load(string(content)) if err != nil { return nil, errors.Wrapf(err, "parsing YAML file %s", filename) } resolveFilepaths(filepath.Dir(filename), cfg) return cfg, nil }
go
{ "resource": "" }
q167334
resolveFilepaths
validation
func resolveFilepaths(baseDir string, cfg *Config) { join := func(fp string) string { if len(fp) > 0 && !filepath.IsAbs(fp) { fp = filepath.Join(baseDir, fp) } return fp } for i, rf := range cfg.RuleFiles { cfg.RuleFiles[i] = join(rf) } tlsPaths := func(cfg *config_util.TLSConfig) { cfg.CAFile = joi...
go
{ "resource": "" }
q167335
isZero
validation
func (c *GlobalConfig) isZero() bool { return c.ExternalLabels == nil && c.ScrapeInterval == 0 && c.ScrapeTimeout == 0 && c.EvaluationInterval == 0 }
go
{ "resource": "" }
q167336
CheckTargetAddress
validation
func CheckTargetAddress(address model.LabelValue) error { // For now check for a URL, we may want to expand this later. if strings.Contains(string(address), "/") { return errors.Errorf("%q is not a valid hostname", address) } return nil }
go
{ "resource": "" }
q167337
NewDiscovery
validation
func NewDiscovery(conf *SDConfig, logger log.Logger) (*Discovery, error) { if logger == nil { logger = log.NewNopLogger() } tls, err := config_util.NewTLSConfig(&conf.TLSConfig) if err != nil { return nil, err } transport := &http.Transport{ IdleConnTimeout: 5 * time.Duration(conf.RefreshInterval), TLSCl...
go
{ "resource": "" }
q167338
shouldWatch
validation
func (d *Discovery) shouldWatch(name string, tags []string) bool { return d.shouldWatchFromName(name) && d.shouldWatchFromTags(tags) }
go
{ "resource": "" }
q167339
shouldWatchFromName
validation
func (d *Discovery) shouldWatchFromName(name string) bool { // If there's no fixed set of watched services, we watch everything. if len(d.watchedServices) == 0 { return true } for _, sn := range d.watchedServices { if sn == name { return true } } return false }
go
{ "resource": "" }
q167340
getDatacenter
validation
func (d *Discovery) getDatacenter() error { // If the datacenter was not set from clientConf, let's get it from the local Consul agent // (Consul default is to use local node's datacenter if one isn't given for a query). if d.clientDatacenter != "" { return nil } info, err := d.client.Agent().Self() if err != ...
go
{ "resource": "" }
q167341
initialize
validation
func (d *Discovery) initialize(ctx context.Context) { // Loop until we manage to get the local datacenter. for { // We have to check the context at least once. The checks during channel sends // do not guarantee that. select { case <-ctx.Done(): return default: } // Get the local datacenter first, i...
go
{ "resource": "" }
q167342
watchServices
validation
func (d *Discovery) watchServices(ctx context.Context, ch chan<- []*targetgroup.Group, lastIndex *uint64, services map[string]func()) error { catalog := d.client.Catalog() level.Debug(d.logger).Log("msg", "Watching services", "tags", d.watchedTags) t0 := time.Now() opts := &consul.QueryOptions{ WaitIndex: *last...
go
{ "resource": "" }
q167343
watchService
validation
func (d *Discovery) watchService(ctx context.Context, ch chan<- []*targetgroup.Group, name string) { srv := &consulService{ discovery: d, client: d.client, name: name, tags: d.watchedTags, labels: model.LabelSet{ serviceLabel: model.LabelValue(name), datacenterLabel: model.LabelValue(d....
go
{ "resource": "" }
q167344
NewPod
validation
func NewPod(l log.Logger, pods cache.SharedInformer) *Pod { if l == nil { l = log.NewNopLogger() } p := &Pod{ informer: pods, store: pods.GetStore(), logger: l, queue: workqueue.NewNamed("pod"), } p.informer.AddEventHandler(cache.ResourceEventHandlerFuncs{ AddFunc: func(o interface{}) { even...
go
{ "resource": "" }
q167345
NewMatcher
validation
func NewMatcher(t MatchType, n, v string) (*Matcher, error) { m := &Matcher{ Type: t, Name: n, Value: v, } if t == MatchRegexp || t == MatchNotRegexp { re, err := regexp.Compile("^(?:" + v + ")$") if err != nil { return nil, err } m.re = re } return m, nil }
go
{ "resource": "" }
q167346
Matches
validation
func (m *Matcher) Matches(s string) bool { switch m.Type { case MatchEqual: return s == m.Value case MatchNotEqual: return s != m.Value case MatchRegexp: return m.re.MatchString(s) case MatchNotRegexp: return !m.re.MatchString(s) } panic("labels.Matcher.Matches: invalid match type") }
go
{ "resource": "" }
q167347
SpanOperation
validation
func (s QueryTiming) SpanOperation() string { switch s { case EvalTotalTime: return "promqlEval" case ResultSortTime: return "promqlSort" case QueryPreparationTime: return "promqlPrepare" case InnerEvalTime: return "promqlInnerEval" case ExecQueueTime: return "promqlExecQueue" case ExecTotalTime: ret...
go
{ "resource": "" }
q167348
NewQueryStats
validation
func NewQueryStats(tg *QueryTimers) *QueryStats { var qt queryTimings for s, timer := range tg.TimerGroup.timers { switch s { case EvalTotalTime: qt.EvalTotalTime = timer.Duration() case ResultSortTime: qt.ResultSortTime = timer.Duration() case QueryPreparationTime: qt.QueryPreparationTime = timer.D...
go
{ "resource": "" }
q167349
NewDiscovery
validation
func NewDiscovery(conf *SDConfig, l log.Logger) (*refresh.Discovery, error) { r, err := newRefresher(conf, l) if err != nil { return nil, err } return refresh.NewDiscovery( l, "openstack", time.Duration(conf.RefreshInterval), r.refresh, ), nil }
go
{ "resource": "" }
q167350
UnmarshalYAML
validation
func (ls *Labels) UnmarshalYAML(unmarshal func(interface{}) error) error { var m map[string]string if err := unmarshal(&m); err != nil { return err } *ls = FromMap(m) return nil }
go
{ "resource": "" }
q167351
Hash
validation
func (ls Labels) Hash() uint64 { b := make([]byte, 0, 1024) for _, v := range ls { b = append(b, v.Name...) b = append(b, sep) b = append(b, v.Value...) b = append(b, sep) } return xxhash.Sum64(b) }
go
{ "resource": "" }
q167352
HashForLabels
validation
func (ls Labels) HashForLabels(names ...string) uint64 { b := make([]byte, 0, 1024) for _, v := range ls { for _, n := range names { if v.Name == n { b = append(b, v.Name...) b = append(b, sep) b = append(b, v.Value...) b = append(b, sep) break } } } return xxhash.Sum64(b) }
go
{ "resource": "" }
q167353
Copy
validation
func (ls Labels) Copy() Labels { res := make(Labels, len(ls)) copy(res, ls) return res }
go
{ "resource": "" }
q167354
Get
validation
func (ls Labels) Get(name string) string { for _, l := range ls { if l.Name == name { return l.Value } } return "" }
go
{ "resource": "" }
q167355
Has
validation
func (ls Labels) Has(name string) bool { for _, l := range ls { if l.Name == name { return true } } return false }
go
{ "resource": "" }
q167356
Equal
validation
func Equal(ls, o Labels) bool { if len(ls) != len(o) { return false } for i, l := range ls { if l.Name != o[i].Name || l.Value != o[i].Value { return false } } return true }
go
{ "resource": "" }
q167357
Map
validation
func (ls Labels) Map() map[string]string { m := make(map[string]string, len(ls)) for _, l := range ls { m[l.Name] = l.Value } return m }
go
{ "resource": "" }
q167358
New
validation
func New(ls ...Label) Labels { set := make(Labels, 0, len(ls)) for _, l := range ls { set = append(set, l) } sort.Sort(set) return set }
go
{ "resource": "" }
q167359
FromStrings
validation
func FromStrings(ss ...string) Labels { if len(ss)%2 != 0 { panic("invalid number of strings") } var res Labels for i := 0; i < len(ss); i += 2 { res = append(res, Label{Name: ss[i], Value: ss[i+1]}) } sort.Sort(res) return res }
go
{ "resource": "" }
q167360
NewBuilder
validation
func NewBuilder(base Labels) *Builder { return &Builder{ base: base, del: make([]string, 0, 5), add: make([]Label, 0, 5), } }
go
{ "resource": "" }
q167361
Del
validation
func (b *Builder) Del(ns ...string) *Builder { for _, n := range ns { for i, a := range b.add { if a.Name == n { b.add = append(b.add[:i], b.add[i+1:]...) } } b.del = append(b.del, n) } return b }
go
{ "resource": "" }
q167362
Labels
validation
func (b *Builder) Labels() Labels { if len(b.del) == 0 && len(b.add) == 0 { return b.base } // In the general case, labels are removed, modified or moved // rather than added. res := make(Labels, 0, len(b.base)) Outer: for _, l := range b.base { for _, n := range b.del { if l.Name == n { continue Oute...
go
{ "resource": "" }
q167363
NewStorage
validation
func NewStorage(l log.Logger, reg prometheus.Registerer, stCallback startTimeCallback, walDir string, flushDeadline time.Duration) *Storage { if l == nil { l = log.NewNopLogger() } s := &Storage{ logger: logging.Dedupe(l, 1*time.Minute), localStartTimeCallback: stCallback, flushDeadline: ...
go
{ "resource": "" }
q167364
ApplyConfig
validation
func (s *Storage) ApplyConfig(conf *config.Config) error { s.mtx.Lock() defer s.mtx.Unlock() cfgBytes, err := json.Marshal(conf.RemoteWriteConfigs) if err != nil { return err } hash := md5.Sum(cfgBytes) if hash == s.configHash { level.Debug(s.logger).Log("msg", "remote write config has not changed, no need...
go
{ "resource": "" }
q167365
Querier
validation
func (s *Storage) Querier(ctx context.Context, mint, maxt int64) (storage.Querier, error) { s.mtx.Lock() queryables := s.queryables s.mtx.Unlock() queriers := make([]storage.Querier, 0, len(queryables)) for _, queryable := range queryables { q, err := queryable.Querier(ctx, mint, maxt) if err != nil { retu...
go
{ "resource": "" }
q167366
Close
validation
func (s *Storage) Close() error { s.mtx.Lock() defer s.mtx.Unlock() for _, q := range s.queues { q.Stop() } return nil }
go
{ "resource": "" }
q167367
RateLimit
validation
func RateLimit(next log.Logger, limit rate.Limit) log.Logger { return &ratelimiter{ limiter: rate.NewLimiter(limit, int(limit)), next: next, } }
go
{ "resource": "" }
q167368
newHypervisorDiscovery
validation
func newHypervisorDiscovery(provider *gophercloud.ProviderClient, opts *gophercloud.AuthOptions, port int, region string, l log.Logger) *HypervisorDiscovery { return &HypervisorDiscovery{provider: provider, authOpts: opts, region: region, port: port, logger: l} }
go
{ "resource": "" }
q167369
New
validation
func New( db func() *tsdb.DB, enableAdmin bool, ) *API { return &API{ db: db, enableAdmin: enableAdmin, } }
go
{ "resource": "" }
q167370
RegisterGRPC
validation
func (api *API) RegisterGRPC(srv *grpc.Server) { if api.enableAdmin { pb.RegisterAdminServer(srv, NewAdmin(api.db)) } else { pb.RegisterAdminServer(srv, &AdminDisabled{}) } }
go
{ "resource": "" }
q167371
HTTPHandler
validation
func (api *API) HTTPHandler(ctx context.Context, grpcAddr string) (http.Handler, error) { enc := new(protoutil.JSONPb) mux := runtime.NewServeMux(runtime.WithMarshalerOption(enc.ContentType(), enc)) opts := []grpc.DialOption{ grpc.WithInsecure(), // Replace the default dialer that connects through proxy when HT...
go
{ "resource": "" }
q167372
extractTimeRange
validation
func extractTimeRange(min, max *time.Time) (mint, maxt time.Time, err error) { if min == nil { mint = minTime } else { mint = *min } if max == nil { maxt = maxTime } else { maxt = *max } if mint.After(maxt) { return mint, maxt, errors.Errorf("min time must be before or equal to max time") } return mi...
go
{ "resource": "" }
q167373
Write
validation
func (c *compressedResponseWriter) Write(p []byte) (int, error) { return c.writer.Write(p) }
go
{ "resource": "" }
q167374
Close
validation
func (c *compressedResponseWriter) Close() { if zlibWriter, ok := c.writer.(*zlib.Writer); ok { zlibWriter.Flush() } if gzipWriter, ok := c.writer.(*gzip.Writer); ok { gzipWriter.Flush() } if closer, ok := c.writer.(io.Closer); ok { defer closer.Close() } }
go
{ "resource": "" }
q167375
newCompressedResponseWriter
validation
func newCompressedResponseWriter(writer http.ResponseWriter, req *http.Request) *compressedResponseWriter { encodings := strings.Split(req.Header.Get(acceptEncodingHeader), ",") for _, encoding := range encodings { switch strings.TrimSpace(encoding) { case gzipEncoding: writer.Header().Set(contentEncodingHeade...
go
{ "resource": "" }
q167376
AlertTemplateData
validation
func AlertTemplateData(labels map[string]string, externalLabels map[string]string, value float64) interface{} { return struct { Labels map[string]string ExternalLabels map[string]string Value float64 }{ Labels: labels, ExternalLabels: externalLabels, Value: value, } }
go
{ "resource": "" }
q167377
Funcs
validation
func (te Expander) Funcs(fm text_template.FuncMap) { for k, v := range fm { te.funcMap[k] = v } }
go
{ "resource": "" }
q167378
ExpandHTML
validation
func (te Expander) ExpandHTML(templateFiles []string) (result string, resultErr error) { defer func() { if r := recover(); r != nil { var ok bool resultErr, ok = r.(error) if !ok { resultErr = errors.Errorf("panic expanding template %s: %v", te.name, r) } } }() tmpl := html_template.New(te.name)...
go
{ "resource": "" }
q167379
NewTarget
validation
func NewTarget(labels, discoveredLabels labels.Labels, params url.Values) *Target { return &Target{ labels: labels, discoveredLabels: discoveredLabels, params: params, health: HealthUnknown, } }
go
{ "resource": "" }
q167380
Metadata
validation
func (t *Target) Metadata(metric string) (MetricMetadata, bool) { t.mtx.RLock() defer t.mtx.RUnlock() if t.metadata == nil { return MetricMetadata{}, false } return t.metadata.getMetadata(metric) }
go
{ "resource": "" }
q167381
hash
validation
func (t *Target) hash() uint64 { h := fnv.New64a() h.Write([]byte(fmt.Sprintf("%016d", t.labels.Hash()))) h.Write([]byte(t.URL().String())) return h.Sum64() }
go
{ "resource": "" }
q167382
offset
validation
func (t *Target) offset(interval time.Duration, jitterSeed uint64) time.Duration { now := time.Now().UnixNano() // Base is a pinned to absolute time, no matter how often offset is called. var ( base = int64(interval) - now%int64(interval) offset = (t.hash() ^ jitterSeed) % uint64(interval) next = base + i...
go
{ "resource": "" }
q167383
Labels
validation
func (t *Target) Labels() labels.Labels { lset := make(labels.Labels, 0, len(t.labels)) for _, l := range t.labels { if !strings.HasPrefix(l.Name, model.ReservedLabelPrefix) { lset = append(lset, l) } } return lset }
go
{ "resource": "" }
q167384
DiscoveredLabels
validation
func (t *Target) DiscoveredLabels() labels.Labels { t.mtx.Lock() defer t.mtx.Unlock() lset := make(labels.Labels, len(t.discoveredLabels)) copy(lset, t.discoveredLabels) return lset }
go
{ "resource": "" }
q167385
SetDiscoveredLabels
validation
func (t *Target) SetDiscoveredLabels(l labels.Labels) { t.mtx.Lock() defer t.mtx.Unlock() t.discoveredLabels = l }
go
{ "resource": "" }
q167386
URL
validation
func (t *Target) URL() *url.URL { params := url.Values{} for k, v := range t.params { params[k] = make([]string, len(v)) copy(params[k], v) } for _, l := range t.labels { if !strings.HasPrefix(l.Name, model.ParamLabelPrefix) { continue } ks := l.Name[len(model.ParamLabelPrefix):] if len(params[ks])...
go
{ "resource": "" }
q167387
LastError
validation
func (t *Target) LastError() error { t.mtx.RLock() defer t.mtx.RUnlock() return t.lastError }
go
{ "resource": "" }
q167388
LastScrape
validation
func (t *Target) LastScrape() time.Time { t.mtx.RLock() defer t.mtx.RUnlock() return t.lastScrape }
go
{ "resource": "" }
q167389
LastScrapeDuration
validation
func (t *Target) LastScrapeDuration() time.Duration { t.mtx.RLock() defer t.mtx.RUnlock() return t.lastScrapeDuration }
go
{ "resource": "" }
q167390
Health
validation
func (t *Target) Health() TargetHealth { t.mtx.RLock() defer t.mtx.RUnlock() return t.health }
go
{ "resource": "" }
q167391
targetsFromGroup
validation
func targetsFromGroup(tg *targetgroup.Group, cfg *config.ScrapeConfig) ([]*Target, error) { targets := make([]*Target, 0, len(tg.Targets)) for i, tlset := range tg.Targets { lbls := make([]labels.Label, 0, len(tlset)+len(tg.Labels)) for ln, lv := range tlset { lbls = append(lbls, labels.Label{Name: string(ln...
go
{ "resource": "" }
q167392
FromTime
validation
func FromTime(t time.Time) int64 { return t.Unix()*1000 + int64(t.Nanosecond())/int64(time.Millisecond) }
go
{ "resource": "" }
q167393
Time
validation
func Time(ts int64) time.Time { return time.Unix(ts/1000, (ts%1000)*int64(time.Millisecond)) }
go
{ "resource": "" }
q167394
SetCORS
validation
func SetCORS(w http.ResponseWriter, o *regexp.Regexp, r *http.Request) { origin := r.Header.Get("Origin") if origin == "" { return } for k, v := range corsHeaders { w.Header().Set(k, v) } if o.String() == "^(?:.*)$" { w.Header().Set("Access-Control-Allow-Origin", "*") return } if o.MatchString(origin...
go
{ "resource": "" }
q167395
Store
validation
func (c *Client) Store(ctx context.Context, req []byte) error { httpReq, err := http.NewRequest("POST", c.url.String(), bytes.NewReader(req)) if err != nil { // Errors from NewRequest are from unparseable URLs, so are not // recoverable. return err } httpReq.Header.Add("Content-Encoding", "snappy") httpReq.H...
go
{ "resource": "" }
q167396
Name
validation
func (c Client) Name() string { return fmt.Sprintf("%d:%s", c.index, c.url) }
go
{ "resource": "" }
q167397
Read
validation
func (c *Client) Read(ctx context.Context, query *prompb.Query) (*prompb.QueryResult, error) { req := &prompb.ReadRequest{ // TODO: Support batching multiple queries into one read request, // as the protobuf interface allows for it. Queries: []*prompb.Query{ query, }, } data, err := proto.Marshal(req) if...
go
{ "resource": "" }
q167398
NewDiscovery
validation
func NewDiscovery(cfg *SDConfig, logger log.Logger) *Discovery { if logger == nil { logger = log.NewNopLogger() } d := &Discovery{ cfg: cfg, port: cfg.Port, logger: logger, } d.Discovery = refresh.NewDiscovery( logger, "azure", time.Duration(cfg.RefreshInterval), d.refresh, ) return d }
go
{ "resource": "" }
q167399
createAzureClient
validation
func createAzureClient(cfg SDConfig) (azureClient, error) { env, err := azure.EnvironmentFromName(cfg.Environment) if err != nil { return azureClient{}, err } activeDirectoryEndpoint := env.ActiveDirectoryEndpoint resourceManagerEndpoint := env.ResourceManagerEndpoint var c azureClient var spt *adal.Service...
go
{ "resource": "" }