Skip to content

Commit

Permalink
Fix: NODE_IP replacement in static_configs (#989)
Browse files Browse the repository at this point in the history
[comment]: # (Note that your PR title should follow the conventional
commit format: https://conventionalcommits.org/en/v1.0.0/#summary)
# PR Description
Move NODE_IP out of incorrect if statement block.
Add to test that up=1 for NODE_IP replacement test
  • Loading branch information
gracewehner authored Oct 5, 2024
1 parent 7770fda commit 77dcfe3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
1 change: 1 addition & 0 deletions .pipelines/azure-pipeline-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ trigger:
branches:
include:
- main

pr:
autoCancel: true
branches:
Expand Down
30 changes: 15 additions & 15 deletions otelcollector/prom-config-validator-builder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,22 +170,22 @@ func generateOtelConfig(promFilePath string, outputFilePath string, otelConfigTe
metricRelabelConfig["replacement"] = modifiedReplacementString
}
}
}

if scrapeConfig["static_configs"] != nil {
staticConfigs := scrapeConfig["static_configs"].([]interface{})
for _, staticConfig := range staticConfigs {
staticConfig := staticConfig.(map[interface{}]interface{})
if staticConfig["labels"] != nil {
labels := staticConfig["labels"].(map[interface{}]interface{})
for key, value := range labels {
if _, isString := value.(string); isString {
labelValue := value.(string)
modifiedLabelValue := strings.ReplaceAll(labelValue, "$$NODE_NAME", "$NODE_NAME")
modifiedLabelValue = strings.ReplaceAll(modifiedLabelValue, "$$NODE_IP", "$NODE_IP")
modifiedLabelValue = strings.ReplaceAll(modifiedLabelValue, "$NODE_NAME", "${env:NODE_NAME}")
modifiedLabelValue = strings.ReplaceAll(modifiedLabelValue, "$NODE_IP", "${env:NODE_IP}")
labels[key] = modifiedLabelValue
}
if scrapeConfig["static_configs"] != nil {
staticConfigs := scrapeConfig["static_configs"].([]interface{})
for _, staticConfig := range staticConfigs {
staticConfig := staticConfig.(map[interface{}]interface{})
if staticConfig["targets"] != nil {
targets := staticConfig["targets"].([]interface{})
for i, target := range targets {
if _, isString := target.(string); isString {
targetValue := target.(string)
modifiedtargetValue := strings.ReplaceAll(targetValue, "$$NODE_NAME", "$NODE_NAME")
modifiedtargetValue = strings.ReplaceAll(modifiedtargetValue, "$$NODE_IP", "$NODE_IP")
modifiedtargetValue = strings.ReplaceAll(modifiedtargetValue, "$NODE_NAME", "${env:NODE_NAME}")
modifiedtargetValue = strings.ReplaceAll(modifiedtargetValue, "$NODE_IP", "${env:NODE_IP}")
staticConfig["targets"].([]interface{})[i] = modifiedtargetValue
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ var _ = Describe("Query Metrics Test Suite", func() {
val, ok := sample.Metric[model.LabelName(label)]
Expect(ok).To(BeTrue(), fmt.Sprintf("Expected label %q not found in metric %q", label, metric))
Expect(val).NotTo(BeEmpty(), fmt.Sprintf("Label %q is empty in metric %q", label, metric))
Expect(sample.Value.String()).To(Equal("1"))
}
}
},
Expand Down

0 comments on commit 77dcfe3

Please sign in to comment.