Commit Graph

327 Commits

Author SHA1 Message Date
Matt T. Proud e782194166 Fix lock semantics on Summary#Reset.
This erroneously used the read lock as opposed to the write lock.

Change-Id: Ib127f8c117a516709eff9fd927603879501089b4
2014-04-15 01:49:28 +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
Bjoern Rabenstein b83e1b7cad Remove redundant __name__ label from protobuf output.
Change-Id: I72d5dbccb0325d6edf7abe5bca88dc5a6001029c
2014-04-03 15:18:12 +02:00
Bjoern Rabenstein ee34486fa1 Add a low-level MetricFamily injection hook.
This hook is needed for the upcoming push gateway.

Also remove go vet warnings and add test for Handler().

Change-Id: If6c56676c7a0f10c16b4effae7285903f8267616
2014-04-02 19:41:44 +02:00
Julius Volz 7524a7a115 Fix test fingerprints after metric name label change.
Change-Id: I9d927ca2bbb7424c4caaeef918971134e3d61acb
2014-03-19 14:17:33 +01:00
Julius Volz f91d98c93e Fix Samples.Less() sorting method.
Change-Id: I337b7e6452674360f43f268c85fe7f31dee18044
2014-03-14 16:51:52 +01:00
Julius Volz bb957bc145 Change internal metric name label to __name__.
This also adds a check that forbids any user-supplied metrics to start
with the reserved label name prefix "__".

Change-Id: I2fe94c740b685ad05c4c670613cf2af7b9e1c1c0
2014-03-14 12:28:25 +01:00
Bernerd Schaefer 29ebb580db Add Reset(map[string]string) to Metric interface
Change-Id: I289cf8796adbd6ff55f23bba7730145329de00e1
2014-02-19 15:18:16 +01:00
Julius Volz 197e83f47e Fix remaining tests to work with new Timestamp type.
Change-Id: Ib0fb4e0b714d723e08e83283fbe95233fd0f987a
2013-12-03 10:17:04 +01:00
Julius Volz 3ffd7c4a6c Add custom Timestamp type for sample times.
So far we've been using Go's native time.Time for anything related to sample
timestamps. Since the range of time.Time is much bigger than what we need, this
has created two problems:

- there could be time.Time values which were out of the range/precision of the
  time type that we persist to disk, therefore causing incorrectly ordered keys.
  One bug caused by this was:

  https://github.com/prometheus/prometheus/issues/367

  It would be good to use a timestamp type that's more closely aligned with
  what the underlying storage supports.

- sizeof(time.Time) is 192, while Prometheus should be ok with a single 64-bit
  Unix timestamp (possibly even a 32-bit one). Since we store samples in large
  numbers, this seriously affects memory usage. Furthermore, copying/working
  with the data will be faster if it's smaller.

*MEMORY USAGE RESULTS*
Initial memory usage comparisons for a running Prometheus with 1 timeseries and
100,000 samples show roughly a 13% decrease in total (VIRT) memory usage. In my
tests, this advantage for some reason decreased a bit the more samples the
timeseries had (to 5-7% for millions of samples). This I can't fully explain,
but perhaps garbage collection issues were involved.

*WHEN TO USE THE NEW TIMESTAMP TYPE*
The new clientmodel.Timestamp type should be used whenever time
calculations are either directly or indirectly related to sample
timestamps.

For example:
- the timestamp of a sample itself
- all kinds of watermarks
- anything that may become or is compared to a sample timestamp (like the timestamp
  passed into Target.Scrape()).

When to still use time.Time:
- for measuring durations/times not related to sample timestamps, like duration
  telemetry exporting, timers that indicate how frequently to execute some
  action, etc.

Change-Id: I253a467388774280c10400fda122369ff77c1730
2013-10-31 17:12:03 +01:00
Bernerd Schaefer ad41ea8439 Merge "Cache signature of an empty label set" 2013-09-16 12:56:13 +02:00
Bernerd Schaefer 26ad852c94 Cache signature of an empty label set
This is an optimization of labelsToSignature to avoid excess allocations
when the label set is empty.

