【问题标题】:Is it possible to convert string values to numbers in LogQL?是否可以在 LogQL 中将字符串值转换为数字?
【发布时间】:2021-04-20 13:52:14
【问题描述】:

我正在关注documentation,感谢| line_formatregexReplaceAll,我能够从一行中获取一些子字符串。

假设现在我有这些列:

line
123
7
123
54
14

如果我想执行一些变换操作、ex sum 或变换操作,则需要进行分组和总计。 它不起作用,因为我怀疑这些值不是数字,而只是字符串。 可以转成数字吗?

我尝试使用unwrap,但没有成功:

sum_over_time(
    {service="some"} 
    |="text expression"
    | json
    | line_format `{{ regexReplaceAll "text expression to remove from (\\d+)" .label_id "${1}" | trim }}`
    | unwrap label_id [1m]
)

结果是

管道错误:系列的“SampleExtractionErr”:

当我过滤掉错误时,没有结果。

【问题讨论】:

    标签: grafana grafana-loki


    【解决方案1】:

    我认为您正在寻找“展开”表达式。

    请参阅有关此 here 的 Loki 文档。

    【讨论】:

    • 感谢您的提示。我已经尝试过了,但没有用 - 问题已更新。
    • 实际上,您使用“line_format”对行进行格式化,但在展开表达式中使用“label-id”而不格式化(整个表达式)。
    猜你喜欢
    • 2017-09-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-03
    • 1970-01-01
    • 2010-12-01
    • 1970-01-01
    相关资源
    最近更新 更多