Rob Harris
2018-04-27 46d9181441c216c7bd4c9e501f3f819c7d56dd33
commit | author | age
20d6cb 1 # Return of the Application Monitoring
43f2f2 2
20d6cb 3 > In this exercise we will create a build monitor to radiate vital build information and statistics
921415 4
D 5 ![monitoring-meme](../images/exercise6/monitoring-meme.jpg)
bedbc0 6
A 7 ## Exercise Intro
46d918 8 Build monitors provide a tight feedback loop which is vital to an agile working environment. Being in a highly visible location, build monitors radiate information rapidly, 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. Finally, build monitors can promote team cohesion as they enable all team members to be on the same page regarding the current project status. The most important thing here isn't the tool, but the visual feedback. In previous labs we've displayed the below 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.
5bb7bd 9
A 10 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 twhy a particular build is failing and fix it faster.
46d918 11
RH 12 ## Why do we use build monitors? 
13 - Provides instant feedback to teams regarding the current status of the build.
14 - Tightens feedback loop by having vital information needed by teams, available upfront.
15 - Motivates teams to fix problems together.
fd4929 16 ____
43f2f2 17 ## Learning Outcomes
D 18 As a learner you will be able to
20d6cb 19 - Create dashboards in Jenkins to display build status
514d37 20 - Seed Jenkins using DSL to create dashboards by default
43f2f2 21
D 22 ## Tools and Frameworks
23 > Name of tool - short description and link to docs or website
24
20d6cb 25 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).
9be9e8 26 1. [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.
94cbda 27 1. [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)
43f2f2 28
D 29 ## Big Picture
30 This exercise begins cluster containing blah blah
31
32 _____
33
34 ## 10,000 Ft View
20d6cb 35 > The goal of this exercise is to introduce Build Monitors to radiate teams progress on Dashboards.
43f2f2 36
20d6cb 37 2. 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.
43f2f2 38
20d6cb 39 2. Use the pipeline views in OpenShift and Jenkins to produce dashboards that teams can use. 
43f2f2 40
D 41 ## Step by Step Instructions
42 > 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. Rule of thumb is learners are dumb.... so over describe _why_ we're doing things
43
20d6cb 44 ### Part 1 - Create a build monitor
94cbda 45 > _In this exercise we will create a new build monitor to show key information about our builds_
43f2f2 46
94cbda 47 2. 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)
20d6cb 48
94cbda 49 2. Give the job a sensible name such as `todolist-monitor` and select `Build Monitor View` 
D 50 ![new-monitor](../images/exercise6/new-monitor.png)
20d6cb 51
94cbda 52 2. On the configuration page; select `Recurse in subfolders`
D 53 ![config-recursive](../images/exercise6/config-recursive.png)
54
55 2. Check the box to use Regular Expression and set the value to be something that should scrape our apps such as `.*todolist.*` 
56 ![config-regex](../images/exercise6/config-regex.png)
57
994c1c 58 2. Finally; select `Display committers` and set the Failure Analyser to `Description`. This allows us to write regex for when fails occur in Jenkins and have the reasons plotted on the graph. For example; number of test scores or common compilation errors. 
94cbda 59 ![config-commiters](../images/exercise6/config-commiters.png)
D 60
61 2. Save your configuration to see your Build Monitor! 
514d37 62 ![build-monitor](../images/exercise6/build-monitor.png)
94cbda 63
994c1c 64 2. 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`
D 65 ![config-pipeline-view](../images/exercise6/config-pipeline-view.png)
66
67 2. On the configure page; set the regex to `todolist.*`
68 ![config-pipeline-regex](../images/exercise6/config-pipeline-regex.png)
69
70 2. Set the view to `Only display last build` for simplicity of the view.
71 ![config-pipeline-ui-settings](../images/exercise6/config-pipeline-ui-settings.png)
72
73 2. Save your configuration to see your Build Monitor! 
74 ![pipeline-monitor](../images/exercise6/pipeline-monitor.png)
94cbda 75
1c8123 76 2. Explore the Jenkins Blue Ocean view for some additional monitors and views that make Jenkins look pretty!
D 77 ![blue-ocean](../images/exercise6/blue-ocean.png)
78
514d37 79 ### Part 2 - Build Fail Analyser
D 80 > _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_
81
82 2. 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.
83
b26e75 84 2. Open one of the tests you wrote in previous labs; 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.
514d37 85 ```javascript
D 86   it("call makImportant when clicked", () => {
87     const wrapper = mount(TodoItem, {
88       methods,
89       propsData: { todoItem: importantTodo }
90     });
91     // TODO - test goes here!
92     const input = wrapper.find(".important-flag");
93     input.trigger("click");
94     expect(methods.markImportant).not.toHaveBeenCalled();
95     });
96 });
97 ```
98
b26e75 99 2. 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!
514d37 100 ![fail-local](../images/exercise6/fail-local.png)
D 101
b26e75 102 2. 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`.
514d37 103
D 104 2. 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.*`. 
105 ![fail-cause](../images/exercise6/fail-cause.png)
106
b26e75 107 2. 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
514d37 108 ```bash
D 109 $ git add .
110 $ git commit -m "TEST - failing build"
111 $ git push
112 ```
113 ![fail-dashboard](../images/exercise6/fail-dashboard.png)
114
115 2. We can save up these regex 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` already contains ones we've collected on previous residencies.
116
117 ### Part 3 - Seed Jenkins Dashboards
94cbda 118 > _TODO - Add instructions for creating dashboards as part of s2i in Jenkins setup using DSL_
D 119
120 2. Open the s2i in `enablement-ci-cd` .....
43f2f2 121
D 122 _____
123
124 ## Extension Tasks
125 > _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._
126
20d6cb 127 Additional Alerting
D 128  - Add `Slack` integration to the Pipeline by setting up a WebHook to call the slack endpoint with Build Stats
129  - Add `Twillio` text integration to send you text messages when the build fails.
130 Additional Monitoring
131  - Explore the Application's FEK stack inside OpenShift
43f2f2 132
D 133 ## Additional Reading
134 > List of links or other reading that might be of use / reference for the exercise
135
01c4da 136 ## Slide Links
RH 137
138 - [Intro](https://docs.google.com/presentation/d/1nfv1f04HkvN6ruOZ5JRMnHsSfDClyMNOhXxcC7WsSr4/)
139 - [Wrap-up](https://docs.google.com/presentation/d/1-HI9Wd5WWlzaMWmFpBEclqdyt9pFumaVbfOUrkfYKY0/)
140 - [All Material](https://drive.google.com/drive/folders/1Lx0OotWjisugCY11Ef0dF7EZXMIPoXOO)