Change-Id: If2d59bbc3ae6d4457e2ded197b6f4e7c67e6a173
2013-09-11 17:41:07 +02:00
Bernerd Schaefer a9b3602cea Register copies the provided baseLabels
This ensures that you can pass the same base label set into multiple
Register() calls, e.g.:

    labels := map[string]string{"key": "value"}
    prometheus.Register("metric_1", "", labels, ...)
    prometheus.Register("metric_2", "", labels, ...)

Change-Id: I951e5c2ed7844c74eb3716d1bf07126ce558f266
2013-09-11 17:38:00 +02:00
Matt T. Proud 148fde894b Include summary sample sums and counts if present.
This commit finally unlocks the ability for the Prometheus client
users of the Summary metric type to automatically get total counts
and sums partitioned by labels.  It exposes them through two
synthetic variables, if the underlying data is present.

The following is the base case:

    foo_samples{quantile=0.5}  = <?>
    foo_samples{quantile=0.99} = <?>

The following results with this change:

    foo_samples{quantile=0.5}  = <?>
    foo_samples{quantile=0.99} = <?>
    foo_samples_sum            = <?>
    foo_samples_count          = <?>

Change-Id: I75b5ea0d8c851da8c0c82ed9c8ac0890e4238f87
2013-08-25 13:52:37 +02:00
juliusv f5f5a2007a Merge pull request #27 from prometheus/refactor/metric-label-merging
Add method to merge a LabelSet into a Metric with collision avoidance.
2013-08-12 06:58:45 -07:00
Julius Volz 9b9a115f95 Add method to merge a LabelSet into a Metric with collision avoidance.
Colliding labels can happen e.g. when an exporter job is scraped and already
includes "job" labels for its samples in /metrics. In this case, a
collisionPrefix of "exporter_" is added to the colliding target labels, but the
specifics (the collision prefix) are managed by Prometheus, not the client
library.
2013-08-12 15:46:42 +02:00
Matt T. Proud 88e73cf99c Merge pull request #25 from prometheus/refactor/ingestion/signatures
Update the Consumer Signature
2013-08-12 04:10:18 -07:00
Matt T. Proud 58af37fb72 Code Review: Get rid of cruft. 2013-08-12 12:59:57 +02:00
Matt T. Proud 28445c8c86 Merge pull request #26 from prometheus/feature/fingerprinting/set
Add formal fingerprint sets for intersection ops.
2013-08-12 03:58:04 -07:00
Matt T. Proud 90425cb55b Add formal fingerprint sets for intersection ops. 2013-08-12 11:32:21 +02:00
Matt T. Proud 89432f861e Remove base labels. 2013-08-12 11:29:41 +02:00
Matt T. Proud 65a55bbf4e Replace Process consumer channel with Ingester. 2013-08-12 11:29:41 +02:00
Matt T. Proud b92fd1caaa Garbage file. 2013-07-22 10:48:05 +02:00
juliusv 98fc5b23c1 Merge pull request #23 from prometheus/feature/summary/subtleties
Refresh of Histogram/Summary Behavior to Reflect Modern Expectations
2013-07-22 01:47:48 -07:00
Matt T. Proud 93130ba5c3 Introduce histogram purging support. 2013-07-21 17:45:57 +02:00
Matt T. Proud a10d055c32 Include sample count and sum in Proto output. 2013-07-21 17:45:57 +02:00
Matt T. Proud 624e57d292 Enclose artifact generation process into Makefile.
Completely decouple the build process from Travis and other things we
cannot control.
2013-07-21 17:45:53 +02:00
Matt T. Proud b6cac8669e Merge pull request #22 from prometheus/feature/accept-header-discrimination
WIP — Protocol Buffer negotiation support in handler.
2013-07-01 08:16:10 -07:00
Matt T. Proud 4956aea5ac Protocol Buffer negotiation support in handler. 2013-07-01 17:14:58 +02:00
Matt T. Proud 1fb7c8d34b Merge pull request #21 from prometheus/feature/accept-header-discrimination
Support Protocol Buffer Message Decoding
2013-06-27 02:16:27 -07:00
Matt T. Proud 35125cdac0 Implement Protocol Buffer Stream Decoding
This commit introduces protocol buffer telemetric stream decoding.
2013-06-26 18:19:50 +02:00
Matt T. Proud 03369306e0 Provide Discriminator For Protocol Buf. Streams
This commit introduces an incomplete processor that decodes varint
record length-delimited streams of io.prometheus.client.MetricFamily
Protocol Buffer messages.  The Go client presently does not support
generation of said messages, but this will unblock a number of Java
changes.
2013-06-26 13:25:10 +02:00
Matt T. Proud 6da8b95237 Fix: Include forgotten LabelSet.MergeFromMetric. 2013-06-23 14:42:10 +02:00
Matt T. Proud 5cadb31d7c Fix: Canned label const types.
We had a syntax error whereby canned label names were not LabelName.
2013-06-22 13:28:25 +02:00
Matt T. Proud 6b26678f98 Fix: Metric sorting comparators.
There was an oversight that resulted in indefinite recursion.
2013-06-22 13:28:15 +02:00
juliusv 024b00bcef Merge pull request #20 from prometheus/update/stringers
Update LabelSet and Metric String() methods from server.
2013-06-12 09:47:59 -07:00
Julius Volz 2c8b7cc19b Update LabelSet and Metric String() methods from server. 2013-06-12 18:47:30 +02:00
Matt T. Proud 14cbd6b8ce Merge pull request #19 from prometheus/refactor/model-inclusion
Include relevant server model artifacts.
2013-06-11 03:49:45 -07:00
Matt T. Proud f761854eff Code Review: Useless time and comment. 2013-06-11 12:42:31 +02:00
Matt T. Proud 10dae5d108 Include relevant server model artifacts.
This commit introduces all relevant server-side artifacts such that the
Result streams can be used by external parties for one-off tools and
such.  This will ultimately better enable us to support additional
wireformats with much more ease.
2013-06-11 11:45:21 +02:00
Matt T. Proud d36afbbd8d Merge pull request #18 from prometheus/refactor/decoder-inclusion
Extract core Prometheus value decoders.
2013-06-10 10:36:40 -07:00
Matt T. Proud 85899b3f4a Extract core Prometheus value decoders.
Bernerd had suggested extracting the value decoders and bundling them
into the client library.  After some reflection, I tend to agree with
this, since we can start breaking the onion of Prometheus itself and
localize the protocol management into its own scope.

