77 Commits
Author SHA1 Message Date
BlindSpot e940f68c3a fix(patch): [sc-1297] use lock for subsummary to get its values 2023-05-26 19:10:09 +03:00
Sam Amin 022c317f5f Fixed Histogram Concurrency Issue
Issue:
In Histogram, some values were being dropped when the histogram is accessed concurrently by multiple threads.

Fix:
In getOrCreateHistogram, the code was copying the dictionary into a local variable, and checking it for the label without a lock. If not there, it would take the lock again to add it. But in line 224, after taking the lock again, it was rechecking the local variable, which of course would not have changed in the meantime. But the original dictionary could have changed, and that's the one we should check the second time.

Improved the concurrency test, as it was missing the bug by only checking the total count and sum without labels.
2022-10-17 11:41:11 +01:00
Fabian Fett 34b9687eb1 Remove unused weak references 2022-08-29 16:32:52 +02:00
Rauhul Varma 3360680fd1 Add missing availability annotations
- Adds missing availability annotations for async functions to allow
  swiftprometheus to compile for other apple platforms.
2022-06-23 16:25:29 -07:00
688e1fd540 Release 1.0.0 (#69)
* Sanitize Dimensions (#68)

* Add failing test for sanitising dimension

* Fix test

* Add new DimensionsSanitizer

* Remove labels parametrisation (#63)

* Stop leaking 'le', 'quantile' in Summary/Histogram labels, remove labels parametrisation

* chore: Remove base labels protocol and add ExpressibleByArrayLiteral

* chore: Cleanup documentation. Remove deprecations

Co-authored-by: Jari (LotU) <j.koopman@jarict.nl>

* Add async/await APIs (#67)

* Add async/await APIs

* Revert unrelated change

* Add #if swift for 5.2

* Fix Swift version number check

* Add task API

Co-authored-by: Tim Condon <0xTim@users.noreply.github.com>
Co-authored-by: Anton <avolokhov@apple.com>
2022-06-20 13:33:40 +02:00
Anton Volokhov 0d1cb7ca3f fix display unit 2021-09-02 00:20:25 +01:00
Anton ba329daafa move labels equality check out of critical section in summary/histogram (#61)
* move labels equality check out of critical section in summary/histogram

* preconditions, addressing review comments
2021-08-31 10:25:09 +02:00
AntonandJari 196573e2f9 make metrics collection independed from metrics creation (#60)
Co-authored-by: Jari (LotU) <j.koopman@jarict.nl>
2021-08-24 10:35:50 +02:00
Anton b31a6e6d09 Finer concurrency in 'MetricType.observe' / 'MetricType.collect' (#59)
* finer concurrency when collecting metrics

* better concurrency for 'PromHistogram.observe'

* make subHistograms a map
2021-08-24 10:33:21 +02:00
MrLotU 354fa7e939 Merge branch 'master' into feature/floating-point-counter 2021-08-16 12:15:17 +02:00
Mikhail Akopov e85499c759 Introduce PromSummary.capacity to improve performance (#57)
* Introduce PromSummary.capacity to improve performance

* Add a test for summary with custom capacity

* Use Deque instead of Array to store summary values

* Revert "Use Deque instead of Array to store summary values"

This reverts commit 1dd8c32f1a.

* Use CircularBuffer instead of Array to store summary values

* Slightly improve wording in comments
2021-08-05 13:00:05 +02:00
MrLotU daf102f0c9 Fix label equality issue 2021-08-02 14:01:43 +02:00
MrLotU 475dc0dfe3 Add floating point counter 2021-08-02 12:38:59 +02:00
Rauhul VarmaandJari 1478fd9939 Fix various misspellings (#53)
Co-authored-by: Jari (LotU) <j.koopman@jarict.nl>
2021-07-30 12:05:26 +02:00
Rauhul Varma d642556913 Reduce allocations (#54)
- Updates DimensionLabels' Equatable and Hashable conformances to avoid
  allocating unnecessary strings. Updates DimensionHistogramLabels and
  DimensionSummaryLabels to use DimensionLabels internally and removes
  manually implemented protocol conformances.
2021-07-30 12:02:51 +02:00
George Barnett 3caacd3226 Perf improvements (#50)
Motivation:

Metrics collecting systems should be efficient enough so that their
impact on the system being instrumented is negligible.

Modifications:

- Store `PromMetric`s in a dictionary keyed by label in
  `PrometheusClient`; this gives fast lookup when checking if a metric
  already exists
- Remove the `metricTypeMap`, we can recover the same information from
  `PromMetric`
- Remove calls to `getMetricInstrumet` in `PrometheusMetricsFactory`
  these were redundant as the same check is done in `createCounter` etc.
- In each `createCounter` (etc.) call we now hold the lock for the
  duration of the call to avoid races between checking the cache and
  creating and storing a new metric.
- The `PrometheusLabelSanitizer` now checks whether input needs
  santizing instead of santizing all input
- Sanitizing is done in one step, mapping each utf8 code point to a
  sanitized code point rather than lowercasing and then checking the
  validity of each character.

Result:

- Sanitizing pre-sanitized labels is ~100x faster
- Sanitizing non-sanitized label is ~20x faster
- Incrementing 10 counters is ~20x faster
- Incrementing 100 counters is ~40x faster
- Incrementing 1000 counters is ~250x faster
- (Similar results for other metrics.)
2021-05-26 12:50:06 +02:00
Jari (LotU) 42edfe0c38 Add fix and test for MetricsSystem.prometheus() (#49) 2021-05-04 09:23:21 +02:00
Anton a5671bad70 Histogram backed timer (#46)
* implement histogram backed timer

* hide timer implementation enum; namespace PrometheusMetricsFactory classes

* address review

* fix test testHistogramBackedTimer_scaleFromNanoseconds

* address PR review comments
2021-04-30 11:51:05 +02:00
AntonandJari 8fb92e78be fix Buckets helpers to not throw fatal error (#41)
* fix Buckets to not throw fatal error

* fix compiler warning

* simplify linear buckets creation

Co-authored-by: Jari (LotU) <j.koopman@jarict.nl>
2021-03-10 15:42:59 +01:00
AntonandJari f4d4adfeb1 make labels classes public to allow users to create their own prometheus classes (#42)
Co-authored-by: Jari (LotU) <j.koopman@jarict.nl>
2021-03-10 15:32:17 +01:00
Anton fb378fd56f New line in reporter (#43)
* fix collection to strign

* make collection into string consistent with collection into buffer
2021-03-10 15:29:23 +01:00
Konrad `ktoso` Malawski 970bd317ca Remove CoreGraphics (#35)
* -remove CoreGraphics

* Update Utils.swift
2020-11-11 10:10:59 +01:00
Matias Villaverde fa3d278e14 Prevent the compiler finding the wrong CGFloat (#34) 2020-05-20 09:04:43 +02:00
Jari (LotU)andKonrad `ktoso` Malawski 938b2a29be Add LabelSanitizers (#32)
* Add s

* Add docs

* Update Sources/Prometheus/PrometheusMetrics.swift

Co-Authored-By: Konrad `ktoso` Malawski <konrad_malawski@apple.com>

* Remarks

Co-authored-by: Konrad `ktoso` Malawski <konrad_malawski@apple.com>
2020-04-22 09:23:39 +02:00
tdotclare d7e25d93f5 Update SwiftPrometheus to use SwiftMetric 2.* (TimeUnit change to struct) (#31)
* Update SwiftPrometheus to use SwiftMetric 2.* SemVer (TimeUnit def change)

* Update Package.swift

* Update SummaryTests.swift

* Update Summary.swift
2020-03-25 09:33:48 +01:00
Jari (LotU) 275d379fb4 Get summary up to spec (#26)
* Get summary up to spec

* Update linuxmain
2020-01-15 23:05:42 +01:00
Jari (LotU) 48b181744a Get Gauge up to spec (#27)
* Get Gauge up to spec

* Update wording remarks
2019-12-04 16:34:59 +01:00
Jari (LotU)andKonrad `ktoso` Malawski 96cb1a3a33 Get Histogram up to Prometheus spec (#25)
* Add Histogram bucket generation methods

* Make buckets a separate type

* Linux tests

* Make buckets ExpressibleByArrayLiteral

* Add histogram.time()

* Use DispatchTime.now().uptimeNanoseconds instead of Date()

* Apply suggestions from code review

Co-Authored-By: Konrad `ktoso` Malawski <konrad_malawski@apple.com>

* Fix final review remarks
2019-11-21 11:20:23 +01:00
Jari (LotU)andJoe Smith f3acccc876 Timer units (#17)
* package.resolved

* WIP: Implement Time Units

* Wrap tests & Up NIO version

* Apply suggestions from code review

Co-Authored-By: Joe Smith <yasumoto7@gmail.com>

* Update linux tests
2019-10-17 15:50:51 +02:00
Joe Smith b6e38ea8db Do not recreate a new counter if we already have one. (#13)
* Do not recreate a new counter if we already have one.

* Apply across the board

* Newline for CI

* Newline for CI
2019-09-30 14:11:46 +02:00
Konrad `ktoso` Malawski ece301fda9 Fix missing newline between metrics when collecting #15 (#16)
* Fix missing newline between metrics when collecting

Resolves #15

* Newline for CI

* Newline for CI
2019-09-29 13:56:13 +02:00
Jari (LotU) 01b4acc136 Get metric promises (#12)
* Update to promises

* Minor cleanup

* NIO 2

* Byte Buffers & no promises

* Move ByteBuffer methods to extensions and (temp) remove Swift 4 tests

* NIO Bump & docs

* Add some helpers & update test wording
2019-08-27 10:50:10 +02:00
Joe Smith 26128570e3 Merge Prometheus and PrometheusMetrics so we're only using one library instead of two 2019-07-10 14:54:42 -07:00
Konrad `ktoso` Malawski dbcfd45cf7 Fix typos in doc comments 2019-07-08 10:50:50 +09:00
MrLotU bb6db844c3 Remove docs & update getMetrics() 2019-07-05 10:03:37 +02:00
MrLotU cb00e4a00c Fixup tests & NIO version 2019-07-04 16:50:59 +02:00
MrLotU 984e26de67 Address comments 2019-07-04 14:27:57 +02:00
MrLotU f903e88617 support 4.2 2019-06-07 17:25:09 -07:00
MrLotU cd98111e9b Tests! 🎉
Finalize

Final docs update

Remove info
2019-06-07 17:10:07 -07:00
MrLotU da8082a2bb Make some things private 2019-06-07 17:08:27 -07:00
MrLotU b59fd7ed06 WIP 2019-06-07 17:08:15 -07:00
MrLotU 12a55f1567 Update a whole buch of things & 100% doc coverage
Signed-off-by: MrLotU <j.koopman@jarict.nl>
2019-06-07 17:08:14 -07:00
MrLotU 037582f68f .
Signed-off-by: MrLotU <j.koopman@jarict.nl>
2019-06-07 17:08:14 -07:00
MrLotU b87006baff Minor update
Signed-off-by: MrLotU <j.koopman@jarict.nl>
2019-06-07 17:08:14 -07:00
MrLotU ac83a7af30 Rebase 2019-06-07 17:06:08 -07:00
Joe Smith 20e7fc7438 Review fixups 2019-04-16 10:45:36 -07:00
Joe Smith b6fd495e65 Review feedback 2019-04-15 10:26:29 -07:00
Joe Smith dbbf9505cd Show off the problem with dual-writing metrics from one function call.
We might want to instead break this out into two separate functions— one that takes a label, the other that doesn't. That might allow us to then properly pass the callback and only call it once when everything is done.
2019-04-07 11:53:00 -07:00
Joe Smith 04e4d4857d Code review feedback 2019-04-07 11:42:08 -07:00
Jari (LotU)andYasumoto 6b53a9d9a7 Update Sources/Prometheus/MetricTypes/Summary.swift
No need to name closure arguments

Co-Authored-By: Yasumoto <yasumoto7@gmail.com>
2019-04-07 09:54:29 -07:00