mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-02-09 15:27:11 +00:00
lib/promrelabel: allow calling Match on nil IfExpression
This simplifies the caller side of IfExpression
This commit is contained in:
parent
8fe21ec707
commit
7b264b0c23
2 changed files with 4 additions and 1 deletions
|
@ -78,6 +78,9 @@ func (ie *IfExpression) MarshalYAML() (interface{}, error) {
|
||||||
|
|
||||||
// Match returns true if ie matches the given labels.
|
// Match returns true if ie matches the given labels.
|
||||||
func (ie *IfExpression) Match(labels []prompbmarshal.Label) bool {
|
func (ie *IfExpression) Match(labels []prompbmarshal.Label) bool {
|
||||||
|
if ie == nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
for _, lf := range ie.lfs {
|
for _, lf := range ie.lfs {
|
||||||
if !lf.match(labels) {
|
if !lf.match(labels) {
|
||||||
return false
|
return false
|
||||||
|
|
|
@ -158,7 +158,7 @@ func FinalizeLabels(dst, src []prompbmarshal.Label) []prompbmarshal.Label {
|
||||||
// See https://prometheus.io/docs/prometheus/latest/configuration/configuration/#relabel_config
|
// See https://prometheus.io/docs/prometheus/latest/configuration/configuration/#relabel_config
|
||||||
func (prc *parsedRelabelConfig) apply(labels []prompbmarshal.Label, labelsOffset int) []prompbmarshal.Label {
|
func (prc *parsedRelabelConfig) apply(labels []prompbmarshal.Label, labelsOffset int) []prompbmarshal.Label {
|
||||||
src := labels[labelsOffset:]
|
src := labels[labelsOffset:]
|
||||||
if prc.If != nil && !prc.If.Match(labels) {
|
if !prc.If.Match(labels) {
|
||||||
if prc.Action == "keep" {
|
if prc.Action == "keep" {
|
||||||
// Drop the target on `if` mismatch for `action: keep`
|
// Drop the target on `if` mismatch for `action: keep`
|
||||||
return labels[:labelsOffset]
|
return labels[:labelsOffset]
|
||||||
|
|
Loading…
Reference in a new issue