A couple of major changes since moving:

- Protocol 0.0.2 has moved to a struct{} so that our tests can perform
  value matching, which cannot be done against function literals.

- Processing now acquires options to dictate behavioral changes of
  metrics bodies.

- Processing no longer closes the stream, thusly returning this to the
  hands of the caller.

- Process() has been renamed to ProcessSingle to better convey that it
  works on complete message bodies.  This paves the way for better
  streaming payload support that the next API version will offer.
2013-06-10 19:35:41 +02:00
Bernerd Schaefer c10c61ce05 Merge pull request #17 from prometheus/rename-test-helper-files
Rename test helper files to helpers_test.go
2013-05-06 02:17:18 -07:00
Bernerd Schaefer af56a93a80 Rename test helper files to helpers_test.go
This ensures that these files are properly included only in testing.

[Fixes #10]
2013-05-06 11:13:44 +02:00
Bernerd Schaefer 8296a0cb49 Merge pull request #16 from prometheus/fix/race-conditions
Fix race conditions in metric methods
2013-05-06 02:08:14 -07: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 9ba7cdf4cf Merge pull request #15 'feature/expose-schema-through-content-type' 2013-04-29 10:18:09 +02:00
Matt T. Proud 4c1c13d109 Merge pull request #9 from prometheus/refactor/user-experience/standardized-directories
Rearrange file and package per convention.
2013-04-28 10:43:02 -07:00
Matt T. Proud 960107461e Migrate documentation to markdown. 2013-04-28 19:21:30 +02:00
Bernerd Schaefer f60c783b29 Adhere to telemetry schema 0.0.2
* The schema and version of telemetry data is exposed through the
  Content-Type header instead of through a custom HTTP Header.

See [Prometheus Client Data Exposition Format][1] for more details.

[1]: https://docs.google.com/a/soundcloud.com/document/d/1ZjyKiKxZV83VI9ZKAXRGKaUKK2BIWCT7oiGBKDBpjEY/edit#heading=h.wnviarbnyxcj
2013-04-25 17:43:03 +02:00