// CreateMeasurement returns 16 bytes that represent a measurement.
//
// If either org or bucket are short then an error is returned, otherwise the
// first 8 bytes of each are combined and returned.
190385
func CreateMeasurement(org, bucket []byte) ([]byte, error) {
	if len(org) < OrgIDLength {
		return nil, fmt.Errorf("org %v has invalid length (%d)", org, len(org))
	} else if len(bucket) < BucketIDLength {
		return nil, fmt.Errorf("bucket %v has invalid length (%d)", bucket, len(bucket))
	}

	name := make([]byte, 0, MeasurementLength)
	name = append(name, org[:OrgIDLength]...)
	return append(name, bucket[:BucketIDLength]...), nil
}
101703
func NewMetricConverter() *MetricConverter {
	return &MetricConverter{
		scheme: scheme.Scheme,
		codecs: serializer.NewCodecFactory(scheme.Scheme),
		internalVersioner: runtime.NewMultiGroupVersioner(
			scheme.SchemeGroupVersion,
			schema.GroupKind{Group: cmint.GroupName, Kind: ""},
			schema.GroupKind{Group: cmv1beta1.GroupName, Kind: ""},
			schema.GroupKind{Group: cmv1beta2.GroupName, Kind: ""},
		),
	}
}
1360212
func (mr *MockStorageClassInterfaceMockRecorder) Create(arg0 interface{}) *gomock.Call {
	return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Create", reflect.TypeOf((*MockStorageClassInterface)(nil).Create), arg0)
}
1261459
func CreateRegommendItem(key interface{}, data map[interface{}]float64) RegommendItem {
	return RegommendItem{
		key:           key,
		data:          data,
	}
}
696231
func (bm *bucketMeta) createBucket(name []byte) *bucketMeta {
	bm.bucketsLock.Lock()
	defer bm.bucketsLock.Unlock()

	// Always create a new Bucket since CreateBucket above fails if the
	// bucket already exists.
	b := newBucketMeta()
	bm.buckets[string(name)] = b
	return b
}
59129
func (i *Index) ComputeMeasurementCardinalityStats() (MeasurementCardinalityStats, error) {
	i.mu.RLock()
	defer i.mu.RUnlock()

	stats := NewMeasurementCardinalityStats()
	for _, p := range i.partitions {
		pstats, err := p.ComputeMeasurementCardinalityStats()
		if err != nil {
			return nil, err
		}
		stats.Add(pstats)
	}
	return stats, nil
}
546034
func (e *Engine) DeleteMeasurement(name []byte) error {
	// Delete the bulk of data outside of the fields lock.
	if err := e.deleteMeasurement(name); err != nil {
		return err
	}
	return nil
}
743922
func (fs *FileSet) Measurement(name []byte) MeasurementElem {
	for _, f := range fs.files {
		if e := f.Measurement(name); e == nil {
			continue
		} else if e.Deleted() {
			return nil
		} else {
			return e
		}
	}
	return nil
}
1141365
func AppendMeasure(b []byte, t time.Time, m stats.Measure) []byte {
	b = append(b, m.Name...)

	for _, tag := range m.Tags {
		b = append(b, ',')
		b = append(b, tag.Name...)
		b = append(b, '=')
		b = append(b, tag.Value...)
	}

	for i, field := range m.Fields {
		if len(field.Name) == 0 {
			field.Name = "value"
		}

		if i == 0 {
			b = append(b, ' ')
		} else {
			b = append(b, ',')
		}

		b = append(b, field.Name...)
		b = append(b, '=')

		switch v := field.Value; v.Type() {
		case stats.Null:
		case stats.Bool:
			if v.Bool() {
				b = append(b, "true"...)
			} else {
				b = append(b, "false"...)
			}
		case stats.Int:
			b = strconv.AppendInt(b, v.Int(), 10)
		case stats.Uint:
			b = strconv.AppendUint(b, v.Uint(), 10)
		case stats.Float:
			b = strconv.AppendFloat(b, v.Float(), 'g', -1, 64)
		case stats.Duration:
			b = strconv.AppendFloat(b, v.Duration().Seconds(), 'g', -1, 64)
		}
	}

	b = append(b, ' ')
	b = strconv.AppendInt(b, t.UnixNano(), 10)

	return append(b, '\n')
}
1012700
func (p *Partition) MeasurementCardinalityStats() MeasurementCardinalityStats {
	p.mu.RLock()
	defer p.mu.RUnlock()

	stats := p.stats.Clone()

	if p.activeLogFile != nil {
		stats.Add(p.activeLogFile.MeasurementCardinalityStats())
	}
	return stats
}
376030
func (f *LogFile) DeleteMeasurement(name []byte) error {
	f.mu.Lock()
	defer f.mu.Unlock()

	e := LogEntry{Flag: LogEntryMeasurementTombstoneFlag, Name: name}
	if err := f.appendEntry(&e); err != nil {
		return err
	}
	f.execEntry(&e)

	// Flush buffer and sync to disk.
	return f.FlushAndSync()
}
479252
func NewMethodMetrics(scope tally.Scope, methodName string, samplingRate float64) MethodMetrics {
	return MethodMetrics{
		Errors:         scope.Counter(methodName + ".errors"),
		Success:        scope.Counter(methodName + ".success"),
		ErrorsLatency:  MustCreateSampledTimer(scope.Timer(methodName+".errors-latency"), samplingRate),
		SuccessLatency: MustCreateSampledTimer(scope.Timer(methodName+".success-latency"), samplingRate),
	}
}
57627
func (f *IndexFile) Measurement(name []byte) MeasurementElem {
	e, ok := f.mblk.Elem(name)
	if !ok {
		return nil
	}
	return &e
}
1029671
func NewBlockServerMeasured(delegate BlockServer, r metrics.Registry) BlockServerMeasured {
	getTimer := metrics.GetOrRegisterTimer("BlockServer.Get", r)
	getEncodedSizeTimer := metrics.GetOrRegisterTimer(
		"BlockServer.GetEncodedSize", r)
	putTimer := metrics.GetOrRegisterTimer("BlockServer.Put", r)
	addBlockReferenceTimer := metrics.GetOrRegisterTimer("BlockServer.AddBlockReference", r)
	removeBlockReferencesTimer := metrics.GetOrRegisterTimer("BlockServer.RemoveBlockReferences", r)
	archiveBlockReferencesTimer := metrics.GetOrRegisterTimer("BlockServer.ArchiveBlockReferences", r)
	getLiveBlockReferencesTimer := metrics.GetOrRegisterTimer("BlockServer.GetLiveBlockReferences", r)
	isUnflushedTimer := metrics.GetOrRegisterTimer("BlockServer.IsUnflushed", r)
	return BlockServerMeasured{
		delegate:                    delegate,
		getTimer:                    getTimer,
		getEncodedSizeTimer:         getEncodedSizeTimer,
		putTimer:                    putTimer,
		addBlockReferenceTimer:      addBlockReferenceTimer,
		removeBlockReferencesTimer:  removeBlockReferencesTimer,
		archiveBlockReferencesTimer: archiveBlockReferencesTimer,
		getLiveBlockReferencesTimer: getLiveBlockReferencesTimer,
		isUnflushedTimer:            isUnflushedTimer,
	}
}
489638
func (m *metricMap) getOrCreateMetricWithLabelValues(
	hash uint64, lvs []string, curry []curriedLabelValue,
) Metric {
	m.mtx.RLock()
	metric, ok := m.getMetricWithHashAndLabelValues(hash, lvs, curry)
	m.mtx.RUnlock()
	if ok {
		return metric
	}

	m.mtx.Lock()
	defer m.mtx.Unlock()
	metric, ok = m.getMetricWithHashAndLabelValues(hash, lvs, curry)
	if !ok {
		inlinedLVs := inlineLabelValues(lvs, curry)
		metric = m.newMetric(inlinedLVs...)
		m.metrics[hash] = append(m.metrics[hash], metricWithLabelValues{values: inlinedLVs, metric: metric})
	}
	return metric
}
1080967
func (b *stdBackend) BeginMeasuring(id string) Measuring {
	if b.etmFilter != nil && !b.etmFilter(id) {
		return &stdMeasuring{}
	}
	return &stdMeasuring{b, id, time.Now(), 0}
}
92889
func (m *mockCostEstimations) create(cvID, workspaceID string) (*tfe.CostEstimation, error) {
	id := generateID("ce-")

	ce := &tfe.CostEstimation{
		ID:     id,
		Status: tfe.CostEstimationQueued,
	}

	w, ok := m.client.Workspaces.workspaceIDs[workspaceID]
	if !ok {
		return nil, tfe.ErrResourceNotFound
	}

	logfile := filepath.Join(
		m.client.ConfigurationVersions.uploadPaths[cvID],
		w.WorkingDirectory,
		"ce.log",
	)

	if _, err := os.Stat(logfile); os.IsNotExist(err) {
		return nil, nil
	}

	m.logs[ce.ID] = logfile
	m.estimations[ce.ID] = ce

	return ce, nil
}