martin-helmich / prometheus-nginxlog-exporter

Export metrics from Nginx access log files to Prometheus
Apache License 2.0
950 stars 171 forks source link

fix blank replacement on relabel matches fixes #363 #391

Open crystalstorm opened 2 months ago

crystalstorm commented 2 months ago

This will fix the relabeling issues reported here #363 and here #377

if len(r.Matches) > 0 {
    replacement := ""
    for i := range r.Matches {
        if r.Matches[i].CompiledRegexp.MatchString(sourceValue) {
            replacement = r.Matches[i].CompiledRegexp.ReplaceAllString(sourceValue, r.Matches[i].Replacement)
            break
        }
    }
    sourceValue = replacement
}

The current logic is flawed, because in the case where there are Matches but the Regexp does NOT match the sourceValue the sourceValue still gets replaced with ""

codeclimate[bot] commented 2 months ago

Code Climate has analyzed commit 93469d52 and detected 0 issues on this pull request.

View more on Code Climate.