Commit Graph

459 Commits

Author SHA1 Message Date
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
beorn7 f34b09877c Pull out ...WithExemplar methods into separate interfaces
This is, sadly, the only way to avoid a breaking change. The cost is
that anyone using exemplars has to perform a type assertion. This is,
however, a common pattern where interfaces turn out to need additional
methods in a stable library or only some implementations can provide
the additional methods (AKA "interface upgrade").

Needless to say that in v2 of this library, we'll do things in a more
straight forward way.

Signed-off-by: beorn7 <beorn@grafana.com>
2020-01-27 15:41:13 +01:00
beorn7 c32ffd121f Add tests for examplars
Signed-off-by: beorn7 <beorn@grafana.com>
2020-01-24 17:12:36 +01:00
beorn7 57d41259e1 Add exemplars to counter and histogram
Signed-off-by: beorn7 <beorn@grafana.com>
2020-01-24 17:12:08 +01:00
Bartlomiej Plotka 9e9cc003f8 Added testutil.CollectAndCount
Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
2020-01-09 11:20:19 +00:00
beorn7 2be4bb406e Improve doc string for `go_gc_duration_seconds`
Fixes #618.

Signed-off-by: beorn7 <beorn@grafana.com>
2020-01-06 13:38:35 +01:00
beorn7 de74638693 Improve doc comment for NewGaugeFunc
- Simplify confusing wording about concurrency safety.
- Add link to example for info metric.

Signed-off-by: beorn7 <beorn@grafana.com>
2019-12-09 18:20:27 +01:00
Dean Coakley 508fc33903
Fix link to writing exporters guide
Signed-off-by: Dean Coakley <dean.s.coakley@gmail.com>
2019-11-28 15:01:46 +00:00
kamaev 06342cf74f
fix tests
Signed-off-by: kamaev <timurkamaev@protonmail.com>
2019-10-23 00:15:54 +05:00
kamaev c333d152b1
add graphite tags
Signed-off-by: kamaev <timurkamaev@protonmail.com>
2019-10-23 00:15:41 +05:00
Jeff Widman 0dc0c2165f Remove old reference to basicMetricVec
Contrary to the code comment, I see no `basicMetricVec` implementation.
Grep'ing this project shows this is the only reference. So I suspect
it's an outdated comment and can be removed to minimize confusion.

I'm unclear whether other parts of that comment are also incorrect and
need updating.

Signed-off-by: Jeff Widman <jeff@jeffwidman.com>
2019-10-18 10:05:25 -07:00
Leo Antunes 4be0ab45ec ensure same collectorID calculated on reg and unreg
Signed-off-by: Leo Antunes <leo@costela.net>
2019-10-17 14:16:32 +02:00
beorn7 679da921f7 Simplify code
`gofmt -s` taught me that this is possible.

Signed-off-by: beorn7 <beorn@grafana.com>
2019-10-16 12:18:16 +02:00
beorn7 19af62dcc8 Use a cleaner initialization of `separatorByteSlice`
The `const separatorByte` wasn't used anymore actually. In `vec.go`,
we were using `model.SeparatorByte`, which is better anyway. So remove
the unused constant and initialize `separatorByteSlice` with
`model.SeparatorByte`, too.

Signed-off-by: beorn7 <beorn@grafana.com>
2019-10-15 19:52:31 +02:00
Björn Rabenstein c13325c862
Merge pull request #655 from prometheus/beorn7/test
Unflake TestGoCollectorGoroutines
2019-10-15 13:19:50 +02:00
Björn Rabenstein 8b3e008442
Merge pull request #657 from prometheus/beorn7/registry
Make hash collisions in the registry much less likely
2019-10-15 11:43:02 +02:00
beorn7 ee1078a03c Move registry hashing to xxhash
This is a much stronger hash function than fnv64a and comparably fast
(with super-fast assembly implementation for amd64).

Performance is not critical here anyway.

