Commit Graph

18 Commits

Author SHA1 Message Date
Gustavo Cairo e8bced74bc
Propagate displayUnit when using MultiplexMetricsHandler (#122) 2023-02-01 11:42:39 -08:00
Fabian Fett 53be78637e
Remove testable import from TestMetrics. (#113) 2022-07-20 17:25:45 +09:00
tomer doron d885a4f5e9
adopt sendable (#109)
motivation: adjust to swift 5.6

changes:
* define sendable shims for protocols and structs that may be used in async context
* refactor Gauge to include rather than inherit Recorder
* adjust tests
* add a test to make sure no warning are emitted
2022-07-01 16:38:50 -07:00
Rauhul Varma 2c58b010a2 remove assertions 2021-08-16 11:49:56 +09:00
Rauhul Varma 42372a8598 Introduce FloatingPointCounter
motivation: It is not currently possible to record floating point values via the swift-metrics API even if the metrics backend supports it.

modifications: Adds a `FloatingPointCounter` type to allow users to accumulate non-integral metrics backed by a `FloatingPointCounterHandler`. Introduces a default implementation for creating and destroying `FloatingPointCounterHandler`s for metric backends that do not natively support floating point counters. On such backends, `FloatingPointCounter` is backed by a `AccumulatingRoundingFloatingPointCounter` which accumulates floating point values internally and record increments to a wrapped `CounterHandler` after crossing integer boundaries.

result: Users can create `FloatingPointCounter`s to record floating point values and get enhanced behavior for backends that support floating point values.
2021-08-16 11:49:56 +09:00
Konrad `ktoso` Malawski 5702ee1174
metrics should include their labels when printed to ease debugging (#82)
motivation: ease debugging

changes: confirm metrics types to CustomStringConvertible
2020-10-08 15:08:43 -07:00
Nathan Harris 8e5110dcd6 Add `Timer.recordNanoseconds` Generic Overload (#28) (#30)
Motivation:

As discussed in Issue #28, there are a few preferred lightweight APIs for getting timestamps such as `DispatchTime` but those APIs return `UInt64` types, which need to be handled for overflow.

Modifications:

Added a generic `BinaryInteger` overload method for `recordNanoseconds` that guards against accidental overflows from `UInt64` to `Int64`

Result:

Users now have access to a new method to record nanosecond measurements with `Timer` that guards against overflows.
2019-05-25 21:36:56 -07:00
Nathan Harris e4883dab79 Add guards for Int64 overflow in `Timer` methods (#29)
Motivation:

`Timer.record*` methods are generic to cover all cases of `BinaryInteger` values and converts the passed value into `Int64` before doing time unit conversions and overflow checks.

Modifications:

All methods that accept `BinaryInteger` types and converts to `Int64` now guards against values higher than `Int64.max`

Result:

Users can reliably use the `Timer.record*` APIs with `BinaryInteger` types without concern for unknowing fatal errors.
2019-05-24 22:41:41 -07:00
tomer doron 6db51d5f32
overflow (#19)
motivation: highlight the need to address overflow in metric objects that are integer based

changes:
* add section in the readme about addressing woverflow
* fix timer's unit conversion to address potential overflow
2019-04-22 09:47:46 -07:00
Konrad `ktoso` Malawski d9f63df00c Introduce metric.destroy() to enable lifecycle management (#17)
motivation: allow middleware libraries better control of metric object lifecycle to reduce potential memory footprint when using metrics libraries that use some kind of registry or cache (eg polling backends)

changes:
* Introduce metric.destroy() to enable lifecycle management
* Add destroy functions to example impl in readme
2019-04-19 10:33:58 -07:00
tomer doron 4729bac3a1
rename Counter::increment "value" parameter to "by" (#4)
* rename Counter::increment "value" parameter to "by"

motivation: nicer API signature

changes: rename Counter::increment and  CounterHandler::increment "value" parameter to "by"
2019-04-08 19:59:15 -07:00
tomer doron 187653d466
address feedback (#13)
motivation: address feedback from community, prepare for moving api to official repo

changes:
* add reset method to counter
* do not force the user facing metric object to implement the mteric handler protocol. this was done for convinience and confuses matters
* adjust tests
* fix a few typos
2019-04-05 07:28:52 -07:00
tomer doron 1f44332af3
refactor APIs to make them closer to swift-log APIs
motivation: after much discussion around logging API, we settled on a different API style, primairly the fact that we will use initializers instead of factories

changes:
* introduce intermediate classes for Counter, Timer and Recorder which are designed to replace the Metrics.makeCounter, Metrics.makeTimer and Metrics.makeRecorder APIs and wrap corresponding CounterHandler, TimerHandler and ReorderHandler coming from the metrics implmentation
* rename Metrics to MetricsSystem
* rename  MetricsHandler -> MetricsFactory
* remove Metrics.withCounter, Metrics.withTimer and Metrics.withRecorder syntactic sugar
* rename Metrics.timed with Timer.measure
* make sure metrics system can only be initialized/bootstrapped once per process
* adjust and add tests
* add a bit of docs on key APIs
2019-02-25 15:04:43 -08:00
tomer doron 2953390316
remove CachingMetricsHandler
motivation: CachingMetricsHandler represents an optimization that is better handled by implementations than dictated by the API

see: https://forums.swift.org/t/discussion-server-metrics-api/19600/2?u=tomerd

changes:
* remove CachingMetricsHandler
* adjust tests
2019-02-24 18:03:07 -08:00
tomer doron 02eeee08d9 license 2019-02-21 19:47:50 -08:00
tomer doron 9907101ff8 format 2019-01-14 02:00:18 -08:00
tomer doron da46fbb762 better caching
motivation: better metrics cache, seperate mutex per type

changes:
* seperate mutex per metric type
* more tests
2019-01-11 10:51:57 -08:00
tomer doron d01123e590 initial commit 2019-01-08 13:25:21 -08:00