// NewCarbonDatapoint creates a new datapoint from a line in carbon and injects into the datapoint
// metadata about the original line.
480537
func NewCarbonDatapoint(line string, metricDeconstructor metricdeconstructor.MetricDeconstructor) (*datapoint.Datapoint, error) {
	parts := strings.SplitN(line, " ", 3)
	meta := map[interface{}]interface{}{
		carbonNative: line,
	}
	if len(parts) != 3 {
		return nil, errors.Errorf("Note: Gateway does not support pickle format: invalid carbon input line: %s", line)
	}
	originalMetricName := parts[0]
	metricName, mtype, dimensions, err := metricDeconstructor.Parse(originalMetricName)
	if err != nil {
		return nil, err
	}

	metricTime, err := strconv.ParseFloat(parts[2], 64)
	if err != nil {
		return nil, errors.Annotatef(err, "invalid carbon metric time on input line %s", line)
	}

	v, err := func() (datapoint.Value, error) {
		metricValueInt, err := strconv.ParseInt(parts[1], 10, 64)
		if err == nil {
			return datapoint.NewIntValue(metricValueInt), nil
		}
		metricValueFloat, err := strconv.ParseFloat(parts[1], 64)
		if err != nil {
			return nil, errors.Annotatef(err, "unable to parse carbon metric value on line %s", line)
		}
		return datapoint.NewFloatValue(metricValueFloat), nil
	}()
	if err != nil {
		return nil, err
	}
	return datapoint.NewWithMeta(metricName, dimensions, meta, v, mtype, time.Unix(0, int64(metricTime*1000)*int64(time.Millisecond))), nil
}
812438
func (m *RequestCounter) Datapoints() []*datapoint.Datapoint {
	return []*datapoint.Datapoint{
		sfxclient.Cumulative("total_connections", nil, atomic.LoadInt64(&m.TotalConnections)),
		sfxclient.Cumulative("total_time_ns", nil, atomic.LoadInt64(&m.TotalProcessingTimeNs)),
		sfxclient.Gauge("active_connections", nil, atomic.LoadInt64(&m.ActiveConnections)),
	}
}
289988
func (instanceApi *InstanceApi) CreateRecoveryPoint(id string, recoveryPoint RecoveryPoint) (bool, error) {
	send, merr := json.Marshal(Instance{
		RecoveryPoint: recoveryPoint,
	})
	if merr != nil {
		return false, merr
	}
	_, err := instanceApi.entityService.Execute(id, INSTANCE_CREATE_RECOVERY_POINT_OPERATION, send, map[string]string{})
	return err == nil, err
}
771073
func (m *BucketRequestCounter) Datapoints() []*datapoint.Datapoint {
	dps := m.Bucket.Datapoints()
	return append(dps,
		sfxclient.Gauge(m.Bucket.MetricName+".active_connections", m.Bucket.Dimensions, atomic.LoadInt64(&m.ActiveConnections)),
	)
}
861619
func (g *MultiPoint) Point(i int) *Point {
	return NewPointFlat(g.layout, g.Coord(i))
}
1024585
func (d *OvsDriver) CreateEndpoint(id string) error {
	var (
		err          error
		intfName     string
		epgKey       string
		epgBandwidth int64
		dscp         int
	)

	cfgEp := &mastercfg.CfgEndpointState{}
	cfgEp.StateDriver = d.oper.StateDriver
	err = cfgEp.Read(id)
	if err != nil {
		return err
	}

	// Get the nw config.
	cfgNw := mastercfg.CfgNetworkState{}
	cfgNw.StateDriver = d.oper.StateDriver
	err = cfgNw.Read(cfgEp.NetID)
	if err != nil {
		log.Errorf("Unable to get network %s. Err: %v", cfgEp.NetID, err)
		return err
	}

	pktTagType := cfgNw.PktTagType
	pktTag := cfgNw.PktTag
	cfgEpGroup := &mastercfg.EndpointGroupState{}
	// Read pkt tags from endpoint group if available
	if cfgEp.EndpointGroupKey != "" {
		cfgEpGroup.StateDriver = d.oper.StateDriver

		err = cfgEpGroup.Read(cfgEp.EndpointGroupKey)
		if err == nil {
			log.Debugf("pktTag: %v ", cfgEpGroup.PktTag)
			pktTagType = cfgEpGroup.PktTagType
			pktTag = cfgEpGroup.PktTag
			epgKey = cfgEp.EndpointGroupKey
			dscp = cfgEpGroup.DSCP
			if cfgEpGroup.Bandwidth != "" {
				epgBandwidth = netutils.ConvertBandwidth(cfgEpGroup.Bandwidth)
			}

		} else if core.ErrIfKeyExists(err) == nil {
			log.Infof("EPG %s not found: %v. will use network based tag ", cfgEp.EndpointGroupKey, err)
		} else {
			return err
		}
	}

	// Find the switch based on network type
	var sw *OvsSwitch
	if pktTagType == "vxlan" {
		sw = d.switchDb["vxlan"]
	} else {
		sw = d.switchDb["vlan"]
	}

	// Skip Veth pair creation for infra nw endpoints
	skipVethPair := (cfgNw.NwType == "infra")

	operEp := &drivers.OperEndpointState{}
	operEp.StateDriver = d.oper.StateDriver
	err = operEp.Read(id)
	if core.ErrIfKeyExists(err) != nil {
		return err
	} else if err == nil {
		// check if oper state matches cfg state. In case of mismatch cleanup
		// up the EP and continue add new one. In case of match just return.
		if operEp.Matches(cfgEp) {
			log.Printf("Found matching oper state for ep %s, noop", id)

			// Ask the switch to update the port
			err = sw.UpdatePort(operEp.PortName, cfgEp, pktTag, cfgNw.PktTag, dscp, skipVethPair)
			if err != nil {
				log.Errorf("Error creating port %s. Err: %v", intfName, err)
				return err
			}

			return nil
		}
		log.Printf("Found mismatching oper state for Ep, cleaning it. Config: %+v, Oper: %+v",
			cfgEp, operEp)
		d.DeleteEndpoint(operEp.ID)
	}

	if cfgNw.NwType == "infra" {
		// For infra nw, port name is network name
		intfName = cfgNw.NetworkName
	} else {
		// Get the interface name to use
		intfName, err = d.getIntfName()
		if err != nil {
			return err
		}
	}

	// Get OVS port name
	ovsPortName := getOvsPortName(intfName, skipVethPair)

	// Ask the switch to create the port
	err = sw.CreatePort(intfName, cfgEp, pktTag, cfgNw.PktTag, cfgEpGroup.Burst, dscp, skipVethPair, epgBandwidth)
	if err != nil {
		log.Errorf("Error creating port %s. Err: %v", intfName, err)
		return err
	}

	// save local endpoint info
	d.oper.localEpInfoMutex.Lock()
	d.oper.LocalEpInfo[id] = &EpInfo{
		Ovsportname: ovsPortName,
		EpgKey:      epgKey,
		BridgeType:  pktTagType,
	}
	d.oper.localEpInfoMutex.Unlock()
	err = d.oper.Write()
	if err != nil {
		return err
	}
	// Save the oper state
	operEp = &drivers.OperEndpointState{
		NetID:       cfgEp.NetID,
		EndpointID:  cfgEp.EndpointID,
		ServiceName: cfgEp.ServiceName,
		IPAddress:   cfgEp.IPAddress,
		IPv6Address: cfgEp.IPv6Address,
		MacAddress:  cfgEp.MacAddress,
		IntfName:    cfgEp.IntfName,
		PortName:    intfName,
		HomingHost:  cfgEp.HomingHost,
		VtepIP:      cfgEp.VtepIP}
	operEp.StateDriver = d.oper.StateDriver
	operEp.ID = id
	err = operEp.Write()
	if err != nil {
		return err
	}

	defer func() {
		if err != nil {
			operEp.Clear()
		}
	}()
	return nil
}
1294292
func (s *MetricAlarm) SetDatapointsToAlarm(v int64) *MetricAlarm {
	s.DatapointsToAlarm = &v
	return s
}
93896
func NewPoint(tags core.TagSlice) (*Point, error) {
	point := new(Point)

	// set defaults
	point.ExtrusionDirection = core.Point{X: 0.0, Y: 0.0, Z: 1.0}

	point.InitBaseEntityParser()
	point.Update(map[int]core.TypeParser{

		10:  core.NewFloatTypeParserToVar(&point.Location.X),
		20:  core.NewFloatTypeParserToVar(&point.Location.Y),
		30:  core.NewFloatTypeParserToVar(&point.Location.Z),
		39:  core.NewFloatTypeParserToVar(&point.Thickness),
		50:  core.NewFloatTypeParserToVar(&point.XAxisAngle),
		210: core.NewFloatTypeParserToVar(&point.ExtrusionDirection.X),
		220: core.NewFloatTypeParserToVar(&point.ExtrusionDirection.Y),
		230: core.NewFloatTypeParserToVar(&point.ExtrusionDirection.Z),
	})

	err := point.Parse(tags)
	return point, err
}
1338489
func (calc *PointCentroidCalculator) AddPoint(point *geom.Point) {
	calc.AddCoord(geom.Coord(point.FlatCoords()))
}
185302
func (z *ReadZipper) Datapoints() []*datapoint.Datapoint {
	return []*datapoint.Datapoint{
		sfxclient.CumulativeP("zipper.hitCount", nil, &z.HitCount),
		sfxclient.CumulativeP("zipper.missCount", nil, &z.MissCount),
		sfxclient.CumulativeP("zipper.newCount", nil, &z.NewCount),
		sfxclient.CumulativeP("zipper.errCount", nil, &z.ErrCount),
	}
}
552847
func (decoder *JSONDecoderV2) Datapoints() []*datapoint.Datapoint {
	return []*datapoint.Datapoint{
		sfxclient.Counter("dropped_points", map[string]string{"protocol": "sfx_json_v2", "reason": "unknown_metric_type"}, atomic.LoadInt64(&decoder.unknownMetricType)),
		sfxclient.Counter("dropped_points", map[string]string{"protocol": "sfx_json_v2", "reason": "invalid_value"}, atomic.LoadInt64(&decoder.invalidValue)),
	}
}
1090811
func NewPointFromWKB(wkb []byte) *Point {
	p := &Point{}
	if err := p.unmarshalWKB(wkb); err != nil {
		return nil
	}

	return p
}
21808
func CreateFromTimestamp(timestamp int64, location string) (*Carbon, error) {
	l, err := time.LoadLocation(location)
	if err != nil {
		return nil, err
	}
	t := NewCarbon(Now().In(l))
	t.SetTimestamp(timestamp)

	return t, nil
}
864939
func (forwarder *BufferedForwarder) AddDatapoints(ctx context.Context, points []*datapoint.Datapoint) error {
	if forwarder.checker.CtxFlagCheck.HasFlag(ctx) {
		forwarder.cdim.With(ctx, forwarder.logger).Log("Datapoint call recieved in buffered forwarder")
	}
	atomic.AddInt64(&forwarder.stats.totalDatapointsBuffered, int64(len(points)))
	if *forwarder.config.MaxTotalDatapoints <= atomic.LoadInt64(&forwarder.stats.totalDatapointsBuffered) {
		atomic.AddInt64(&forwarder.stats.totalDatapointsBuffered, int64(-len(points)))
		return errDPBufferFull(forwarder.identifier)
	}
	select {
	case forwarder.dpChan <- points:
		return nil
	case <-forwarder.stopContext.Done():
		return forwarder.stopContext.Err()
	case <-ctx.Done():
		return ctx.Err()
	}
}
901661
func newCiliumEndpoints(c *CiliumV2Client, namespace string) *ciliumEndpoints {
	return &ciliumEndpoints{
		client: c.RESTClient(),
		ns:     namespace,
	}
}
135643
func NewWithMeta(metric string, dimensions map[string]string, meta map[interface{}]interface{}, value Value, metricType MetricType, timestamp time.Time) *Datapoint {
	return &Datapoint{
		Metric:     metric,
		Dimensions: dimensions,
		Meta:       meta,
		Value:      value,
		MetricType: metricType,
		Timestamp:  timestamp,
	}
}
792904
func (a *AdditionalSpanTags) AddDatapoints(ctx context.Context, points []*datapoint.Datapoint) error {
	return a.next.AddDatapoints(ctx, points)
}