mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/protoparser/opentsdb: follow-up after 04b0e4e7bf
- Simplify the parser code to be less error prone - Document the change - Add a test for OpenTSDB put line with trailing whitespace without tags Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3290
This commit is contained in:
parent
04b0e4e7bf
commit
b8839df32c
3 changed files with 34 additions and 19 deletions
|
@ -16,10 +16,11 @@ The following tip changes can be tested by building VictoriaMetrics components f
|
|||
## tip
|
||||
|
||||
* FEATURE: [vmagent](https://docs.victoriametrics.com/vmagent.html): expose `__meta_consul_partition` label for targets discovered via [consul_sd_configs](https://docs.victoriametrics.com/sd_configs.html#consul_sd_configs) in the same way as [Prometheus 2.40 does](https://github.com/prometheus/prometheus/pull/11482).
|
||||
* FEATURE: [vmui](https://docs.victoriametrics.com/#vmui): show the trace in JSON view. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/2814). Thanks to @michal-kralik for [the pull request](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/3316).
|
||||
* FEATURE: [vmui](https://docs.victoriametrics.com/#vmui): show the [query trace](https://docs.victoriametrics.com/#query-tracing) in JSON view. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/2814). Thanks to @michal-kralik for [the pull request](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/3316).
|
||||
|
||||
* BUGFIX: [VictoriaMetrics enterprise](https://docs.victoriametrics.com/enterprise.html): fix a panic at `vminsert` when the discovered list of `vmstorage` nodes is changed during [automatic vmstorage discovery](https://docs.victoriametrics.com/Cluster-VictoriaMetrics.html#automatic-vmstorage-discovery). See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/3329).
|
||||
* BUGFIX: properly register new time series in per-day inverted index if they were ingested during the last 10 seconds of the day. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3309). Thanks to @lmarszal for the bugreport and for the [initial fix](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/3320).
|
||||
* BUGFIX: properly accept [OpenTSDB telnet put lines](https://docs.victoriametrics.com/#sending-data-via-telnet-put-protocol) without tags without the need to specify the trailing whitespace. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3290).
|
||||
|
||||
|
||||
## [v1.83.0](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.83.0)
|
||||
|
|
|
@ -82,26 +82,31 @@ func (r *Row) unmarshal(s string, tagsPool []Tag) ([]Tag, error) {
|
|||
}
|
||||
r.Timestamp = int64(timestamp)
|
||||
tail = trimLeadingSpaces(tail[n+1:])
|
||||
valueStr := ""
|
||||
tagsStr := ""
|
||||
n = strings.IndexByte(tail, ' ')
|
||||
if n < 0 {
|
||||
// see https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3290
|
||||
n = len(tail)
|
||||
// Missing tags.
|
||||
// Accept this case even if OpenTSDB forbids it according to http://opentsdb.net/docs/build/html/api_telnet/put.html:
|
||||
// > At least one tag pair must be present.
|
||||
// See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3290
|
||||
valueStr = tail
|
||||
} else {
|
||||
valueStr = tail[:n]
|
||||
tagsStr = tail[n+1:]
|
||||
}
|
||||
v, err := fastfloat.Parse(tail[:n])
|
||||
v, err := fastfloat.Parse(valueStr)
|
||||
if err != nil {
|
||||
return tagsPool, fmt.Errorf("cannot parse value from %q: %w", tail[:n], err)
|
||||
return tagsPool, fmt.Errorf("cannot parse value from %q: %w", valueStr, err)
|
||||
}
|
||||
r.Value = v
|
||||
if len(tail) > n {
|
||||
tagsStart := len(tagsPool)
|
||||
tagsPool, err = unmarshalTags(tagsPool, tail[n+1:])
|
||||
if err != nil {
|
||||
return tagsPool, fmt.Errorf("cannot unmarshal tags in %q: %w", s, err)
|
||||
}
|
||||
tags := tagsPool[tagsStart:]
|
||||
r.Tags = tags[:len(tags):len(tags)]
|
||||
tagsStart := len(tagsPool)
|
||||
tagsPool, err = unmarshalTags(tagsPool, tagsStr)
|
||||
if err != nil {
|
||||
return tagsPool, fmt.Errorf("cannot unmarshal tags in %q: %w", s, err)
|
||||
}
|
||||
|
||||
tags := tagsPool[tagsStart:]
|
||||
r.Tags = tags[:len(tags):len(tags)]
|
||||
return tagsPool, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -101,14 +101,23 @@ func TestRowsUnmarshalSuccess(t *testing.T) {
|
|||
},
|
||||
}},
|
||||
})
|
||||
// No tags
|
||||
f("put foobar 789 -123.456", &Rows{
|
||||
// Missing first tag
|
||||
// See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3290
|
||||
f("put aaa 123 43", &Rows{
|
||||
Rows: []Row{{
|
||||
Metric: "foobar",
|
||||
Value: -123.456,
|
||||
Timestamp: 789,
|
||||
Metric: "aaa",
|
||||
Value: 43,
|
||||
Timestamp: 123,
|
||||
}},
|
||||
})
|
||||
f("put aaa 123 43 ", &Rows{
|
||||
Rows: []Row{{
|
||||
Metric: "aaa",
|
||||
Value: 43,
|
||||
Timestamp: 123,
|
||||
}},
|
||||
})
|
||||
|
||||
// Fractional timestamp that is supported by Akumuli.
|
||||
f("put foobar 789.4 -123.456 a=b", &Rows{
|
||||
Rows: []Row{{
|
||||
|
|
Loading…
Reference in a new issue