mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-25 11:50:13 +01:00
f41b36bb9a
Extra labels may be added to the imported data by passing `extra_label=name=value` query args. Multiple query args may be passed in order to add multiple extra labels. Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/719
27 lines
668 B
Go
27 lines
668 B
Go
package common
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"strings"
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/prompbmarshal"
|
|
)
|
|
|
|
// GetExtraLabels extracts name:value labels from `extra_label=name=value` query args from req.
|
|
func GetExtraLabels(req *http.Request) ([]prompbmarshal.Label, error) {
|
|
q := req.URL.Query()
|
|
var result []prompbmarshal.Label
|
|
for _, label := range q["extra_label"] {
|
|
tmp := strings.SplitN(label, "=", 2)
|
|
if len(tmp) != 2 {
|
|
return nil, fmt.Errorf("`extra_label` query arg must have the format `name=value`; got %q", label)
|
|
}
|
|
result = append(result, prompbmarshal.Label{
|
|
Name: tmp[0],
|
|
Value: tmp[1],
|
|
})
|
|
}
|
|
return result, nil
|
|
}
|