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
d3ad0d365e
commit
8bd5aa3516
2 changed files with 4 additions and 6 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.
|
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.
|
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.
|
It can be overriden by passing unix timestamp in *milliseconds* via `timestamp` query arg. For example, `/api/v1/import/prometheus?timestamp=1594370496905`.
|
||||||
For example, `/api/v1/import/prometheus?timestamp=1594370496.905`.
|
|
||||||
|
|
||||||
VictoriaMetrics accepts arbitrary number of lines in a single request to `/api/v1/import/prometheus`, i.e. it supports data streaming.
|
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"
|
"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.
|
// It returns 0 if there is no `timestamp` query arg.
|
||||||
func GetTimestamp(req *http.Request) (int64, error) {
|
func GetTimestamp(req *http.Request) (int64, error) {
|
||||||
|
@ -14,10 +14,9 @@ func GetTimestamp(req *http.Request) (int64, error) {
|
||||||
if len(ts) == 0 {
|
if len(ts) == 0 {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
timestamp, err := strconv.ParseFloat(ts, 64)
|
timestamp, err := strconv.ParseInt(ts, 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, fmt.Errorf("cannot parse `timestamp=%s` query arg: %w", ts, err)
|
return 0, fmt.Errorf("cannot parse `timestamp=%s` query arg: %w", ts, err)
|
||||||
}
|
}
|
||||||
// Convert seconds to milliseconds.
|
return timestamp, nil
|
||||||
return int64(timestamp * 1e3), nil
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue