func()

in pipeline/endpoints/servicecontrol.go [141:177]


func (ep *ServiceControlEndpoint) format(r pipeline.EndpointReport) *servicecontrol.Operation {
	value := servicecontrol.MetricValue{
		StartTime: r.StartTime.UTC().Format(time.RFC3339Nano),
		EndTime:   r.EndTime.UTC().Format(time.RFC3339Nano),
	}

	if r.Value.Int64Value != nil {
		value.Int64Value = util.NewInt64(*r.Value.Int64Value)
	} else if r.Value.DoubleValue != nil {
		value.DoubleValue = util.NewFloat64(*r.Value.DoubleValue)
	}

	op := &servicecontrol.Operation{
		OperationId: r.Id,
		// ServiceControl requires this field but doesn't indicate what it's supposed to be.
		OperationName: fmt.Sprintf("%v/report", ep.serviceName),
		StartTime:     r.StartTime.UTC().Format(time.RFC3339Nano),
		EndTime:       r.EndTime.UTC().Format(time.RFC3339Nano),
		ConsumerId:    ep.consumerId,
		UserLabels:    r.Labels,
		MetricValueSets: []*servicecontrol.MetricValueSet{
			{
				MetricName:   fmt.Sprintf("%v/%v", ep.serviceName, r.Name),
				MetricValues: []*servicecontrol.MetricValue{&value},
			},
		},
	}

	if op.UserLabels == nil {
		op.UserLabels = make(map[string]string)
	}

	// Add the agent ID label
	op.UserLabels[agentIdLabel] = ep.agentId

	return op
}