普罗米修斯:普罗米修斯如何处理数据类型溢出? [英] prometheus: how prometheus handles the data type overflow?

查看:71
本文介绍了普罗米修斯:普罗米修斯如何处理数据类型溢出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

prometheus 客户端不断更新指标,似乎没有考虑溢出.例如,计数器 Add():

The prometheus client keeps updating the metric and seems do not consider overflow. For example, the counster Add():

func (c *counter) Add(v float64) {
    if v < 0 {
        panic(errors.New("counter cannot decrease in value"))
    }
    ival := uint64(v)
    if float64(ival) == v {
        atomic.AddUint64(&c.valInt, ival)
        return
    }

    for {
        oldBits := atomic.LoadUint64(&c.valBits)
        newBits := math.Float64bits(math.Float64frombits(oldBits) + v)
        if atomic.CompareAndSwapUint64(&c.valBits, oldBits, newBits) {
            return
        }
    }
}

c.valInt 会溢出并从 0 开始回绕.普罗米修斯在抓取此类回滚指标时如何处理这种情况?

The c.valInt would overflow and wrapped around from 0. How prometheus handles this case when it scrapes such rewind metric?

推荐答案

Prometheus 旨在处理这样的计数器重置,rate 函数有它的代码.当进程重新启动时,这种情况更常见.

Prometheus is designed to handle counter resets like this, the rate function has code for it. It more commonly happens when a process restarts.

溢出也不太可能.即使每秒增加 10 亿,也需要数百年才能溢出.

An overflow is also quite unlikely. Even if you were incrementing by a billion a second it'd take several hundred years to overflow.

这篇关于普罗米修斯:普罗米修斯如何处理数据类型溢出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