Skip to main content

Crate sentry_options_validation

Crate sentry_options_validation 

Source
Expand description

Schema validation library for sentry-options.

Schemas are loaded once into a SchemaRegistry and shared via Arc. Values are validated against schemas as complete objects.

§Refresh-on-read scheme

Values are held in a ValuesStore that wraps an ArcSwap for lock-free reads. There is no background thread — every load() decides whether the cached snapshot is stale and, if so, the calling thread refreshes it.

Each load() does:

  1. Read now and last_updated (an AtomicU64 of nanoseconds since a monotonic baseline) with Acquire.
  2. Compute a per-call jitter in [0, 1s) from the address of a stack local — different threads have different stack bases, so the value differs across threads. No thread_local is involved.
  3. If now - last_updated < threshold + jitter, return the current snapshot. Otherwise: a. Read all values files from disk and build the new map. b. On success, publish the new map into the ArcSwap (last-writer-wins under contention). c. compare_exchange last_updated from the previously-observed value to now with AcqRel. The Release on the timestamp publishes the prior ArcSwap::store: any reader that Acquire-loads the bumped timestamp and short-circuits the refresh is guaranteed to subsequently load the new snapshot. d. On a parse/validation failure, leave the old map in place — the bumped timestamp makes other threads back off until the next window.

Multiple threads racing through the stale window will redundantly read files and publish; the last ArcSwap::store wins. The jitter spreads the threshold boundary so that the herd doesn’t cross it together. On error the timestamp is still bumped so a broken values directory does not turn into an I/O storm.

Structs§

NamespaceSchema
Schema for a namespace, containing validator and option metadata
OptionMetadata
Metadata for a single option in a namespace schema
SchemaRegistry
Registry for loading and storing schemas
ValuesStore

Enums§

ValidationError
Errors that can occur during schema and value validation

Constants§

LOCAL_OPTIONS_DIR
Local fallback path for development
OPTIONS_DIR_ENV
Environment variable to override options directory
OPTIONS_SUPPRESS_MISSING_DIR_ENV
Environment variable to suppress missing directory errors
PRODUCTION_OPTIONS_DIR
Production path where options are deployed via config map

Functions§

resolve_options_dir
Resolve options directory using fallback chain:
validate_k8s_name_component
Validate a name component is valid for K8s (lowercase alphanumeric, ‘-’, ‘.’)

Type Aliases§

PropagationCallback
Lazily reloads values from disk when reads detect they are stale.
ValidationResult
Result type for validation operations
ValuesByNamespace
A map of option values keyed by their namespace