Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[oximeter] use Cow<'static, str> for FieldValue::String #5670

Merged
merged 3 commits into from
May 8, 2024

Commits on Apr 30, 2024

  1. [oximeter] change FieldValue::String to Cow

    Currently, Oximeter `FieldValue::String` fields are always represented
    by a `String` value. This is somewhat unfortunate, as it requires
    allocating a new `String` for every string field value that's emitted to
    Oximeter, even when the string value is fixed at compile-time --- for
    example, when an enum is used to generate a metric label with
    `&'static str` values, they must be alloced into new `String`s to record
    the metric.
    
    This commit changes `FieldValue::String` from holding a `String` to
    holding a `Cow<'static, str>`, so that static string constants need not
    be heap-allocated.
    hawkw committed Apr 30, 2024
    Configuration menu
    Copy the full SHA
    1b5d618 View commit details
    Browse the repository at this point in the history
  2. [oximeter] use Cow<'static, str> in self-stats

    This commit changes Oximeter's `self_stats` module to use `Cow<'static,
    str>` to represent the field value generated by the `FailureReason`
    enum. This way, a heap-allocated string is only necessary for
    dynamically formatted variants (the `FailureReason::Other` variant,
    which owns an HTTP `StatusCode`). For the `FailureReason::Unreachable`
    and `FailureReason::Deserialization` variants, we can just emit a
    `&'static str` without allocating. Hopefully, this reduces resident
    memory for the collector process somewhat when encountering a lot of
    failures.
    hawkw committed Apr 30, 2024
    Configuration menu
    Copy the full SHA
    d191278 View commit details
    Browse the repository at this point in the history
  3. whoops i missed one

    hawkw committed Apr 30, 2024
    Configuration menu
    Copy the full SHA
    a84e072 View commit details
    Browse the repository at this point in the history