Skip to content

Commit

Permalink
Fix $ substitution issue in relabel and metric relabel config (#618)
Browse files Browse the repository at this point in the history
* dollar fix for node name and node ip

* test $ replacement

* clean up build
  • Loading branch information
rashmichandrashekar authored Oct 6, 2023
1 parent 59ab96a commit 83ab2ac
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions otelcollector/prom-config-validator-builder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ func generateOtelConfig(promFilePath string, outputFilePath string, otelConfigTe
regexString := relabelConfig["regex"].(string)
modifiedRegexString := strings.ReplaceAll(regexString, "$$", "$")
modifiedRegexString = strings.ReplaceAll(modifiedRegexString, "$", "$$")
// Doing the below since we dont want to substitute $ with $$ for env variables NODE_NAME and NODE_IP.
modifiedRegexString = strings.ReplaceAll(modifiedRegexString, "$$NODE_NAME", "$NODE_NAME")
modifiedRegexString = strings.ReplaceAll(modifiedRegexString, "$$NODE_IP", "$NODE_IP")
relabelConfig["regex"] = modifiedRegexString
}
}
Expand All @@ -129,6 +132,8 @@ func generateOtelConfig(promFilePath string, outputFilePath string, otelConfigTe
replacement := relabelConfig["replacement"].(string)
modifiedReplacementString := strings.ReplaceAll(replacement, "$$", "$")
modifiedReplacementString = strings.ReplaceAll(modifiedReplacementString, "$", "$$")
modifiedReplacementString = strings.ReplaceAll(modifiedReplacementString, "$$NODE_NAME", "$NODE_NAME")
modifiedReplacementString = strings.ReplaceAll(modifiedReplacementString, "$$NODE_IP", "$NODE_IP")
relabelConfig["replacement"] = modifiedReplacementString
}
}
Expand All @@ -145,6 +150,8 @@ func generateOtelConfig(promFilePath string, outputFilePath string, otelConfigTe
regexString := metricRelabelConfig["regex"].(string)
modifiedRegexString := strings.ReplaceAll(regexString, "$$", "$")
modifiedRegexString = strings.ReplaceAll(modifiedRegexString, "$", "$$")
modifiedRegexString = strings.ReplaceAll(modifiedRegexString, "$$NODE_NAME", "$NODE_NAME")
modifiedRegexString = strings.ReplaceAll(modifiedRegexString, "$$NODE_IP", "$NODE_IP")
metricRelabelConfig["regex"] = modifiedRegexString
}
}
Expand All @@ -154,6 +161,8 @@ func generateOtelConfig(promFilePath string, outputFilePath string, otelConfigTe
replacement := metricRelabelConfig["replacement"].(string)
modifiedReplacementString := strings.ReplaceAll(replacement, "$$", "$")
modifiedReplacementString = strings.ReplaceAll(modifiedReplacementString, "$", "$$")
modifiedReplacementString = strings.ReplaceAll(modifiedReplacementString, "$$NODE_NAME", "$NODE_NAME")
modifiedReplacementString = strings.ReplaceAll(modifiedReplacementString, "$$NODE_IP", "$NODE_IP")
metricRelabelConfig["replacement"] = modifiedReplacementString
}
}
Expand Down

0 comments on commit 83ab2ac

Please sign in to comment.