mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/protoparser: accept timestamp in milliseconds instead of seconds at /api/v1/import/prometheus
This improves consistency with timestamps in Prometheus text exposition format
This commit is contained in:
parent
2380e9b017
commit
f95eea60d1
3 changed files with 5 additions and 8 deletions
|
@ -552,8 +552,7 @@ Extra labels may be added to all the imported metrics by passing `extra_label=na
|
|||
For example, `/api/v1/import/prometheus?extra_label=foo=bar` would add `{foo="bar"}` label to all the imported metrics.
|
||||
|
||||
If timestamp is missing in `<metric> <value> <timestamp>` Prometheus exposition format line, then the current timestamp is used during data ingestion.
|
||||
It can be overriden by passing unix timestamp in seconds via `timestamp` query arg. The value may be fractional when millisecond precision is needed.
|
||||
For example, `/api/v1/import/prometheus?timestamp=1594370496.905`.
|
||||
It can be overriden by passing unix timestamp in *milliseconds* via `timestamp` query arg. For example, `/api/v1/import/prometheus?timestamp=1594370496905`.
|
||||
|
||||
VictoriaMetrics accepts arbitrary number of lines in a single request to `/api/v1/import/prometheus`, i.e. it supports data streaming.
|
||||
|
||||
|
|
|
@ -552,8 +552,7 @@ Extra labels may be added to all the imported metrics by passing `extra_label=na
|
|||
For example, `/api/v1/import/prometheus?extra_label=foo=bar` would add `{foo="bar"}` label to all the imported metrics.
|
||||
|
||||
If timestamp is missing in `<metric> <value> <timestamp>` Prometheus exposition format line, then the current timestamp is used during data ingestion.
|
||||
It can be overriden by passing unix timestamp in seconds via `timestamp` query arg. The value may be fractional when millisecond precision is needed.
|
||||
For example, `/api/v1/import/prometheus?timestamp=1594370496.905`.
|
||||
It can be overriden by passing unix timestamp in *milliseconds* via `timestamp` query arg. For example, `/api/v1/import/prometheus?timestamp=1594370496905`.
|
||||
|
||||
VictoriaMetrics accepts arbitrary number of lines in a single request to `/api/v1/import/prometheus`, i.e. it supports data streaming.
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
"strconv"
|
||||
)
|
||||
|
||||
// GetTimestamp extracts unix timestamp from `timestamp` query arg.
|
||||
// GetTimestamp extracts unix timestamp in milliseconds from `timestamp` query arg.
|
||||
//
|
||||
// It returns 0 if there is no `timestamp` query arg.
|
||||
func GetTimestamp(req *http.Request) (int64, error) {
|
||||
|
@ -14,10 +14,9 @@ func GetTimestamp(req *http.Request) (int64, error) {
|
|||
if len(ts) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
timestamp, err := strconv.ParseFloat(ts, 64)
|
||||
timestamp, err := strconv.ParseInt(ts, 10, 64)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("cannot parse `timestamp=%s` query arg: %w", ts, err)
|
||||
}
|
||||
// Convert seconds to milliseconds.
|
||||
return int64(timestamp * 1e3), nil
|
||||
return timestamp, nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue