Skip to content

Commit

Permalink
Merge pull request #232 from VictoriaMetrics/fixes-vmagent-inline-rel…
Browse files Browse the repository at this point in the history
…abeling

fixes inline relabeling args for vmagent
  • Loading branch information
f41gh7 authored Apr 22, 2021
2 parents 0ead317 + 9ee78ab commit ba3a055
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
4 changes: 2 additions & 2 deletions controllers/factory/vmagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand Down Expand Up @@ -957,7 +957,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))
}
Expand Down
40 changes: 40 additions & 0 deletions controllers/factory/vmagent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit ba3a055

Please sign in to comment.