// NewProtobufDataPointWithType creates a new datapoint from SignalFx's protobuf definition (backwards compatable with old API)
347811
func NewProtobufDataPointWithType(dp *com_signalfx_metrics_protobuf.DataPoint, mType com_signalfx_metrics_protobuf.MetricType) (*datapoint.Datapoint, error) {
	var mt com_signalfx_metrics_protobuf.MetricType

	if dp.GetValue() == nil {
		return nil, errDatapointValueNotSet
	}
	if dp.MetricType != nil {
		mt = dp.GetMetricType()
	} else {
		mt = mType
	}

	dims := make(map[string]string, len(dp.GetDimensions())+1)
	if dp.GetSource() != "" {
		dims["sf_source"] = dp.GetSource()
	}

	dpdims := dp.GetDimensions()
	for _, dpdim := range dpdims {
		dims[dpdim.GetKey()] = dpdim.GetValue()
	}

	dpToRet := datapoint.New(dp.GetMetric(), dims, NewDatumValue(dp.GetValue()), fromMT(mt), fromTs(dp.GetTimestamp()))
	return dpToRet, nil
}
22650
func procJoinEndpoint(c libnetwork.NetworkController, vars map[string]string, body []byte) (interface{}, *responseStatus) {
	var ej endpointJoin
	var setFctList []libnetwork.EndpointOption
	err := json.Unmarshal(body, &ej)
	if err != nil {
		return nil, &responseStatus{Status: "Invalid body: " + err.Error(), StatusCode: http.StatusBadRequest}
	}

	nwT, nwBy := detectNetworkTarget(vars)
	epT, epBy := detectEndpointTarget(vars)

	ep, errRsp := findEndpoint(c, nwT, epT, nwBy, epBy)
	if !errRsp.isOK() {
		return nil, errRsp
	}

	sb, errRsp := findSandbox(c, ej.SandboxID, byID)
	if !errRsp.isOK() {
		return nil, errRsp
	}

	for _, str := range ej.Aliases {
		name, alias, err := netutils.ParseAlias(str)
		if err != nil {
			return "", convertNetworkError(err)
		}
		setFctList = append(setFctList, libnetwork.CreateOptionAlias(name, alias))
	}

	err = ep.Join(sb, setFctList...)
	if err != nil {
		return nil, convertNetworkError(err)
	}
	return sb.Key(), &successResponse
}
707181
func SetupProtobufV1Paths(r *mux.Router, handler http.Handler) {
	r.Path("/datapoint").Methods("POST").Headers("Content-Type", "application/x-protobuf").Handler(handler)
	r.Path("/v1/datapoint").Methods("POST").Headers("Content-Type", "application/x-protobuf").Handler(handler)
}
139121
func NewVppAdapter() *VppAdapter {
	a := &VppAdapter{
		msgIDSeq:     1000,
		msgIDsToName: make(map[uint16]string),
		msgNameToIds: make(map[string]uint16),
		binAPITypes:  make(map[string]reflect.Type),
	}
	a.registerBinAPITypes()
	return a
}
310988
func NewOnHostDatapointDimensions(metric string, value datapoint.Value, metricType datapoint.MetricType, dimensions map[string]string) *datapoint.Datapoint {
	return Wrap(datapoint.New(metric, dimensions, value, metricType, time.Now()))
}
1254014
func (f *Facade) AddPublicEndpointPort(ctx datastore.Context, serviceID, endpointName, portAddr string,
	usetls bool, protocol string, isEnabled bool, restart bool) (*servicedefinition.Port, error) {
	defer ctx.Metrics().Stop(ctx.Metrics().Start("Facade.AddPublicEndpointPort"))
	alog := f.auditLogger.Message(ctx, "Adding Public Endpoint Port").Action(audit.Update).ID(serviceID).
		WithFields(logrus.Fields{
			"endpointname": endpointName,
			"portaddr":     portAddr,
			"usetls":       usetls,
			"protocol":     protocol,
			"isenabled":    isEnabled,
		})
	// Scrub the port for all checks, as this is what gets stored against the service.
	portAddr = service.ScrubPortString(portAddr)

	// Validate the port number
	portParts := strings.Split(portAddr, ":")
	if len(portParts) < 2 {
		err := fmt.Errorf("Invalid port address. Port address must be \":[PORT NUMBER]\" or \"[IP ADDRESS]:[PORT NUMBER]\"")
		glog.Error(err)
		return nil, alog.Error(err)
	}

	if portAddr == "0" || strings.HasSuffix(portAddr, ":0") {
		err := fmt.Errorf("Invalid port address. Port 0 is invalid.")
		glog.Error(err)
		return nil, alog.Error(err)
	}

	// Check to make sure the port is available.  Don't allow adding a port if it's already being used.
	// This has the added benefit of validating the port address before it gets added to the service
	// definition.
	if err := checkPort("tcp", fmt.Sprintf("%s", portAddr)); err != nil {
		glog.Error(err)
		return nil, alog.Error(err)
	}

	// Get the service for this service id.
	svc, err := f.GetService(ctx, serviceID)
	if err != nil {
		err = fmt.Errorf("Could not find service %s: %s", serviceID, err)
		glog.Error(err)
		return nil, alog.Error(err)
	}
	alog = alog.Entity(svc)

	// check other ports for redundancy
	// FIXME: GetAllServices is really expensive. Can this be replaced
	//        with a more targeted method like get-all-services with portAddr "blah"?
	services, err := f.GetAllServices(ctx)
	if err != nil {
		err = fmt.Errorf("Could not get the list of services: %s", err)
		glog.Error(err)
		return nil, alog.Error(err)
	}

	for _, service := range services {
		if service.Endpoints == nil {
			continue
		}

		for _, endpoint := range service.Endpoints {
			for _, epPort := range endpoint.PortList {
				if portAddr == epPort.PortAddr {
					err := fmt.Errorf("Port %s already defined for service: %s", epPort.PortAddr, service.Name)
					glog.Error(err)
					return nil, alog.Error(err)
				}
			}
		}
	}

	// Add the port to the service definition.
	port, err := svc.AddPort(endpointName, portAddr, usetls, protocol, isEnabled)
	if err != nil {
		glog.Error(err)
		return nil, alog.Error(err)
	}

	// Make sure no other service currently has zzk data for this port -- this would result
	// in the service getting turned off during restart but not being able to start again.
	if err := f.validateServiceStart(ctx, svc); err != nil {
		// We don't call UpdateService() service here; effectively unwinding the svc.AddPort() call above.
		glog.Error(err)
		return nil, alog.Error(err)
	}

	glog.V(2).Infof("Added port public endpoint %s to service %s", portAddr, svc.Name)

	if err = f.UpdateService(ctx, *svc); err != nil {
		glog.Error(err)
		return nil, alog.Error(err)
	}

	glog.V(2).Infof("Service (%s) updated", svc.Name)
	alog.Succeeded()
	return port, nil
}
1220621
func (h *HistoCounter) AddDatapoints(ctx context.Context, points []*datapoint.Datapoint, next Sink) error {
	h.DatapointBucket.Add(float64(len(points)))
	return h.sink.AddDatapoints(ctx, points, next)
}
982376
func (t *Type) createTypeFromPropProperty(name string, apiDef *APIDefinition) {
	p := t.Properties[name]
	// only process map[interface]interface{}
	propMap, ok := p.(map[interface{}]interface{})
	if !ok {
		return
	}

	// only process if it has 'properties' field
	propsIf, ok := propMap["properties"]
	if !ok {
		return
	}

	// check validity of the properties
	props, ok := propsIf.(map[interface{}]interface{})
	if !ok {
		panic("inline properties expect properties in type:map[string]interface{}")
	}

	newName := t.Name + name
	created := apiDef.createType(newName, propMap["type"], props)

	propMap["type"] = newName

	// delete the 'properties' field
	delete(propMap, "properties")

	t.Properties[name] = propMap

	// post process the created type
	if created {
		createdType := apiDef.Types[newName]
		createdType.postProcess(newName, apiDef)
	}

}
1180454
func NewOutPointFromProto(op *lnrpc.OutPoint) OutPoint {
	return OutPoint(fmt.Sprintf("%s:%d", op.TxidStr, op.OutputIndex))
}
440027
func (s *UsageService) NewAddTrafficTypeParams(physicalnetworkid string, traffictype string) *AddTrafficTypeParams {
	p := &AddTrafficTypeParams{}
	p.p = make(map[string]interface{})
	p.p["physicalnetworkid"] = physicalnetworkid
	p.p["traffictype"] = traffictype
	return p
}
1065380
func ParseEndpointType(str string) EndpointType {
	str = strings.ToLower(str)
	switch str {
	case "unix":
		return UnixEndpoint
	case "tcp":
		return TCPEndpoint
	}
	return UnknownEndpointType
}
1166544
func (s *Endpoint) SetEndpointType(v string) *Endpoint {
	s.EndpointType = &v
	return s
}
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,
	}
}
528848
func (s *Server) AddPublicEndpointPort(request *PublicEndpointRequest, reply *servicedefinition.Port) error {
	port, err := s.f.AddPublicEndpointPort(s.context(), request.Serviceid, request.EndpointName, request.Name,
		request.UseTLS, request.Protocol, request.IsEnabled, request.Restart)
	if err != nil {
		return err
	}
	*reply = *port
	return err
}
478091
func (o *GetDebuginfoOK) WithPayload(payload *models.DebugInfo) *GetDebuginfoOK {
	o.Payload = payload
	return o
}
851289
func NewProtoWrapperWithSerializer(db keyval.CoreBrokerWatcher, serializer keyval.Serializer) *ProtoWrapper {
	// OBSOLETE, use NewProtoWrapper
	return NewProtoWrapper(db, serializer)
}
728254
func (f *Forwarder) AddDatapoints(ctx context.Context, points []*datapoint.Datapoint) (err error) {
	openConnection := f.pool.Get()
	if openConnection == nil {
		openConnection, err = f.dialer("tcp", f.connectionAddress, f.connectionTimeout)
		if err != nil {
			err = errors.Annotatef(err, "cannot dial %s", f.connectionAddress)
			return
		}
	}
	defer func() {
		if err == nil {
			f.pool.Return(openConnection)
		} else {
			err = errors.NewMultiErr([]error{err, openConnection.Close()})
		}
	}()

	if err := f.setMinTime(ctx, openConnection); err != nil {
		return err
	}

	points = f.FilterDatapoints(points)
	if len(points) == 0 {
		return nil
	}

	var buf bytes.Buffer
	for _, dp := range points {
		if carbonLine, exists := NativeCarbonLine(dp); exists {
			_, err = fmt.Fprintf(&buf, "%s\n", carbonLine)
			errors.PanicIfErr(err, "buffer writes should not error out")
			continue
		}
		_, err = fmt.Fprintf(&buf, "%s %s %d\n", f.datapointToGraphite(dp),
			dp.Value,
			dp.Timestamp.UnixNano()/time.Second.Nanoseconds())
		errors.PanicIfErr(err, "buffer writes should not error out")
	}
	_, err = buf.WriteTo(openConnection)
	if err != nil {
		return errors.Annotate(err, "cannot fully write buf to carbon connection")
	}
	return nil
}