* Fix convention violating names for generated collector metrics
Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>
* Add new Go collector example
Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>
* WIP partial match
Signed-off-by: Zach Stone <zach@giantswarm.io>
* Cleanup
Signed-off-by: Zach Stone <zach@giantswarm.io>
* Comments
Signed-off-by: Zach Stone <zach@giantswarm.io>
* Tests and comments
Signed-off-by: Zach Stone <zach@giantswarm.io>
* Handle properly deleting multiple metrics, update tests
Signed-off-by: Zach Stone <zach@giantswarm.io>
* Comments
Signed-off-by: Zach Stone <zach@giantswarm.io>
* Try using curry values
Signed-off-by: Zach Stone <zach@giantswarm.io>
* Skip curry value to demo
Signed-off-by: Zach Stone <zach@giantswarm.io>
* Fix curry deletion, remove outdated comment.
Signed-off-by: Zach Stone <zach@giantswarm.io>
* Fix logic for deletion of metrics from prior to currying
Signed-off-by: Zach Stone <zach@giantswarm.io>
* Don't match curried values. Update tests.
Signed-off-by: Zach Stone <zach@giantswarm.io>
* Remove unneccesasry helper and todo comments
Signed-off-by: Zach Stone <zach@giantswarm.io>
* Comment about partial matching curried labels
Signed-off-by: Zach Stone <zach@giantswarm.io>
* Simplify curried value check
Signed-off-by: Zach Stone <zach@giantswarm.io>
* Renamed files.
Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
* gocollector: Added options to Go Collector for diffetent collections.
Fixes https://github.com/prometheus/client_golang/issues/983
Also:
* fixed TestMemStatsEquivalence, it was noop before (:
* Removed gc_cpu_fraction metric completely, since it's not working completely for Go1.17+
Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
Add PushContext and AddContext to Pusher, which are context-aware
version of Push and Add respectively. They give a caller the ability
to cancel an HTTP request.
Signed-off-by: Tatsuhiro Tsujikawa <ttsujika@zlab.co.jp>
* Add config to test against go1.18
Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>
* Try to fix circleci
Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>
* Add support for exemplars on constHistogram
Co-authored-by: William Perron <william.perron@shopify.com>
Signed-off-by: William Perron <william.perron@shopify.com>
* remove GetExemplars function
Signed-off-by: William Perron <william.perron@shopify.com>
* fixed linting warnings
reduce repetition in constHistogram w/ exemplar
Signed-off-by: William Perron <william.perron@shopify.com>
* Add values to correct bucket
Signed-off-by: William Perron <william.perron@shopify.com>
* Misc fixes
Co-authored-by: Francis Bogsanyi <francis.bogsanyi@shopify.com>
Signed-off-by: William Perron <william.perron@shopify.com>
* avoid panic when there are fewer buckets than exemplars
Co-authored-by: Arun Mahendra <arun.mahendra@shopify.com>
Signed-off-by: William Perron <william.perron@shopify.com>
* Added MustNewMetricWithExemplars that wraps metrics with exemplar (#3)
Changes:
* Make sure to not "leak" dto.Metric
* Reused upper bounds we already have for histogram
* Common code for all types.
Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
Co-authored-by: Arun Mahendra <arun.mahendra@shopify.com>
Co-authored-by: Bartlomiej Plotka <bwplotka@gmail.com>
The Go runtime/metrics package currently exports extremely granular
histograms. Exponentially bucket any histogram with unit "seconds"
or "bytes" instead to dramatically reduce the number of buckets, and
thus the number of metrics.
This change also adds a test to check for expected cardinality to
prevent cardinality surprises in the future.
Signed-off-by: Michael Anthony Knyszek <mknyszek@google.com>
A previous PR made it so that the Go 1.17 collector locked only around
uses of rmSampleBuf, but really that means that Metric values may be
sent over the channel containing some values from future metrics.Read
calls. While generally-speaking this isn't a problem, we lose any
consistency guarantees provided by the runtime/metrics package.
Also, that optimization to not just lock around all of Collect was
premature. Truthfully, Collect is called relatively infrequently, and
its critical path is fairly fast (10s of µs). To prove it, this change
also adds a benchmark.
name old time/op new time/op delta
GoCollector-16 43.7µs ± 2% 43.2µs ± 2% ~ (p=0.190 n=9+9)
Note that because the benchmark is single-threaded it actually looks
like it might be getting *slightly* faster, because all those Collect
calls for the Metrics are direct calls instead of interface calls.
Signed-off-by: Michael Anthony Knyszek <mknyszek@google.com>
* Check validity of method and code label values
Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>
* Use more flexibly functional option pattern for configuration
Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>
* Update documentation
Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>
* Simplify
Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>
* Fix inconsistent method naming
Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>
This change introduces use of the runtime/metrics package in place of
runtime.MemStats for Go 1.17 or later. The runtime/metrics package was
introduced in Go 1.16, but not all the old metrics were accounted for
until 1.17.
The runtime/metrics package offers several advantages over using
runtime.MemStats:
* The list of metrics and their descriptions are machine-readable,
allowing new metrics to get added without any additional work.
* Detailed histogram-based metrics are now available, offering much
deeper insights into the Go runtime.
* The runtime/metrics API is significantly more efficient than
runtime.MemStats, even with the additional metrics added, because
it does not require any stop-the-world events.
That being said, integrating the package comes with some caveats, some
of which were discussed in #842. Namely:
* The old MemStats-based metrics need to continue working, so they're
exported under their old names backed by equivalent runtime/metrics
metrics.
* Earlier versions of Go need to continue working, so the old code
remains, but behind a build tag.
Finally, a few notes about the implementation:
* This change includes a whole bunch of refactoring to avoid significant
code duplication.
* This change adds a new histogram metric type specifically optimized
for runtime/metrics histograms. This type's methods also include
additional logic to deal with differences in bounds conventions.
* This change makes a whole bunch of decisions about how runtime/metrics
names are translated.
* This change adds a `go generate` script to generate a list of expected
runtime/metrics names for a given Go version for auditing. Users of
new versions of Go will transparently be allowed to use new metrics,
however.
Signed-off-by: Michael Anthony Knyszek <mknyszek@google.com>
This function calculates exponential buckets with different arguments
than the existing ExponentialBuckets function. Instead of specifying the
start and factor, the user can specify the min and max bucket value. We
have been doing it this way internally at my company for some time.
Signed-off-by: Seth Bunce <seth.bunce@getcruise.com>
Since 1.16 is out, we still support the last four minor releases.
The bump was required by the prometheus/procfs package using the new
`%w` printf directives. However, it also allows us to remove some
special casing about build info.
Signed-off-by: beorn7 <beorn@grafana.com>
Without this fix, the `InstrumentHandler...` middlewares get locked in
an endless loop in case of an invalid Collector, eating all the memory.
Signed-off-by: beorn7 <beorn@grafana.com>
MetricVec was already exported in early versions of this library, but
nobody really used it to implement vectors of custom Metric
implementations. Now #796 has shown up with a fairly special use case
for which I'd prefer a custom implementation of a special
"auto-sampling histogram" outside of this library. Therefore, I'd like
to reinstate support for creating vectors of custom Metric
implementations.
I played around for quite some while with the option of a separate
package providing the tools one would need to create vectors of custom
Metric implementations. However, with the current structure of the
prometheus/client_golang/prometheus package, this leads to a lot of
complications with circular dependencies. (The new package would need
the primitives from the prometheus package, while the existing metric
vectors like GaugeVec need to import the new vector package to not
duplicate the implementation. Separating vector types from the main
prometheus package is out of the question at this point because that
would be a breaking change.)
Signed-off-by: beorn7 <beorn@grafana.com>
I assume older Nanoc versions rendered the anchors with commas, but
the current doesn't.
Also, this adds the same link to another doc comment where it is also
relevant.
Signed-off-by: beorn7 <beorn@grafana.com>