Commit Graph

69 Commits

Author SHA1 Message Date
Honza Dvorsky 98d36172c1
Allow providing a custom MetricsFactory to Counter and friends (#172)
### Motivation:

To allow for things like parallel testing, it'd be useful if we can
explicitly provide a MetricsFactory to the existing Counter/... types.

### Modifications:

Added a `factory: MetricsFactory` parameter to all the initializers of
Counter/... types, and kept the existing methods that continue to
default to `MetricsSystem.factory`.

### Result:

Adopters can use a custom MetricsFactory explicitly passed in at metric
creation time. Existing adopters are not affected, unless you opt in,
you continue to use the global factory.
2025-04-29 15:07:30 +02:00
Franz Busch 44491db7cc
Fix 5.10 compile on Ubuntu 24.04 (#168)
Specifically Swift 5.10 on Intel on Ubuntu Noble (24.04) has a crazy bug
which leads to compilation failures in a #if compiler(>=6.0) block:
swiftlang/swift#79285 .

This workaround fixes the compilation by changing the whitespace.

Fixes https://github.com/apple/swift-metrics/issues/166
2025-03-18 16:21:52 +01:00
Franz Busch 3c0f419970
Add `Timer.measure` methods (#140)
# Motivation

This PR supersedes https://github.com/apple/swift-metrics/pull/135. The
goal is to make it easier to measure asynchronous code when using
`Metrics`.

# Modification

This PR does:
- Deprecate the current static method for measuring synchronous code
- Add a new instance method to measure synchronous code
- Add a new instance method to measure asynchronous code
2025-03-10 10:46:27 +01:00
Cory Benfield 58f390a873
Tell the truth about the supported metric types (#161)
Our README claims we support 4 metric types, and then lists five. But it
fails to list FloatingPointCounter, which we also support, so the real
number is six.

While I was here I also fixed the DocC topic, which omitted
FloatingPointCounter from the list of metrics but _also_ omitted Gauge
for some weird reason.
2025-01-31 14:31:14 +00:00
Marc Prud'hommeaux 5e63558d12
Android support (#159)
This PR makes the single `import Android` addition that is needed to get
this package building for Android. `skip android test` passes against
the emulator after I made this one change.
2025-01-09 22:49:28 +01:00
Rick Newton-Rogers d720898dbf
Migrate to GitHub Actions (#151) 2024-11-06 22:32:20 +09:00
Gustavo Cairo e0165b53d4
Fix Sendability warnings (#137)
* Fix Sendability warnings

* Apply suggestions from code review

* Fix another warning and @unknown default issue

---------

Co-authored-by: Konrad `ktoso` Malawski <konrad.malawski@project13.pl>
2024-06-21 17:18:13 +01:00
Franz Busch d067b0e0f7
Add missing `Sendable` annotations (#148)
# Motivation
We were missing a few `Sendable` annotations on our public types.

# Modification
This PR adds `Sendable` to the missing types.
2024-06-21 05:40:32 +09:00
Konrad `ktoso` Malawski ce594e71e9
fix availability of record(:Duration) API (#146) 2024-05-15 18:08:10 +09:00
hamzahrmalik 0124d9ad5c
Change Timer.record(duration: Duration) signature to avoid source breakage (#144) 2024-05-15 14:36:25 +09:00
Si Beaumont eb18581491
Support compiling against Musl (#142)
Co-authored-by: Konrad `ktoso` Malawski <konrad.malawski@project13.pl>
2024-05-14 13:16:51 +09:00
Si Beaumont 33d3f71e00
Update API breakage CI script (#143)
* Update API breakage CI script

* restate sendable conformance to avoid warning/as-error

---------

Co-authored-by: Konrad `ktoso` Malawski <konrad_malawski@apple.com>
2024-05-14 13:09:54 +09:00
Franz Busch 7e53749103
Align supported Swift versions with rest of the ecosystem (#141)
# Motivation

Most of the server ecosystem follows the supported Swift versions from `swift-nio`. This means supporting the latest 3 Swift releases.

# Modification

This PR drops support for all Swift versions before 5.8.

# Result

This makes maintaining this repository easier and allows us to clean up some no longer needed stuff.
2024-05-09 11:19:06 +09:00
Natik Gadzhi 13ea1fe7fc
Introducing Timer.record(_ duration:), closes #114 (#133)
Motivation:

`Duration` is available starting Swift 5.7, and we
should probably support it in our convinience API.

Modifications:
- Timer.record(_ duration: Duration) implementation
- A unit test case
- Generated Linux tests
2023-06-28 14:56:55 -07:00
tomer doron 971ba26378
add increment and decrement public API to Meter (#132)
motivation: expose increment and decrement public APIs

changes:
* add increment and decrement public API to Meter
* improve the implementation of AccumulatingMeter and TestMeter
* add tests for new APIs
* refactor/modernize other tests
2023-06-21 14:15:23 -07:00
hamzahrmalik 3402510406
Make 'values' on TestCounter, TestRecorder and TestMeter public (#129)
Co-authored-by: Hamzah Malik <hamzah_malik@apple.com>
2023-05-26 14:49:59 +02:00
hamzahrmalik 8bcdb6e82b
MetricsTestKit: expose all metrics publicly. This allows users to run checks on counters when they might not know the exact label (#127)
Co-authored-by: Hamzah Malik <hamzah_malik@apple.com>
2023-05-26 14:02:46 +02:00
hamzahrmalik 9d5ff3d48f
Use the MetricsTestKit in the MetricsTests rather than using a copy of the TestMetrics utilities (#128)
Co-authored-by: Hamzah Malik <hamzah_malik@apple.com>
2023-05-26 13:25:08 +02:00
tomer doron 32eef8ae84
add "meter" - a new type of metric and metric handler (#123)
motivation: seperate gauge from recorder in a backwards compatible way

changes:
* add new meter and meter handler pair
* add increment and decrement to meter handler
* add default implementation based on recorder for backwards compatibility
* add and adjust tests
2023-05-24 13:55:56 -07:00
Fabian Fett 78b6238009
Use UUID instead of NSUUID in MetricsTests (#126) 2023-05-05 11:01:45 +09:00
Gustavo Cairo e8bced74bc
Propagate displayUnit when using MultiplexMetricsHandler (#122) 2023-02-01 11:42:39 -08:00
Konrad `ktoso` Malawski bcea8c19fe
+docc prepare for docc publishing (#118)
* +docc prepare for docc publishing

* fix test discovery on 5.5 and 5.6

* Delete Package@swift-5.6.swift

* Update Package.swift

* Apply suggestions from code review

Co-authored-by: Yim Lee <yim_lee@apple.com>

Co-authored-by: Yim Lee <yim_lee@apple.com>
2022-08-24 11:20:06 +09:00
Fabian Fett bd1b935c8e
Make `MetricsFactory` Sendable (#116) 2022-07-21 10:53:47 +09: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
tomer doron fd0ee6956b
better abstration for MetricsSystem state (#112)
motivation: prepare for sendable checks (they dont work well with static state)

changes:
* abstract the MetricsSystem state into a "boxed" class that handles the locking
* adjust call sites
2022-06-29 11:08:12 -07:00
Konrad `ktoso` Malawski eadb828f87
Import TestMetrics from swift-metrics-extras (#106)
* Import TestMetrics from swift-metrics-extras

* support the year 2021

* rename module
2022-03-18 12:02:04 +09:00
Rauhul Varma 3edd2f57af update comment 2021-08-16 11:49:56 +09: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
Jari (LotU) e382458581 Remove reader lock 2020-11-12 18:10:16 +09:00
Jari (LotU) 2b6e31e1b3 Expose lock functionality 2020-11-12 18:10:16 +09:00
Konrad `ktoso` Malawski f5ed78cb26 =core remove not used import (Dispatch) 2020-10-13 10:39:24 +09:00
Moritz Lang 44e8bfc7f5
Add Timer.recordInterval method (#83)
* Add Timer.recordInterval method

Co-authored-by: Konrad `ktoso` Malawski <ktoso@apple.com>
2020-10-12 12:18:21 -07: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
tomer doron 41d2db7675
update ci setup (#67)
motivation: 5.2 adoption, prepare for 5.3

changes:
* add 5.2 docker-compose setup
* add 5.3 docker-compose setup (placeholder)
* remove 4.2 docker-compose setup
* format
2020-04-03 19:50:13 -07:00
tomer doron 708b960b46
Add microseconds to TimeUnit (#64)
Motivation:
I have a metrics backend where I need to store timer values in
microseconds. The "preferred display unit" models this exactly, but it
seems to have (inadvertently?) omitted the possibility to express
microseconds. Note that among the timer "report" methods there is
already a microseconds option.

Changes:
* change TimeUnit from enum to struct with static members to support non-api breaking future evolution 
* add scaleFromNanoseconds to TimeUnit to make it easy to compute the values without switching over
* add tests

Co-authored-by: Chris Burrows <cburrows@gmail.com>
2020-03-03 17:51:39 -08:00
Christian Priebe 09b72f68ed
Improve precondition error messages in Lock functions (#58)
This commit adds error messages to the precondition checks in Lock functions
that state the action that failed as well as the OS error code.
2020-02-10 11:15:04 -08:00
Christian Priebe f1514a4c74
Bugfix: Print correct error message if bootstrap is called multiple times (#57)
MetricsSystem.bootstrap verifies that the metric system has not been previously
initialized. Otherwise it should fail with a corresponding error message. The
precondition error message includes the name of the currently used factory and
for that accesses self.factory. However, because bootstrap already holds
self.lock as a writer lock, self.factory fails to get it as a reader and
crashes with a less useful precondition error message. This commit ensures that
the correct error message is printed.
2020-02-10 11:11:28 -08:00
tomer doron 998de4b2cf better format
motivation: adjust format to xcode format

changes:
* update .swiftformat no-indent setting and run formatter
* update test generation script to match correct format
2019-12-18 12:14:01 +09:00
MrLotU 49431459f9 Update Timer.measure() to use DispatchTime instead of Date 2019-11-11 09:39:33 +09:00
Jari (LotU) 3fefedaaef TimeUnits (#42)
motivation: some metrics backend prefer to be given a hint about the preferred display unit (seconds, milliseconds, etc) to drive the ux 

changes: add a `preferedUnit` to TimerHandler (and `TimeUnits`) to capture the prefer display unit
2019-09-09 09:53:03 -07:00
Konrad `ktoso` Malawski e0ec4aea36 define record() more explicitly that it is a "set the value" (#35)
motivation: define record() more explicitly that it is a "set the value" operation as it seemed to be confusing when implementing or using the API.

changes: update API docs accordingly
2019-07-30 14:55:38 -07:00
tomer doron 25c2c17b45 test formatting issues as part of sanity check
motivaiton: unified format

changes:
* use official docker image 🎉
* fix outstanding formatting issues
* add a call to swiftformat as part of sanity script
* fix sanity script language check debugging statements
2019-07-30 14:10:30 +09:00
Konrad `ktoso` Malawski c7bbb2c55f Docs #26 shuffle around definitions to show user API first (#31) 2019-07-09 16:43:48 +01: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
Konrad `ktoso` Malawski 4a9e0de637
doc: #26 clarify which init to use, reformat docs for easier noticing this (#27)
* doc: #26 clarify which init to use, reformat docs for easier noticing this

* Mark all "we do not expect this API to be used in normal..." as warnings
2019-05-25 14:33:16 +09:00
Yim Lee e7de07004c Fix API documentation (#24)
Motivation:

API documentation contains typos and grammatical errors.

Modifications:

Fix typos and grammatical errors. Update to use code syntax where
appropriate.

Result:

Eliminate typos and grammatical errors found.
2019-04-24 22:54:53 -07:00
tomer doron b017e02759
add note about convergence tag (#20)
motivation: starting convergence period for swift-metrics 1.0.0 release

changes:
* add info in readme about the convergence phase/version
* format
2019-04-22 10:20:44 -07:00