lib/promrelabel: allow calling Match on nil IfExpression

This simplifies the caller side of IfExpression
This commit is contained in:
Aliaksandr Valialkin 2022-12-30 16:47:17 -08:00
parent 8fe21ec707
commit 7b264b0c23
No known key found for this signature in database
GPG key ID: A72BEC6CD3D0DED1
2 changed files with 4 additions and 1 deletions

View file

@ -78,6 +78,9 @@ func (ie *IfExpression) MarshalYAML() (interface{}, error) {
// Match returns true if ie matches the given labels.
func (ie *IfExpression) Match(labels []prompbmarshal.Label) bool {
if ie == nil {
return true
}
for _, lf := range ie.lfs {
if !lf.match(labels) {
return false

View file

@ -158,7 +158,7 @@ func FinalizeLabels(dst, src []prompbmarshal.Label) []prompbmarshal.Label {
// See https://prometheus.io/docs/prometheus/latest/configuration/configuration/#relabel_config
func (prc *parsedRelabelConfig) apply(labels []prompbmarshal.Label, labelsOffset int) []prompbmarshal.Label {
src := labels[labelsOffset:]
if prc.If != nil && !prc.If.Match(labels) {
if !prc.If.Match(labels) {
if prc.Action == "keep" {
// Drop the target on `if` mismatch for `action: keep`
return labels[:labelsOffset]