magic starSummarize by Aili

Trying Out Cloudflare's `foundations` Library for Rust

๐ŸŒˆ Abstract

The article discusses the author's experience using Cloudflare's Rust foundations library, a modular set of tools and utilities for building networked services and microservices in Rust. The author shares their thoughts on the library's features, modularity, and overall experience in setting it up and using it in a production project.

๐Ÿ™‹ Q&A

[01] Modular and Incrementally Adoptable

1. What are the key features of the Cloudflare Rust foundations library?

  • The library provides a re-usable and common toolkit containing common pieces of functionality for building server-side applications in Rust, such as logging, metrics, tracing, security, settings, and more.
  • The library is extremely modular, with every individual piece of functionality exposed behind well-documented feature flags, allowing developers to opt-in to only the functionality they need.
  • The modular design and feature flag setup make the library incrementally adoptable in existing codebases, with no compilation issues or other problems experienced by the author.

2. How does the modular design of the library compare to other feature-flagged code in Rust?

  • The author notes that they have worked with feature-flagged code in Rust before and found it easy to introduce compilation failures or incompatibilities with certain combinations of flags.
  • However, the author found that the foundations library has its feature flags set up very well, and they experienced no such issues when selectively enabling and disabling features.

[02] Settings Management

1. How does the settings management feature of the foundations library work?

  • The library provides support for runtime parameters and application-specific config values through a settings file, which is auto-generated from a settings specification in the code.
  • The author found the settings setup to be straightforward and the generated YAML file to be easy to work with.
  • The main complaint the author had was the need to use a helper crate for implementing the Default trait for some settings, as the library relies on serde for serialization and deserialization.

2. What feature does the author wish the settings management had?

  • The author would have liked to see support for environment variables for application configuration, as they find this to be a useful feature. The author notes that there is an open issue suggesting this addition, and the library authors seem open to it.

[03] Logging and Tracing

1. What challenges did the author face with the logging functionality of the foundations library?

  • The foundations library uses the slog logging library internally, which is not compatible with other popular logging facades like log and tracing by default.
  • The author spent time trying to integrate the tracing logging system with the slog logger from the foundations library, but was unable to get it to work satisfactorily.
  • Ultimately, the author decided to drop the foundations library's logging support and use tracing and tracing-subscriber directly, as it was a waste of time for their simple project.

2. How does the author view the logging ecosystem fragmentation in Rust?

  • The author blames the pain experienced with logging on the fragmentation of the logging ecosystem in Rust, rather than on a design flaw of the foundations library.
  • The author notes that the library has plans to add support for funneling events from tracing into the foundations library, which they expect would greatly improve the situation.

[04] Metrics and Monitoring

1. How did the author's experience with the metrics functionality of the foundations library go?

  • The author had never set up a proper metrics collection system in their projects before, but decided to try out the metrics functionality of the foundations library.
  • The author found the process of setting up Prometheus and Grafana to be much easier than expected, and the foundations library's support for defining and recording metrics to be straightforward and well-documented.
  • The author was able to easily define various metrics for their application, such as HTTP response times and request counts, and expose them for Prometheus to collect.

2. What additional metrics did the foundations library provide?

  • The foundations library also provides support for exposing internal metrics for the Tokio runtime, which the author found to be a valuable addition, especially for applications making more advanced use of Tokio features.

[05] Other Features

1. What other features of the foundations library did the author not explore in depth?

  • The author did not try out the syscall sandboxing feature for security, as it was not needed for their application.
  • The author also did not explore the advanced memory profiling support through jemalloc, but noted that it could be useful in the future.

2. How does the author view the overall maturity and maintenance of the foundations library?

  • The author plans to include the foundations library by default in all new Rust services they create in the future, citing the confidence they have in the library's maturity and ongoing maintenance due to its use at Cloudflare.
Shared by Daniel Chen ยท
ยฉ 2024 NewMotor Inc.