25
CodeGuru Reviewer
In previous parts, we have done setup for the environment and made integrations between CodeBuild and CodeGuru.
Now ready for production code. The develop branch’s code has passed all unit tests and deploy, so we will deploy it to the production environment. developers usually don’t have permission to push directly to the master branch. So, through pull-request, we will go through a code review with a senior developer or a other developer and merge it in the master.
Go to the CodeCommit console to create a pull-request.
Go to CodeCommit: https://console.aws.amazon.com/codesuite/codecommit/repositories
Select Repositories in Source and click on concurrencysample.
Select Pull requests from Repositories and click Create pull request in the upper right.
Create pull request, Destination set master and Source set develop and click the Compare button.
You have created a pull-request. Now let`s see what happens.
let’s check what kind of code review has doing in pull-request.(almost wait 5min.)
Go to CodeCommit’s console: https://console.aws.amazon.com/codesuite/codecommit/repositories
If CodeCommit and Repository are connected, the following screen will appear. Select Activity at the top.
The code review comment was attached to the code that I thought had no problems.
Temporary Security Credentials rather than long-term Security Credentials such as AccessKey and SceretKey. CodeGuru tells you how and how to use the AWS SDK secure. These are things that cannot be found in simple unit tests or experience!
Let’s change SingletonRepo.java code. Delete the AWS SDK credential code. And you just need to give EC2 the IAM Role to access the necessary resources. let’s delete the AWS SDK credentials related code of SingleRepo.java.
And… We have other problem. CodeGuru recommend that you use the Regions enum. not using string. Regions is an enumeration of all publicly available regions. To create a client with a region from the enum, use the following code.
You can evaluate whether CodeGuru’s suggestions are really useful through feedback. These can contribute to better CodeGuru comments.
I thought concurrentHashMap was a thread-safe data structure, but there was one problem. ConcurrentHashMap does not lock the entire map when performing put command for performance. Of course, you can declare a function to be synchronized , but in this case, it is the same as a single-thread, which can cause performance problems.
Edit the code and push.
~ git add .
~ git commit -m "fix put(), containsKey()-> putifAbsent()"
~ git push
The problem has been fixed, we will end the Pull-Request. Click the Merg button in the top right corner of the AWS console.
Since master has not changed, we choose Fast forward merge. Source is develop branch, uncheck the box of Delete source branch develop after merging?.
Using the CD/CI pipeline, modifications of the code can be safely reflected as the master. Also, developers can easily see the test results and process of the code by simply using Commit and push.
UnitTest and CodeReview are one of the best ways to improve code quality. For each process, you can use the CodeBuild Report and CodeGuru Reviwer to make code review and UnitTest safer and more effective.
In the next final part, we will check the profiling results that are actually deployed and running.
25