【问题标题】:loki: "error at least one label pair is required per stream"loki:“错误每个流至少需要一个标签对”
【发布时间】:2021-12-16 23:20:56
【问题描述】:

我根据these instructions在docker本地运行loki、pomtrail、grafana

当我尝试运行以下测试以直接向 loki 发送数据时:

curl -i -H "Content-type: application/json" -X POST --data '{ "streams": [ { "labels": { "job": "randomjob" }, "entries": [{ "ts": "2021-10-12T16:13:06.801064Z", "line": "TEST!" }] } ] }' http://localhost:3100/loki/api/v1/push

我得到错误:

HTTP/1.1 400 Bad Request
Content-Type: text/plain; charset=utf-8
X-Content-Type-Options: nosniff
Date: Tue, 02 Nov 2021 12:09:26 GMT
Content-Length: 53

error at least one label pair is required per stream

为什么找不到标签? 谢谢。

【问题讨论】:

    标签: logging grafana-loki loki


    【解决方案1】:

    标签对的格式应该是(对于旧端点/api/prom/push)并且它有效:

    "labels": "{job=\"randomjob\"}"
    

    例如:

    curl -H "Content-Type: application/json" -XPOST -s "172.30.11.21:3100/api/prom/push" --data-raw   '{"streams": [
      { 
          "labels": "{job=\"randomjob\"}", 
          "entries": [
              { 
                  "ts": "2021-11-13T19:55:51.801064-00:00", 
                  "line": "TEST!" 
              }
          ] 
      }
    ]
    

    }'

    对于新端点/loki/api/v1/push,似乎需要将labels 字段更改为stream

    curl -H "Content-Type: application/json" -XPOST -s "172.30.11.21:3100/loki/api/v1/push" --data-raw '{"streams": [{ "stream": {"job": "randomjob"}, "values": [["1636841990000000000",  "TEST!" ]] }] }]}'
    

    【讨论】:

    • 天哪,修复了它。所以我只需要反斜杠??!我现在收到一个新错误loghttp.PushRequest.Streams: []*loghttp.Stream: Skip: do not know how to skip: 92, error found in #10 byte of ...,但这清楚地修复了标签对错误,所以接受答案!
    • 嗯,是的,对于旧端点,您需要使用 labels 值作为单个字符串,除了它包含 json-object,然后您需要转义内部双引号。对于新端点,字段不同:streamvalues
    猜你喜欢
    • 2014-11-18
    • 2017-11-16
    • 1970-01-01
    • 2011-07-21
    • 2016-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-01
    相关资源
    最近更新 更多