influxdata / influxdb

Scalable datastore for metrics, events, and real-time analytics
https://influxdata.com
Apache License 2.0
28.59k stars 3.54k forks source link

HTTP API timestamps don't evaluate correctly #23835

Open hnandiwada opened 1 year ago

hnandiwada commented 1 year ago

Steps to reproduce: List the minimal actions needed to reproduce the behavior.

  1. Create a row, eg meas,tag1=1,tag2=2 value=1 1665946265
  2. Send a POST request via Python requests module:
    rsp = requests.post(
    "https://us-east-1-1.aws.cloud2.influxdata.com/api/v2/write",
    params={"org": org, "bucket": bucket, "precision": "s"},
    headers=headers,
    data=data,
    )
  3. Look at raw data for bucket in UI

Expected behavior: I see my data point submitted with the correct time.

Actual behavior: No matter what timestamp I pass in, it evaluates to 2022-12-30T00:52:50.000Z. I'm submitting 4 points with an old timestamp and 4 with a more recent timestamp, and only 4 show up when I look at raw data.

Environment info:

Code:

    now = pytz.utc.localize(datetime.utcnow())
    headers = {"Authorization": f"Token {token}"}
    params = {"org": influx_org, "bucket": f"org_{org_id}", "precision": "s"}
    new_ts = int(now.timestamp())
    old_ts = int((now - timedelta(days=8)).timestamp())
    data = f"""\
advertising,campaign=campaign,... impressions=1 {old_ts}
advertising,campaign=... impressions=1 {old_ts}
advertising,campaign=... impressions=1 {old_ts}
advertising,campaign=... impressions=1 {old_ts}
advertising,campaign=... impressions=1 {new_ts}
advertising,campaign=... impressions=1 {new_ts}
advertising,campaign=... impressions=1 {new_ts}
advertising,campaign=... impressions=1 {new_ts}
"""
    rsp = requests.post(
        "https://us-east-1-1.aws.cloud2.influxdata.com/api/v2/write",
        params=params,
        headers=headers,
        data=data,
    )

This returns with a 204. I've tried different newline conventions with no luck. I've also tried converting data into a list and submitting each data point individually, and this yielded the same results. So, I don't think it's a newline issue.

hnandiwada commented 1 year ago

I found a solution for the issue. Previously, I submitted rows with measurement="advertising" and field="impressions". Something here causes the problem. When I submit the field as "advertising.impressions", it works without a hitch. The docs do not say or imply this. In fact, the examples given are specifically NOT dot-separated:

Please update the docs! This has been impossible to figure out without random experimentation.