mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-18 14:40:26 +01:00
70 lines
1.4 KiB
Plaintext
70 lines
1.4 KiB
Plaintext
{% import (
|
|
"slices"
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/logstorage"
|
|
) %}
|
|
|
|
{% stripspace %}
|
|
|
|
// LabelsForHits formats labels for /select/logsql/hits response
|
|
{% func LabelsForHits(columns []logstorage.BlockColumn, rowIdx int) %}
|
|
{
|
|
{% if len(columns) > 0 %}
|
|
{%q= columns[0].Name %}:{%q= columns[0].Values[rowIdx] %}
|
|
{% for _, c := range columns[1:] %}
|
|
,{%q= c.Name %}:{%q= c.Values[rowIdx] %}
|
|
{% endfor %}
|
|
{% endif %}
|
|
}
|
|
{% endfunc %}
|
|
|
|
{% func HitsSeries(m map[string]*hitsSeries) %}
|
|
{
|
|
{% code
|
|
sortedKeys := make([]string, 0, len(m))
|
|
for k := range m {
|
|
sortedKeys = append(sortedKeys, k)
|
|
}
|
|
slices.Sort(sortedKeys)
|
|
%}
|
|
"hits":[
|
|
{% if len(sortedKeys) > 0 %}
|
|
{%= hitsSeriesLine(m, sortedKeys[0]) %}
|
|
{% for _, k := range sortedKeys[1:] %}
|
|
,{%= hitsSeriesLine(m, k) %}
|
|
{% endfor %}
|
|
{% endif %}
|
|
]
|
|
}
|
|
{% endfunc %}
|
|
|
|
{% func hitsSeriesLine(m map[string]*hitsSeries, k string) %}
|
|
{
|
|
{% code
|
|
hs := m[k]
|
|
hs.sort()
|
|
timestamps := hs.timestamps
|
|
values := hs.values
|
|
%}
|
|
"fields":{%s= k %},
|
|
"timestamps":[
|
|
{% if len(timestamps) > 0 %}
|
|
{%q= timestamps[0] %}
|
|
{% for _, ts := range timestamps[1:] %}
|
|
,{%q= ts %}
|
|
{% endfor %}
|
|
{% endif %}
|
|
],
|
|
"values":[
|
|
{% if len(values) > 0 %}
|
|
{%s= values[0] %}
|
|
{% for _, v := range values[1:] %}
|
|
,{%s= v %}
|
|
{% endfor %}
|
|
{% endif %}
|
|
]
|
|
}
|
|
{% endfunc %}
|
|
|
|
{% endstripspace %}
|