func (cs *clientServer) metricsToPublishMetricRequests() ([]*ecstcs.PublishMetricsRequest, error) {
	metadata, taskMetrics, err := cs.statsEngine.GetInstanceMetrics()
	if err != nil {
		return nil, err
	}

	var requests []*ecstcs.PublishMetricsRequest
	if *metadata.Idle {
		metadata.Fin = aws.Bool(true)
		// Idle instance, we have only one request to send to backend.
		requests = append(requests, ecstcs.NewPublishMetricsRequest(metadata, taskMetrics))
		return requests, nil
	}
	var messageTaskMetrics []*ecstcs.TaskMetric
	numTasks := len(taskMetrics)

	for i, taskMetric := range taskMetrics {
		messageTaskMetrics = append(messageTaskMetrics, taskMetric)
		var requestMetadata *ecstcs.MetricsMetadata
		if (i + 1) == numTasks {
			// If this is the last task to send, set fin to true
			requestMetadata = copyMetricsMetadata(metadata, true)
		} else {
			requestMetadata = copyMetricsMetadata(metadata, false)
		}
		if (i+1)%tasksInMetricMessage == 0 {
			// Construct payload with tasksInMetricMessage number of task metrics and send to backend.
			requests = append(requests, ecstcs.NewPublishMetricsRequest(requestMetadata, copyTaskMetrics(messageTaskMetrics)))
			messageTaskMetrics = messageTaskMetrics[:0]
		}
	}

	if len(messageTaskMetrics) > 0 {
		// Create the new metadata object and set fin to true as this is the last message in the payload.
		requestMetadata := copyMetricsMetadata(metadata, true)
		// Create a request with remaining task metrics.
		requests = append(requests, ecstcs.NewPublishMetricsRequest(requestMetadata, messageTaskMetrics))
	}
	return requests, nil
}
func (cs *clientServer) metricsToPublishMetricRequests() ([]*ecstcs.PublishMetricsRequest, error) {
	metadata, taskMetrics, err := cs.statsEngine.GetInstanceMetrics()
	if err != nil {
		return nil, err
	}

	var requests []*ecstcs.PublishMetricsRequest
	if *metadata.Idle {
		metadata.Fin = aws.Bool(true)
		
		requests = append(requests, ecstcs.NewPublishMetricsRequest(metadata, taskMetrics))
		return requests, nil
	}
	var messageTaskMetrics []*ecstcs.TaskMetric
	numTasks := len(taskMetrics)

	for i, taskMetric := range taskMetrics {
		messageTaskMetrics = append(messageTaskMetrics, taskMetric)
		var requestMetadata *ecstcs.MetricsMetadata
		if (i + 1) == numTasks {
			
			requestMetadata = copyMetricsMetadata(metadata, true)
		} else {
			requestMetadata = copyMetricsMetadata(metadata, false)
		}
		if (i+1)%tasksInMetricMessage == 0 {
			
			requests = append(requests, ecstcs.NewPublishMetricsRequest(requestMetadata, copyTaskMetrics(messageTaskMetrics)))
			messageTaskMetrics = messageTaskMetrics[:0]
		}
	}

	if len(messageTaskMetrics) > 0 {
		
		requestMetadata := copyMetricsMetadata(metadata, true)
		
		requests = append(requests, ecstcs.NewPublishMetricsRequest(requestMetadata, messageTaskMetrics))
	}
	return requests, nil
}
func ( cs * clientServer ) metricsToPublishMetricRequests ( ) ( [ ] * ecstcs . PublishMetricsRequest , error ) { metadata , taskMetrics , err := cs . statsEngine . GetInstanceMetrics ( ) if err != nil { return nil , err } var requests [ ] * ecstcs . PublishMetricsRequest if * metadata . Idle { metadata . Fin = aws . Bool ( true ) // Idle instance, we have only one request to send to backend. requests = append ( requests , ecstcs . NewPublishMetricsRequest ( metadata , taskMetrics ) ) return requests , nil } var messageTaskMetrics [ ] * ecstcs . TaskMetric numTasks := len ( taskMetrics ) for i , taskMetric := range taskMetrics { messageTaskMetrics = append ( messageTaskMetrics , taskMetric ) var requestMetadata * ecstcs . MetricsMetadata if ( i + 1 ) == numTasks { // If this is the last task to send, set fin to true requestMetadata = copyMetricsMetadata ( metadata , true ) } else { requestMetadata = copyMetricsMetadata ( metadata , false ) } if ( i + 1 ) % tasksInMetricMessage == 0 { // Construct payload with tasksInMetricMessage number of task metrics and send to backend. requests = append ( requests , ecstcs . NewPublishMetricsRequest ( requestMetadata , copyTaskMetrics ( messageTaskMetrics ) ) ) messageTaskMetrics = messageTaskMetrics [ : 0 ] } } if len ( messageTaskMetrics ) > 0 { // Create the new metadata object and set fin to true as this is the last message in the payload. requestMetadata := copyMetricsMetadata ( metadata , true ) // Create a request with remaining task metrics. requests = append ( requests , ecstcs . NewPublishMetricsRequest ( requestMetadata , messageTaskMetrics ) ) } return requests , nil }
// metricsToPublishMetricRequests gets task metrics and converts them to a list of PublishMetricRequest
// objects.
metricsToPublishMetricRequests gets task metrics and converts them to a list of PublishMetricRequest objects .