Commit Graph

601 Commits

Author SHA1 Message Date
Bartlomiej Plotka 6f576e2c6f
histogram docs: Fixed minor nit. (#1324)
Signed-off-by: bwplotka <bwplotka@gmail.com>
2023-08-13 14:11:06 +01:00
Arthur Silva Sens 1a88780343
Bump prometheus/client_model (#1323)
By upgrading prometheus/client_model, several test functions had to be re-written due to 2 breaking changes made in protobuf when parsing messages to text:
1. '<' and '>' characters were replaced with '{' and '}' respectively.
2. The text format is non-deterministic. More information in https://github.com/golang/protobuf/issues/1121

Signed-off-by: Arthur Silva Sens <arthur.sens@coralogix.com>
2023-08-11 20:17:55 +01:00
Kemal Akkoyun 06d4592b1c
Add Go 1.21 support (#1325)
* Add Go 1.21 support

Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>

* Update README.md

Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>

---------

Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>
2023-08-11 12:27:52 +02:00
Chris Banks f16b435f04
docs: trivial grammar fixes to improve readability
Fix a few typos / grammatical errors in the Godoc comments for promauto.
Only trivial stuff but slightly helps readability of the docs.

Signed-off-by: Chris Banks <chris.banks@digital.cabinet-office.gov.uk>
2023-08-05 11:41:47 +01:00
Tiago Silva 59c00e3e9c
Fix data-race in metric without code and method but with `WithLabelFromCtx` (#1318)
This commit fixes a data race that exists when the metric used in any
`promhttp` middleware doesn't collect the `code` and `method` but uses
`WithLabelFromCtx` to collect values from context.

The problem happens because when no `code` and `method` tags are
collected, the `labels` function returns a pre-initialized map
`emptyLabels` for every request.

When one or multipe `WithLabelFromCtx` options are configured, the
returned map from the `labels` function call is used to collect the
metrics from context which creates a multi-write data race.

Signed-off-by: Tiago Silva <tiago.silva@goteleport.com>
2023-08-01 17:11:17 +01:00
beorn7 3d82c94432 histogram: Add a no-op span for an otherwise empty histogram
Fixes #1127.

If a native histogram has no observations and a zero threshold of
zero, then it is indistinguishable from a classic histogram. To give
scrapers a hint that it is indeed a native histogram, we add a no-op
span.

This needs follow-up PRs in prometheus/prometheus and
prometheus/client_model.

Signed-off-by: beorn7 <beorn@grafana.com>
2023-07-20 17:34:00 +02:00
beorn7 f9db3821a8 histograms: Small code comment and code formatting improvements
Signed-off-by: beorn7 <beorn@grafana.com>
2023-07-20 16:13:28 +02:00
Quentin D 644c80d136
Do not allocate memory when there's no constraints (#1296)
Signed-off-by: Quentin Devos <4972091+Okhoshi@users.noreply.github.com>
2023-06-27 12:21:36 +01:00
Bartlomiej Plotka 2feda42e44
Fixed README & CHANGELOG; Added fmt makefile command (+bingo) for easier contributions. (#1289)
* Fixed README; Added fmt command for easier contributions.

Signed-off-by: bwplotka <bwplotka@gmail.com>

* Updated golint.

Signed-off-by: bwplotka <bwplotka@gmail.com>

* Update Makefile

Co-authored-by: Kemal Akkoyun <kakkoyun@users.noreply.github.com>
Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>

---------

Signed-off-by: bwplotka <bwplotka@gmail.com>
Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
Co-authored-by: Kemal Akkoyun <kakkoyun@users.noreply.github.com>
2023-06-13 14:54:49 +01:00
Julius Volz 1b19d5f458 Fix docstring references to renamed native histogram fields / functions.
Signed-off-by: Julius Volz <julius.volz@gmail.com>
2023-06-13 10:36:40 +02:00
Aviv Litman e4ff34d23e
Improve metricUnits runtime (#1286)
We tested this function runtime in both cases using "testing",
and the runtime for this pr is much shorter.

Signed-off-by: alitman <alitman@redhat.com>
2023-06-08 11:35:32 +01:00
Bulat Khasanov a09a1d34cb
Reduce constrainLabels allocations (#1272)
* Add bench

Signed-off-by: Bulat Khasanov <afti@yandex.ru>

* Reduce constrainLabels allocations

Signed-off-by: Bulat Khasanov <afti@yandex.ru>

---------

Signed-off-by: Bulat Khasanov <afti@yandex.ru>
2023-06-07 08:39:02 +01:00
Björn Rabenstein 5e78d5f66b
Merge pull request #1279 from prometheus/beorn7/histogram
Fix bug in bucket key calculation
2023-05-29 00:09:18 +02:00
Han Kang b8cb86a865
add process start time header to client_golang prometheus (#1278)
* add process start time header to client_golang prometheus

Signed-off-by: Han Kang <hankang@google.com>

* Apply suggestions from code review

Co-authored-by: Bartlomiej Plotka <bwplotka@gmail.com>
Signed-off-by: Han Kang <hankang@google.com>

* fix up changes due to incorporation of feedback

* fix lint issues

---------

Signed-off-by: Han Kang <hankang@google.com>
Co-authored-by: Bartlomiej Plotka <bwplotka@gmail.com>
2023-05-26 12:58:36 +01:00
beorn7 77e97da564 histogram: Fix bug in bucket key calculation
The current code doesn't work fork negative schemas if the observed
value should go into a bucket with a non-positive key.

Signed-off-by: beorn7 <beorn@grafana.com>
2023-05-25 19:03:43 +02:00
beorn7 30948120dc histogram: expose bug in bucket key calculation
The current code doesn't work fork negative schemas if the observed
value should go into a bucket with a non-positive key.

Signed-off-by: beorn7 <beorn@grafana.com>
2023-05-25 19:02:28 +02:00
Kemal Akkoyun f51d823bda
Merge pull request #1267 from prometheus/release-1.15
Merge release 1.15.1 to main
2023-05-17 11:37:25 +02:00
Ben Kochie 8a51463540
Cleanup proto use in tests (#1264)
Switch tests over to new proto libary, eliminating the direct dependency
on the old proto library. Note the indirect requirement is still needed
due to upstream use by the client_model package.

Related: https://github.com/prometheus/client_golang/issues/1175

Signed-off-by: SuperQ <superq@gmail.com>
2023-05-03 09:46:41 +01:00
bwplotka b8fdd239b2 Added clarification.
Signed-off-by: bwplotka <bwplotka@gmail.com>
2023-05-03 09:41:34 +01:00
bwplotka 2ea234eef0 Revert "Remove unnecessary check if label is nil in observeWithExemplar (#1235)"
This reverts commit 3ce88f33d1.

Signed-off-by: bwplotka <bwplotka@gmail.com>
2023-05-03 09:41:26 +01:00
Max Coplan c36c6abb8d
[collectors]: fix typo in test assertion (#1153)
Signed-off-by: Max 👨🏽‍💻 Coplan Max.Coplan@walmart.com

Signed-off-by: Max 👨🏽‍💻 Coplan Max.Coplan@walmart.com
Co-authored-by: Max 👨🏽‍💻 Coplan <Max.Coplan@walmart.com>
2023-04-17 21:35:49 +01:00
Daria Bialobrzeska eb339714f5
Filter expected metrics as well in CollectAndCompare (#1143)
* Filter expected metrics as well in CollectAndCompare

Signed-off-by: Daria Danilenko <daria.danilenko@fluxninja.com>

* Add testcase for multiple expected metrics
Signed-off-by: Daria Danilenko <daria.danilenko@fluxninja.com>

* Change test values for filtering multiple expected metrics
Signed-off-by: Daria Danilenko <daria.danilenko@fluxninja.com>

---------

Signed-off-by: Daria Danilenko <daria.danilenko@fluxninja.com>
2023-03-22 10:45:45 +00:00
Bartlomiej Plotka e79d7e71ce
timer: Added support for exemplars. (#1233)
Signed-off-by: bwplotka <bwplotka@gmail.com>
2023-03-21 19:35:31 +00:00
Bartlomiej Plotka 232b949d1f
Added support for go 1.20. (#1234)
Signed-off-by: bwplotka <bwplotka@gmail.com>
2023-03-21 13:46:37 +00:00
dimonl 3ce88f33d1
Remove unnecessary check if label is nil in observeWithExemplar (#1235)
* Remove unnecessary check if label is nil in observeWithExemplar instrumentation

Signed-off-by: dlituyev <dlituyev@slb.com>

* Remove unnecessary check if label is nil in observeWithExemplar instrumentation

Signed-off-by: dlituyev <dlituyev@slb.com>

---------

Signed-off-by: dlituyev <dlituyev@slb.com>
Co-authored-by: dlituyev <dlituyev@slb.com>
2023-03-20 10:23:36 +01:00
Jon Kartago Lamida 3d2cf0b338
Indent example in godoc consistently (#1226)
* Indent example in godoc consistently

Signed-off-by: Jon Kartago Lamida <me@lamida.net>

* Add missed one line indentation fix

Signed-off-by: Jon Kartago Lamida <me@lamida.net>

---------

Signed-off-by: Jon Kartago Lamida <me@lamida.net>
2023-03-01 16:45:01 +00:00
songjiayang 2771bcc5da
Add `Header` method to Pusher for custom header (#1218)
Signed-off-by: songjiayang <songjiayang1@gmail.com>
2023-02-07 16:16:37 +01:00
Quentin D fcdc3ec54a
Add possibility to dynamically get label values for http instrumentation (#1066)
Signed-off-by: Quentin Devos <4972091+Okhoshi@users.noreply.github.com>

Signed-off-by: Quentin Devos <4972091+Okhoshi@users.noreply.github.com>
2023-01-19 10:19:08 +00:00
zhsj 7f99379117
Replace deprecated github.com/golang/protobuf package (#1183)
This replaces usage of proto.{Float64,Int32,Int64,String,Uint32,Uint64},
which doesn't break the interface.

And remove usage of proto.MarshalTextString in wrap_test.go

Updates: #1175

Signed-off-by: Shengjing Zhu <zhsj@debian.org>

Signed-off-by: Shengjing Zhu <zhsj@debian.org>
2022-12-22 16:14:00 +01:00
João Vilaça e29ed9f2cd
Support for multiple samples within same metric (#1181)
Signed-off-by: João Vilaça <jvilaca@redhat.com>

Signed-off-by: João Vilaça <jvilaca@redhat.com>
2022-12-15 16:07:45 +01:00
Quentin D fae2f6306b
Add constrained labels and Constrained variant for all MetricVecs (#1151)
* Introduce MetricVecOpts and add constraints to VariableLabels

MetricVecOpts exposes options specific to MetricVec initialisation. The
first option exposed by MetricVecOpts are constraints on VariableLabels,
allowing restrictions on the possible values a label can take, to
prevent cardinality explosion when the label value comes from a
non-trusted source (as a user input or HTTP header).

Signed-off-by: Quentin Devos <4972091+Okhoshi@users.noreply.github.com>

* Add tests

Signed-off-by: Quentin Devos <4972091+Okhoshi@users.noreply.github.com>

Signed-off-by: Quentin Devos <4972091+Okhoshi@users.noreply.github.com>
2022-12-13 13:47:52 +01:00
SpencerMalone 3d765a161a
Add context to "duplicate label names" to enable debugging (#1177)
* Add context to "duplicate label names" to enable debugging

Signed-off-by: SpencerMalone <malone.spencer@gmail.com>

* Remove unused errors package import.

Signed-off-by: SpencerMalone <malone.spencer@gmail.com>

Signed-off-by: SpencerMalone <malone.spencer@gmail.com>
2022-12-13 11:39:55 +01:00
beorn7 043372ee04 Initialize atomic variables in histogramCounts with atomic.Store...
Signed-off-by: beorn7 <beorn@grafana.com>
2022-11-14 15:03:17 +01:00
beorn7 efef9034c5 Rename histogram tests (from sparse to native)
Signed-off-by: beorn7 <beorn@grafana.com>
2022-11-14 14:53:16 +01:00
Kemal Akkoyun 870469ecf9
Test and support 1.19 (#1160)
* Add new Go 1.19 metrics

Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>

* Format files with the latest formatter

Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>

Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>
2022-11-08 00:14:19 +01:00
copy rogers b785d0c828
Fix go_collector_latest_test Fail on go1.19 (#1136)
Signed-off-by: rogerogers <rogers@rogerogers.com>

Signed-off-by: rogerogers <rogers@rogerogers.com>
2022-11-07 20:17:41 +01:00
Seth Bunce 4d54769c6b
Fix float64 comparison test failure on archs using FMA (#1133)
* Fix float64 comparison test failure on archs using FMA

Architectures using FMA optimization yield slightly different results so
we cannot assume floating point values will be precisely the same across
different architectures.

The solution in this change is to check "abs(a-b) < tolerance" instead
of comparing the exact values. This will give us confidence that the
histogram buckets are near identical.

Signed-off-by: Seth Bunce <seth.bunce@getcruise.com>

* Apply suggestions from code review

Co-authored-by: Daniel Swarbrick <daniel.swarbrick@gmail.com>
Signed-off-by: Seth Bunce <seth.bunce@getcruise.com>

* copy float compare dependency

Per discussion in the pull request, we'd like to avoid having an extra
dependency on a float comparison package. Instead, we copy the float compare
functions from the float comparison package.

The float comparison package we're choosing is this. The author of this
package has commented in the pull request and it looks like we have consensus
that this is the best option.
github.com/beorn7/floats

Signed-off-by: Seth Bunce <seth.bunce@gmail.com>

* remove float32 variant, relocate into separate file

This change removes the float32 variant of the AlmostEqual funcs, that we will
likely never use. This change also relocates the function into a separate file
to avoid modifying a file that's a fork of another vendored package.

Signed-off-by: Seth Bunce <seth.bunce@gmail.com>

Signed-off-by: Seth Bunce <seth.bunce@getcruise.com>
Signed-off-by: Seth Bunce <seth.bunce@gmail.com>
Co-authored-by: Daniel Swarbrick <daniel.swarbrick@gmail.com>
2022-11-07 19:20:43 +01:00
beorn7 fffb76cafe Merge branch 'main' into sparsehistogram 2022-10-31 16:30:59 +01:00
beorn7 e92a8c7f48 Avoid the term 'sparse' where possible
This intends to avoid confusing users by the subtle difference between
a native histogram and a sparse bucket.

Signed-off-by: beorn7 <beorn@grafana.com>
2022-10-31 16:23:08 +01:00
Jéssica Lins 9b5c5b8a47
Update basic example to use custom registry
Signed-off-by: Jéssica Lins <jessicaalins@gmail.com>
2022-10-21 16:06:49 +02:00
beorn7 d31f13b599 Add SparseBucketsZeroThresholdZero and groom doc comments
Signed-off-by: beorn7 <beorn@grafana.com>
2022-10-19 19:22:46 +02:00
beorn7 111fae11e1 Merge branch 'main' into sparsehistogram 2022-10-19 18:09:21 +02:00
Fabian Stäber 10b0550932
Fix race condition with Exemplar in Counter (#1146)
* Fix race condition with Exemplar in Counter

Potential fix for #1145.

Signed-off-by: Fabian Stäber <fabian@fstab.de>

* Fix race condition with Exemplar in Counter

Signed-off-by: Fabian Stäber <fabian@fstab.de>

Signed-off-by: Fabian Stäber <fabian@fstab.de>
2022-10-17 20:50:50 +02:00
Balint Zsilavecz dcea97eee2
Fix `CumulativeCount` value of `+Inf` bucket created from exemplar (#1148)
* Fix `CumulativeCount` value of `+Inf` bucket created from exemplar

Signed-off-by: Balint Zsilavecz <balint.zsilavecz@skyscanner.net>

* Update prometheus/metric_test.go

Co-authored-by: Bartlomiej Plotka <bwplotka@gmail.com>
Signed-off-by: Balint Zsilavecz <balint.zsilavecz@skyscanner.net>

* Clarify description of implicit `+Inf` bucket count

Signed-off-by: Balint Zsilavecz <balint.zsilavecz@skyscanner.net>

* Fix test variables

Signed-off-by: Balint Zsilavecz <balint.zsilavecz@skyscanner.net>

Signed-off-by: Balint Zsilavecz <balint.zsilavecz@skyscanner.net>
Co-authored-by: Bartlomiej Plotka <bwplotka@gmail.com>
2022-10-13 13:52:19 +02:00
beorn7 6942f9e454 sparse buckets: Fix handling of +Inf/-Inf/NaN observations
NaN observations now go to no bucket, but increment count (and
effectively set sum to NaN, too).

±Inf observations now go to the bucket following the bucket that would
have received math.MaxFloat64. The former is now the last bucket that
can be created.

The getLe is modified to return math.MaxFloat64 for the penultimate
possible bucket.

Also add a test for getLe.

Signed-off-by: beorn7 <beorn@grafana.com>
2022-10-06 17:40:15 +02:00
Rafael Franco 7c46c150bd
Clarify documentation around what constructors do (#1125)
The wording of the documentation is slightly misleading. Before this
commit, it says that the returned collectors are "already registered".
This could be interpreted in two ways, one could think that promauto
keeps some sort of cache of already registered Collectors that are
returned by this package, and the other way is that the Collectors
constructed are registered before being returned. What is actually
happening is the latter, and the wording after this PR leaves no room to
think that the former could be the case.

Signed-off-by: Rafael Franco <me@rafaelfranco.es>

Signed-off-by: Rafael Franco <me@rafaelfranco.es>
2022-09-12 11:17:56 +02:00
beorn7 95cf173f19 Merge branch 'main' into sparsehistogram 2022-08-23 14:28:33 +02:00
Robert Fratto 83d56b1144
Extend prometheus.Registry to implement Collector (#1103)
* prometheus: implement Collector interface for Registry

This change allows Registries to be used as Collectors.

This enables new instances of Registry to be passed to ephemeral
subroutines for collecting metrics from subroutines which are still
running:

```go
package main

import (
  "fmt"

  "github.com/prometheus/client_golang/prometheus"
)

func main() {
  globalReg := prometheus.NewRegistry()

  for i := 0; i < 100; i++ {
    workerReg := prometheus.WrapRegistererWith(prometheus.Labels{
      // Add an ID label so registered metrics from workers don't
      // collide.
      "worker_id": fmt.Sprintf("%d", i),
    }, prometheus.NewRegistry()

    globalReg.MustRegister(workerReg)

    go func(i int) {
      runWorker(workerReg)

      // Unregister any metrics the worker may have created.
      globalReg.Unregister(workerReg)
    }(i)
  }
}

// runWorker runs a worker, registering worker-specific metrics.
func runWorker(reg *prometheus.Registry) {
  // ... register metrics ...
  // ... do work ...
}
```

This change makes it easier to avoid leaking metrics from subroutines
which do not consistently properly unregister metrics.

Signed-off-by: Robert Fratto <robertfratto@gmail.com>

* fix grammar in doc comment

Signed-off-by: Robert Fratto <robertfratto@gmail.com>

* document why Registry implements Collector with example

Signed-off-by: Robert Fratto <robertfratto@gmail.com>

Signed-off-by: Robert Fratto <robertfratto@gmail.com>
2022-08-23 11:09:29 +02:00
Dave Henderson 4c41dfbcd5
Clarify exemplar(Add|Observe) by renaming to (add|observe)WithExemplar (#1122)
* Clarify exemplarAdd by renaming to addWithExemplar

Signed-off-by: Dave Henderson <dhenderson@gmail.com>

* Documenting addWithExemplar

Signed-off-by: Dave Henderson <dhenderson@gmail.com>

* Also rename exemplarObserve to follow the same pattern

Signed-off-by: Dave Henderson <dhenderson@gmail.com>

Signed-off-by: Dave Henderson <dhenderson@gmail.com>
2022-08-22 17:31:08 +02:00
Dave Henderson f73e3cc0e2
Fix double-counting bug in promhttp.InstrumentRoundTripperCounter (#1118)
Signed-off-by: Dave Henderson <dhenderson@gmail.com>

Signed-off-by: Dave Henderson <dhenderson@gmail.com>
2022-08-22 08:28:46 +03:00