Skip to content

TextFormatUtil.writeTimestamp writes a value with a decimal point but the spec specifies an int64 #1277

@garthy

Description

@garthy

The method here https://github.com/prometheus/client_java/blob/7016bf7c5749e806ef91a918fdb294d394b83a16/prometheus-metrics-exposition-textformats/src/main/java/io/prometheus/metrics/expositionformats/TextFormatUtil.java#L24C15-L35

static void writeTimestamp(Writer writer, long timestampMs) throws IOException {
    writer.write(Long.toString(timestampMs / 1000L));
    writer.write(".");

Writes a decimal point.

The spec https://prometheus.io/docs/instrumenting/exposition_formats/#text-format-details

specifies the timestamp as an int64

The timestamp is an int64 (milliseconds since epoch, i.e. 1970-01-01 00:00:00 UTC, excluding leap seconds), represented as required by Go's [ParseInt()](https://golang.org/pkg/strconv/#ParseInt) function.

This causes Prometheus/promtool to error on metrics with a timestamp

error while linting: text format parsing error in line 17: expected integer as timestamp, got "1739889638.000"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions