mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
app/vmalert/templates: add toTime()
template function in the same way as Prometheus 2.38 does
See https://github.com/prometheus/prometheus/pull/10993
This commit is contained in:
parent
511805d88d
commit
d335694add
2 changed files with 18 additions and 5 deletions
|
@ -373,10 +373,23 @@ func templateFuncs() textTpl.FuncMap {
|
||||||
if math.IsNaN(v) || math.IsInf(v, 0) {
|
if math.IsNaN(v) || math.IsInf(v, 0) {
|
||||||
return fmt.Sprintf("%.4g", v), nil
|
return fmt.Sprintf("%.4g", v), nil
|
||||||
}
|
}
|
||||||
t := TimeFromUnixNano(int64(v * 1e9)).Time().UTC()
|
t := timeFromUnixTimestamp(v).Time().UTC()
|
||||||
return fmt.Sprint(t), nil
|
return fmt.Sprint(t), nil
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// toTime converts given timestamp to a time.Time.
|
||||||
|
"toTime": func(i interface{}) (time.Time, error) {
|
||||||
|
v, err := toFloat64(i)
|
||||||
|
if err != nil {
|
||||||
|
return time.Time{}, err
|
||||||
|
}
|
||||||
|
if math.IsNaN(v) || math.IsInf(v, 0) {
|
||||||
|
return time.Time{}, fmt.Errorf("cannot convert %v to time.Time", v)
|
||||||
|
}
|
||||||
|
t := timeFromUnixTimestamp(v).Time().UTC()
|
||||||
|
return t, nil
|
||||||
|
},
|
||||||
|
|
||||||
/* URLs */
|
/* URLs */
|
||||||
|
|
||||||
// externalURL returns value of `external.url` flag
|
// externalURL returns value of `external.url` flag
|
||||||
|
@ -492,10 +505,9 @@ func templateFuncs() textTpl.FuncMap {
|
||||||
// (1970-01-01 00:00 UTC) excluding leap seconds.
|
// (1970-01-01 00:00 UTC) excluding leap seconds.
|
||||||
type Time int64
|
type Time int64
|
||||||
|
|
||||||
// TimeFromUnixNano returns the Time equivalent to the Unix Time
|
// timeFromUnixTimestamp returns the Time equivalent to t in unix timestamp.
|
||||||
// t provided in nanoseconds.
|
func timeFromUnixTimestamp(t float64) Time {
|
||||||
func TimeFromUnixNano(t int64) Time {
|
return Time(t * 1e3)
|
||||||
return Time(t / nanosPerTick)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// The number of nanoseconds per minimum tick.
|
// The number of nanoseconds per minimum tick.
|
||||||
|
|
|
@ -19,6 +19,7 @@ The following tip changes can be tested by building VictoriaMetrics components f
|
||||||
|
|
||||||
* FEATURE: [VictoriaMetrics cluster](https://docs.victoriametrics.com/Cluster-VictoriaMetrics.html): improve performance for heavy queries on systems with many CPU cores.
|
* FEATURE: [VictoriaMetrics cluster](https://docs.victoriametrics.com/Cluster-VictoriaMetrics.html): improve performance for heavy queries on systems with many CPU cores.
|
||||||
* FEATURE: [vmagent](https://docs.victoriametrics.com/vmagent.html): add support for MX record types in [dns_sd_configs](https://docs.victoriametrics.com/sd_configs.html#dns_sd_configs) in the same way as Prometheus 2.38 [does](https://github.com/prometheus/prometheus/pull/10099).
|
* FEATURE: [vmagent](https://docs.victoriametrics.com/vmagent.html): add support for MX record types in [dns_sd_configs](https://docs.victoriametrics.com/sd_configs.html#dns_sd_configs) in the same way as Prometheus 2.38 [does](https://github.com/prometheus/prometheus/pull/10099).
|
||||||
|
* FEATURE: [vmalert](https://docs.victoriametrics.com/vmalert.html): add `toTime()` template function in the same way as Prometheus 2.38 [does](https://github.com/prometheus/prometheus/pull/10993). See [these docs](https://prometheus.io/docs/prometheus/latest/configuration/template_reference/#numbers).
|
||||||
|
|
||||||
* BUGFIX: prevent from excess CPU usage when the storage enters [read-only mode](https://docs.victoriametrics.com/Cluster-VictoriaMetrics.html#readonly-mode).
|
* BUGFIX: prevent from excess CPU usage when the storage enters [read-only mode](https://docs.victoriametrics.com/Cluster-VictoriaMetrics.html#readonly-mode).
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue