Phase 5: Platform Engineering

Quality gates: test coverage, security scans & SLO checks

Intermediate ~3 min read
Think of it this way A friendly analogy. Read this if the technical version feels dense. Show Hide

Imagine you’re baking a super special cake for a big party. You wouldn't just throw ingredients into a bowl, bake it, and hope for the best, right? You’d check things carefully along the way. In the world of making computer programs, we do something similar with "quality gates." These are like important checkpoints built into the process of creating and updating a program. They automatically make sure everything is perfect before your program gets used by real people, just like you check your cake batter before it goes in the oven! This prevents yucky, broken, or even unsafe changes from messing things up. It’s all about catching little problems super early, saving a lot of headaches later on.

One important checkpoint is like tasting the batter or checking the recipe steps. This is called "test coverage." Your recipe might say, "mix the sugar and butter for 5 minutes until fluffy." A test coverage gate makes sure that most of your recipe steps are actually being followed and checked by automatic "tasters." If our digital recipe isn't "tasted" enough, we might accidentally let in parts that don't work. Another gate is like checking your ingredients for expiry dates or hidden allergens. These are "security scans." Just as you wouldn't want mouldy flour or peanuts in a cake for someone with an allergy, these scans automatically look for known "bad stuff" – like computer viruses or weak spots – in the program's ingredients before they can cause trouble.

Then there are "how-well-it-works checks." After your cake is baked, you might have some rules: "it must be at least three inches tall," or "it should taste perfectly sweet and moist." These are like "SLO checks" (which stands for Service Level Objective). They automatically check if your program is performing exactly how it should – for example, if it's running super fast, or if it's always available when people need it, like a cake always being delicious and ready to eat. If your cake comes out flat, or tastes bland, it fails this check, and you know something went wrong in the baking process. By doing all these checks before the cake is fully delivered, you ensure that every cake you serve is yummy and perfect.

So, when you build your own computer programs one day, think about these quality gates. You'll want to build in these automatic checks to make sure your creations are always reliable, safe, and do exactly what they're supposed to. It means you can be confident that whatever you put out into the world is going to be a top-quality, awesome piece of work!

As a Site Reliability Engineer, building reliable CI/CD pipelines is fundamental, and at the heart of this reliability are quality gates. These are automated checkpoints integrated into your CI/CD workflow that enforce specific standards before code can progress to the next stage, ultimately preventing low-quality, insecure, or unreliable changes from reaching production. They act as critical safeguards, ensuring that every deployment candidate meets a predefined bar for stability and performance. By "shifting left" quality checks, SREs empower teams to catch and fix issues earlier, drastically reducing the cost and impact of errors.

Key quality gates include test coverage, security scans, and SLO checks. A test coverage gate ensures that a minimum percentage of your codebase is exercised by automated tests, preventing untested or insufficiently tested code from being deployed. For instance, a gate might fail the build if coverage drops below 80%, ensuring changes have proper validation. Security scans, such as Static Application Security Testing (SAST) or Software Composition Analysis (SCA), automatically scan your code and dependencies for known vulnerabilities, insecure configurations, or deprecated libraries. Critical findings here will typically halt the pipeline, demanding remediation before deployment. Finally, SLO checks in CI/CD ensure that a new deployment or code change won't inherently violate your Service Level Objectives. This can involve validating the deployment configuration itself (e.g., checking minimum replica counts for availability, sufficient resource allocations for performance, or ensuring proper monitoring annotations are present), or even running quick performance tests in a staging environment to confirm latency or error rate targets aren't immediately breached.

From an SRE perspective, implementing robust quality gates is about automating the enforcement of your reliability standards. These gates provide an objective, consistent, and immediate feedback loop, fostering a culture of quality and accountability. They build confidence in your deployment process, reduce the cognitive load on engineers, and allow for faster, safer releases. While the gates must be strict enough to catch critical issues, they should also be thoughtfully designed and evolved to avoid unnecessary friction, striking a balance between rigor and development velocity to maintain a healthy and reliable software delivery lifecycle.

Key Takeaways

  • Quality gates are automated checkpoints in CI/CD pipelines preventing unreliable code from reaching production.
  • Test coverage gates enforce a minimum percentage of code validated by automated tests.
  • Security scans (SAST, SCA) automatically detect vulnerabilities in code and dependencies.
  • SLO checks in CI/CD ensure deployment configurations or performance characteristics align with reliability targets.
  • SREs use quality gates to automate reliability standards, reduce risk, and build confidence in releases.

Code Example

yaml
# .gitlab-ci.yml or .github/workflows/main.yml snippet
quality_gates:
  stage: validate
  script:
    # 1. Test Coverage Gate: Fail if coverage is below 80%
    - ./run_tests_and_check_coverage.sh --min-coverage 80

    # 2. Security Scan Gate: Fail if critical vulnerabilities are found
    - ./run_sast_scan.sh --fail-on-critical

    # 3. SLO Check Gate: Validate K8s deployment for min replicas for high availability SLO
    - K8S_DEPLOYMENT_FILE="kubernetes/deployment.yaml"
    - if ! yq e '.spec.replicas >= 3' $K8S_DEPLOYMENT_FILE; then
        echo "Error: Deployment must have at least 3 replicas for HA SLO.";
        exit 1;
      fi
  allow_failure: false # This pipeline step MUST pass

How this code works

The quality_gates job acts as a crucial checkpoint in the CI/CD pipeline, ensuring that all code changes meet predefined standards for reliability and quality before they can move forward. This job runs during the validate stage and executes a series of script commands. A key aspect is the allow_failure: false setting; this ensures that if any of the checks within this job fail, the entire pipeline stops, preventing problematic code from reaching production environments. This enforcement is vital for maintaining high standards, as it doesn't just warn about issues, it actively blocks progress.

The first script command, ./run_tests_and_check_coverage.sh, establishes a Test Coverage Gate, failing the build if code coverage falls below 80%. Following this, the ./run_sast_scan.sh command performs a Security Scan Gate, which immediately halts the process if any critical vulnerabilities are discovered. Lastly, an SLO Check Gate utilizes the yq command to parse kubernetes/deployment.yaml. It specifically checks if .spec.replicas is set to 3 or more, a requirement for high availability. If this condition isn't met, an error message is displayed, and the script exits, failing the gate.