First, sorry for not being around much. I've been lucky enough to be busy with work.
We had all the unit tests passing, smoke and integration tests passing but when we put the full enterprise environment to the test things which were failing.
The technology we are using can't be run locally. So stepping through the code and debugging the issue wasn't possible. We had to go old school and add print statements to the code to see what was happening.
First, you should be using something like log4j to control the log levels. This way you can add debug statements to the code but be able to turn them off when you deploy to a production environment.
But how do you determine how much is enough log statements? How do you determine what is too little?
I looked at our build. The end to end tests were passing on Monday. They only run nightly. In the course of the day there were 11 commits to the git repository. First, was the end to end test failing because of a commit in the code? Or was there a change in the enterprise environment?
My first step was to deploy the code from the last time it was working.
Fortunately, most build pipelines will let you build and deploy based on the git commit hash. So I looked up the last time the build was working for the end to end tests. The pipeline would tell me which git commit was used to build it.
So I run the pipeline and ask it to deploy that specific git commit. Then I run the current end to end tests on the deployed application. The end to end test passed. Now I have the git commit for when it was working.
I also have the git commit for the current master commit. This commit is failing today.
Let's say that the commit which was working was 0a803c1 and the latest commit was ea3dbb9. There are 11 commits. So how do I figure out what commit broke it?
I can see all the files which were changed using the git show command. The exact syntax is:
git show --pretty="" --name-only 0a803c1..ea3dbb9
This will provide a list of all the files which have changed. If a file was changed in different commits, multiple times, it will show the file more than once in the list. If all you care about is a short list of files which changed I'd actually use:
git show --pretty="" --name-only 0a903c1..ea3dbb9 | sort | uniq
This will get rid of duplication.
Once I know which files have been affected, I can start adding debug statements to these files and not bother focusing on any of the other files in the repository.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.