// check for nil client, and perform sampling calculation
169568
func (s *Client) includeStat(rate float32) bool {
	if s == nil {
		return false
	}

	// test for nil in case someone builds their own
	// client without calling new (result is nil sampler)
	if s.sampler != nil {
		return s.sampler(rate)
	}
	return DefaultSampler(rate)
}
1291025
func CheckIsCLIUpdateCheckRequired() bool {
	config, err := loadBitriseConfig()
	if err != nil {
		return false
	}

	duration := time.Now().Sub(config.LastCLIUpdateCheck)
	if duration.Hours() >= 24 {
		return true
	}

	return false
}
795802
func SampleEvery(stats Stats, t time.Duration) {
	c := time.Tick(t)
	for _ = range c {
		r := newRuntimeSample()
		r.drain(stats)
	}
}
307006
func (s *Sensu) GetEventsCheckForClient(client string, check string) ([]interface{}, error) {
	//return s.get("events", client)
	// TODO  is this the correct way? need validation??
	return s.getList(fmt.Sprintf("events/%s/%s", client, check), 0, 0)
}
497621
func (rc *rawConn) checkOperation(projectID string, op *compute.Operation) (*compute.Operation, error) {
	var call opDoer
	if op.Zone != "" {
		zoneName := path.Base(op.Zone)
		call = rc.ZoneOperations.Get(projectID, zoneName, op.Name)
	} else if op.Region != "" {
		region := path.Base(op.Region)
		call = rc.RegionOperations.Get(projectID, region, op.Name)
	} else {
		call = rc.GlobalOperations.Get(projectID, op.Name)
	}

	operation, err := doOpCall(call)
	if err != nil {
		return nil, errors.Annotatef(err, "request for GCE operation %q failed", op.Name)
	}
	return operation, nil
}
1057081
func (p *PerKeyThroughput) GetSampleRate(key string) int {
	p.lock.Lock()
	defer p.lock.Unlock()
	p.currentCounts[key]++
	if rate, found := p.savedSampleRates[key]; found {
		return rate
	}
	return 1
}
1009258
func NewCountingSampler(rate float64) (Sampler, error) {
	if rate == 0.0 {
		return NeverSample, nil
	}
	if rate == 1.0 {
		return AlwaysSample, nil
	}
	if rate < 0.01 || rate > 1 {
		return nil, fmt.Errorf("rate should be 0.0 or between 0.01 and 1: was %f", rate)
	}
	var (
		i         = 0
		outOf100  = int(rate*100 + math.Copysign(0.5, rate*100)) // for rounding float to int conversion instead of truncation
		decisions = randomBitSet(100, outOf100, rand.New(rand.NewSource(time.Now().UnixNano())))
		mtx       = &sync.Mutex{}
	)

	return func(_ uint64) bool {
		mtx.Lock()
		result := decisions[i]
		i++
		if i == 100 {
			i = 0
		}
		mtx.Unlock()
		return result
	}, nil
}
742338
func (c *accountIDOptions) Check() error {
	_, err := strkey.Decode(strkey.VersionByteAccountID, c.AccountID)
	if err != nil {
		return ErrInvalidAccountID
	}
	return nil
}
52656
func (c *HeapProfiler) StartSampling(samplingInterval float64) (*gcdmessage.ChromeResponse, error) {
	var v HeapProfilerStartSamplingParams
	v.SamplingInterval = samplingInterval
	return c.StartSamplingWithParams(&v)
}
648522
func (c *Clientset) SamplecontrollerV1alpha1() samplecontrollerv1alpha1.SamplecontrollerV1alpha1Interface {
	return &fakesamplecontrollerv1alpha1.FakeSamplecontrollerV1alpha1{Fake: &c.Fake}
}
1360449
func Evaluate(clients []*Client, truth [][]time.Duration) (stats Stats) {
	nodes := len(clients)
	count := 0
	for i := 0; i < nodes; i++ {
		for j := i + 1; j < nodes; j++ {
			est := clients[i].DistanceTo(clients[j].GetCoordinate()).Seconds()
			actual := truth[i][j].Seconds()
			error := math.Abs(est-actual) / actual
			stats.ErrorMax = math.Max(stats.ErrorMax, error)
			stats.ErrorAvg += error
			count += 1
		}
	}

	stats.ErrorAvg /= float64(count)
	fmt.Printf("Error avg=%9.6f max=%9.6f\n", stats.ErrorAvg, stats.ErrorMax)
	return
}
1037780
func NewCountingSampler(rate float64) Sampler {
	if rate <= 0 {
		return neverSample
	}
	if rate >= 1.0 {
		return alwaysSample
	}
	var (
		i         = 0
		outOf100  = int(rate*100 + math.Copysign(0.5, rate*100)) // for rounding float to int conversion instead of truncation
		decisions = randomBitSet(100, outOf100, rand.New(rand.NewSource(time.Now().UnixNano())))
		mtx       = &sync.Mutex{}
	)

	return func(_ uint64) bool {
		mtx.Lock()
		defer mtx.Unlock()
		result := decisions[i]
		i++
		if i == 100 {
			i = 0
		}
		return result
	}
}
919750
func (c *Memory) StartSampling(samplingInterval int, suppressRandomness bool) (*gcdmessage.ChromeResponse, error) {
	var v MemoryStartSamplingParams
	v.SamplingInterval = samplingInterval
	v.SuppressRandomness = suppressRandomness
	return c.StartSamplingWithParams(&v)
}
1298127
func (s *StatusCheck) Sample(sample float64, sampleRate float32, message string, hostname string) {
	s.Value = sample
	s.Message = message
	s.HostName = hostname
}
984800
func (remote *RemoteDebugger) GetPreciseCoverage(precise bool) ([]interface{}, error) {
	var res map[string]interface{}
	var err error

	if precise {
		res, err = remote.SendRequest("Profiler.takePreciseCoverage", nil)
	} else {
		res, err = remote.SendRequest("Profiler.getBestEffortCoverage", nil)
	}
	if res == nil || err != nil {
		return nil, err
	}
	log.Println(res)
	return res["result"].([]interface{}), nil
}
135855
func (u *user) check(ca checkArg) {
	var err error

	defer func() {
		u.ca.log.Debug("Check %s, err: %v", ca, err)
		ca.retCh <- err
	}()

	if err = u.repopulate(); err != nil {
		return
	}

	if !ca.loadDeleted && u.isDeleted {
		err = ErrUserDeleted
		return
	}

	if ca.username != nil {
		if err = u.checkUsername(*ca.username); err != nil {
			return
		}
	}

	if ca.kid != nil {
		if err = u.checkKey(*ca.kid); err != nil {
			return
		}
	}

	if ca.sibkeys != nil {
		if err = u.compareSibkeys(ca.sibkeys); err != nil {
			return
		}
	}

	if ca.subkeys != nil {
		if err = u.compareSubkeys(ca.subkeys); err != nil {
			return
		}
	}
}
836759
func calculateCAPin(client auth.ClientI) (string, error) {
	localCA, err := client.GetClusterCACert()
	if err != nil {
		return "", trace.Wrap(err)
	}
	tlsCA, err := tlsca.ParseCertificatePEM(localCA.TLSCA)
	if err != nil {
		return "", trace.Wrap(err)
	}

	return utils.CalculateSPKI(tlsCA), nil
}