Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release's Name Update #544

Merged
merged 7 commits into from
Aug 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/releaseTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ jobs:
with:
role-to-assume: ${{ secrets.TERRAFORM_AWS_ASSUME_ROLE }}
aws-region: us-west-2

- name: Get Release Tag
run: echo ${{ github.event.release.tag_name }}
- name: Update isRelease for this release
run: |
cd integration/test/performancetest
export IS_RELEASE=true
export SHA=$GITHUB_SHA
export RELEASE_NAME=${{ github.event.release.tag_name }}
go test -run TestUpdateCommit -p 1 -v --tags=integration

Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const (
HASH = "Hash"
COMMIT_DATE= "CommitDate"
SHA_ENV = "SHA"
RELEASE_NAME_ENV = "RELEASE_NAME"
SHA_DATE_ENV = "SHA_DATE"
IS_RELEASE = "isRelease"
TEST_ID ="TestID"
Expand Down
8 changes: 6 additions & 2 deletions integration/test/performancetest/performance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,15 @@ func TestUpdateCommit(t*testing.T){
}
t.Log("Updating Release Commit",os.Getenv(SHA_ENV))
dynamoDB := InitializeTransmitterAPI("CWAPerformanceMetrics") //add cwa version here
testHash := os.Getenv(SHA_ENV)
releaseHash := os.Getenv(SHA_ENV)
releaseName := os.Getenv(RELEASE_NAME_ENV)
if dynamoDB == nil{
t.Fatalf("Error: generating dynamo table")
return
}

dynamoDB.UpdateReleaseTag(testHash)
err := dynamoDB.UpdateReleaseTag(releaseHash,releaseName)
if err!=nil{
t.Fatalf("Error: %s",err)
}
}
32 changes: 19 additions & 13 deletions integration/test/performancetest/transmitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue"
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
"github.com/aws/aws-sdk-go-v2/service/dynamodb/types"
"github.com/google/uuid"
)

const (
Expand Down Expand Up @@ -223,7 +224,7 @@ func (transmitter *TransmitterAPI) SendItem(packet map[string]interface{}, tps i
fmt.Println("Item already exist going to update", len(currentItem))
}
// item already exist so update the item instead
err = transmitter.UpdateItem(packet, tps) //try to update the item
err = transmitter.UpdateItem(packet[HASH].(string), packet, tps) //try to update the item
//this may be overwritten by other test threads, in that case it will return a specific error
if err != nil {
return "", err
Expand Down Expand Up @@ -266,7 +267,10 @@ func (transmitter *TransmitterAPI) PacketMerger(newPacket map[string]interface{}
newAttributes[RESULTS] = mergedResults
}
if newPacket[IS_RELEASE] != nil {
newAttributes[IS_RELEASE] = true
newAttributes[IS_RELEASE] = newPacket[IS_RELEASE]
}
if newPacket[HASH] != currentPacket[HASH] {
newAttributes[HASH] = newPacket[HASH]
}
// newAttributes, _ := attributevalue.MarshalMap(mergedResults)
// newAttributes[IS_RELEASE] = &types.AttributeValueMemberBOOL{Value: true}
Expand All @@ -283,11 +287,10 @@ Params:
targetAttributes: this is the targetAttribute to be added to the dynamo item
testHash: this is the hash of the last item, used like a version check
*/
func (transmitter *TransmitterAPI) UpdateItem(packet map[string]interface{}, tps int) error {
func (transmitter *TransmitterAPI) UpdateItem(hash string, packet map[string]interface{}, tps int) error {
var ae *types.ConditionalCheckFailedException // this exception represent the atomic check has failed
rand.Seed(time.Now().UnixNano())
randomSleepDuration := time.Duration(rand.Intn(UPDATE_DELAY_THRESHOLD)) * time.Second
hash := packet[HASH].(string)
for attemptCount := 0; attemptCount < MAX_ATTEMPTS; attemptCount++ {
fmt.Println("Updating:", hash)
item, err := transmitter.Query(hash) // get most Up to date item from dynamo | O(1) bcs of global sec. idx.
Expand All @@ -307,19 +310,23 @@ func (transmitter *TransmitterAPI) UpdateItem(packet map[string]interface{}, tps
}
//setup the update expression
expressionAttributeValues := make(map[string]types.AttributeValue)
expressionAttributeNames := make(map[string]string)
expression := "set "
n_expression := len(targetAttributes)
i := 0
for attribute, value := range targetAttributes {
expressionName := ":" + strings.ToLower(attribute)
expression += fmt.Sprintf("%s = %s", attribute, expressionName)
expressionAttributeValues[expressionName] = value
expressionKey := ":" + strings.ToLower(attribute)
expressionName := "#" + strings.ToLower(attribute)
expression += fmt.Sprintf("%s = %s", expressionName, expressionKey)
expressionAttributeValues[expressionKey] = value
expressionAttributeNames[expressionName] = attribute
if n_expression-1 > i {
expression += ", "
}
i++
}
expressionAttributeValues[":testID"] = &types.AttributeValueMemberS{Value: testHash}
expressionAttributeNames["#testID"] = TEST_ID
//call update
_, err = transmitter.dynamoDbClient.UpdateItem(context.TODO(), &dynamodb.UpdateItemInput{
TableName: aws.String(transmitter.DataBaseName),
Expand All @@ -330,9 +337,7 @@ func (transmitter *TransmitterAPI) UpdateItem(packet map[string]interface{}, tps
UpdateExpression: aws.String(expression),
ExpressionAttributeValues: expressionAttributeValues,
ConditionExpression: aws.String("#testID = :testID"),
ExpressionAttributeNames: map[string]string{
"#testID": TEST_ID,
},
ExpressionAttributeNames: expressionAttributeNames,
})
if errors.As(err, &ae) { //check if our call got overwritten
// item has changed
Expand All @@ -355,12 +360,13 @@ UpdateReleaseTag()
Desc: This function takes in a commit hash and updates the release value to true
Param: commit hash in terms of string
*/
func (transmitter *TransmitterAPI) UpdateReleaseTag(hash string) error {
func (transmitter *TransmitterAPI) UpdateReleaseTag(hash string, tagName string) error {
var err error
packet := make(map[string]interface{})
packet[HASH] = hash
packet[HASH] = tagName
packet[IS_RELEASE] = true
err = transmitter.UpdateItem(packet, 0) //try to update the item
packet[TEST_ID] = uuid.New().String()
err = transmitter.UpdateItem(hash, packet, 0) //try to update the item
//this may be overwritten by other test threads, in that case it will return a specific error
if err != nil {
return err
Expand Down