mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-11 14:53:49 +00:00
0881e5fd5c
Empty fields are treated as non-existing fields by VictoriaLogs data model.
So there is no sense in returning empty fields in query results, since they may mislead and confuse users.
(cherry picked from commit bac193e50b
)
64 lines
1.4 KiB
Text
64 lines
1.4 KiB
Text
{% import (
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/logstorage"
|
|
) %}
|
|
|
|
{% stripspace %}
|
|
|
|
// JSONRow creates JSON row from the given fields.
|
|
{% func JSONRow(columns []logstorage.BlockColumn, rowIdx int) %}
|
|
{% code
|
|
i := 0
|
|
for i < len(columns) && columns[i].Values[rowIdx] == "" {
|
|
i++
|
|
}
|
|
columns = columns[i:]
|
|
%}
|
|
{% if len(columns) == 0 %}
|
|
{% return %}
|
|
{% endif %}
|
|
{
|
|
{% code c := &columns[0] %}
|
|
{%q= c.Name %}:{%q= c.Values[rowIdx] %}
|
|
{% code columns = columns[1:] %}
|
|
{% for colIdx := range columns %}
|
|
{% code
|
|
c := &columns[colIdx]
|
|
v := c.Values[rowIdx]
|
|
%}
|
|
{% if v == "" %}
|
|
{% continue %}
|
|
{% endif %}
|
|
,{%q= c.Name %}:{%q= c.Values[rowIdx] %}
|
|
{% endfor %}
|
|
}{% newline %}
|
|
{% endfunc %}
|
|
|
|
// JSONRows prints formatted rows
|
|
{% func JSONRows(rows [][]logstorage.Field) %}
|
|
{% if len(rows) == 0 %}
|
|
{% return %}
|
|
{% endif %}
|
|
{% for _, fields := range rows %}
|
|
{% code fields = logstorage.SkipLeadingFieldsWithoutValues(fields) %}
|
|
{% if len(fields) == 0 %}
|
|
{% continue %}
|
|
{% endif %}
|
|
{
|
|
{% if len(fields) > 0 %}
|
|
{% code
|
|
f := fields[0]
|
|
fields = fields[1:]
|
|
%}
|
|
{%q= f.Name %}:{%q= f.Value %}
|
|
{% for _, f := range fields %}
|
|
{% if f.Value == "" %}
|
|
{% continue %}
|
|
{% endif %}
|
|
,{%q= f.Name %}:{%q= f.Value %}
|
|
{% endfor %}
|
|
{% endif %}
|
|
}{% newline %}
|
|
{% endfor %}
|
|
{% endfunc %}
|
|
|
|
{% endstripspace %}
|