mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-22 16:36:27 +01:00
a350d1e81c
Previously SearchMetricNames was returning unmarshaled metric names. This wasn't great for vmstorage, which should spend additional CPU time for marshaling the metric names before sending them to vmselect. While at it, remove possible duplicate metric names, which could occur when multiple samples for new time series are ingested via concurrent requests. Also sort the metric names before returning them to the client. This simplifies debugging of the returned metric names across repeated requests to /api/v1/series
32 lines
886 B
Plaintext
32 lines
886 B
Plaintext
{% import (
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/storage"
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/querytracer"
|
|
) %}
|
|
|
|
{% stripspace %}
|
|
SeriesResponse generates response for /api/v1/series.
|
|
See https://prometheus.io/docs/prometheus/latest/querying/api/#finding-series-by-label-matchers
|
|
{% func SeriesResponse(metricNames []string, qt *querytracer.Tracer, qtDone func()) %}
|
|
{
|
|
"status":"success",
|
|
"data":[
|
|
{% code var mn storage.MetricName %}
|
|
{% for i, metricName := range metricNames %}
|
|
{% code err := mn.UnmarshalString(metricName) %}
|
|
{% if err != nil %}
|
|
{%q= err.Error() %}
|
|
{% else %}
|
|
{%= metricNameObject(&mn) %}
|
|
{% endif %}
|
|
{% if i+1 < len(metricNames) %},{% endif %}
|
|
{% endfor %}
|
|
]
|
|
{% code
|
|
qt.Printf("generate response: series=%d", len(metricNames))
|
|
qtDone()
|
|
%}
|
|
{%= dumpQueryTrace(qt) %}
|
|
}
|
|
{% endfunc %}
|
|
{% endstripspace %}
|