Enhance Code Reliability With Datadog Quality Gates | Datadog

Enhance code reliability with Datadog Quality Gates

Author Bowen Chen

Published: 8月 3, 2023

Maintaining the quality of your code becomes increasingly difficult as your organization grows. Engineering teams need to release code quickly while still finding a way to enforce best practices, catch security vulnerabilities, and prevent flaky tests. To address this challenge, Datadog is pleased to introduce Quality Gates, a feature that automatically halts code merges when they fail to satisfy your configured quality checks.

Using Quality Gates, your teams can configure rules based on their specific priorities to ensure high standards of code quality, performance, and security. For example, you can choose to block any code merges that would lower your code coverage for only a select few branches and repositories while blocking all merges that would introduce flaky tests across all of your repositories. This provides enough flexibility for your engineers to rapidly develop and test new features while still helping you ensure that your code meets all of your standards before it reaches production.

In this post, we’ll cover how Quality Gates can help you:

View your existing quality gates in Datadog CI.

Prevent flaky tests and maintain code coverage

Datadog Test Visibility provides end-to-end insights into your test runs and highlights flaky tests across recent commits. When flaky tests are merged into your codebase, they introduce a variable factor that can indiscriminately break builds and inhibit development speed. As these flaky tests compound over time, they are increasingly likely to affect your pipeline—and their prevalence makes remediation more difficult.

Quality Gates enables you to prevent flaky tests from propagating across your codebase. As shown below, you can configure a rule that evaluates all code releases and blocks those that introduce new flaky tests. By defining your rule scope, you can configure your quality gate to evaluate all of your CI pipelines or only those that apply to specific repositories and branches.

Block commits that introduce flaky tests to your codebase.

Similarly, you can define rules to ensure that new commits do not decrease the code coverage of a given service. Datadog compares your test session with your default branch’s latest commit to check if your changes would reduce your code coverage. Preventing a reduction in code coverage reduces the risk of introducing bugs to production, so you can confidently make changes and ship new products.

Block commits that lower your service’s code coverage.

Enforce best practices with Static Analysis gates

Datadog Static Analysis helps you ensure code quality by identifying maintainability issues and violations of best practices prior to runtime. Although best practices are necessary for maintaining the quality and readability of your code, they can be difficult to enforce when developing at high velocity.

With Quality Gates, you can enforce Static Analysis results and address code violations before your release is deployed. Datadog classifies Static Analysis rules into different categories (e.g., best practices, code style, performance, security) and severity levels. The following screenshot shows an example of a high-severity security violation that could leave your application vulnerable to SQL injections. You can use this taxonomy to create flexible Quality Gate rules to suit your specific needs.

View recent security violations in the CI Static Analysis view.

The screenshot below shows how you could configure a rule to block any commit that would introduce even a single security violation to your service. Implementing this rule can help ensure that all code violations under Datadog’s security rule set are addressed before any changes go live.

Block commits that introduce flaky tests to your codebase.

On the other hand, you can take a more lenient approach when enforcing linting for code style and best practices by blocking deployments only when they introduce three or more violations in these categories. You can also create non-blocking rules to track the overall compliance of releases without slowing down your development speed.

Defining quality gates on various categories and thresholds helps you address issues earlier in the software development lifecycle, before they impact customers and hinder application performance and security. You can visualize your recent static analysis results and track your recent and most common violations of best practices in the CI Static Analysis view. For the full list of Static Analysis rules provided by Datadog, you can check out our documentation.

Maintain code quality with Datadog

Datadog Quality Gates enables you to create flexible, actionable rules to enforce coding best practices and ensure the quality of your test suites. Quality Gates is now available in Preview—request access via this form or learn more about creating and evaluating rules for your current pipeline in our documentation.

If you don’t already have a Datadog account, you can sign up for a today.