# 全面支持 Node Exporter 上报大盘 | Greptime 双周精选

Source: https://greptime.cn/blogs/2024-04-24-biweekly

## 内容概述

作为一个成长中的开源项目，GreptimeDB 的进展离不开来自全球的社区贡献者们，感谢各位！

最近的内容更新如下：

- 实现了 PromQL 的 `scalar()` 函数。目前 GreptimeDB 已经全面支持了 node-exporter 的 Grafana 大盘（[https://grafana.com/grafana/dashboards/1860-node-exporter-full/](https://grafana.com/grafana/dashboards/1860-node-exporter-full/)，个别数字口径正在校准中）

- 支持查询时指定 Prometheus 协议的 `lookback` 参数。该参数可以控制 instant query 时选点 (`lookback`) 的时间范围，对于查询不同采集间隔的数据比较有用

- 兼容了 SQL 的 `TINYTEXT`，`MEDIUMTEXT` 和 `LONGTEXT` 类型。一些外部工具如 Apache SkyWalking 需要用到这些类型。

## 社区贡献者名单

在过去的两周里，GreptimeDB 共合并了 54 个 PR，其中有 5 位独立贡献者，累计 8 个 PR 被成功合并，还有很多待合并的 PR。

祝贺以下各位在过去 2 周内成为我们活跃的贡献者：

- @[CookiePieWw](https://github.com/CookiePieWw) ([#3731](https://github.com/GreptimeTeam/greptimedb/pull/3731) [#3732](https://github.com/GreptimeTeam/greptimedb/pull/3732))

- @[dimbtp](https://github.com/dimbtp)（[#3684](https://github.com/GreptimeTeam/greptimedb/pull/3684)）

- @[etolbakov](https://github.com/etolbakov)（[#3630](https://github.com/GreptimeTeam/greptimedb/pull/3630) [#3722](https://github.com/GreptimeTeam/greptimedb/pull/3722) [#3742](https://github.com/GreptimeTeam/greptimedb/pull/3742))

- @[realtaobo](https://github.com/realtaobo) ([#3700](https://github.com/GreptimeTeam/greptimedb/pull/3700) [#3725](https://github.com/GreptimeTeam/greptimedb/pull/3725))

- @[irenjj](https://github.com/irenjj) ([#3638](https://github.com/GreptimeTeam/greptimedb/pull/3638))

🎉 热烈欢迎@[irenjj](https://github.com/irenjj) 作为新的贡献者加入社区并成功合并了首个 PR，还有更多来自其他独立贡献者的 PR 正在等待合并。

<img src="/zh/blogs/2024-04-24-biweekly/image1.png" alt="Contributor of GreptimeDB" style="width: 80%; margin: 0 auto"/>

同时衷心感谢我们所有的成员和贡献者！是你们的付出让我们的项目得以成功，也是你们让 GreptimeDB 成为一个更优质的产品。让我们一起努力，建立一个更棒的社区！

## PR 亮点

### [db#3693](https://github.com/GreptimeTeam/greptimedb/pull/3693) 增加了对 `PromQL scalar()` 函数的支持

- `scalar()` 函数用于将一个 instant vector 转化为一个 scalar；

- 部分 Grafana 大盘，如 node-exporter 的大盘会用到该函数。例如使用以下 PromQL 计算 CPU 的平均负载（average load）：

```sql
scalar(node_load1{instance="node-exporter:9100",job="node"}) * 100
/
count(
    count by (cpu) (node_cpu_seconds_total{instance="node-exporter:9100",job="node"})
)
```

- 现 GreptimeDB 已经支持上述查询。

### [db#3630](https://github.com/GreptimeTeam/greptimedb/pull/3630) 支持查询时指定 Prometheus 协议的 `lookback` 参数，默认为 5 分钟

- `lookback` 的值用于控制 PromQL instant query 选择数据点的时间范围；

- 如果数据的采集间隔超过 5 分钟，那么使用默认的 `lookback` 值可能会出现找不到点的情况；

- 此前该参数无法设置，现在你可以通过以下方式设置 `lookback `的值：
    - 在 Prometheus 的 query HTTP API 中传入 `lookback` 参数 

    - 在 SQL 界面查询 PromQL 时可以通过以下语法传入 `lookback` 参数 `TQL EVAL (<start>, <end>, <step>, [lookback]) <promql>`
    
例如以下数据的采集精度为 10 分钟：

```sql
CREATE TABLE test(i DOUBLE, j TIMESTAMP TIME INDEX, k STRING PRIMARY KEY);

INSERT INTO test VALUES (1, 1713888001000, "a"), (2, 1713888601000, "a");
```

使用默认 `lookback` 参数时：


```sql
TQL EVAL (1713888400, 1713888520, '60s') test;
```

查询结果为空：

```sql
Empty set
```

如果设置 `lookback` 为 10 分钟：

```sql
TQL EVAL (1713888400, 1713888520, '60s', '10m') test;
```

则可以查询到结果：

```sql
+------+---------------------+------+
| i    | j                   | k    |
+------+---------------------+------+
|    1 | 2024-04-23 16:06:40 | a    |
|    1 | 2024-04-23 16:07:40 | a    |
|    1 | 2024-04-23 16:08:40 | a    |
+------+---------------------+------+
3 rows in set
```

### [db#3731](https://github.com/GreptimeTeam/greptimedb/pull/3731) 兼容了 SQL 的 `TINYTEXT`，`MEDIUMTEXT` 和 `LONGTEXT` 类型

这些类型在对接一些外部工具时需要用到，如 Apache SkyWalking。现在建表时可以指定这些类型，这些类型都会映射到 GreptimeDB 的字符串类型。

### [db#3638](https://github.com/GreptimeTeam/greptimedb/pull/3638) 增加了 `is_strict_mode` 参数用于对 Prometheus 协议写入的字符串做严格的 UTF-8 校验

出于性能考虑，该参数默认关闭。如果要校验写入的数据中是否包含非法的 UTF-8 字符, 则可以设置该参数为 `true`。

具体方法: 设置配置文件 `[http]` section 中的 `is_strict_mode` 为 true, 即可开启校验。

```
[http]
is_strict_mode = true
```

### [db#3684](https://github.com/GreptimeTeam/greptimedb/pull/3684) 修复了 CLI 工具导出名字带 `.` 的表时出错的问题

此前如果表名中带有 `.` 字符，如 `a.b.c.d`，在使用 CLI 工具导出数据时可能会报错。导出命令如下：

`greptime cli export --addr '127.0.0.1:4001' --output-dir /tmp/greptimedb-export --target create-table`。

### [db#3772](https://github.com/GreptimeTeam/greptimedb/pull/3772) 修复了写入时内存占用不统计 NULL 值的问题

此前，如果用户写入的数据以 NULL 为主，在写入时 GreptimeDB 可能会长时间不触发刷盘（flush），导致内存占用过高。

## Good First Issue

### [db#3336 为 GreptimeDB 的 gRPC 服务增加 TLS 支持](https://github.com/GreptimeTeam/greptimedb/issues/3336) 

目前 GreptimeDB 的 gRPC 服务不支持加密，为 gRPC 服务增加 TLS 协议支持可以提高使用 gRPC 协议时的安全性。

关键词：gRPC，TLS，安全

难度：中等

### [db#3511 在 COPY FROM 语句中支持指定时间范围，从而避免导入不需要的数据](https://github.com/GreptimeTeam/greptimedb/issues/3511)

COPY FROM 语句常常用于从备份文件中恢复表的数据，如果能够支持过滤指定时间范围，可以避免导入不需要的数据，加快数据恢复的速度。

关键词：备份/恢复、过滤、时间戳

难度：中等

### [db#3597 从 `orc-rs` 迁移到 `datafusion-orc` ](https://github.com/GreptimeTeam/greptimedb/issues/3597) 

Crate `orc-rs` 已不再维护，需要将相关依赖迁移到替代 crate `datafusion-orc` 上。

关键词：更新依赖

难度：中等

## 关于 Greptime

[Greptime 格睿科技](https://greptime.cn/)专注于为可观测、物联网及车联网等领域提供实时、高效的数据存储和分析服务，帮助客户挖掘数据的深层价值。目前基于云原生的时序数据库 [GreptimeDB](https://github.com/GreptimeTeam/greptimedb) 已经衍生出多款适合不同用户的解决方案，更多信息或 demo 展示请联系下方小助手（微信号：greptime）。

欢迎对开源感兴趣的朋友们参与贡献和讨论，从带有 good first issue 标签的 issue 开始你的开源之旅吧～期待在开源社群里遇见你！添加小助手微信即可加入“技术交流群”与志同道合的朋友们面对面交流哦~

Star us on GitHub Now: https://github.com/GreptimeTeam/greptimedb

官网：https://greptime.cn/

文档：https://docs.greptime.cn/

Twitter: https://twitter.com/Greptime

Slack: https://greptime.com/slack

LinkedIn: https://www.linkedin.com/company/greptime/
