Ravi Srinivasan
2019-02-05 fbdd685635a6ea6e56034b99211c78d5f5611af4
commit | author | age
66abfd 1 # Return of the Monitoring
5a16fd 2
bfabf3 3 > In this exercise we will create a build monitor to radiate vital build information and statistics
d03287 4
fbdd68 5 <!-- ![monitoring-meme](../images/exercise6/monitoring-meme.jpg) -->
5a16fd 6
0284bf 7 ## Exercise Intro
3e28c6 8 Build monitors provide a tight feedback loop which is vital to high performing teams. Being in a highly visible location, build monitors radiate crucial build and test information, meaning the team doesn't have to go out of their way to find it. Build monitors also provide a degree of accountability whilst also keeping the team motivated to fix problems. With broken components visualised, seeing build monitors change from red to green can give the collective feeling that progress is being made. 
79c7e5 9
867471 10 On residencies we display the build monitors on Raspberry Pi's hooked up to large TV screens that everyone can see at a glance. We've also used colour-changing lightbulbs in the labs that change from Green to Red depending on the success/fail status of jobs. There are many other ways to notify people of Build Failures such as Slack notices, text messages or just plain old email. This exercise is about radiating the information to allow teams respond quickly to change.
3e28c6 11
DS 12 In this Exercise we will be creating a build monitor to display all of our jobs in one visual display as well as pipeline views. We will then add the cause of build failures for each job to the monitors. This will allow you to rapidly see why a particular build is failing and fix it faster.
13
14 Finally, build monitors can promote team cohesion as they enable all team members to be on the same page regarding the current project status. They can also engage business users and clients on the stats of the system. __The most important thing here isn't the tool, but the visual feedback.__ 
a4e18f 15
RH 16 ## Why do we use build monitors? 
17 - Provides instant feedback to teams regarding the current status of the build.
18 - Tightens feedback loop by having vital information needed by teams, available upfront.
19 - Motivates teams to fix problems together.
3e28c6 20
a85dba 21 ____
5a16fd 22 ## Learning Outcomes
D 23 As a learner you will be able to
bfabf3 24 - Create dashboards in Jenkins to display build status
f386eb 25 - Seed Jenkins using DSL to create dashboards by default
5a16fd 26
D 27 ## Tools and Frameworks
28 > Name of tool - short description and link to docs or website
29
bfabf3 30 1. [Build Monitor plugin](https://wiki.jenkins.io/display/JENKINS/Build+Monitor+Plugin) - Build Monitor Plugin provides a highly visible view of the status of selected Jenkins jobs. It easily accommodates different computer screen sizes and is ideal as an Extreme Feedback Device to be displayed on a screen on your office wall. (Inspired by the no longer maintained RadiatorView plugin).
fbdd68 31 2. [Build Fail Analyser](https://wiki.jenkins.io/display/JENKINS/Build+Failure+Analyzer) - This plugin analyses the causes of failed builds and presents the causes on the build page. It does this by using a knowledge base of build failure causes that is built up from scratch. Saving statistics about failure causes is also possible.
RS 32 3. [Pipeline Aggregator View](https://wiki.jenkins.io/display/JENKINS/Pipeline+Aggregator+View) - Allows the users to view the history of their pipelines with stage information (failed/In Progress/Passed) and the changes monitored)
5a16fd 33
D 34 ## Big Picture
1a8071 35 > From the previous exercise; we introduced non-functional testing to our pipeline. This exercise focuses on radiation of useful information such as build stats and times from our pipeline. 
D 36
0862e2 37 ![big-picture](../images/big-picture/big-picture-6.jpg)
5a16fd 38
D 39 _____
40
41 ## 10,000 Ft View
853f0c 42 > The goal of this exercise is to introduce Build Monitors to radiate team's progress on Dashboards.
5a16fd 43
fbdd68 44 1. Create a new Dashboard for our Builds using the plugin above. Use Regex to add jobs to it. Use the BuildFail Analyser to add meaningful data to the reason for failures.
5a16fd 45
542e51 46 2. Use the pipeline views in OpenShift and Jenkins to produce dashboards that teams can use.
5a16fd 47
D 48 ## Step by Step Instructions
fbdd68 49 <!-- > This is a fairly structured guide with references to exact filenames and sections of text to be added. Include pictures and code snippets where appropriate. -->
5a16fd 50
bfabf3 51 ### Part 1 - Create a build monitor
6bd3ef 52 > _In this exercise we will create a new build monitor to show key information about our builds_
5a16fd 53
fbdd68 54 1. On Jenkins home page; create a new view by hitting the plus icon on the home screen (should be beside the `all` above the jobs list)
bfabf3 55
6bd3ef 56 2. Give the job a sensible name such as `todolist-monitor` and select `Build Monitor View` 
D 57 ![new-monitor](../images/exercise6/new-monitor.png)
bfabf3 58
fbdd68 59 3. On the configuration page; select `Recurse in subfolders`
6bd3ef 60 ![config-recursive](../images/exercise6/config-recursive.png)
D 61
fbdd68 62 4. Check the box to use Regular Expression and set the value to be something that should scrape our apps such as `.*todolist.*` 
6bd3ef 63 ![config-regex](../images/exercise6/config-regex.png)
D 64
fbdd68 65 5. Finally; select `Display committers` and set the Failure Analyser to `Description`. This allows us to write regexes for when failures occur in Jenkins and have the reasons plotted on the graph. For example; number of test scores or common compilation errors. 
6bd3ef 66 ![config-commiters](../images/exercise6/config-commiters.png)
D 67
fbdd68 68 6. Save your configuration to see your Build Monitor! 
f386eb 69 ![build-monitor](../images/exercise6/build-monitor.png)
fbdd68 70 > NOTE: You can exit the build monitor view by clicking on the Jenkins icon in the top left corner.
6bd3ef 71
fbdd68 72 7. Let's create another view for Jenkins using the `Pipeline Aggregator View` plugin. This view is great because it shows lots of valuable information in a clean; easy to visualise way. Create a new view called `todolist-pipelines` and select `Pipeline Aggregator View`
fd42cf 73 ![config-pipeline-view](../images/exercise6/config-pipeline-view.png)
D 74
fbdd68 75 8. On the configure page; set the regex to `todolist.*`
fd42cf 76 ![config-pipeline-regex](../images/exercise6/config-pipeline-regex.png)
D 77
fbdd68 78 9. Set the view to `Only display last build` for simplicity of the view, and select the `Use condensed tables` option.
fd42cf 79 ![config-pipeline-ui-settings](../images/exercise6/config-pipeline-ui-settings.png)
D 80
fbdd68 81 10. Save your configuration to see your Build Monitor! 
fd42cf 82 ![pipeline-monitor](../images/exercise6/pipeline-monitor.png)
6bd3ef 83
fbdd68 84 11. Explore the Jenkins Blue Ocean view for some additional monitors and views that make Jenkins look pretty!
364c66 85 ![blue-ocean](../images/exercise6/blue-ocean.png)
D 86
f386eb 87 ### Part 2 - Build Fail Analyser
D 88 > _In this exercise we will intentionally fail the build to capture some metrics about why it's failed and how we can tighten the feedback for future failures_
89
fbdd68 90 1. Open the `todolist-fe` app in your favourite editor. In this exercise, we will fail a test and capture the message in the log and visualise it on a dashboard.
f386eb 91
867471 92 2. Open one of the tests you wrote in previous exercises; for example `tests/unit/vue-components/TodoItem.spec.js`. Negate the test at the very bottom of the file by adding a `.not` to the `expect()` statement as shown below.
f386eb 93 ```javascript
D 94   it("call makImportant when clicked", () => {
95     const wrapper = mount(TodoItem, {
96       methods,
97       propsData: { todoItem: importantTodo }
98     });
99     // TODO - test goes here!
100     const input = wrapper.find(".important-flag");
101     input.trigger("click");
102     expect(methods.markImportant).not.toHaveBeenCalled();
103     });
104 });
105 ```
106
fbdd68 107 3. Run your tests locally and you should see one failing test as shown below. Jenkins will have the same output so we can capture this as code!
f386eb 108 ![fail-local](../images/exercise6/fail-local.png)
D 109
fbdd68 110 4. The `Test Suites: 1 failed, 11 passed, 12 total` string can be coded into a regex. On Jenkins homepage; hit the `Failure Cause Management` nav on the left hand menu. On the page that loads; hit `Create new`.
f386eb 111
fbdd68 112 5. Call the new Failure Cause `jest-tests`. Set the Description to be `${1,1} failed out of ${1,2}`. The `${1,1}` refers to the first capture group in a regex. Click `Add indication > Build log`. Set the Pattern to match for the test output we've seen in our test execution on the terminal using this regex `.*Tests:.*(\d+) failed.*(\d+) total.*`. Click `Save` at the bottom of the page.
f386eb 113 ![fail-cause](../images/exercise6/fail-cause.png)
D 114
fbdd68 115 6. Our dashboards are set to show the `Description` field from the `Build Fail Analyser`. Run a build by checking in our failed tests and check the result on the Build Monitor created in the previous step
f386eb 116 ```bash
58480f 117 git add .
D 118 ```
119 ```bash
120 git commit -m "TEST - failing build"
121 ```
122 ```bash
123 git push
f386eb 124 ```
D 125 ![fail-dashboard](../images/exercise6/fail-dashboard.png)
126
fbdd68 127 7. We can save up these regexes and inject them into the `jenkins-s2i` so the configuration is there the next time we launch and we don't have to code them up again. In `enablement-ci-cd` repo; the `jenkins-s2i/configuration/build-failure-analyzer.xml` contains common regex patterns that can be reused.
f386eb 128
fbdd68 129 <!-- ### Part 3 - Seed Jenkins Dashboards
6bd3ef 130 > _TODO - Add instructions for creating dashboards as part of s2i in Jenkins setup using DSL_
D 131
fbdd68 132 2. Open the s2i in `enablement-ci-cd` ..... -->
5a16fd 133
D 134 _____
135
fbdd68 136 <!-- ## Extension Tasks
5a16fd 137 > _Ideas for go-getters. Advanced topic for doers to get on with if they finish early. These will usually not have a solution and are provided for additional scope._
D 138
bfabf3 139 Additional Alerting
D 140  - Add `Slack` integration to the Pipeline by setting up a WebHook to call the slack endpoint with Build Stats
141  - Add `Twillio` text integration to send you text messages when the build fails.
142 Additional Monitoring
5e7a31 143  - Explore the Application's EFK stack inside OpenShift
5a16fd 144
D 145 ## Additional Reading
146 > List of links or other reading that might be of use / reference for the exercise
147
4f0295 148 ## Slide Links
RH 149
150 - [Intro](https://docs.google.com/presentation/d/1nfv1f04HkvN6ruOZ5JRMnHsSfDClyMNOhXxcC7WsSr4/)
151 - [Wrap-up](https://docs.google.com/presentation/d/1-HI9Wd5WWlzaMWmFpBEclqdyt9pFumaVbfOUrkfYKY0/)
fbdd68 152 - [All Material](https://drive.google.com/drive/folders/1Lx0OotWjisugCY11Ef0dF7EZXMIPoXOO) -->