-
Notifications
You must be signed in to change notification settings - Fork 31
Prometheus dependency upgrades #349
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -195,8 +195,12 @@ $(CONTROLLER_GEN): $(LOCALBIN) | |
| test -s $(LOCALBIN)/controller-gen && $(LOCALBIN)/controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION) || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION) | ||
|
|
||
| .PHONY: goimports | ||
| goimports: | ||
| @echo $(ALL_SRC) | xargs -n 10 $(LOCALBIN)/goimports -w -local $(CW_AGENT_OPERATOR_IMPORT_PATH) || GOBIN=$(LOCALBIN) go install golang.org/x/tools/cmd/goimports | ||
| goimports: install-goimports | ||
| @echo $(ALL_SRC) | xargs -n 10 $(LOCALBIN)/goimports -w -local $(CW_AGENT_OPERATOR_IMPORT_PATH) | ||
|
|
||
| .PHONY: install-goimports | ||
| install-goimports: $(LOCALBIN) | ||
| @test -s $(LOCALBIN)/goimports || GOBIN=$(LOCALBIN) go install golang.org/x/tools/cmd/[email protected] | ||
|
|
||
| .PHONY: impi | ||
| impi: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,16 +24,13 @@ func NewRelabelConfigTargetFilter(log logr.Logger) Hook { | |
| } | ||
| } | ||
|
|
||
| // helper function converts from model.LabelSet to []labels.Label. | ||
| func convertLabelToPromLabelSet(lbls model.LabelSet) []labels.Label { | ||
| newLabels := make([]labels.Label, len(lbls)) | ||
| index := 0 | ||
| // helper function converts from model.LabelSet to labels.Labels. | ||
| func convertLabelToPromLabelSet(lbls model.LabelSet) labels.Labels { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I want to make sure the changes made here are covered with unit tests |
||
| builder := labels.NewBuilder(labels.EmptyLabels()) | ||
| for k, v := range lbls { | ||
| newLabels[index].Name = string(k) | ||
| newLabels[index].Value = string(v) | ||
| index++ | ||
| builder.Set(string(k), string(v)) | ||
| } | ||
| return newLabels | ||
| return builder.Labels() | ||
| } | ||
|
|
||
| func (tf *RelabelConfigTargetFilter) Apply(targets map[string]*target.Item) map[string]*target.Item { | ||
|
|
@@ -49,12 +46,12 @@ func (tf *RelabelConfigTargetFilter) Apply(targets map[string]*target.Item) map[ | |
| keepTarget := true | ||
| lset := convertLabelToPromLabelSet(tItem.Labels) | ||
| for _, cfg := range tf.relabelCfg[tItem.JobName] { | ||
| if newLset, keep := relabel.Process(lset, cfg); !keep { | ||
| newLset, keep := relabel.Process(lset, cfg) | ||
| if !keep { | ||
| keepTarget = false | ||
| break // inner loop | ||
| } else { | ||
| lset = newLset | ||
| } | ||
| lset = newLset | ||
| } | ||
|
|
||
| if !keepTarget { | ||
|
|
@@ -85,6 +82,8 @@ func (tf *RelabelConfigTargetFilter) replaceRelabelConfig(cfg []*relabel.Config) | |
| if str == "$(SHARD)" { | ||
| cfg[i].Regex = relabel.MustNewRegexp("0") | ||
| } | ||
| // Set the validation scheme for the new Prometheus library | ||
| cfg[i].NameValidationScheme = model.UTF8Validation | ||
| } | ||
|
|
||
| return cfg | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,12 @@ import ( | |
| "github.com/aws/amazon-cloudwatch-agent-operator/cmd/amazon-cloudwatch-agent-target-allocator/target" | ||
| ) | ||
|
|
||
| func init() { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prometheus v0.308.0 changed default metric name validation. This aligns test validation scheme with prometheus-operator's config generation to prevent assertion mismatches. |
||
| // Set the validation scheme to UTF8 for the new Prometheus library | ||
| //nolint:staticcheck // SA1019 - intentionally using deprecated NameValidationScheme for test compatibility | ||
| model.NameValidationScheme = model.UTF8Validation | ||
| } | ||
|
|
||
| var ( | ||
| logger = logf.Log.WithName("unit-tests") | ||
| defaultNumTargets = 100 | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prometheus library v0.308.0 populates additional default fields internally. Switched from exact struct comparison to field-by-field assertion to avoid test brittleness across library versions. Config loading behavior unchanged.