Commit Graph

13 Commits

Author SHA1 Message Date
beorn7 a2facc3074 Iterate on a proposed performance improvement for counters
Original discussion see
https://github.com/prometheus/client_golang/pull/362 .

Assuming that the most frequently used method of a `Gauge` is `Set`
and the most frequently used method of a `Conuter` is `Inc`, this
separates the implementation of both metric types. `Inc` and integral
`Add` of a counter is now handled in a separate `uint64`. This would
create a race in `Set`, but luckily, there is no `Set` anymore in a
counter.

All attempts to solve above race (to use the same idea for a `Gauge`)
slow down `Set`, So we just stick with the old implementation
(formerly `value`) for `Gauge`.
2018-01-19 19:06:43 +01:00
beorn7 606b8f85e5 - Point from Inc and Dec to Add and Sub in doc comments.
- Deprecate Untyped for direct instrumentation.

- Add a SetToCurrentTime method to Gauge

Note that adding the SetToCurrentTime method is not really following
Go's principle of lean interfaces. However, the Gauge interface is
already quite fat. (The only methods really required are Set and
Add. Everything else could be expressed in terms of those two.) So we
have already quite a few "convenience" methods traditionally, so I
think we should stay consistent here.

The alternatives would be:

- Not support SetToCurrentTime at all (it's only a SHOULD in the
  guidelines).

- A top level function `SetToCurrentTime(Gauge)`.

- Just a helper `CurrentTime()` that returns the curent unix time in
  seconds as a float (which is pretty verbose using the standard
  library, see code in this commit). This would allow
  `myGauge.Set(CurrentTime)`.

Weighing all circumstances, I believe the way in this commit is the
least evil. Issue #223 could be used to rework interfaces more
fundamentally in a breaking change if feasible.
2016-11-18 19:32:10 +01:00
Julius Volz 738b69e61a Use non-rewritten Godep imports. 2015-02-27 16:49:40 +01:00
Julius Volz 169c8a68e1 Use godep with import rewriting for vendoring.
The new vendoring was produced by running:

    godep save -r ./examples/... ./prometheus/... ./text/... ./model/... ./extraction/...

Two things to note:

- "extraction/processor0_0_{1,2}_test.go" imported a package from
  "github.com/prometheus/prometheus", all for just one tiny testing
  function. To not have to deal with a circular vendoring dependency, I
  simply replaced the usage of the function by some in-line logic.

- godep grouped the rewritten imports slightly differently for some
  reason, but at least the standard library imports are still in a
  separate section. Not sure if it's worth manually keeping our old
  import grouping scheme or if we should simply use that godep-generated
  one.
2015-02-26 00:47:03 +01:00
beorn7 4f73a8b017 Improve Gauge and Counter performance.
This is accomplished by using the functions from the atomic packages
instead of a mutex.

benchmark                                      old ns/op     new ns/op     delta
BenchmarkGaugeNoLabels-2                       118           9.40          -92.03%
BenchmarkGaugeNoLabels                         117           9.38          -91.98%
BenchmarkGaugeNoLabels-4                       117           9.40          -91.97%
BenchmarkCounterNoLabels-2                     137           16.8          -87.74%
BenchmarkCounterNoLabels                       136           16.8          -87.65%
BenchmarkCounterNoLabels-4                     136           16.8          -87.65%
BenchmarkGaugeWithLabelValues-4                400           279           -30.25%
BenchmarkGaugeWithLabelValues-2                398           279           -29.90%
BenchmarkGaugeWithLabelValues                  400           283           -29.25%
BenchmarkCounterWithLabelValues-4              397           286           -27.96%
BenchmarkCounterWithLabelValues-2              396           286           -27.78%
BenchmarkCounterWithLabelValues                394           285           -27.66%
BenchmarkCounterWithPreparedMappedLabels       587           454           -22.66%
BenchmarkCounterWithPreparedMappedLabels-2     581           456           -21.51%
BenchmarkCounterWithPreparedMappedLabels-4     654           539           -17.58%
BenchmarkCounterWithMappedLabels-2             1441          1218          -15.48%
BenchmarkCounterWithMappedLabels               1099          963           -12.37%
BenchmarkCounterWithMappedLabels-4             1636          1501          -8.25%
2015-02-02 18:11:11 +01:00
Bjoern Rabenstein d7f8eb1083 Change "Prometheus Team" to "The Prometheus Authors". 2015-02-02 15:14:36 +01:00
Bjoern Rabenstein f9401ffab9 Added "callback" metrics, e.g. GaugeFunc.
Change-Id: I449b558207963ce60572bd04c8102f1db684dd4c
2014-06-23 14:35:01 +02:00
Bjoern Rabenstein 5d40912fd2 Complete rewrite of the exposition library.
This rewrite had may backs and forths. In my git repository, it
consists of 35 commits which I cannot group or merge into reasonable
review buckets. Gerrit breaks fundamental git semantics, so I have to
squash the 35 commits into one for the review.

I'll push this not with refs/for/master, but with refs/for/next so
that we can transition after submission in a controlled fashion.

For the review, I recommend to start with looking at godoc and in
particular the many examples. After that, continue with a line-by-line
detailed review. (The big picture is hopefully as expected after
wrapping up the discussion earlier.)

Change-Id: Ib38cc46493a5139ca29d84020650929d94cac850
2014-06-17 14:08:22 +02:00
Bjoern Rabenstein 00816363e4 Remove the one duplication of the Tester interface.
Change-Id: Ie17ec3393a7e12e0f27e51b4060aa478a172f612
2014-04-25 20:51:08 +02:00
Bernerd Schaefer 29ebb580db Add Reset(map[string]string) to Metric interface
Change-Id: I289cf8796adbd6ff55f23bba7730145329de00e1
2014-02-19 15:18:16 +01:00
Bernerd Schaefer 71dd60e431 Registry and Metrics implement json.Marshaler
* Drop `AsMarshallable()` from the Metric interface. Use
  `json.Marshaler` and `MarshalJSON()`, and leverage JSON struct tags
  where possible.

* Add `MarshalJSON()` to Registry and remove `dumpToWriter`, which
  makes the registry handler much simpler.

In addition to simplifying some of the marshalling behavior, this also
has the nice side effect of cutting down the number of
`map[string]interface{}` instances.
2013-04-19 15:07:24 +02:00
Bernerd Schaefer 3433b798b3 Use raw string literals in tests 2013-04-19 15:04:07 +02:00
Matt T. Proud f320d28a6c Rearrange file and package per convention.
WIP - Please review but do not merge.
2013-04-04 15:27:09 +02:00