简体   繁体   English

是否可以在 LogQL 中将字符串值转换为数字?

[英]Is it possible to convert string values to numbers in LogQL?

I am following documentation and thanks to | line_format我正在关注文档并感谢| line_format | line_format and regexReplaceAll I was able to fetch some substring from a line. | line_formatregexReplaceAll我能够从一行中获取一些 substring。

Let's say now I have those columns:假设现在我有这些列:

line
123
7
123
54
14

Having that I want to perform some transform operation, ex sum, or transform operation with grouping by and taking total.有了这个,我想执行一些转换操作,ex sum,或转换操作,分组并取总数。 It is not working as I am suspecting those values are not being numbers, but only strings.它不起作用,因为我怀疑这些值不是数字,而只是字符串。 Is it possible to convert it to numbers?是否可以将其转换为数字?

I was trying using unwrap but it didn't worked:我正在尝试使用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]
)

it ends up with结果是

pipeline error: 'SampleExtractionErr' for series:管道错误:系列的“SampleExtractionErr”:

when I am filtering out errors, there is no results.当我过滤掉错误时,没有结果。

I think you're looking for the "unwrap" expression.我认为您正在寻找“展开”表达式。

See the Loki documentation about this here .请参阅此处的 Loki 文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM