Prometheus instrumentation library for Go applications
Go to file
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
documentation Migrate documentation to markdown. 2013-04-28 19:21:30 +02:00
examples Enclose artifact generation process into Makefile. 2013-07-21 17:45:53 +02:00
extraction Change internal metric name label to __name__. 2014-03-14 12:28:25 +01:00
model Fix test fingerprints after metric name label change. 2014-03-19 14:17:33 +01:00
prometheus Optimize fingerprinting and metric locks. 2014-04-14 19:06:09 +02:00
test Include relevant server model artifacts. 2013-06-11 11:45:21 +02:00
vendor/goautoneg Protocol Buffer negotiation support in handler. 2013-07-01 17:14:58 +02:00
.gitignore Enclose artifact generation process into Makefile. 2013-07-21 17:45:53 +02:00
.travis.yml Enclose artifact generation process into Makefile. 2013-07-21 17:45:53 +02:00
LICENSE Rearrange file and package per convention. 2013-04-04 15:27:09 +02:00
Makefile Optimize fingerprinting and metric locks. 2014-04-14 19:06:09 +02:00
README.md Include link to generated API documentation. 2013-03-28 10:46:16 +01:00
TODO Rearrange file and package per convention. 2013-04-04 15:27:09 +02:00

README.md

Overview

These Go packages are an extraction of pieces of instrumentation code I whipped-up for a personal project that a friend of mine and I are working on. We were in need for some rudimentary statistics to observe behaviors of the server's various components, so this was written.

The code here is not a verbatim copy thereof but rather a thoughtful re-implementation should other folks need to consume and analyze such telemetry.

N.B. --- I have spent a bit of time working through the model in my head and probably haven't elucidated my ideas as clearly as I need to. If you examine examples/{simple,uniform_random}/main.go and registry.go, you'll find several examples of what types of potential instrumentation use cases this package addresses. There are probably numerous Go language idiomatic changes that need to be made, but this task has been deferred for now.

Continuous Integration

Build Status

Documentation

Please read the generated documentation for the project's documentation from source code.

Basic Overview

Metrics

A metric is a measurement mechanism.

Gauge

A Gauge is a metric that exposes merely an instantaneous value or some snapshot thereof.

Counter

A Counter is a metric that exposes merely a sum or tally of things.

Histogram

A Histogram is a metric that captures events or samples into Buckets. It exposes its values via percentile estimations.

Buckets

A Bucket is a generic container that collects samples and their values. It prescribes no behavior on its own aside from merely accepting a value, leaving it up to the concrete implementation to what to do with the injected values.

Accumulating Bucket

An Accumulating Bucket is a Bucket that appends the new sample to a queue such that the eldest values are evicted according to a given policy.

Eviction Policies

Once an Accumulating Bucket reaches capacity, its eviction policy is invoked. This reaps the oldest N objects subject to certain behavior.

####### Remove Oldest This merely removes the oldest N items without performing some aggregation replacement operation on them.

####### Aggregate Oldest This removes the oldest N items while performing some summary aggregation operation thereupon, which is then appended to the list in the former values' place.

Tallying Bucket

A Tallying Bucket differs from an Accumulating Bucket in that it never stores any of the values emitted into it but rather exposes a simplied summary representation thereof. For instance, if a values therein is requested, it may situationally emit a minimum, maximum, an average, or any other reduction mechanism requested.

Getting Started

Testing

This package employs gocheck for testing. Please ensure that all tests pass by running the following from the project root:

$ go test ./...

The use of gocheck is summarily being phased out; however, old tests that use it still exist.