-
Notifications
You must be signed in to change notification settings - Fork 170
LOG-9356: Implement Collector ServiceMonitor Changes #3270
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
Open
Clee2691
wants to merge
1
commit into
openshift:master
Choose a base branch
from
Clee2691:LOG-9356
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| package metrics | ||
|
|
||
| import ( | ||
| "strings" | ||
|
|
||
| monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" | ||
| ) | ||
|
|
||
| type metricAllowlistConfig struct { | ||
| allowedMetrics []string | ||
| } | ||
|
|
||
| type metricDropConfig struct { | ||
| labelName string | ||
| labelValue string | ||
| excludeMetrics []string | ||
| } | ||
|
|
||
| var collectorMinimalAllowlist = &metricAllowlistConfig{ | ||
| allowedMetrics: []string{ | ||
| // Metrics used in alerts (collector_alerts.yaml) | ||
| "logcollector_component_event_unmatched_count", | ||
| "vector_http_client_errors_total", | ||
| "vector_http_client_requests_sent_total", | ||
| "vector_http_client_responses_total", | ||
| "vector_buffer_byte_size", | ||
| "vector_component_errors_total", | ||
| "vector_component_received_events_total", | ||
|
|
||
| // Metrics used in recording rules (collector_alerts.yaml, telemetry_rules.yaml) | ||
| "vector_component_received_bytes_total", | ||
|
|
||
| // Metrics used in dashboards (openshift-logging-dashboard.json) | ||
| "vector_component_sent_bytes_total", | ||
| "vector_component_received_event_bytes_total", | ||
| "vector_open_files", | ||
| "vector_component_discarded_events_total", | ||
|
|
||
| // Additional buffer and event metrics | ||
| "vector_buffer_discarded_events_total", | ||
| "vector_buffer_events", | ||
| "vector_buffer_sent_events_total", | ||
| "vector_events_in_total", | ||
| }, | ||
| } | ||
|
|
||
| var collectorMinimalDropConfigs = []metricDropConfig{ | ||
| { | ||
| labelName: "component_kind", | ||
| labelValue: "transform", | ||
| excludeMetrics: []string{ | ||
| "vector_component_received_bytes_total", | ||
| "vector_component_received_event_bytes_total", | ||
| "vector_component_received_events_total", | ||
| "vector_component_sent_bytes_total", | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| var lfmeMinimalAllowlist = &metricAllowlistConfig{ | ||
| allowedMetrics: []string{ | ||
| // Used in recording rule (collector_alerts.yaml) and dashboard | ||
| "log_logged_bytes_total", | ||
| }, | ||
| } | ||
|
|
||
| var CollectorMinimalRelabelConfigs = buildRelabelConfigs(collectorMinimalAllowlist, collectorMinimalDropConfigs) | ||
| var LFMEMinimalRelabelConfigs = buildRelabelConfigs(lfmeMinimalAllowlist, nil) | ||
| var FullRelabelConfigs = buildRelabelConfigs(nil, nil) | ||
|
|
||
| func buildRelabelConfigs(allowlist *metricAllowlistConfig, dropConfigs []metricDropConfig) []*monitoringv1.RelabelConfig { | ||
| configs := []*monitoringv1.RelabelConfig{ | ||
| { | ||
| SourceLabels: []monitoringv1.LabelName{"__name__"}, | ||
| TargetLabel: "__name__", | ||
| Regex: "(.*)-(.*)", | ||
| Replacement: "${1}_${2}", | ||
| }, | ||
| } | ||
|
|
||
| if allowlist != nil && len(allowlist.allowedMetrics) > 0 { | ||
| configs = append(configs, &monitoringv1.RelabelConfig{ | ||
| Action: "keep", | ||
| SourceLabels: []monitoringv1.LabelName{"__name__"}, | ||
| Regex: strings.Join(allowlist.allowedMetrics, "|"), | ||
| }) | ||
| } | ||
|
|
||
| for _, drop := range dropConfigs { | ||
| configs = append(configs, &monitoringv1.RelabelConfig{ | ||
| Action: "drop", | ||
| SourceLabels: []monitoringv1.LabelName{monitoringv1.LabelName(drop.labelName), "__name__"}, | ||
|
jcantrill marked this conversation as resolved.
|
||
| Regex: drop.labelValue + ";(" + strings.Join(drop.excludeMetrics, "|") + ")", | ||
| }) | ||
| } | ||
|
|
||
| return configs | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| package metrics | ||
|
|
||
| import ( | ||
| . "github.com/onsi/ginkgo/v2" | ||
| . "github.com/onsi/gomega" | ||
| monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" | ||
| ) | ||
|
|
||
| var _ = Describe("buildRelabelConfigs", func() { | ||
| It("should return only the rename rule when no allowlist or drops are provided", func() { | ||
| configs := buildRelabelConfigs(nil, nil) | ||
| Expect(configs).To(HaveLen(1)) | ||
| Expect(configs[0].TargetLabel).To(Equal("__name__")) | ||
| Expect(configs[0].Regex).To(Equal("(.*)-(.*)")) | ||
| Expect(configs[0].Replacement).To(Equal("${1}_${2}")) | ||
| }) | ||
|
|
||
| It("should return rename + keep when an allowlist is provided", func() { | ||
| allowlist := &metricAllowlistConfig{ | ||
| allowedMetrics: []string{"metric_a", "metric_b"}, | ||
| } | ||
| configs := buildRelabelConfigs(allowlist, nil) | ||
| Expect(configs).To(HaveLen(2)) | ||
|
|
||
| Expect(configs[0].Regex).To(Equal("(.*)-(.*)")) | ||
|
|
||
| Expect(string(configs[1].Action)).To(Equal("keep")) | ||
| Expect(configs[1].SourceLabels).To(Equal([]monitoringv1.LabelName{"__name__"})) | ||
| Expect(configs[1].Regex).To(Equal("metric_a|metric_b")) | ||
| }) | ||
|
|
||
| It("should return rename + keep + drop when allowlist and drops are provided", func() { | ||
| allowlist := &metricAllowlistConfig{ | ||
| allowedMetrics: []string{"metric_a", "metric_b", "metric_c"}, | ||
| } | ||
| drops := []metricDropConfig{ | ||
| { | ||
| labelName: "component_kind", | ||
| labelValue: "transform", | ||
| excludeMetrics: []string{"metric_a", "metric_b"}, | ||
| }, | ||
| } | ||
| configs := buildRelabelConfigs(allowlist, drops) | ||
| Expect(configs).To(HaveLen(3)) | ||
|
|
||
| Expect(string(configs[1].Action)).To(Equal("keep")) | ||
| Expect(configs[1].Regex).To(Equal("metric_a|metric_b|metric_c")) | ||
|
|
||
| Expect(string(configs[2].Action)).To(Equal("drop")) | ||
| Expect(configs[2].SourceLabels).To(Equal([]monitoringv1.LabelName{"component_kind", "__name__"})) | ||
| Expect(configs[2].Regex).To(Equal("transform;(metric_a|metric_b)")) | ||
| }) | ||
|
|
||
| It("should build valid CollectorMinimalRelabelConfigs", func() { | ||
| Expect(CollectorMinimalRelabelConfigs).To(HaveLen(3)) | ||
| Expect(string(CollectorMinimalRelabelConfigs[1].Action)).To(Equal("keep")) | ||
| Expect(string(CollectorMinimalRelabelConfigs[2].Action)).To(Equal("drop")) | ||
|
|
||
| keepRegex := CollectorMinimalRelabelConfigs[1].Regex | ||
| for _, m := range collectorMinimalAllowlist.allowedMetrics { | ||
| Expect(keepRegex).To(ContainSubstring(m), "missing metric in keep regex: %s", m) | ||
| } | ||
| }) | ||
|
|
||
| It("should build valid LFMEMinimalRelabelConfigs", func() { | ||
| Expect(LFMEMinimalRelabelConfigs).To(HaveLen(2)) | ||
| Expect(string(LFMEMinimalRelabelConfigs[1].Action)).To(Equal("keep")) | ||
| Expect(LFMEMinimalRelabelConfigs[1].Regex).To(Equal("log_logged_bytes_total")) | ||
| }) | ||
|
|
||
| It("should build FullRelabelConfigs with only the rename rule", func() { | ||
| Expect(FullRelabelConfigs).To(HaveLen(1)) | ||
| Expect(FullRelabelConfigs[0].Regex).To(Equal("(.*)-(.*)")) | ||
| }) | ||
|
|
||
| It("should return only the rename rule when allowlist has empty metrics", func() { | ||
| allowlist := &metricAllowlistConfig{ | ||
| allowedMetrics: []string{}, | ||
| } | ||
| configs := buildRelabelConfigs(allowlist, nil) | ||
| Expect(configs).To(HaveLen(1)) | ||
| Expect(configs[0].TargetLabel).To(Equal("__name__")) | ||
| }) | ||
|
|
||
| It("should return rename + drop when only drop configs are provided", func() { | ||
| drops := []metricDropConfig{ | ||
| { | ||
| labelName: "component_kind", | ||
| labelValue: "transform", | ||
| excludeMetrics: []string{"metric_a"}, | ||
| }, | ||
| } | ||
| configs := buildRelabelConfigs(nil, drops) | ||
| Expect(configs).To(HaveLen(2)) | ||
|
|
||
| Expect(configs[0].Regex).To(Equal("(.*)-(.*)")) | ||
| Expect(string(configs[1].Action)).To(Equal("drop")) | ||
| Expect(configs[1].SourceLabels).To(Equal([]monitoringv1.LabelName{"component_kind", "__name__"})) | ||
| Expect(configs[1].Regex).To(Equal("transform;(metric_a)")) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.