0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[Prometheus] Created Timestamps Zero Injection

Last updated at Posted at 2025-05-12

はじめに

この記事は Prometheus の Created Timestamps Zero Injection がどういった機能なのかを理解するために自分なりに情報を整理した内容になっています。正確な情報を知りたい方は参考資料をご参照ください。

Created Timestamps Zero Injection とは?

メトリクスのメタデータで提供される 0 値の開始時間 (リセット時間) を元に、Counter、Summary、Classic Histogram メトリクスに 0 値の合成サンプルを注入する機能です。

現時点では Prometheus Protobuf フォーマットのメトリクスのみがサポートされていて、他フォーマットのサポートは WIP となっています。

chunk-with-created-timestamps.png

上図でいうと、T-1 と T と T+2 の3サンプルが収集されていて T+2 でリセットが発生している場合に、メトリクスが持つ開始時間 (リセット時間) を元に Prometheus が T-5 と T+1 に 0 値の合成サンプルが注入するイメージです。

ちなみに OpenMetricsOpenTelemetry も Counter の開始時間を提供する仕様になっていますが、Prometheus 側でパーサーが実装されておらず現在は未サポートという状態です。

#OpenMetrics
A MetricPoint in a Metric with the type Counter SHOULD have a Timestamp value called Created. This can help ingestors discern between new metrics and long-running ones it did not see before.

#OpenTelemetry
Every OTLP metric data point has two associated timestamps. The first, mandatory timestamp is the one associated with the observation, the moment when the measurement became current or took effect, and is referred to as TimeUnixNano. The second, optional timestamp is used to indicate when a sequence of points is unbroken, and is referred to as StartTimeUnixNano.

導入された背景

以下のような Counter メトリクスのエッジケースに対応するために導入されました。

  • 初期化されていない Counter はインクリメントされた値でメトリクスが開始するため、0 値がいつ開始したのか分からず可視化やアラートに影響する可能性がある (レート計算など)
  • 値のリセット後すぐにインクリメントされてその値が最後に収集した値より大きい場合、Counter のリセットを検出できない可能性がある

なお、Summary や Classic Histogram のメトリクスも Counter で表現されるので同じ問題が発生します。

有効にする方法

Prometheus 側

まだ実験的な機能という位置付けでデフォルト無効なので Feature Flag での有効化が必要です (公式ドキュメント)。ちなみに v2.50.0 から導入された機能なので、それ以前のバージョンを使用している場合はバージョンアップが必要です。

--enable-feature=created-timestamp-zero-ingestion

この機能は Prometheus Protobuf プロトコルのみをサポートしている兼ね合いで、この機能を有効にすると scrape_config.scrape_protocols のデフォルト値が変わり、Exporter とのネゴシエーションで Prometheus Protobuf プロトコルが優先されるようになります。

Exporters 側

prometheus/client_golang の v1.17.0 以降を利用している場合は、Content Negotiation で Prometheus Protobuf が使用されると Created Timestamp の公開がデフォルトで有効になっています。Exporter の実装では基本的にこのライブラリを使用すると思うのでバージョンアップ以外に特別な作業は不要かと思われます。

参考資料

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?