From 9ee78abc0acc0842ec88ca7538373099a6768bd4 Mon Sep 17 00:00:00 2001 From: f41gh7 Date: Thu, 22 Apr 2021 16:07:39 +0300 Subject: [PATCH] fixes inline relabeling args for vmagent --- controllers/factory/vmagent.go | 4 +-- controllers/factory/vmagent_test.go | 40 +++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/controllers/factory/vmagent.go b/controllers/factory/vmagent.go index fd000c77..5ac4abc8 100644 --- a/controllers/factory/vmagent.go +++ b/controllers/factory/vmagent.go @@ -362,7 +362,7 @@ func makeSpecForVMAgent(cr *victoriametricsv1beta1.VMAgent, c *config.BaseOperat configReloadArgs := buildConfigReloaderArgs(cr) - if cr.Spec.RelabelConfig != nil { + if cr.Spec.RelabelConfig != nil || len(cr.Spec.InlineRelabelConfig) > 0 { args = append(args, "-remoteWrite.relabelConfig="+path.Join(RelabelingConfigDir, globalRelabelingName)) } @@ -956,7 +956,7 @@ func BuildRemoteWrites(cr *victoriametricsv1beta1.VMAgent, rwsBasicAuth map[stri value = "" - if rws.UrlRelabelConfig != nil { + if rws.UrlRelabelConfig != nil || len(rws.InlineUrlRelabelConfig) > 0 { urlRelabelConfig.isNotNull = true value = path.Join(RelabelingConfigDir, fmt.Sprintf(urlRelabelingName, i)) } diff --git a/controllers/factory/vmagent_test.go b/controllers/factory/vmagent_test.go index f59dd7f1..15402b28 100644 --- a/controllers/factory/vmagent_test.go +++ b/controllers/factory/vmagent_test.go @@ -655,6 +655,46 @@ func TestBuildRemoteWrites(t *testing.T) { }, want: []string{"-remoteWrite.url=localhost:8429", "-remoteWrite.tlsInsecureSkipVerify=true", "-remoteWrite.label=label1=value1,label2=value2"}, }, + { + name: "test inline relabeling", + args: args{ + cr: &victoriametricsv1beta1.VMAgent{ + Spec: victoriametricsv1beta1.VMAgentSpec{ + RemoteWrite: []victoriametricsv1beta1.VMAgentRemoteWriteSpec{ + { + URL: "localhost:8429", + TLSConfig: &victoriametricsv1beta1.TLSConfig{ + InsecureSkipVerify: true, + }, + InlineUrlRelabelConfig: []victoriametricsv1beta1.RelabelConfig{ + {TargetLabel: "rw-1", Replacement: "present"}, + }, + }, + { + URL: "remote-1:8429", + Labels: map[string]string{"label1": "value1", "label2": "value2"}, + TLSConfig: &victoriametricsv1beta1.TLSConfig{ + InsecureSkipVerify: true, + }, + }, + { + URL: "remote-1:8429", + TLSConfig: &victoriametricsv1beta1.TLSConfig{ + InsecureSkipVerify: true, + }, + InlineUrlRelabelConfig: []victoriametricsv1beta1.RelabelConfig{ + {TargetLabel: "rw-2", Replacement: "present"}, + }, + }, + }, + InlineRelabelConfig: []victoriametricsv1beta1.RelabelConfig{ + {TargetLabel: "dst", Replacement: "ok"}, + }, + }, + }, + }, + want: []string{"-remoteWrite.label=label1=value1,label2=value2", "-remoteWrite.url=localhost:8429,remote-1:8429,remote-1:8429", "-remoteWrite.tlsInsecureSkipVerify=true,true,true", "-remoteWrite.urlRelabelConfig=/etc/vm/relabeling/url_rebaling-0.yaml,,/etc/vm/relabeling/url_rebaling-2.yaml"}, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {