Live Blogging at DeveloperWeek: Promoting Reliable Code
Tags: codequality
Published: 2020-02-12 21:59:49

---
title: Live Blogging at DeveloperWeek: Promoting Reliable Code
published: true
description: I'm enjoying myself live-blogging about DeveloperWeek and some of the talks I'm attending. Here's one about scoring code for reliability.
tags: #codequality
---
<em>I'm live blogging my experience at DeveloperWeek, en masse, <a href="https://daedtech.com/live-blogging-developer-week-2020-day-1/">at my site</a>. You can follow along there, or look for me to post some talk summaries here, individually.</em>

This is a talk by <a href="https://www.linkedin.com/in/chenh/">Chen Harel, co-founder of OverOps</a>.

He wants to suggest a few quality gates that those of us in attendance can take back to our engineering groups.  This is ultimately about preventing severity-one production defects.

Consider that speed and stability are naturally at odds when it comes to software development and deployment.  With an emphasis on time to market, the cost of poorly written software is actually growing, notwithstanding agile methodologies and increased awareness of the importance of software quality.

And here's a contextual linchpin for the talk:
<blockquote>"Speed is important. Quality is fundamental."</blockquote>
So how do organizations address this today?  Here are some ways:
<ol>
 	<li>DevOps: "you build it, you run it," to increase accountability.</li>
 	<li>A "shift left" approach to software quality -- bake quality concerns into the process earlier.</li>
</ol>
But how do we <em>measure</em> quality?
<h3>Measuring Code Quality</h3>
Measuring software quality is all about good data.  And we tend not to have that data readily at our disposal as much as we might want.

Here are some conventional sources of this type of data:
<ul>
 	<li>Static code analysis</li>
 	<li>Code coverage</li>
 	<li>Log files</li>
</ul>
But what about the following as a new approach?
<ul>
 	<li>New errors</li>
 	<li>Increasing errors</li>
 	<li>Slowdowns</li>
</ul>
Using these metrics, the OverOps team was able to create a composite means of scoring code quality.
<h3>A Scoring Process</h3>
So, let's look at the reliability score. Releases are scored for stability and safety based these measures.  And it requires the following activities for data gathering:
<ul>
 	<li>Detect all errors and slowdowns</li>
 	<li>Classify each detected event</li>
 	<li>Prioritize them by severity</li>
 	<li>Score the build</li>
 	<li>Block builds that score too low</li>
 	<li>And then, in retrospect, visualize the data</li>
</ul>
Toward this, let's consider some data detection methods.  Manually, they have log files and metrics libraries.  But they can automatically detect issues using APM, log aggregators, and error tracking.

<em>(Halfway through the talk, and I'm really enjoying this. As both a techie and business builder, gathering actionable data is a constant focus for me these days. I love the idea of measuring code quality both with leading and lagging indicators, and feeding both into a feedback loop.)</em>
<h3>Classification</h3>
Now, drilling a little further into step (2) above, classification.  Ask questions like:
<ul>
 	<li>Is the dev group responsible?</li>
 	<li>What's the type or potential impact?</li>
 	<li>What dependent services are affected?</li>
 	<li>What is the volume and rate of this issue -- how often did it happen or not happen?</li>
</ul>
<h3>Prioritizing</h3>
When it comes to prioritizing, we can think of new errors as ones that have never been observed. And a new error is severe if it's
<ul>
 	<li>Uncaught</li>
 	<li>A critical exception</li>
 	<li>Volume/rate exceeds a threshold</li>
</ul>
There's also the idea of  <em>increasing </em>errors that can help determine severity. An error can become severe if its rate or volume is increasing past a threshold.

And you think about errors in terms of <em>seasonality</em> as well to mitigate this concern a bit. That is, do you have cyclical error rates, depending on time of day or week, or other cyclical factors? If so, you want to account for that to make sure temporary rate increases aren't expected as the normal course of business.

And, finally, you can think of prioritizing slowdowns. Slowdowns mean response time starts tot take longer, and a slowdown becomes severe based on the number of standard deviations it is away from normal operation.
<h3>Scoring Formula</h3>
So based on classification and priority, the OverOps team starts to assign points to errors that occur. They took a look at severity, as measured by things like "did this get us up in the middle of the night," and adjusted scoring weights accordingly until they fit known data.

This then provides the basis for future prediction and a reliable scoring mechanism.

Now, assume all of this is in place. You can automate the gathering of this type of data and generate scores right from within your CI/CD setup, using them as a quality gate.
<h3>A Code Quality Report</h3>
Having this integrated into you build not only allows you to reject builds that don't pass the quality gate. You can also generate some nice reporting.

Have a readout for why a given build failed, and have general reporting on the measured quality of each build that you do.
<h3>My Takeaway:</h3>
I've spent a lot of time in my career on static code analysis, which I find to be a fascinating topic. It promises to be a compile-time, leading indicator of code quality, and, in some ways, it does this quite well. But the weakness here is that it's never really tied reliably into actual runtime behaviors.

In a sense, a lot of static analysis involves predicting the future. "Methods this complex will probably result in bugs" or "you might have exposed yourself to a SQL injection."

But the loop never gets closed. <em>Does </em>this code wind up causing problems?

I love this approach because it starts to close the loop. By all means, keep doing static analysis. But also run experiments and measure what's actually happening when you deploy code, and feed that information back into how you work.