hyperlane-plugin-metrics 23.2.0

A lock-free atomic Prometheus/OpenMetrics observability plugin for the Hyperlane framework with built-in HTTP request counters, in-flight gauges, latency histograms, custom user metric registration, and a scrapeable /metrics endpoint.
Documentation
/// Default Prometheus scrape endpoint path.
pub const DEFAULT_METRICS_ENDPOINT: &str = "/metrics";

/// Default metric prefix namespace.
pub const DEFAULT_METRICS_NAMESPACE: &str = "hyperlane";

/// Prometheus text exposition format 0.0.4 `Content-Type` header value.
pub const PROMETHEUS_CONTENT_TYPE: &str = "text/plain; version=0.0.4; charset=utf-8";

/// Default latency histogram bucket upper bounds in seconds.
pub const DEFAULT_LATENCY_BUCKETS: [f64; 12] = [
    0.001, 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1.0, 2.5, 5.0, 10.0,
];

/// Stack buffer length for fast decimal formatting of signed and unsigned 64-bit integers.
pub(crate) const INT_STACK_BUF_LEN: usize = 24;

/// Two-digit ASCII decimal lookup table for branch-light integer formatting.
pub(crate) const PROM_DEC_DIGITS_LUT: &[u8; 200] = b"00010203040506070809101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899";

/// Pre-formatted `"0\n"`..=`"99\n"` strings avoiding division and UTF-8 validation on common small counts.
pub(crate) const PROM_DEC_0_99_NL: [&str; 100] = [
    "0\n", "1\n", "2\n", "3\n", "4\n", "5\n", "6\n", "7\n", "8\n", "9\n", "10\n", "11\n", "12\n",
    "13\n", "14\n", "15\n", "16\n", "17\n", "18\n", "19\n", "20\n", "21\n", "22\n", "23\n", "24\n",
    "25\n", "26\n", "27\n", "28\n", "29\n", "30\n", "31\n", "32\n", "33\n", "34\n", "35\n", "36\n",
    "37\n", "38\n", "39\n", "40\n", "41\n", "42\n", "43\n", "44\n", "45\n", "46\n", "47\n", "48\n",
    "49\n", "50\n", "51\n", "52\n", "53\n", "54\n", "55\n", "56\n", "57\n", "58\n", "59\n", "60\n",
    "61\n", "62\n", "63\n", "64\n", "65\n", "66\n", "67\n", "68\n", "69\n", "70\n", "71\n", "72\n",
    "73\n", "74\n", "75\n", "76\n", "77\n", "78\n", "79\n", "80\n", "81\n", "82\n", "83\n", "84\n",
    "85\n", "86\n", "87\n", "88\n", "89\n", "90\n", "91\n", "92\n", "93\n", "94\n", "95\n", "96\n",
    "97\n", "98\n", "99\n",
];

/// Estimated digit bytes reserved per metric line when pre-sizing the Prometheus output buffer.
pub(crate) const PROM_EST_DIGITS_PER_LINE: usize = 16;

/// Maximum bucket count eligible for branchless linear scan in [`crate::Histogram::observe`].
pub(crate) const LINEAR_SCAN_BUCKET_LIMIT: usize = 16;

/// Predefined HTTP status class labels emitted by Prometheus exposition.
pub(crate) const STATUS_CLASS_LABELS: [&str; 6] = ["1xx", "2xx", "3xx", "4xx", "5xx", "other"];

/// Context attribute key storing request start `Instant` for latency observation.
pub(crate) const ATTR_METRICS_STARTED_AT: &str = "hyperlane_plugin_metrics_started_at";

/// `Cache-Control` directive preventing caching of live Prometheus scrapes.
pub(crate) const CACHE_CONTROL_NO_STORE: &str = "no-store";

/// Lowercase `bearer ` prefix for optional `/metrics` scrape authentication.
pub(crate) const PREFIX_BEARER: &str = "bearer ";

/// Default help text for built-in HTTP duration histogram.
pub(crate) const HELP_HTTP_DURATION: &str = "HTTP request latency distribution in seconds.";

/// ASCII digit zero byte (`0`).
pub(crate) const ASCII_ZERO: u8 = b'0';