* Extend Counters, Summaries and Histograms with creation timestamp
Signed-off-by: Arthur Silva Sens <arthur.sens@coralogix.com>
* Backport created timestamp to existing tests
Signed-off-by: Arthur Silva Sens <arthur.sens@coralogix.com>
* Last touches (readability and consistency)
Changes:
* Comments for "now" are more explicit and not inlined.
* populateMetrics is simpler and bit more efficient without timestamp to time to timestamp conversionts for more common code.
* Test consistency and simplicity - the fewer variables the better.
* Fixed inconsistency for v2 and MetricVec - let's pass opt.now consistently.
* We don't need TestCounterXXXTimestamp - we test CT in many other places already.
* Added more involved test for counter vectors with created timestamp.
* Refactored normalization for simplicity.
* Make histogram, summaries now consistent.
* Simplified histograms CT flow and implemented proper CT on reset.
TODO for next PRs:
* NewConstSummary and NewConstHistogram - ability to specify CTs there.
Signed-off-by: bwplotka <bwplotka@gmail.com>
* Update prometheus/counter_test.go
Co-authored-by: Arthur Silva Sens <arthursens2005@gmail.com>
Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
---------
Signed-off-by: Arthur Silva Sens <arthur.sens@coralogix.com>
Signed-off-by: bwplotka <bwplotka@gmail.com>
Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
Co-authored-by: bwplotka <bwplotka@gmail.com>
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>
* 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>
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>
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>
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>
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>
* 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>
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>
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>
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>
* 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>
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>
* 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>
* 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>
* 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>
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>