influxdb/influxdb_line_protocol
Phil Bracikowski 8afa2f473d
fix(lp parser): adjust parsing tagsets: better error message and error on corner case (#7997)
* fix(lp parser): improves the error message when parsing tagsets

A tagset is an optional list of (tag_key=tag_value) that start
immediatelly after the measurement. The tagset and measurement are
separated by a comma. If that comma is present, at least one tag=value
pair must be present.

This pr expresses that must relationship and provides a Tag Set
Malformed erorr now if there's something wrong with the tag set.

The input test case is added which is missing the tag value - I'd like
to improve the errors to be more specific still, but one case at a time.

* fixes #7772

* chore: add test case

This commit adds a test case for a comma after the measurement but no
tagset thereafter. This is also an error condition. Before this PR this
was accepted as an empty tagset, but the spec and the canonical golang
parser do not permit this.
2023-06-16 15:16:11 +00:00
..
src fix(lp parser): adjust parsing tagsets: better error message and error on corner case (#7997) 2023-06-16 15:16:11 +00:00
Cargo.toml chore(deps): Bump log from 0.4.18 to 0.4.19 (#7966) 2023-06-12 08:38:44 +00:00
README.md chore(influxdb_line_protocol): Prepare `influxdb_line_protocol` for crates.io release (#7195) 2023-03-16 17:55:10 +00:00
RELEASE.md chore(influxdb_line_protocol): Prepare `influxdb_line_protocol` for crates.io release (#7195) 2023-03-16 17:55:10 +00:00

README.md

influxdb_line_protocol

This crate contains pure Rust implementations of

  1. A parser for InfluxDB Line Protocol developed as part of the InfluxDB IOx project. This implementation is intended to be compatible with the Go implementation, however, this implementation uses a nom combinator-based parser rather than attempting to port the imperative Go logic so there are likely some small diferences.

  2. A builder to contruct valid InfluxDB Line Protocol

Example

Here is an example of how to parse the following line protocol data into a ParsedLine:

cpu,host=A,region=west usage_system=64.2 1590488773254420000
use influxdb_line_protocol::{ParsedLine, FieldValue};

let mut parsed_lines =
    influxdb_line_protocol::parse_lines(
        "cpu,host=A,region=west usage_system=64i 1590488773254420000"
    );
let parsed_line = parsed_lines
    .next()
    .expect("Should have at least one line")
    .expect("Should parse successfully");

let ParsedLine {
    series,
    field_set,
    timestamp,
} = parsed_line;

assert_eq!(series.measurement, "cpu");

let tags = series.tag_set.unwrap();
assert_eq!(tags[0].0, "host");
assert_eq!(tags[0].1, "A");
assert_eq!(tags[1].0, "region");
assert_eq!(tags[1].1, "west");

let field = &field_set[0];
assert_eq!(field.0, "usage_system");
assert_eq!(field.1, FieldValue::I64(64));

assert_eq!(timestamp, Some(1590488773254420000));