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