Conventions
This page collects the project-specific rules that aren't mechanical enough for the style guide or a lint: design preferences, scope decisions, and matters of taste. Reviewers call these out in PR reviews when they're missed. A pull request number at the end of a rule points to the fix for a bug that the rule guards against.
When a review or a design discussion settles a question that's likely to come up again, add it here.
Code comments
Keep code comments, including rustdoc on private items, short. A comment should do one of two things:
- flag a caveat that a reader could easily miss
- annotate a large block of logic at a high level, so that it's easier to navigate
Don't write comments that restate what the code already says, and don't re-explain the design at every call site. Explain a design once, in the module documentation, and keep comments at call sites to a sentence or two. Before keeping a comment, ask whether deleting it would make the reader miss anything.
Comments describe the code as it is now. Don't write comments that describe a change, such as "previously," "now uses," or "replaces X": Git keeps the history. A regression test can name the failure that it guards against and link its issue. Outside tests, don't add banner comments such as // ---- Section ----. To annotate a large block, write a full sentence instead. Don't commit proof-of-concept notes or design write-ups as Markdown files, next to the code or under docs/. Move the useful details into code comments, or into the docs page that owns the topic. Plans for work that spans several pull requests follow Plans.
Word comments in the ASD-STE100 style.
Generated and vendored files
Never hand-edit files marked @generated or DO NOT EDIT. Change their source of truth, and regenerate them.
The vendored Datadog configuration schema under lib/datadog-agent/config/schema/core/ is a pristine upstream copy, so never hand-edit it either. Configuration system explains how to change what the schema feeds into.
Matching the Datadog Agent
agent-data-plane (ADP) matches what users observe from the Datadog Agent: output, defaults, accepted input, and the result of bad input. ADP can differ when the Agent's reason for a behavior doesn't apply and the pull request description or a code comment says so. Don't flag that difference. ADP doesn't copy Agent internals, or Go patterns that don't fit Tokio, unless the pull request says why. An example is a rendezvous channel on every loop iteration.
- Some changes claim parity, or change a default, a limit, or the accepted input for a setting or protocol that the Agent also has. Such a change links to Agent source pinned to a commit, or tests against values from the Agent. If it does neither, ask what the Agent does.
- When a change fixes one path, check its sibling paths. Sibling paths include aggregated and timestamped metrics; series and sketches; each encoder version; each transport, including Windows named pipes; and each signal. Flag a sibling that has the same defect and stays unfixed, or that inherits behavior meant for another path.
- When the Agent logs a bad value and continues, ADP continues too. Flag a new startup error for such a value, and a startup step that a short outage can make fatal. A startup error becomes a crash loop.
Reuse what exists
Before you add a mechanism, look for an existing one that does the job.
Flag a new type, handle, or task that does the work of an existing mechanism, and ask what it adds. These come up most often:
- Event batching and dispatch use
BufferedDispatcherfromlib/saluki-core. - Retries and backoff use
ExponentialBackoffand the retry policies inlib/saluki-io/src/net/util/retry/. - Datadog sites, endpoints, and request building live in
lib/saluki-components/src/common/datadog/. - A pooled object goes back to its pool when it drops, so it doesn't need a hand-written return path.
- Flag logic that the standard library or a workspace crate already provides, and a constant that two crates each define.
API routes and control plane workers
Flag a new static handler added with APIBuilder::with_handler or APIBuilder::with_grpc_service: a worker asserts a DynamicRoute instead. Flag a library builder that assembles a binary's control plane from several workers.
Dynamic routes let any worker in the supervision tree contribute to an endpoint it doesn't own, which keeps workers composable.
Hot paths and memory
Much of Saluki runs once for each metric, log, or span. In that per-event code, flag:
- a clone, an owned
String, or aformat!call where a borrow, a&'static str, or a value that the code already owns works - a method that clones large data and doesn't say so in its name
- a fixed string in an event, tag, or context that doesn't use
MetaString::from_staticor string interning - a builder, resolver, buffer, or metric handle that the code makes for each event, when one instance works
- a temporary
Vecor map that the code fills only to iterate over once - a
SystemTime::nowcall where one-second precision is enough: usesaluki_common::time::get_coarse_unix_timestamp
Regressions that only affect tail latency (p95, p99) also count. In production code, outside bin/correctness/ and test/, flag:
- an unbounded channel or queue, or a very large bound with no reason. A new channel usually holds 64 to 128 items. A queue that something else bounds, such as a supervisor's queue of children to spawn, is fine.
- a collection that grows for each connection, key, or context with no size limit, expiration, or removal on every exit path. Exit paths include disconnect, flush, capture stop, and delete. Also check an expiry setting of
0, which turns expiry off. - a per-connection or per-request value in a task name, metric tag, or component ID. Each value makes a new metric series.
Concurrency and lifecycle
Components run concurrently on Tokio, under supervisors, with explicit startup and shutdown. Flag:
- a blocking call in async code, such as
std::fsI/O - a spawned task that nothing joins or cancels
- a final flush or shutdown path that reuses a steady-state condition, such as an idle timeout, and so leaves buffered data unsent. A lifecycle change has a test that stops the component right after input and checks the output.
- a shutdown path that can hang, or that differs between
select!arms - a notification sent before readers can see the new state, and a ready signal sent before the listener binds.
abort()as the only way to stopspawn_blockingwork or a thread. That work checks asaluki_common::sync::shutdown::ShutdownHandleinstead.- two tasks that can each block on a full bounded channel that the other one drains
- a silent drop where backpressure works, such as a
broadcastchannel whose receivers can lag. Anmpscchannel that replaces abroadcastchannel has one receiver, so check that no second subscriber exists. - a
broadcastreceiver that handlesRecvError::LaggedlikeRecvError::Closed. A receiver that lags can still receive. - a
Notifyused as ifnotify_waiters()stores a permit, asnotify_one()does. It wakes only theNotifiedfutures that exist when it runs.
The owner is a supervisor or a scope. If something outside has a shorter limit, it preempts by aborting the subtree. That's by design.
Numbers and identity
- Use checked or saturating math on sizes, bounds, and durations from configuration. Tagged releases build with
overflow-checks = false, so integer overflow wraps silently.Durationarithmetic panics in every build. - Flag plain
-between two snapshots of an unsigned counter. Usesaturating_suborchecked_sub, because a reset or a key collision can make the later value smaller. - Flag division or scaling by an input or configured value that can be
0, such as a sample rate. - Flag a feature, a report, or a limit that a setting turns off with its default or with a valid
0, when the Agent doesn't. For example, a rate limit keyed on an interval that defaults to0can send no reports at all. - Flag hashing, serialization, or IDs that depend on
HashMapiteration order. Sort first, or use aBTreeMap.
Internal telemetry
agent-data-planeadds theadp.prefix to internal metric names at bootstrap, throughAppBootstrapper::with_metrics_prefix. Flag a metric that code registers with the prefix in its name. Remap rules match the prefixed name, which is correct.- A metric measures what its name says, in that unit, and its type fits. A counter of events doesn't count payloads.
- Components emit the standard
component_*_totalmetrics with a tag for the cause, such ascomponent_events_dropped_totalwithdrop_reason. Flag a component-specific name for the same thing. - Each path that drops or changes input increments a counter. Count an outcome after it happens, such as bytes sent after a successful response.
Security
- Each
unsafeblock andunsafe implhas a// SAFETY:comment that says why its invariants hold. - A route that changes runtime state, or that returns configuration, workload data, or captured traffic, uses
EndpointType::Privileged. That endpoint requires a client certificate. - Outside tests, code that builds a TLS config directly with
rustls, and not with thesaluki-tlsbuilders, callsensure_client_config_fips_compliantorensure_server_config_fips_compliant. - Flag
danger_accept_invalid_certsoutside tests, unless a setting turns it on and the code logs a warning. - Flag logs, errors, and
Debugoutput that can contain API keys, tokens, or passwords. Flare files that ADP returns to the Core Agent are fine, because the Core Agent scrubs each file that it adds to a flare. - Scrubbing and obfuscation fail closed. Flag an error branch that returns or forwards the input unchanged.
Build and release plumbing
These rules cover the build and release files at the root of the repository, and code that depends on the platform. Examples are the Makefile, ci/, docker/, .gitlab-ci.yml, and Cargo.lock.
- A renamed or new build variable has the same name in every producer and consumer. This covers Make variables, Docker build
ARGvalues, CI variables, and theAPP_*variables thatlib/saluki-metadata/build.rsreads. - Developers build on macOS. Flag
Makefiledefaults from the host, such asrustc -vVoruname, that reach Linux container builds. Flag scripts that fail on an unknown architecture. - In
Cargo.lock, flag a downgrade of a crate that the pull request doesn't target. - ADP builds for Linux, macOS, Windows, and AIX, which is big-endian. Flag code that assumes little-endian byte order at runtime, such as
from_ne_bytesortransmuteon bytes from outside the process, a union layout, or a tag at a fixed byte index.make check-aix-crossonly type-checks.
Core crate
These rules cover the data model, the interconnect, the object pools, and the internal metrics registry in lib/saluki-core, which every other crate uses.
Apply these rules to files under lib/saluki-core: the data model, the interconnect, the object pools, and the internal metrics registry.
- The event types under
src/data_model/event/are Saluki's own model. Flag a field or method on them that takes or returns a protocol type, such as an OTLP or protobuf type. Sources and decoders translate input into the model. Encoders translate the model into output, so one encoder works for events from every source.DDSketchand theserde_json::Valuein log properties are part of the model. Payload types undersrc/data_model/payload/are transport-level and can hold types such ashttp::Request. Opaqueevents are the exception to the rule above. AnOpaqueholds a type name and encoded bytes, so that payloads outside the model can move through the topology.saluki-commondefines it, andsrc/data_model/event/re-exports it. Don't flag itsBytesfield. Flag anOpaquepayload that a modeled event type can hold, and code that decodesOpaquedata directly instead of withtry_decode, which checks the type name first.- When behavior depends on the input protocol, the event holds it in a typed field that the source sets at construction, as
TraceIngestInfodoes. Flag a new event method that gets the protocol from tags or attributes, because transforms can change or remove them. Eventis as large as its largest variant, and it moves by value through each component. Each new field costs memory, and a field on the largest variant makes every event larger. Flag a new event field that nothing reads, even when the Datadog Agent has that field. A field is fine when the description names the stacked pull request that reads it. Flag a larger budget incore_event_types_stay_within_size_budgetthat the description doesn't explain.- Each supervised child declares its own shutdown strategy, and its owner enforces exactly that strategy. Flag an owner that keeps back part of a child's grace period as a margin, passes its own deadline down to its children, or treats a child supervisor differently from a child worker. A child that overruns its grace period has a bug: fix the child and its tests, not the deadlines.
Project scope
- The
standalonemode ofagent-data-planeis left over from earlier development and testing. It isn't for production use, and supporting it shouldn't block feature development. panoramicunderbin/correctness/is our black-box correctness and integration tool.steleis a library of simplified telemetry data types shared by the correctness tools. Neither replaces unit tests for the branches inside a crate, and neither is the Antithesis platform, which lives separately undertest/antithesis/. See Testing.