Commit Graph

491 Commits

Author SHA1 Message Date
Bartlomiej Plotka 989baa30fe
promhttp: Check validity of method and code label values (#962) (#987)
* 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>

Co-authored-by: Kemal Akkoyun <kakkoyun@users.noreply.github.com>
2022-02-15 10:38:19 +00:00
beorn7 f34145a85e Document implications of negative observations
Signed-off-by: beorn7 <beorn@grafana.com>
2021-05-26 23:41:30 +02:00
beorn7 81a9556c8b Make dbStatsCollector more DRY
Signed-off-by: beorn7 <beorn@grafana.com>
2021-05-20 22:31:53 +02:00
Mitsuo Heijo a66da1df4a
Add collector for database/sql#DBStats (#866)
* Add collector for database/sql#DBStats

Signed-off-by: Mitsuo Heijo <mitsuo.heijo@gmail.com>
2021-05-20 22:22:17 +02:00
Mitsuo Heijo e07445a773
Add new collectors package
Signed-off-by: Mitsuo Heijo <mitsuo.heijo@gmail.com>
2021-05-08 10:43:31 +09:00
Dean Coakley 3998a677f9
Improve description of MaxAge in summary docs (#864)
* Improve description of MaxAge in summary docs

Signed-off-by: Dean Coakley <dean.s.coakley@gmail.com>
2021-05-04 15:58:41 +02:00
beorn7 e92283d644 Fix linter ignores
Signed-off-by: beorn7 <beorn@grafana.com>
2021-03-16 17:19:03 +01:00
beorn7 6635a8f35b Bump minumim required Go version to 1.13
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>
2021-03-11 20:45:00 +01:00
debiandebiandebian 9443f4449b Fix typo in comments
Signed-off-by: debiandebiandebian <debiandebiandebiandebian@gmail.com>
2021-02-08 08:58:51 +09:00
beorn7 98eb6cbf7c promhttp: Correctly detect invalid metric and label names
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>
2020-12-09 17:58:53 +01:00
beorn7 34ca120377 Be more explicit about the multi-line properties of MultiError
Signed-off-by: beorn7 <beorn@grafana.com>
2020-12-02 19:53:38 +01:00
Michael Vetter cf6dc82780 Correct spelling: possibilites -> possibilities
Signed-off-by: Michael Vetter <jubalh@iodoru.org>
2020-12-01 21:20:26 +01:00
sbookworm 469ec2747b add the NewPidFileFn to helper
Signed-off-by: sbookworm <lisong.cruise@gmail.com>
2020-10-23 09:23:59 +08:00
beorn7 85aa957f63 Export MetricVec (again)
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>
2020-10-15 14:32:54 +02:00
beorn7 b54b73c7b1 Remove spurious commas from links to the docs site
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>
2020-09-07 22:31:29 +02:00
Björn Rabenstein c650ae9fa1
Merge pull request #784 from hummerd/master
Remove reference to Metric after reslicing
2020-07-25 00:01:35 +02:00
Björn Rabenstein 77b35d0377
Merge pull request #783 from roidelapluie/gc15
Update collector comment about GC stop-the-world
2020-07-24 23:48:32 +02:00
Dima Kozlov 0c48254b62 remove reference to metrics after reslicing
Signed-off-by: Dima Kozlov <hummerd@mail.ru>
2020-07-22 23:12:23 +03:00
Julien Pivotto 4759649876 Update collector comment about GC stop-the-world
Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
2020-07-22 01:42:37 +02:00
Mitsuo Heijo 916659fee0 fix tests warning about string(int) type conversions
See https://github.com/golang/go/issues/32479

Signed-off-by: Mitsuo Heijo <mitsuo.heijo@gmail.com>
2020-07-06 21:19:31 +09:00
Mark Hansen 7687ac2137 histogram.go: fix copy/paste typo
This method calls NewConstHistogram.

Signed-off-by: Mark Hansen <mark@markhansen.co.nz>
2020-06-21 13:47:29 +10:00
Tom Wilkie 9c8ba1f945 Review feedback: add comment and tests for WrapRegistererWith.
Signed-off-by: Tom Wilkie <tom.wilkie@gmail.com>
2020-06-04 11:51:51 +01:00
Tom Wilkie 614377c550 Review feedback: use one line.
Signed-off-by: Tom Wilkie <tom.wilkie@gmail.com>
2020-06-04 10:57:40 +01:00
Tom Wilkie 8961609f91 Ensure that nil registers are treat as a no-op, even when wrapping.
Signed-off-by: Tom Wilkie <tom.wilkie@gmail.com>
2020-06-04 10:30:51 +01:00
beorn7 3ba240a80f Improve doc comments in promauto
In particular, point out that `With(nil)` is valid.

Signed-off-by: beorn7 <beorn@grafana.com>
2020-06-03 13:56:49 +02:00
Matt Layher 3afa5ab1e1
testutil/promlint: allow Kelvin as a base unit for color temperature
Signed-off-by: Matt Layher <mdlayher@gmail.com>
2020-05-28 11:54:54 -04:00
Björn Rabenstein bff02dd561
Merge pull request #754 from prometheus/beorn7/deprecation
Add lint:ignore for protobuf deprecation
2020-05-18 15:31:02 +02:00
Björn Rabenstein d8b51d4981
Merge pull request #753 from prometheus/beorn7/test
Improve CollectAndCount
2020-05-15 13:19:43 +02:00
beorn7 dba1478b8a Add lint:ignore for protobuf deprecation
`github.com/golang/protobuf/proto` is deprecated in lieu of
`google.golang.org/protobuf/proto`. However, we cannot simply
migrate. Types from the proto package are exposed to users of packages
in this repo. If we migrate here, users have to migrate to. Thus, we
could only migrate with a major version bump.

In different news, with all the inline lint:ignore comments, including
the existing ones, there is no need to repeat the exception in the
Makefile.

A current version of `staticcheck` is happy with the code after this
commit. golangci-lint is broken at the moment, however, and ignores
the lint:ignore comments in the code as well as those via envvar.

Signed-off-by: beorn7 <beorn@grafana.com>
2020-05-14 20:11:22 +02:00
beorn7 0577ef6c57 Improve CollectAndCount
Now that we have also added CollectAndLint and GatherAndLint, I
thought we should bring CollectAndCount in line. So:

- Add GatherAndCount.
- Add filtering by metric name.
- Add tests.

Minor wart: CollectAndCount should now return `(int, error)`, but that
would be a breaking change as the current version just returns
`int`. I decided to let the new version panic when it should return an
error. An error is anyway very unlikely, so the biggest annoyance here
is really just the inconsistency.

Signed-off-by: beorn7 <beorn@grafana.com>
2020-05-14 00:17:45 +02:00
beorn7 389d3c3b9a Properly handle empty job and label values
An empty job name was always an error, but it was previously only
detected when pushing to the PGW and receiving an error. With this
commit, the error is detected before pushing.

An empty label value should have been OK but was encoded in a way that
couldn't be pushed to the
PGW. Cf. https://github.com/prometheus/pushgateway/issues/344 . This
commit changes the creation of the path in the URL so that it works
with empty label values.

Signed-off-by: beorn7 <beorn@grafana.com>
2020-05-13 23:35:31 +02:00
Michael Cristina be019d1f24 Fix typo in godoc help text
Signed-off-by: Michael Cristina <mcristina444@gmail.com>
2020-05-02 10:44:25 -05:00
beorn7 dc79bd6093 Improve various comments
Signed-off-by: beorn7 <beorn@grafana.com>
2020-04-25 15:59:53 +02:00
beorn7 39dbb24d13 Add helper functions for linting to testutil
Signed-off-by: beorn7 <beorn@grafana.com>
2020-04-24 23:44:59 +02:00
beorn7 6433bcf819 Add the capability to lint MetricFamilies directly
Also, change all the `dto.MetricFamily` arguments to pointers to be
more consistent with what we do in client_golang in general.

Signed-off-by: beorn7 <beorn@grafana.com>
2020-04-24 23:42:49 +02:00
Björn Rabenstein a3a59237d1
Merge pull request #739 from RainbowMango/pr_porting_promlint
Porting promlint from prometheus/prometheus
2020-04-24 16:06:34 +02:00
Björn Rabenstein a200f1930c
Merge pull request #738 from colega/colega/gauge-func-const-labels-godoc
GaugeFunc: ConstLabels godoc example
2020-04-24 14:29:25 +02:00
Oleg Zaytsev 38045061c3
GaugeFunc: ConstLabels godoc example
Document the example usage of ConstLabels to register several GaugeFuncs
on the same metric name. Also reference it from the NewCounterFunc
documentation as it's similar.

Ref: https://github.com/prometheus/client_golang/pull/736

Signed-off-by: Oleg Zaytsev <mail@olegzaytsev.com>
2020-04-24 09:33:20 +02:00
RainbowMango 50cda505d1 fix static check warnings by Goland.
Signed-off-by: RainbowMango <renhongcai@huawei.com>
2020-04-24 10:15:27 +08:00
RainbowMango af6ade7230 Fix unit test failing with Go1.14+
Signed-off-by: RainbowMango <renhongcai@huawei.com>
2020-04-23 15:14:34 +08:00
RainbowMango 3c5e60edc1 Porting promlint from prometheus/prometheus.
Signed-off-by: RainbowMango <renhongcai@huawei.com>
2020-04-23 14:09:29 +08:00
cobolbaby c6babafd27 feat: Change processMemoryCounters struct uint declaration to uintptr
Signed-off-by: cobolbaby <cobolbaby@qq.com>
2020-04-13 10:44:09 +08:00
cobolbaby 0bb7f92c09 fix: process_resident_memory_bytes detected is incorrect in Win7 32bit
Ref: https://github.com/prometheus/client_golang/issues/728
Signed-off-by: Cobolbaby <Zhang.Xing-Long@inventec.com>
2020-04-10 16:38:16 +08:00
beorn7 586178b4ab Fix promhttp error handling
Essentially, just don't try to set a status code and send any error
message in the body once metrics gathering has succeeded. At that
point, the most likely reason for errors is anyway that the client has
disconnected, in which sending an error is moot. The other possible
reason for an error is a problem during metrics encoding. This is
unlikely to happen (it's a coding error here in client_golang in any
case), and if it is happening, the odds are we have already sent
something to the ResponseWriter, which means we cannot set a status
code anymore. The doc comment for HTTPErrorOnError now describes these
circumstances explicitly and recommends to set a logger to report that
kind of error.

This should fix the reason for the infamous `superfluous
response.WriteHeader call` message.

Signed-off-by: beorn7 <beorn@grafana.com>
2020-03-13 00:10:32 +01:00
Björn Rabenstein b25ce2693a
Merge pull request #713 from prometheus/beorn7/promauto
Add a "factory" to make promauto work for custom registries
2020-02-14 16:41:32 +01:00
beorn7 1c2884b807 Add NewUntypedFunc to promauto
This constructor was simply forgotten.

Signed-off-by: beorn7 <beorn@grafana.com>
2020-02-13 22:08:18 +01:00
beorn7 92c1ac77e7 Add a "factory" to make promauto work for custom registries
Also, update the package documentation. The concerns about the global
registry aren't really valid anymore because promauto now also works
with custom registries.

The musings about the http.DefaultMux are more a digression and
shouldn't be in a doc comment.

Signed-off-by: beorn7 <beorn@grafana.com>
2020-02-13 22:03:30 +01:00
beorn7 87f9434351 Remove obsolete references to `Untyped` from doc comments
Signed-off-by: beorn7 <beorn@grafana.com>
2020-02-13 22:03:05 +01:00
beorn7 aa6eadda9c Explicitly forward metricVec methods Collect, Describe, Reset
Interestingly, methods implicitly forwarded from embedded types are
detected by GoDoc if they are just one level deep. Embedded types in
the embedded type are not recognized. This commit therefore adds
explicit forwarding methods for Collect, Describe, and Reset.

Signed-off-by: beorn7 <beorn@grafana.com>
2020-02-13 20:22:37 +01:00
Shreyas Srivatsan bc9e50c39f Initialize now fn for counters
Signed-off-by: Shreyas Srivatsan <shreyas@chronosphere.io>
2020-02-05 22:25:47 -08:00