Skip to content

Commit deda44c

Browse files
authored
Merge pull request #1083 from lucperkins/lperkins/issue-927-protobuf
Remove mentions of the Protobuf format
2 parents f725aa4 + 6a34bd3 commit deda44c

File tree

2 files changed

+77
-111
lines changed

2 files changed

+77
-111
lines changed

content/docs/instrumenting/exposition_formats.md

Lines changed: 71 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -5,104 +5,98 @@ sort_rank: 6
55

66
# Exposition formats
77

8-
Prometheus implements two different wire formats which clients may use to
9-
expose metrics to a Prometheus server: a simple text-based format and a more
10-
efficient and robust protocol-buffer format. Prometheus servers and clients use
11-
[content negotiation](http://en.wikipedia.org/wiki/Content_negotiation) to
12-
establish the actual format to use. A server will prefer receiving the
13-
protocol-buffer format, and will fall back to the text-based format if the
14-
client does not support the former.
15-
16-
NOTE: **NOTE:** Prometheus 2.0 removed support for the protocol-buffer format
17-
and only supports the text-based format.
18-
19-
The majority of users should use the existing [client libraries](/docs/instrumenting/clientlibs/)
20-
that already implement the exposition formats.
21-
22-
## Format version 0.0.4
23-
24-
This is the current metrics exposition format version.
25-
26-
As of this version, there are two alternate formats understood by Prometheus: a
27-
protocol-buffer based format and a text format. Clients must support at least
28-
one of these two alternate formats.
29-
30-
In addition, clients may optionally expose other text formats that are not
31-
understood by Prometheus. They exist solely for consumption by human beings and
32-
are meant to facilitate debugging. It is strongly recommended that a client
33-
library supports at least one human-readable format. A human-readable format
34-
should be the fallback in case the HTTP `Content-Type` header is not understood
35-
by the client library. The version `0.0.4` text format is generally considered
36-
human readable, so it is a good fallback candidate (and also understood by
37-
Prometheus).
38-
39-
### Format variants comparison
40-
41-
| | Protocol buffer format | Text format |
42-
|---------------|------------------------|-------------|
43-
| **Inception** | April 2014 | April 2014 |
44-
| **Supported in** | Prometheus version `>=0.4.0`, `<2.0.0` | Prometheus version `>=0.4.0` |
45-
| **Transmission** | HTTP | HTTP |
46-
| **Encoding** | [32-bit varint-encoded record length-delimited](https://developers.google.com/protocol-buffers/docs/reference/java/com/google/protobuf/AbstractMessageLite#writeDelimitedTo(java.io.OutputStream)) Protocol Buffer messages of type [io.prometheus.client.MetricFamily](https://github.com/prometheus/client_model/blob/086fe7ca28bde6cec2acd5223423c1475a362858/metrics.proto#L76- L81) | UTF-8, `\n` line endings |
47-
| **HTTP `Content-Type`** | `application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=delimited` | `text/plain; version=0.0.4` (A missing `version` value will lead to a fall-back to the most recent text format version.) |
48-
| **Optional HTTP `Content-Encoding`** | `gzip` | `gzip` |
49-
| **Advantages** | <ul><li>Cross-platform</li><li>Size</li><li>Encoding and decoding costs</li><li>Strict schema</li><li>Supports concatenation and theoretically streaming (only server-side behavior would need to change)</li></ul> | <ul><li>Human-readable</li><li>Easy to assemble, especially for minimalistic cases (no nesting required)</li><li>Readable line by line (with the exception of type hints and docstrings)</li></ul> |
50-
| **Limitations** | <ul><li>Not human-readable</li></ul> | <ul><li>Verbose</li><li>Types and docstrings not integral part of the syntax, meaning little-to-nonexistent metric contract validation</li><li>Parsing cost</li></ul>|
51-
| **Supported metric primitives** | <ul><li>Counter</li><li>Gauge</li><li>Histogram</li><li>Summary</li><li>Untyped</li></ul> | <ul><li>Counter</li><li>Gauge</li><li>Histogram</li><li>Summary</li><li>Untyped</li></ul> |
52-
| **Compatibility** | Version `0.0.3` protocol buffers are also valid version `0.0.4` protocol buffers. | none |
53-
54-
### Protocol buffer format details
55-
56-
Reproducible sorting of the protocol buffer fields in repeated expositions is
57-
preferred but not required, i.e. do not sort if the computational cost is
58-
prohibitive.
59-
60-
Each `MetricFamily` within the same exposition must have a unique name. Each
61-
`Metric` within the same `MetricFamily` must have a unique set of `LabelPair`
62-
fields. Otherwise, the ingestion behavior is undefined.
8+
Metrics can be exposed to Prometheus using a simple [text-based](#text-based-format)
9+
exposition format. There's a variety of [client libraries](/docs/instrumenting/clientlibs/)
10+
that implement this format for you. If your preferred language doesn't have a client
11+
library you can [create your own](/docs/instrumenting/writing_clientlibs/).
12+
13+
NOTE: **NOTE** Some earlier versions of Prometheus supported an exposition format based on
14+
[Protocol Buffers](https://developers.google.com/protocol-buffers/) (aka Protobuf) in
15+
addition to the current text-based format. As of version 2.0, however, Prometheus no
16+
longer supports the Protobuf-based format. You can read about the reasoning behind
17+
this change in [this
18+
document](https://github.com/RichiH/OpenMetrics/blob/master/protobuf_vs_text.md).
19+
20+
## Text-based format
21+
22+
As of Prometheus version 2.0, all processes that expose metrics to Prometheus need to use
23+
a text-based format. In this section you can find some [basic information](#basic-info)
24+
about this format as well as a more [detailed breakdown](#text-format-details) of the
25+
format.
26+
27+
### Basic info
28+
29+
| Aspect | Description |
30+
|--------|-------------|
31+
| **Inception** | April 2014 |
32+
| **Supported in** | Prometheus version `>=0.4.0` |
33+
| **Transmission** | HTTP |
34+
| **Encoding** | UTF-8, `\n` line endings |
35+
| **HTTP `Content-Type`** | `text/plain; version=0.0.4` (A missing `version` value will lead to a fall-back to the most recent text format version.) |
36+
| **Optional HTTP `Content-Encoding`** | `gzip` |
37+
| **Advantages** | <ul><li>Human-readable</li><li>Easy to assemble, especially for minimalistic cases (no nesting required)</li><li>Readable line by line (with the exception of type hints and docstrings)</li></ul> |
38+
| **Limitations** | <ul><li>Verbose</li><li>Types and docstrings not integral part of the syntax, meaning little-to-nonexistent metric contract validation</li><li>Parsing cost</li></ul>|
39+
| **Supported metric primitives** | <ul><li>Counter</li><li>Gauge</li><li>Histogram</li><li>Summary</li><li>Untyped</li></ul> |
6340

6441
### Text format details
6542

66-
The protocol is line-oriented. A line-feed character (`\n`) separates lines.
67-
The last line must end with a line-feed character. Empty lines are ignored.
43+
Prometheus' text-based format is line oriented. Lines are separated by a line
44+
feed character (`\n`). The last line must end with a line feed character.
45+
Empty lines are ignored.
46+
47+
#### Line format
6848

6949
Within a line, tokens can be separated by any number of blanks and/or tabs (and
70-
have to be separated by at least one if they would otherwise merge with the
71-
previous token). Leading and trailing whitespace is ignored.
50+
must be separated by at least one if they would otherwise merge with the previous
51+
token). Leading and trailing whitespace is ignored.
52+
53+
#### Comments, help text, and type information
7254

7355
Lines with a `#` as the first non-whitespace character are comments. They are
7456
ignored unless the first token after `#` is either `HELP` or `TYPE`. Those
7557
lines are treated as follows: If the token is `HELP`, at least one more token
7658
is expected, which is the metric name. All remaining tokens are considered the
7759
docstring for that metric name. `HELP` lines may contain any sequence of UTF-8
78-
characters (after the metric name), but the backslash and the line-feed
60+
characters (after the metric name), but the backslash and the line feed
7961
characters have to be escaped as `\\` and `\n`, respectively. Only one `HELP`
80-
line may exist for the same metric name.
62+
line may exist for any given metric name.
8163

8264
If the token is `TYPE`, exactly two more tokens are expected. The first is the
8365
metric name, and the second is either `counter`, `gauge`, `histogram`,
8466
`summary`, or `untyped`, defining the type for the metric of that name. Only
85-
one `TYPE` line may exist for the same metric name. The `TYPE` line for a
86-
metric name has to appear before the first sample is reported for that metric
67+
one `TYPE` line may exist for a given metric name. The `TYPE` line for a
68+
metric name must appear before the first sample is reported for that metric
8769
name. If there is no `TYPE` line for a metric name, the type is set to
88-
`untyped`. Remaining lines describe samples, one per line, with the following
89-
syntax (EBNF):
70+
`untyped`.
71+
72+
The remaining lines describe samples (one per line) using the following syntax
73+
([EBNF](https://en.wikipedia.org/wiki/Extended_Backus%E2%80%93Naur_form)):
74+
75+
```
76+
metric_name [
77+
"{" label_name "=" `"` label_value `"` { "," label_name "=" `"` label_value `"` } [ "," ] "}"
78+
] value [ timestamp ]
79+
```
80+
81+
In the sample syntax:
9082

91-
metric_name [
92-
"{" label_name "=" `"` label_value `"` { "," label_name "=" `"` label_value `"` } [ "," ] "}"
93-
] value [ timestamp ]
83+
* `metric_name` and `label_name` carry the usual Prometheus expression language restrictions.
84+
* `label_value` can be any sequence of UTF-8 characters, but the backslash (`\`, double-quote (`"`}, and line feed (`\n`) characters have to be escaped as `\\`, `\"`, and `\n`, respectively.
85+
* `value` is a float.
86+
* the `timestamp` is an `int64` (milliseconds since epoch, i.e. 1970-01-01 00:00:00 UTC, excluding leap seconds), represented as required by the [Go strconv package](http://golang.org/pkg/strconv/) (see functions [`ParseInt`](https://golang.org/pkg/strconv/#ParseInt) and [`ParseFloat`](https://golang.org/pkg/strconv/#ParseFloat)). In addition to standard integers, `Nan`, `+Inf`, and `-Inf` are valid values representing not a number, positive infinity, and negative infinity, respectively.
9487

95-
`metric_name` and `label_name` have the usual Prometheus expression language restrictions. `label_value` can be any sequence of UTF-8 characters, but the backslash, the double-quote, and the line-feed characters have to be escaped as `\\`, `\"`, and `\n`, respectively.
96-
`value` is a float, and timestamp an `int64` (milliseconds since epoch, i.e. 1970-01-01 00:00:00 UTC, excluding leap seconds), represented as required by the [Go strconv package](http://golang.org/pkg/strconv/) (see functions `ParseInt` and `ParseFloat`). In particular, `Nan`, `+Inf`, and `-Inf` are valid values.
88+
#### Grouping and sorting
9789

98-
All lines for a given metric must be provided as one uninterrupted group, with
90+
All lines for a given metric must be provided as one single group, with
9991
the optional `HELP` and `TYPE` lines first (in no particular order). Beyond
10092
that, reproducible sorting in repeated expositions is preferred but not
10193
required, i.e. do not sort if the computational cost is prohibitive.
10294

103-
Each line must have a unique combination of metric name and labels. Otherwise,
95+
Each line must have a unique combination of a metric name and labels. Otherwise,
10496
the ingestion behavior is undefined.
10597

98+
#### Histograms and summaries
99+
106100
The `histogram` and `summary` types are difficult to represent in the text
107101
format. The following conventions apply:
108102

@@ -113,7 +107,11 @@ format. The following conventions apply:
113107
* A histogram _must_ have a bucket with `{le="+Inf"}`. Its value _must_ be identical to the value of `x_count`.
114108
* The buckets of a histogram and the quantiles of a summary must appear in increasing numerical order of their label values (for the `le` or the `quantile` label, respectively).
115109

116-
See also the example below.
110+
### Text format example
111+
112+
Below is an example of a full-fledged Prometheus metric exposition, including
113+
comments, `HELP` and `TYPE` expressions, a histogram, a summary, character
114+
escaping examples, and more.
117115

118116
```
119117
# HELP http_requests_total The total number of HTTP requests.
@@ -154,31 +152,6 @@ rpc_duration_seconds_sum 1.7560473e+07
154152
rpc_duration_seconds_count 2693
155153
```
156154

157-
#### Optional Text Representations
158-
159-
The following three optional text formats are meant for human consumption only
160-
and are not understood by Prometheus. Their definition may therefore be
161-
somewhat loose. Client libraries may or may not support these formats. Tools
162-
should not rely on these formats.
163-
164-
1. HTML: This format is requested by an HTTP `Content-Type` header with value
165-
of `text/html`. It is a "pretty" rendering of the metrics to be looked at in a
166-
browser. While the generating client is technically completely free in
167-
assembling the HTML, consistency between client libraries should be aimed for.
168-
2. Protocol buffer text format: Identical to the protocol buffer format, but in
169-
text form. It consists of the protocol messages concatenated in their text
170-
format (also known as "debug strings"), separated by an additional new line
171-
character (i.e. there is an empty line between protocol messages). The format
172-
is requested as the protocol buffer format, but the `encoding` in the HTTP
173-
`Content-Type` header set to `text`.
174-
3. Protocol buffer compact text format: Identical to (2) but using the compact
175-
text format instead of the normal text format. The compact text format puts the
176-
whole protocol message on one line. The protocol messages are still separated
177-
by new line characters, but no "empty line" is needed for separation. (Simply
178-
one protocol message per line.) The format is requested as the protocol buffer
179-
format, but the `encoding` in the HTTP `Content-Type` header set to
180-
`compact-text`.
181-
182155
## Historical versions
183156

184157
For details on historical format versions, see the legacy

content/docs/instrumenting/writing_clientlibs.md

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -312,15 +312,8 @@ descriptions, to lead by example.
312312

313313
## Exposition
314314

315-
Clients MUST implement one of the documented [exposition
316-
formats](/docs/instrumenting/exposition_formats).
317-
318-
Clients MAY implement more than one format. There SHOULD be a human readable
319-
format offered.
320-
321-
If in doubt, go for the text format. It doesn’t have a dependency (protobuf),
322-
tends to be easy to produce, is human readable and the performance benefits of
323-
protobuf are not that significant for most use cases.
315+
Clients MUST implement the text-based exposition format outlined in the
316+
[exposition formats](/docs/instrumenting/exposition_formats) documentation.
324317

325318
Reproducible order of the exposed metrics is ENCOURAGED (especially for human
326319
readable formats) if it can be implemented without a significant resource cost.
@@ -368,12 +361,12 @@ unit-test their use of the instrumentation code. For example, the
368361
## Packaging and dependencies
369362

370363
Ideally, a client library can be included in any application to add some
371-
instrumentation, without having to worry about it breaking the application.
364+
instrumentation without breaking the application.
372365

373366
Accordingly, caution is advised when adding dependencies to the client library.
374-
For example, if a user adds a library that uses a Prometheus client that
375-
requires version 1.4 of protobuf but the application uses 1.2 elsewhere, what
376-
will happen?
367+
For example, if you add a library that uses a Prometheus client that requires
368+
version x.y of a library but the application uses x.z elsewhere, will that have
369+
an adverse impact on the application?
377370

378371
It is suggested that where this may arise, that the core instrumentation is
379372
separated from the bridges/exposition of metrics in a given format. For

0 commit comments

Comments
 (0)