管理 Pipeline
在 GreptimeDB 中,每个 pipeline 是一个数据处理单元集合,用于解析和转换写入的日志内容。本文档旨在指导您如何创建和删除 Pipeline,以便高效地管理日志数据的处理流程。
有关 Pipeline 的具体配置,请阅读 Pipeline 配置。
创建 Pipeline
GreptimeDB 提供了专用的 HTTP 接口用于创建 Pipeline。 假设你已经准备好了一个 Pipeline 配置文件 pipeline.yaml,使用以下命令上传配置文件,其中 test 是你指定的 Pipeline 的名称:
1. ## 上传 pipeline 文件。test 为 Pipeline 的名称
2. curl -X "POST" "http://localhost:4000/v1/events/pipelines/test" -F "[email protected]"
删除 Pipeline
可以使用以下 HTTP 接口删除 Pipeline:
1. ## test 为 Pipeline 的名称
2. curl -X "DELETE" "http://localhost:4000/v1/events/pipelines/test?version=2024-06-27%2012%3A02%3A34.257312110Z"
上面的例子中,我们删除了一个名为 test 的 Pipeline。version 参数是必须的,用于指定要删除的 Pipeline 的版本号。
查询 Pipeline
目前可以使用 SQL 来查询 Pipeline 的信息。
1. SELECT * FROM greptime_private.pipelines;
请注意,如果您使用 MySQL 或者 PostgreSQL 协议作为连接 GreptimeDB 的方式,查询出来的 Pipeline 时间信息精度可能有所不同,可能会丢失纳秒级别的精度。
为了解决这个问题,可以将 created_at 字段强制转换为 timestamp 来查看 Pipeline 的创建时间。例如,下面的查询将 created_at 以 bigint 的格式展示:
1. SELECT name, pipeline, created_at::bigint FROM greptime_private.pipelines;
查询结果如下:
1. name | pipeline | greptime_private.pipelines.created_at
2. ------+-----------------------------------+---------------------------------------
3. test | processors: +| 1719489754257312110
4. | - date: +|
5. | field: time +|
6. | formats: +|
7. | - "%Y-%m-%d %H:%M:%S%.3f"+|
8. | ignore_missing: true +|
9. | +|
10. | transform: +|
11. | - fields: +|
12. | - id1 +|
13. | - id2 +|
14. | type: int32 +|
15. | - fields: +|
16. | - type +|
17. | - logger +|
18. | type: string +|
19. | index: tag +|
20. | - fields: +|
21. | - log +|
22. | type: string +|
23. | index: fulltext +|
24. | - field: time +|
25. | type: time +|
26. | index: timestamp +|
27. | |
28. (1 row)
然后可以使用程序将 SQL 结果中的 bigint 类型的时间戳转换为时间字符串。
1. timestamp_ns="1719489754257312110"; readable_timestamp=$(TZ=UTC date -d @$((${timestamp_ns:0:10}+0)) +"%Y-%m-%d %H:%M:%S").${timestamp_ns:10}Z; echo "Readable timestamp (UTC): $readable_timestamp"
输出:
1. Readable timestamp (UTC): 2024-06-27 12:02:34.257312110Z
输出的 Readable timestamp (UTC) 即为 Pipeline 的创建时间同时也是版本号。
