func()

in validator/validators/performance/performance_validator.go [78:113]


func (s *PerformanceValidator) SendPacketToDatabase(perfInfo PerformanceInformation) error {
	var (
		dataType               = s.vConfig.GetDataType()
		receiver               = s.vConfig.GetPluginsConfig()[0] //Assuming one plugin at a time
		commitHash, commitDate = s.vConfig.GetCommitInformation()
		agentCollectionPeriod  = fmt.Sprint(s.vConfig.GetAgentCollectionPeriod().Seconds())
		// The secondary global index that is used for checking if there are item has already been exist in the table
		// The performance validator will query based on the UseCaseHash to confirm if the current commit with the use case
		// has been exist or not? If yes, merge it. If not, sending it to the database
		// https://github.com/aws/amazon-cloudwatch-agent-test/blob/e07fe7adb1b1d75244d8984507d3f83a7237c3d3/terraform/setup/main.tf#L46-L53
		kCheckingAttribute = []string{"CommitHash", "UseCase"}
		vCheckingAttribute = []string{fmt.Sprint(commitHash), receiver}
	)

	err := backoff.Retry(func() error {
		existingPerfInfo, err := awsservice.GetItemInDatabase(DynamoDBDataBase, "UseCaseHash", kCheckingAttribute, vCheckingAttribute, perfInfo)
		if err != nil {
			return err
		}

		// Get the latest performance information from the database and update by merging the existing one
		// and finally replace the packet in the database
		maps.Copy(existingPerfInfo["Results"].(map[string]interface{}), perfInfo["Results"].(map[string]interface{}))

		finalPerfInfo := packIntoPerformanceInformation(existingPerfInfo["UniqueID"].(string), receiver, dataType, agentCollectionPeriod, commitHash, commitDate, existingPerfInfo["Results"])

		err = awsservice.ReplaceItemInDatabase(DynamoDBDataBase, finalPerfInfo)

		if err != nil {
			return err
		}
		return nil
	}, awsservice.StandardExponentialBackoff)

	return err
}