Probing DNS at Cloudflare
Captured source
source ↗Probing DNS at Cloudflare | Cloudflare Blog
Skip to content
Imagine this: you’ve just pushed a release. All the unit tests passed and your dashboards are green. You sit back to relax but then suddenly your phone starts blowing up: prod is broken. This is something the Cloudflare DNS team has experienced firsthand. In one rollout of the service that publishes DNS records to our edge, a scheduling bug let some record changes sit unpublished for hours. The service stayed up and was healthy, but new hostnames were slow to resolve and certificates couldn't be issued until the bug was squashed. DNS failures are hard to catch because they are slow, spread across the network, and partial in where they cause impact. We needed to figure out a way to test DNS the way customers experience it: constantly, from every data center, and against production. For us, the answer was to extend Flamingo, the end-to-end testing framework we were already using to run hundreds of millions of tests a day against Cloudflare's edge. This post covers how Flamingo's modular design lets us add DNS support, how we measure propagation, and how those measurements now decide whether a release goes ahead or gets rolled back. A little background At Cloudflare we’re obsessed with improving performance and safety for our customers. It’s crucial that our code is tested constantly, both at scale and against the real Cloudflare edge that our users operate in. That’s one reason why we created a tool called Flamingo: to measure the behavior of our production environments and make sure that code in lower-tier environments behaves as expected. We’ve already written a little about how this tool has been used in the upgrades to our CDN stack. However, this is only a small portion of how we use Flamingo internally. One of the features of Flamingo is its modular architecture that enables teams to extend the capabilities of the tool to speak other networking protocols. In our case, we wanted to use these modular capabilities to test DNS. What is Flamingo? Testing is hard. Testing at scale, when you have a widely distributed system, is even harder. There are many complex pathways that requests take and multiple systems that each network request must traverse before making its way to the origin. Unit testing alone is not nearly enough for this. We need to run constant automated testing against real systems and measure the outcomes of those requests to make informed decisions on the health of a service. Enter Flamingo. Originally built around complex multi-step HTTP testing, its capabilities and scope have increased substantially over the years. Flamingo is built from the ground up with Cloudflare’s infrastructure in mind. We built a control plane and scheduler that let teams target specific environments, data centers, or percentages of metals. We needed to integrate with custom reporting, metrics, and analytics tooling. Additionally, it needed to be a tool with predictable performance and run well on bare-metal servers in resource-constrained environments. Being delightful When we’re building internal tooling like this, we strive to create a delightful developer experience. Internal tooling should be as easy as possible to use, but also powerful enough to handle over 80% of all use cases. And in order for a new edge acceptance test framework to be successful, it needs to be built in such a way that it forces teams to follow common guidelines and build reusable scripts in an environment that is stable, scalable, and manages complexity. One thing that is not delightful is debugging a test. If you allow a user to write tests in a traditional programming language, when their test fails they then both need to debug the upstream system being tested and the test itself. This is why we built Flamingo to use a custom domain-specific language (DSL) consisting of a simple setup-request-response format. For example, let’s imagine that we want to make sure we are redirecting all unencrypted traffic to its encrypted counterpart. TEST test-redirect SET $hostname www.cloudflare.com
GET "http://$(hostname)/"
ASSERT STATUS IS 301 ASSERT HEADER Location IS "https://$(hostname)/" Here we can see the power of the DSL. In five lines of code, we have a script that can run anywhere on Cloudflare’s edge and scale to thousands of requests per minute. We can take the data produced from the millions of data points generated from this and turn those into a graph defining how our service is actually performing in the real world. Taking the setup-request-response test format from above and modifying it slightly allows us to use Flamingo for more than just HTTP testing. Instead of the middle step being a request, we can now look at it as an action . Now we’ve changed our system from something that makes HTTP requests into something that can perform any action for which we’d like to measure the outcome. In Flamingo we call these modules and have put immense effort into making them as easy as possible for anyone to write. Flamingo is written in Rust, due to its consistent performance characteristics and strong type system. The type system in particular lends itself to this modularity, by allowing us to use strongly-typed enumerations for input and output in the Flamingo action runner: pub enum Action { Query { method: String, url: Expression, parameters: Vec<http::QueryParameters>, }, DnsQuery { query_name: Expression, query_type: Expression, parameters: Vec<dns::DnsQueryParameters>, }, }
pub enum ActionOutput { Http(http::FetchResponse), Dns(dns::QueryResponse), }
pub type ActionHandlerFunction = Arc< dyn Fn( Action, Arc<Ctx>, InterpreterConfig, ) -> BoxFuture<'static, Result<ActionOutput>> + Send + Sync + 'static, >;
pub type ActionHandlerLUT = Arc< dyn Fn(&Action) -> ActionHandlerFunction + Send + Sync + 'static, >; What we’ve done here is decouple the logic for performing an action (in this case an HTTP request) into a dynamically dispatched function that we can then call independently of other actions. This leaves things like test scheduling and resource management as higher-level operations that someone implementing a module doesn’t need to worry about. All the author needs to focus on is the logic. pub async fn query( action: Action, ctx: Arc<Ctx>, cfg: InterpreterConfig, ) -> Result<ActionOutput> { let Action::Query { method, url, parameters, } = action else { bail!("Invalid action for...
Excerpt shown — open the source for the full document.
Notability
notability 1.0/10Not AI-related, low traction, routine technical post.