Commit Graph

10 Commits

Author SHA1 Message Date
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 e5dc0421cd Move signature.go and related tests to the model package.
The LabelsToSignature function is now used outside of the prometheus
package, too. Leaving it in the prometheuos package is misleading
design and will lead to circulat import chains soon.

Change-Id: If1ca442d4023b33b138cf79fee68e82ff2a355be
2014-04-25 20:48:16 +02:00
Matt T. Proud 7efd34a6f8 Optimize fingerprinting and metric locks.
These are all simple changes we should have caught a long time ago:

1. The hashing mechanism for fingerprint label sets should have not
   allocated new objects for the actual hashing---at least not
   egregiously.  This simplifies the hash writing by just byte-
   dumping the string stream into the hasher.

2. The hashing mechanism within the scope of a metric does not care
   about the value of the label keys themselves but only of the label
   values.  The keys can be dropped from the calculation.

3. The locking mechanism for the metrics should not block on hash
   computation but rather solely on the actual mutation or critical
   section reads.

4. For scalar metrics (i.e., ones with niladic label signatures), we
   should rely on a preallocated map versus requesting a new one
   ad hoc.

This is tested with Go 1.1, so the results may yield other values
for us elsewhere:

BEFORE
BenchmarkLabelValuesToSignatureScalar	500000000	         3.97 ns/op	       0 B/op	       0 allocs/op
BenchmarkLabelValuesToSignatureSingle	 5000000	       714 ns/op	      74 B/op	       4 allocs/op
BenchmarkLabelValuesToSignatureDouble	 1000000	      1153 ns/op	     107 B/op	       5 allocs/op
BenchmarkLabelValuesToSignatureTriple	 1000000	      1588 ns/op	     138 B/op	       6 allocs/op
BenchmarkLabelToSignatureScalar	500000000	         3.91 ns/op	       0 B/op	       0 allocs/op
BenchmarkLabelToSignatureSingle	 2000000	       874 ns/op	      92 B/op	       5 allocs/op
BenchmarkLabelToSignatureDouble	 1000000	      1528 ns/op	     139 B/op	       7 allocs/op
BenchmarkLabelToSignatureTriple	 1000000	      2172 ns/op	     186 B/op	       9 allocs/op

AFTER
BenchmarkLabelValuesToSignatureScalar	500000000	         4.36 ns/op	       0 B/op	       0 allocs/op
BenchmarkLabelValuesToSignatureSingle	 5000000	       378 ns/op	      89 B/op	       4 allocs/op
BenchmarkLabelValuesToSignatureDouble	 5000000	       574 ns/op	     142 B/op	       5 allocs/op
BenchmarkLabelValuesToSignatureTriple	 5000000	       758 ns/op	     186 B/op	       6 allocs/op
BenchmarkLabelToSignatureScalar	500000000	         4.06 ns/op	       0 B/op	       0 allocs/op
BenchmarkLabelToSignatureSingle	 5000000	       472 ns/op	     106 B/op	       5 allocs/op
BenchmarkLabelToSignatureDouble	 2000000	       746 ns/op	     174 B/op	       7 allocs/op
BenchmarkLabelToSignatureTriple	 1000000	      1061 ns/op	     235 B/op	       9 allocs/op

In effect, a single metric mutation operation's lookup overhead will
move from Before::iBenchmarkLabelToSignature to
After::BenchmarkLabelValuesToSignature.  This MINIMALLY reduces
1/2 the overhead.  I would be hesitant in reading the memory
allocation statistics, for this was run with the GC still on and
thusly inaccurate per Go benchmarking documentation.

Before::BenchmarkLabelValuesToSignature never existed, so it is not
of any intrinsic value in itself.  That said, the cases that still
rely on LabelToSignature experience consistently a 1/2 drop in time.

Change-Id: Ifc9e69f718af65a59f5be8117473518233258159
2014-04-14 19:06:09 +02:00
Bernerd Schaefer 29ebb580db Add Reset(map[string]string) to Metric interface
Change-Id: I289cf8796adbd6ff55f23bba7730145329de00e1
2014-02-19 15:18:16 +01:00
Matt T. Proud 4956aea5ac Protocol Buffer negotiation support in handler. 2013-07-01 17:14:58 +02:00
Bernerd Schaefer d4ff2cc87a Fix race conditions in metric methods
Methods which expect to use a mutex must be defined for the pointer
value, because mutexes are not copyable.
2013-05-03 16:02:03 +02: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 0b30e065c8 Metrics explicitly implement Metric interface 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