//go:generate stringer -type=MetricType
762258
func (m MetricType) isCompatibleInt(val int) bool {
	v := int64(val)
	switch m {
	case Int32Type:
		return v >= math.MinInt32 && v <= math.MaxInt32
	case Int64Type:
		return true
	case Uint32Type:
		return v >= 0 && v <= math.MaxUint32
	case Uint64Type:
		return v >= 0
	}
	return false
}
662210
func Gauge(metricName string, dimensions map[string]string, val int64) *datapoint.Datapoint {
	return datapoint.New(metricName, dimensions, datapoint.NewIntValue(val), datapoint.Gauge, time.Time{})
}
147534
func (v *ServiceGenerator_Generate_Args) String() string {
	if v == nil {
		return "<nil>"
	}

	var fields [1]string
	i := 0
	if v.Request != nil {
		fields[i] = fmt.Sprintf("Request: %v", v.Request)
		i++
	}

	return fmt.Sprintf("ServiceGenerator_Generate_Args{%v}", strings.Join(fields[:i], ", "))
}
955952
func (self *StringTypeDef) UnmarshalJSON(b []byte) error {
	var m rawStringTypeDef
	err := json.Unmarshal(b, &m)
	if err == nil {
		o := StringTypeDef(m)
		*self = o
		err = self.Validate()
	}
	return err
}
342529
func (r *PCPRegistry) AddMetricByString(str string, val interface{}, t MetricType, s MetricSemantics, u MetricUnit) (Metric, error) {
	metric, indom, instances, err := parseString(str)
	if err != nil {
		return nil, err
	}

	if instances == nil {
		return r.addSingletonMetricByString(metric, val, t, s, u)
	}

	return r.addInstanceMetricByString(metric, val, indom, instances, t, s, u)
}
1348602
func (r Rope) GoString() string {
	// Perhaps technically more correct, but not nearly as useful:
	//	 return fmt.Sprintf("rope.New(%q)", r.String())

	// Instead, (mostly) pretend we're a regular string.
	if MarkGoStringedRope {
		return fmt.Sprintf("/*Rope*/ %#v", r.String())
	}
	return fmt.Sprintf("%#v", r.String())
}
669539
func (g *Generator) String(length, cardinality int) string {
	if length > 32 {
		length = 32
	}

	val := g.Uint64(cardinality)

	b := make([]byte, 8)
	binary.BigEndian.PutUint64(b, val)
	_, _ = g.hsh.Write(b) // no need to check err
	hashed := g.hsh.Sum(nil)
	g.hsh.Reset()
	return base32.StdEncoding.EncodeToString(hashed)[:length]
}
411044
func StringToType(s string, p reflect.Type) interface{} {
	switch p {
	case reflects.TypeTime:
		return ToTime(s)
	case reflects.TypeDuration:
		return ToDuration(s)
	default:
		switch p.Kind() {
		case reflect.String:
			return s
		case reflect.Bool:
			return ToBool(s)
		case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
			return ToInt(s)
		case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
			return ToUint(s)
		case reflect.Slice:
			et := p.Elem()
			if et.Kind() == reflect.String {
				return strings.Split(s, ",")
			}
		default:
			panic(errors.New("unsupported type: " + p.Name()))
		}
	}
	return nil
}
247624
func generateInstanceMetric(vals map[string]interface{}, name string, instances []string, t MetricType, s MetricSemantics, u MetricUnit, desc ...string) (*pcpInstanceMetric, error) {
	indomname := name + ".indom"
	indom, err := NewPCPInstanceDomain(indomname, instances)
	if err != nil {
		return nil, errors.Errorf("cannot create indom, error: %v", err)
	}

	d, err := newpcpMetricDesc(name, t, s, u, desc...)
	if err != nil {
		return nil, err
	}

	return newpcpInstanceMetric(vals, indom, d)
}
716086
func UnmarshallMetricTypes(contentType string, payload []byte) ([]MetricType, error) {
	switch contentType {
	case SnapGOBContentType:
		var metrics []MetricType
		r := bytes.NewBuffer(payload)
		err := gob.NewDecoder(r).Decode(&metrics)
		if err != nil {
			log.WithFields(log.Fields{
				"_module": "control-plugin",
				"block":   "unmarshal-content-type",
				"error":   err.Error(),
			}).Error("error while unmarshalling")
			return nil, err
		}
		return metrics, nil
	case SnapJSONContentType:
		var metrics []MetricType
		err := json.Unmarshal(payload, &metrics)
		if err != nil {
			log.WithFields(log.Fields{
				"_module": "control-plugin",
				"block":   "unmarshal-content-type",
				"error":   err.Error(),
			}).Error("error while unmarshalling")
			return nil, err
		}
		return metrics, nil
	default:
		// We don't recognize this content type as one we can unmarshal. Log and return error.
		es := fmt.Sprintf("invalid snap content type for unmarshalling: %s", contentType)
		log.WithFields(log.Fields{
			"_module": "control-plugin",
			"block":   "unmarshal-content-type",
			"error":   es,
		}).Error("error while unmarshalling")
		return nil, errors.New(es)
	}
}
535580
func generateLabelString(source, key, value string) string {
	return fmt.Sprintf("%s:%s=%s", source, key, value)
}
352133
func (t Type) String() string {
	switch t {
	case Bool:
		return "bool"
	case Int64:
		return "int64"
	case Float64:
		return "float64"
	case Text:
		return "text"
	case Blob:
		return "blob"
	default:
		return "UNKNOWN"
	}
}
123922
func (mag MaterialAttributesGit) GenerateGeneric() (ma map[string]interface{}) {
	ma = map[string]interface{}{
		"name":             mag.Name,
		"url":              mag.URL,
		"auto_update":      mag.AutoUpdate,
		"branch":           mag.Branch,
		"submodule_folder": mag.SubmoduleFolder,
		"destination":      mag.Destination,
		"shallow_clone":    mag.ShallowClone,
		"invert_filter":    mag.InvertFilter,
	}
	if f := mag.Filter.GenerateGeneric(); f != nil {
		ma["filter"] = f
	}
	return
}
238299
func (gt GraphType) String() string {
	if gt == DIGRAPH {
		return "digraph"
	} else if gt == GRAPH {
		return "graph"
	} else if gt == SUBGRAPH {
		return "subgraph"
	}
	return "(invalid)"
}
1355755
func (reporterOptions) Metrics(metrics *Metrics) ReporterOption {
	return func(r *reporterOptions) {
		r.metrics = metrics
	}
}
1148279
func Metrics(harness metrics.Harness, labeler Labeler) Rule {
	if harness == nil {
		panic("harness is a required parameter")
	}
	if labeler == nil {
		labeler = defaultLabeler
	}
	return func(ctx context.Context, e *scheduler.Event, err error, ch Chain) (context.Context, *scheduler.Event, error) {
		labels := labeler(ctx, e)
		harness(func() error {
			ctx, e, err = ch(ctx, e, err)
			return err
		}, labels...)
		return ctx, e, err
	}
}
1172135
func Metrics() []telegraf.Metric {
	registry.mu.Lock()
	now := time.Now()
	metrics := make([]telegraf.Metric, len(registry.stats))
	i := 0
	for _, stats := range registry.stats {
		if len(stats) > 0 {
			var tags map[string]string
			var name string
			fields := map[string]interface{}{}
			j := 0
			for fieldname, stat := range stats {
				if j == 0 {
					tags = stat.Tags()
					name = stat.Name()
				}
				fields[fieldname] = stat.Get()
				j++
			}
			metric, err := metric.New(name, tags, fields, now)
			if err != nil {
				log.Printf("E! Error creating selfstat metric: %s", err)
				continue
			}
			metrics[i] = metric
			i++
		}
	}
	registry.mu.Unlock()
	return metrics
}