Commit Graph

587 Commits

Author SHA1 Message Date
Darya Melentsova b801f06e31 fix ErrorCallbackFunc
Signed-off-by: Darya Melentsova <ifireice@gmail.com>
2023-06-21 08:53:05 +03:00
Darya Melentsova 8bc96219a0 added support backward compatibility
Signed-off-by: Darya Melentsova <ifireice@gmail.com>
2023-06-21 08:53:05 +03:00
Darya Melentsova a7ff852155 fix test
Signed-off-by: Darya Melentsova <ifireice@gmail.com>
2023-06-21 08:53:05 +03:00
Darya Melentsova b64fe48b5f fix test
Signed-off-by: Darya Melentsova <ifireice@gmail.com>
2023-06-21 08:53:05 +03:00
Darya Melentsova c18237f5f6 remove line
Signed-off-by: Darya Melentsova <ifireice@gmail.com>
2023-06-21 08:53:05 +03:00
Darya Melentsova 707a76763e graphite: refactor error handling
Signed-off-by: ifireice <ifireice@gmail.com>

Signed-off-by: Darya Melentsova <ifireice@gmail.com>
2023-06-21 08:53:05 +03: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
Bartlomiej Plotka 5b7e8b2e67
collectors.GoCollector: Added rule support for granular metric configuration. (#1102)
* goCollector: Added rule support for granular metric configuration.

Fixes: https://github.com/prometheus/client_golang/issues/1089

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

* Added compatibility mode with old options. (#1107)

* Added compatibility mode with old options.

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

* Copyright header.

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

* Remove bucket option for now. (#1108)

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

* collectors/GoCollector: Add tests and examples (#1109)

* Add tests and examples

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

* Add docs for the presets

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

Co-authored-by: Kemal Akkoyun <kakkoyun@users.noreply.github.com>
2022-08-05 19:37:46 +02:00
Christian Stewart d44fbbefdd
Fix build against GopherJS (#897)
* Fix build against GopherJS

When building against GopherJS, ThreadCreateProfile and Getpid are not
available.

Return 1 to shim the functions.

Signed-off-by: Christian Stewart <christian@paral.in>

* Fix formatting

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

* Fix linter issue

Move build tags for licence header checks

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

Co-authored-by: Kemal Akkoyun <kakkoyun@gmail.com>
2022-08-05 16:28:54 +02:00
Soroosh Azary Marhabi 1638da9ae4
testutil: Add ScrapeAndCompare (#1043)
* testutil: Add ScrapeAndCompare

Signed-off-by: sazary <soroosh@azary.ir>

* testutil: Use %w verb wherever we're using an error in fmt.Errorf

Signed-off-by: sazary <soroosh@azary.ir>

* Format

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

Co-authored-by: Kemal Akkoyun <kakkoyun@users.noreply.github.com>
Co-authored-by: Kemal Akkoyun <kakkoyun@gmail.com>
2022-08-05 16:27:47 +02:00
Kemal Akkoyun c576b951ad
Generate new Go runtime metrics for go 1.19 (#1105)
* Generate new Go runtime metrics

Fix generation script

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

* Address review issues

Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>
2022-08-05 15:48:33 +02:00
Christoph Mewes 618194de6a
fix assorted oddities found by golangci-lint (#1040)
* fix assorted oddities found by golangci-lint

Signed-off-by: Christoph Mewes <christoph@kubermatic.com>

* permanently enable the linters

Signed-off-by: Christoph Mewes <christoph@kubermatic.com>

* post-rebase blues

Signed-off-by: Christoph Mewes <christoph@kubermatic.com>
2022-08-03 06:30:51 +02:00
Bartlomiej Plotka c7488be2e4
Added exemplar support to http middleware. (#1055)
* Added exemplar support to http middlewares.

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

* Small fix.

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

* Fixed test.

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

* Added tests and options for RT.

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

* goimports.

Signed-off-by: bwplotka <bwplotka@gmail.com>
2022-08-02 19:33:08 +02:00
Bartlomiej Plotka 3faf3bae70
Fixed support for unordered input of exemplars. (#1100)
Signed-off-by: bwplotka <bwplotka@gmail.com>
2022-08-02 11:32:30 +02:00
Arun Mahendra 807b1ee73c
explicitly add +inf bucket in withExemplarsMetric (#1094)
* explicitly adding +inf bucket to withExemplarsMetric

Signed-off-by: Arun Mahendra <arun.mahendra@shopify.com>

* Update prometheus/metric_test.go

Co-authored-by: Bartlomiej Plotka <bwplotka@gmail.com>

* Update prometheus/metric.go

Co-authored-by: Bartlomiej Plotka <bwplotka@gmail.com>

* updated comment and removed unnecessary test

Co-authored-by: Bartlomiej Plotka <bwplotka@gmail.com>
2022-08-02 10:48:18 +02:00
inosato 44c2c4de85
Remove ioutil (#1096)
Signed-off-by: inosato <si17_21@yahoo.co.jp>
2022-08-02 10:27:49 +02:00
Fredrik Enestad a528affed9
Update documentation for exemplar label limit (#1095)
Signed-off-by: Fredrik Enestad <fredrik@enestad.com>
2022-07-27 17:45:49 +02:00
beorn7 8cbcd4076a histograms: Move to new exposition protobuf format
Note that this is an incompatible change. To scrape this new format,
the Prometheus server needs to be updated at the same time. PR
incoming.

Signed-off-by: beorn7 <beorn@grafana.com>
2022-07-19 16:54:05 +02:00
Bryan Boreham ba4a543ab4
Raise exemplar labels limit from 64 to 128 (#1091)
In line with the OpenMetrics spec:
"The combined length of the label names and values of an Exemplar's
LabelSet MUST NOT exceed 128 UTF-8 character code points"

https://github.com/OpenObservability/OpenMetrics/blob/98ae26c87b/specification/OpenMetrics.md#exemplars

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
2022-07-19 16:50:45 +02:00
beorn7 525d042127 Merge branch 'main' into sparsehistogram 2022-07-06 16:09:36 +02:00
Curith 810fcb46ab
Add Error API for pusher (#1075)
Signed-off-by: kun <oiooj@qq.com>
2022-06-30 17:00:36 +02:00