// Creates a new FailureCounter with threshold FailedThreshold and time window WorkerThresholdTimeWindow.
483416
func NewFailureCounter(FailedThreshold int32, WorkerThresholdTimeWindow time.Duration) *FailureCounter {
	counter := &FailureCounter{
		failedThreshold: FailedThreshold,
		stop:            make(chan bool),
	}
	go func() {
		for {
			timeout := time.NewTimer(WorkerThresholdTimeWindow)
			select {
			case <-timeout.C:
				{
					if counter.count >= FailedThreshold {
						counter.failed = true
						return
					} else {
						inLock(&counter.countLock, func() {
							counter.count = 0
						})
					}
				}
			case <-counter.stop:
				timeout.Stop()
				return
			}
		}
	}()
	return counter
}
580549
func failedToStart(c context.Context, build *ui.MiloBuildLegacy, res *swarming.SwarmingRpcsTaskResult, host string) error {
	build.Summary.Status = model.InfraFailure
	started, err := time.Parse(SwarmingTimeLayout, res.StartedTs)
	if err != nil {
		return err
	}
	ended, err := time.Parse(SwarmingTimeLayout, res.CompletedTs)
	if err != nil {
		return err
	}
	build.Summary.ExecutionTime = ui.NewInterval(c, started, ended)
	infoComp := infoComponent(model.InfraFailure,
		"LogDog stream not found", "Job likely failed to start.")
	infoComp.ExecutionTime = build.Summary.ExecutionTime
	build.Components = append(build.Components, infoComp)
	return addTaskToBuild(c, host, res, build)
}
308827
func MustCreateSampledTimer(base tally.Timer, rate float64) tally.Timer {
	t, err := NewSampledTimer(base, rate)
	if err != nil {
		panic(err)
	}
	return t
}
571092
func (cb *Breaker) ResetCounters() {
	atomic.StoreInt64(&cb.consecFailures, 0)
	cb.counts.Reset()
}
1265228
func createNewNotifier(args ...interface{}) (chainntnfs.ChainNotifier, error) {
	if len(args) != 3 {
		return nil, fmt.Errorf("incorrect number of arguments to "+
			".New(...), expected 3, instead passed %v", len(args))
	}

	config, ok := args[0].(*neutrino.ChainService)
	if !ok {
		return nil, errors.New("first argument to neutrinonotify.New " +
			"is incorrect, expected a *neutrino.ChainService")
	}

	spendHintCache, ok := args[1].(chainntnfs.SpendHintCache)
	if !ok {
		return nil, errors.New("second argument to neutrinonotify.New " +
			"is  incorrect, expected a chainntfs.SpendHintCache")
	}

	confirmHintCache, ok := args[2].(chainntnfs.ConfirmHintCache)
	if !ok {
		return nil, errors.New("third argument to neutrinonotify.New " +
			"is  incorrect, expected a chainntfs.ConfirmHintCache")
	}

	return New(config, spendHintCache, confirmHintCache), nil
}
1093150
func (sbself *splitBufferedWriter) InstallNewUserBufferAndResetRemainder(
	data []byte) {

	sbself.remainder.Reset()
	sbself.userBuffer = data
	sbself.userBufferCount = 0
}
1345219
func (p expvarProvider) NewCounter(name string) metrics.Counter {
	return expvar.NewCounter(name)
}
1354817
func startProvisionerWorker(
	runner *worker.Runner,
	containerType instance.ContainerType,
	provisioner *apiprovisioner.State,
	config agent.Config,
	broker environs.InstanceBroker,
	toolsFinder ToolsFinder,
	distributionGroupFinder DistributionGroupFinder,
	credentialAPI workercommon.CredentialAPI,
) error {

	workerName := fmt.Sprintf("%s-provisioner", containerType)
	// The provisioner task is created after a container record has
	// already been added to the machine. It will see that the
	// container does not have an instance yet and create one.
	return runner.StartWorker(workerName, func() (worker.Worker, error) {
		w, err := NewContainerProvisioner(containerType,
			provisioner,
			config,
			broker,
			toolsFinder,
			distributionGroupFinder,
			credentialAPI,
		)
		if err != nil {
			return nil, errors.Trace(err)
		}
		return w, nil
	})
}
1001232
func (o *Enterprise) CreateRateLimiter(child *RateLimiter) *bambou.Error {

	return bambou.CurrentSession().CreateChild(o, child)
}
389073
func NewCleaner(st StateCleaner, clock clock.Clock) (worker.Worker, error) {
	watcher, err := st.WatchCleanups()
	if err != nil {
		return nil, errors.Trace(err)
	}
	c := Cleaner{
		st:      st,
		watcher: watcher,
		clock:   clock,
	}
	if err := catacomb.Invoke(catacomb.Plan{
		Site: &c.catacomb,
		Work: c.loop,
		Init: []worker.Worker{watcher},
	}); err != nil {
		return nil, errors.Trace(err)
	}
	return &c, nil
}
256179
func (p *ProvisionerAPI) WatchMachineErrorRetry() (params.NotifyWatchResult, error) {
	result := params.NotifyWatchResult{}
	if !p.authorizer.AuthController() {
		return result, common.ErrPerm
	}
	watch := newWatchMachineErrorRetry()
	// Consume any initial event and forward it to the result.
	if _, ok := <-watch.Changes(); ok {
		result.NotifyWatcherId = p.resources.Register(watch)
	} else {
		return result, watcher.EnsureErr(watch)
	}
	return result, nil
}
451609
func (s *DescribeThingRegistrationTaskOutput) SetFailureCount(v int64) *DescribeThingRegistrationTaskOutput {
	s.FailureCount = &v
	return s
}
242679
func NewCleanupWorker(w worker.Worker, cleanup func()) worker.Worker {
	return &CleanupWorker{
		Worker:  w,
		cleanup: cleanup,
	}
}
551363
func (s *EndpointGroup) SetThresholdCount(v int64) *EndpointGroup {
	s.ThresholdCount = &v
	return s
}
589745
func (api *NFSAPI) AsyncSleepWhileCopying(id int64, timeout time.Duration, maxRetry int) (chan (interface{}), chan (interface{}), chan (error)) {
	handler := waitingForAvailableFunc(func() (hasAvailable, error) {
		return api.Read(id)
	}, maxRetry)
	return poll(handler, timeout)
}
207418
func NewHistoCounter(sink *Counter) *HistoCounter {
	return &HistoCounter{
		sink:            sink,
		DatapointBucket: sfxclient.NewRollingBucket("datapoint_batch_size", map[string]string{}),
		EventBucket:     sfxclient.NewRollingBucket("event_batch_size", map[string]string{}),
		SpanBucket:      sfxclient.NewRollingBucket("span_batch_size", map[string]string{}),
	}
}
549931
func NewCounterFrom(opts prometheus.CounterOpts, labelNames []string) *Counter {
	cv := prometheus.NewCounterVec(opts, labelNames)
	prometheus.MustRegister(cv)
	return NewCounter(cv)
}