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>
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>
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>
* 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>
* 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>
* 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>
* 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>
* 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>
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>