The old fnv64a is kept for vectors, where collision detection is in
place and the weakness of the hashing doesn't matter that much. I
implemented a vector version with xxhash and found that xxhash is
slower in all cases except very very high cardinality (where it is
only slightly faster). Also, ``xxhash.New`` comes with an allocation
of 80 bytes. Thus, to keep vectors alloc-free, we needed to add a
`sync.Pool`, which would have an additional performance overhead.

Signed-off-by: beorn7 <beorn@grafana.com>
2019-10-14 21:18:38 +02:00
beorn7 c2e3855f3b Minimal “fix” for hash collisions
This makes the collisions a bit less likely by XOR'ing descIDs rather
than adding them up for the collectorID.

Signed-off-by: beorn7 <beorn@grafana.com>
2019-10-14 20:14:43 +02:00
beorn7 bf9ff715fe Expose bug #633
Signed-off-by: beorn7 <beorn@grafana.com>
2019-10-14 20:02:58 +02:00
beorn7 6fa429cf42 Unflake TestGoCollectorGoroutines
This is not a great solution, but it's also hard to test for this
moving target.

Signed-off-by: beorn7 <beorn@grafana.com>
2019-10-14 19:44:28 +02:00
beorn7 bd362a9ced Use HTTP status code constants rather than numerical literals
Signed-off-by: beorn7 <beorn@grafana.com>
2019-10-14 19:27:09 +02:00
beorn7 f24de70161 Update push test to use status code 200
Signed-off-by: beorn7 <beorn@grafana.com>
2019-10-14 19:24:20 +02:00
Xin Zhang 7c6a9d7568 Fix check status code
Signed-off-by: Xin Zhang <ahjdzx1990@gmail.com>
2019-10-12 16:08:00 +08:00
beorn7 ad58180fde Add WriteHeader call to Flush
Flush is another of the methods that will call WriteHeader if it
hasn't happened yet. Since we want to call observeWriteHeader (if
set), we need to do the WriteHeader call already here, similar to what
we have done in Write and ReadFrom.

This commit also adds comments explaining the above to not tempt
developers to remove the WriteHeader call.

Signed-off-by: beorn7 <beorn@grafana.com>
2019-08-19 18:19:23 +02:00
Andrey Yurchenkov b0bcec8f2e
Fix typo in documentation
Signed-off-by: Andrey Yurchenkov <painhardcore@gmail.com>
2019-08-13 13:43:39 +03:00
beorn7 4b95c4ab42 Support new base64 encoding for pushing to the Pushgateway
This should only be released after PGW 0.9 is released.

Signed-off-by: beorn7 <beorn@grafana.com>
2019-07-22 20:31:37 +02:00
beorn7 48cd700822 Use method constants from the http package
Signed-off-by: beorn7 <beorn@grafana.com>
2019-06-28 15:23:00 +02:00
beorn7 9a1440d469 Add Delete method
Fixes #611.

Signed-off-by: beorn7 <beorn@grafana.com>
2019-06-28 15:12:09 +02:00
beorn7 2f3a0f8f2e Make the AlreadyRegisteredError useful for wrapped registries
Signed-off-by: beorn7 <beorn@grafana.com>
2019-06-14 17:55:35 +02:00
beorn7 f61dbeaded Update doc comment of NewProcessCollector
- Now also works on MS Windows.
- The hints for updating from older versions is obsolete by now.

Signed-off-by: beorn7 <beorn@grafana.com>
2019-06-14 12:33:52 +02:00
Calle Pettersson c5f4190338 Implement process collector for Windows (#596)
* Implement process collector for Windows

Signed-off-by: Calle Pettersson <calle@cape.nu>
2019-06-14 12:26:55 +02:00
beorn7 e7f6132a76 Remove work duplication in doc comment
Signed-off-by: beorn7 <beorn@grafana.com>
2019-06-12 01:46:17 +02:00
beorn7 761a2ff07c Remove all deprecated features
This is in preparation of the upcoming v1 release.

Signed-off-by: beorn7 <beorn@grafana.com>
2019-06-11 16:28:47 +02:00