Rob Harris
2018-04-27 fd49290d84a3a45572baa6e52a0f5bfe758eb663
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
fd4929 8 Why do we use visual monitors? Visual monitors support the tight feedback loop which is vital to an agile working environment. Being in a centrally visible location, visual monitors radiate information rapidly, meaning the team doesn't have to go looking for it. Visual monitors also provide a degree of accountibility while also keeping the team motivated to fix problems. With broken components visualised, seeing progress monitors change from red to green can give the collective feeling that progress is being made. Finally visual monitors can promote team cohesion as it enables all team members to be on the same page regarding the current project status. 
RH 9 ____
43f2f2 10 ## Learning Outcomes
D 11 As a learner you will be able to
20d6cb 12 - Create dashboards in Jenkins to display build status
514d37 13 - Seed Jenkins using DSL to create dashboards by default
43f2f2 14
D 15 ## Tools and Frameworks
16 > Name of tool - short description and link to docs or website
17
20d6cb 18 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 19 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 20 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 21
D 22 ## Big Picture
23 This exercise begins cluster containing blah blah
24
25 _____
26
27 ## 10,000 Ft View
20d6cb 28 > The goal of this exercise is to introduce Build Monitors to radiate teams progress on Dashboards.
43f2f2 29
20d6cb 30 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 31
20d6cb 32 2. Use the pipeline views in OpenShift and Jenkins to produce dashboards that teams can use. 
43f2f2 33
D 34 ## Step by Step Instructions
35 > 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
36
20d6cb 37 ### Part 1 - Create a build monitor
94cbda 38 > _In this exercise we will create a new build monitor to show key information about our builds_
43f2f2 39
94cbda 40 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 41
94cbda 42 2. Give the job a sensible name such as `todolist-monitor` and select `Build Monitor View` 
D 43 ![new-monitor](../images/exercise6/new-monitor.png)
20d6cb 44
94cbda 45 2. On the configuration page; select `Recurse in subfolders`
D 46 ![config-recursive](../images/exercise6/config-recursive.png)
47
48 2. Check the box to use Regular Expression and set the value to be something that should scrape our apps such as `.*todolist.*` 
49 ![config-regex](../images/exercise6/config-regex.png)
50
994c1c 51 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 52 ![config-commiters](../images/exercise6/config-commiters.png)
D 53
54 2. Save your configuration to see your Build Monitor! 
514d37 55 ![build-monitor](../images/exercise6/build-monitor.png)
94cbda 56
994c1c 57 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 58 ![config-pipeline-view](../images/exercise6/config-pipeline-view.png)
59
60 2. On the configure page; set the regex to `todolist.*`
61 ![config-pipeline-regex](../images/exercise6/config-pipeline-regex.png)
62
63 2. Set the view to `Only display last build` for simplicity of the view.
64 ![config-pipeline-ui-settings](../images/exercise6/config-pipeline-ui-settings.png)
65
66 2. Save your configuration to see your Build Monitor! 
67 ![pipeline-monitor](../images/exercise6/pipeline-monitor.png)
94cbda 68
1c8123 69 2. Explore the Jenkins Blue Ocean view for some additional monitors and views that make Jenkins look pretty!
D 70 ![blue-ocean](../images/exercise6/blue-ocean.png)
71
514d37 72 ### Part 2 - Build Fail Analyser
D 73 > _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_
74
75 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.
76
b26e75 77 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 78 ```javascript
D 79   it("call makImportant when clicked", () => {
80     const wrapper = mount(TodoItem, {
81       methods,
82       propsData: { todoItem: importantTodo }
83     });
84     // TODO - test goes here!
85     const input = wrapper.find(".important-flag");
86     input.trigger("click");
87     expect(methods.markImportant).not.toHaveBeenCalled();
88     });
89 });
90 ```
91
b26e75 92 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 93 ![fail-local](../images/exercise6/fail-local.png)
D 94
b26e75 95 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 96
D 97 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.*`. 
98 ![fail-cause](../images/exercise6/fail-cause.png)
99
b26e75 100 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 101 ```bash
D 102 $ git add .
103 $ git commit -m "TEST - failing build"
104 $ git push
105 ```
106 ![fail-dashboard](../images/exercise6/fail-dashboard.png)
107
108 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.
109
110 ### Part 3 - Seed Jenkins Dashboards
94cbda 111 > _TODO - Add instructions for creating dashboards as part of s2i in Jenkins setup using DSL_
D 112
113 2. Open the s2i in `enablement-ci-cd` .....
43f2f2 114
D 115 _____
116
117 ## Extension Tasks
118 > _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._
119
20d6cb 120 Additional Alerting
D 121  - Add `Slack` integration to the Pipeline by setting up a WebHook to call the slack endpoint with Build Stats
122  - Add `Twillio` text integration to send you text messages when the build fails.
123 Additional Monitoring
124  - Explore the Application's FEK stack inside OpenShift
43f2f2 125
D 126 ## Additional Reading
127 > List of links or other reading that might be of use / reference for the exercise
128
01c4da 129 ## Slide Links
RH 130
131 - [Intro](https://docs.google.com/presentation/d/1nfv1f04HkvN6ruOZ5JRMnHsSfDClyMNOhXxcC7WsSr4/)
132 - [Wrap-up](https://docs.google.com/presentation/d/1-HI9Wd5WWlzaMWmFpBEclqdyt9pFumaVbfOUrkfYKY0/)
133 - [All Material](https://drive.google.com/drive/folders/1Lx0OotWjisugCY11Ef0dF7EZXMIPoXOO)