Fix promtail scrape config job name validation (#7402)

pull/7412/head
Vijal Patel 4 years ago committed by GitHub
parent b3c0670f3a
commit 5f7543d047
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      clients/pkg/promtail/targets/lokipush/pushtargetmanager.go
  2. 13
      clients/pkg/promtail/targets/lokipush/pushtargetmanager_test.go

@ -3,11 +3,11 @@ package lokipush
import (
"errors"
"fmt"
"strings"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/prometheus/util/strutil"
"github.com/grafana/loki/clients/pkg/logentry/stages"
"github.com/grafana/loki/clients/pkg/promtail/api"
@ -69,7 +69,7 @@ func validateJobName(scrapeConfigs []scrapeconfig.Config) error {
}
jobNames[cfg.JobName] = struct{}{}
scrapeConfigs[i].JobName = strings.Replace(cfg.JobName, " ", "_", -1)
scrapeConfigs[i].JobName = strutil.SanitizeLabelName(cfg.JobName)
}
return nil
}

@ -58,6 +58,19 @@ func Test_validateJobName(t *testing.T) {
},
wantErr: true,
},
{
name: "validate with special characters",
configs: []scrapeconfig.Config{
{
JobName: "job$1-2!3@4*job",
PushConfig: &scrapeconfig.PushTargetConfig{
Server: server.Config{},
},
},
},
wantErr: false,
expectedJob: "job_1_2_3_4_job",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {

Loading…
Cancel
Save