NETOBSERV-2655: additionalIncludeList field to append metrics to default#2546
NETOBSERV-2655: additionalIncludeList field to append metrics to default#2546Amoghrd merged 2 commits intonetobserv:mainfrom
Conversation
|
@Amoghrd: This pull request references NETOBSERV-2655 which is a valid jira issue. Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "4.22.0" version, but no target version was set. DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
4221dd0 to
735d68e
Compare
e341726 to
2999d48
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2546 +/- ##
==========================================
- Coverage 72.07% 71.91% -0.17%
==========================================
Files 105 105
Lines 10924 10943 +19
==========================================
- Hits 7874 7870 -4
- Misses 2565 2584 +19
- Partials 485 489 +4
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
jotak
left a comment
There was a problem hiding this comment.
We can't change the behaviour of the existing API, it would be a breaking change.
We need instead to create a new setting, such as "additionalIncludeList", and keep the existing as it is.
|
Sounds good, will do that |
c089707 to
e970bd3
Compare
|
@Amoghrd: This pull request references NETOBSERV-2655 which is a valid jira issue. Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "4.22.0" version, but no target version was set. DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
jotak
left a comment
There was a problem hiding this comment.
just a small comment, LGTM otherwise
e970bd3 to
8f898d8
Compare
|
/ok-to-test |
|
New images: quay.io/netobserv/network-observability-operator:aa88674
quay.io/netobserv/network-observability-operator-bundle:v0.0.0-sha-aa88674
quay.io/netobserv/network-observability-operator-catalog:v0.0.0-sha-aa88674They will expire in two weeks. To deploy this build: # Direct deployment, from operator repo
IMAGE=quay.io/netobserv/network-observability-operator:aa88674 make deploy
# Or using operator-sdk
operator-sdk run bundle quay.io/netobserv/network-observability-operator-bundle:v0.0.0-sha-aa88674Or as a Catalog Source: apiVersion: operators.coreos.com/v1alpha1
kind: CatalogSource
metadata:
name: netobserv-dev
namespace: openshift-marketplace
spec:
sourceType: grpc
image: quay.io/netobserv/network-observability-operator-catalog:v0.0.0-sha-aa88674
displayName: NetObserv development catalog
publisher: Me
updateStrategy:
registryPoll:
interval: 1m |
|
/label qe-approved |
📝 WalkthroughWalkthroughAdds Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
182b09c to
e29c833
Compare
|
(Rebased without any changes) |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
api/flowcollector/v1beta2/flowcollector_validation_webhook.go (1)
443-445: Extract this warning text into a shared constant.The same long message is duplicated across validator and tests; centralizing it will prevent drift and brittle string updates.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@api/flowcollector/v1beta2/flowcollector_validation_webhook.go` around lines 443 - 445, Extract the duplicated long warning into a single exported constant (e.g., MetricsIncludeListWarning) in a shared package file (like a new messages.go or constants.go in the same package as flowcollector_validation_webhook.go), set its value to the provided multi-sentence text about spec.processor.metrics.includeList vs additionalIncludeList, then replace the inline string occurrences in flowcollector_validation_webhook.go and in the tests with that constant (referencing MetricsIncludeListWarning) so both validator and tests use the same centralized message.internal/controller/flp/flp_pipeline_builder_test.go (1)
220-237: Add edge-case tests forAdditionalIncludeListdedup/empty behavior.This test covers the happy path, but it does not lock in empty-list and dedup behavior (including overlap with defaults), which is part of the merge contract.
Suggested test additions
+func TestMergeMetricsConfiguration_WithAdditionalList_Empty(t *testing.T) { + assert := assert.New(t) + cfg := getConfig() + cfg.Processor.Metrics.AdditionalIncludeList = &[]flowslatest.FLPMetric{} + b := monoBuilder("namespace", &cfg) + scm, _, dcm, err := b.configMaps() + assert.NoError(err) + cfs, _ := validatePipelineConfig(t, scm, dcm) + names := getSortedMetricsNames(cfs.Parameters[5].Encode.Prom.Metrics) + assert.NotEmpty(names) // defaults still present +} + +func TestMergeMetricsConfiguration_WithAdditionalList_Dedup(t *testing.T) { + assert := assert.New(t) + cfg := getConfig() + cfg.Processor.Metrics.AdditionalIncludeList = &[]flowslatest.FLPMetric{ + "node_ingress_bytes_total", // already default + "node_ingress_bytes_total", // duplicate in additional + } + b := monoBuilder("namespace", &cfg) + scm, _, dcm, err := b.configMaps() + assert.NoError(err) + cfs, _ := validatePipelineConfig(t, scm, dcm) + names := getSortedMetricsNames(cfs.Parameters[5].Encode.Prom.Metrics) + count := 0 + for _, n := range names { + if n == "node_ingress_bytes_total" { + count++ + } + } + assert.Equal(1, count) +}As per coding guidelines,
**/*_test.goshould include edge-case coverage (empty, nil values).🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@internal/controller/flp/flp_pipeline_builder_test.go` around lines 220 - 237, Add edge-case tests for AdditionalIncludeList to assert dedup and empty/nil behavior: create tests similar to TestMergeMetricsConfiguration_WithAdditionalList that set cfg.Processor.Metrics.AdditionalIncludeList to nil, to an empty slice, and to a slice with duplicates and overlaps with default metrics; then call monoBuilder(...).configMaps(), validatePipelineConfig(...), and inspect cfs.Parameters[5].Encode.Prom.Metrics (using getSortedMetricsNames) to assert that nil/empty results in only defaults and that duplicates/overlaps are deduplicated (no duplicate names) while still including defaults and the unique additional entries. Ensure assertions cover presence/absence of specific metric names and that Prom.Prefix remains unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@api/flowcollector/v1beta2/flowcollector_validation_webhook.go`:
- Around line 443-445: Extract the duplicated long warning into a single
exported constant (e.g., MetricsIncludeListWarning) in a shared package file
(like a new messages.go or constants.go in the same package as
flowcollector_validation_webhook.go), set its value to the provided
multi-sentence text about spec.processor.metrics.includeList vs
additionalIncludeList, then replace the inline string occurrences in
flowcollector_validation_webhook.go and in the tests with that constant
(referencing MetricsIncludeListWarning) so both validator and tests use the same
centralized message.
In `@internal/controller/flp/flp_pipeline_builder_test.go`:
- Around line 220-237: Add edge-case tests for AdditionalIncludeList to assert
dedup and empty/nil behavior: create tests similar to
TestMergeMetricsConfiguration_WithAdditionalList that set
cfg.Processor.Metrics.AdditionalIncludeList to nil, to an empty slice, and to a
slice with duplicates and overlaps with default metrics; then call
monoBuilder(...).configMaps(), validatePipelineConfig(...), and inspect
cfs.Parameters[5].Encode.Prom.Metrics (using getSortedMetricsNames) to assert
that nil/empty results in only defaults and that duplicates/overlaps are
deduplicated (no duplicate names) while still including defaults and the unique
additional entries. Ensure assertions cover presence/absence of specific metric
names and that Prom.Prefix remains unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 97211d4c-8494-4e52-97f8-c4dc0a429db8
⛔ Files ignored due to path filters (1)
api/flowcollector/v1beta2/zz_generated.deepcopy.gois excluded by!**/zz_generated.deepcopy.go
📒 Files selected for processing (10)
api/flowcollector/v1beta2/flowcollector_alert_types.goapi/flowcollector/v1beta2/flowcollector_types.goapi/flowcollector/v1beta2/flowcollector_validation_webhook.goapi/flowcollector/v1beta2/flowcollector_validation_webhook_test.gobundle/manifests/flows.netobserv.io_flowcollectors.yamlbundle/manifests/netobserv-operator.clusterserviceversion.yamlconfig/crd/bases/flows.netobserv.io_flowcollectors.yamldocs/FlowCollector.mdhelm/crds/flows.netobserv.io_flowcollectors.yamlinternal/controller/flp/flp_pipeline_builder_test.go
e29c833 to
0fee230
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
internal/controller/flp/flp_pipeline_builder_test.go (1)
220-323: Consider extracting a small helper to reduce repeated setup in these tests.
monoBuilder/configMaps/validatePipelineConfig/getSortedMetricsNamesis repeated in each test; a helper would keep these cases shorter and easier to evolve.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@internal/controller/flp/flp_pipeline_builder_test.go` around lines 220 - 323, Tests repeatedly build the pipeline and extract sorted metric names using monoBuilder, configMaps, validatePipelineConfig and getSortedMetricsNames; extract that repeated setup into a small helper (e.g., func buildAndGetMetricNames(cfg *flowslatest.Config) ([]string, *ConfigStructType) or similar) that runs monoBuilder(...), calls b.configMaps(), asserts no error, calls validatePipelineConfig and returns getSortedMetricsNames(cfs.Parameters[5].Encode.Prom.Metrics) plus any needed cfs for assertions; update each TestMergeMetricsConfiguration_* to call this helper to reduce duplication and keep assertions focused.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@docs/FlowCollector.md`:
- Line 11610: Update the documentation text for the additionalIncludeList vs
includeList mutual-exclusivity to state that not only is additionalIncludeList
ignored when includeList is set, but a validation warning is emitted at apply
time; specifically modify the sentence referencing additionalIncludeList and
includeList in FlowCollector.md so it mentions the validation warning users will
see when both fields are provided.
---
Nitpick comments:
In `@internal/controller/flp/flp_pipeline_builder_test.go`:
- Around line 220-323: Tests repeatedly build the pipeline and extract sorted
metric names using monoBuilder, configMaps, validatePipelineConfig and
getSortedMetricsNames; extract that repeated setup into a small helper (e.g.,
func buildAndGetMetricNames(cfg *flowslatest.Config) ([]string,
*ConfigStructType) or similar) that runs monoBuilder(...), calls b.configMaps(),
asserts no error, calls validatePipelineConfig and returns
getSortedMetricsNames(cfs.Parameters[5].Encode.Prom.Metrics) plus any needed cfs
for assertions; update each TestMergeMetricsConfiguration_* to call this helper
to reduce duplication and keep assertions focused.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 107c8d19-2182-48cf-9029-0d355a8b83fd
⛔ Files ignored due to path filters (1)
api/flowcollector/v1beta2/zz_generated.deepcopy.gois excluded by!**/zz_generated.deepcopy.go
📒 Files selected for processing (11)
api/flowcollector/v1beta2/flowcollector_alert_types.goapi/flowcollector/v1beta2/flowcollector_types.goapi/flowcollector/v1beta2/flowcollector_validation_webhook.goapi/flowcollector/v1beta2/flowcollector_validation_webhook_test.goapi/flowcollector/v1beta2/validation_messages.gobundle/manifests/flows.netobserv.io_flowcollectors.yamlbundle/manifests/netobserv-operator.clusterserviceversion.yamlconfig/crd/bases/flows.netobserv.io_flowcollectors.yamldocs/FlowCollector.mdhelm/crds/flows.netobserv.io_flowcollectors.yamlinternal/controller/flp/flp_pipeline_builder_test.go
✅ Files skipped from review due to trivial changes (1)
- bundle/manifests/netobserv-operator.clusterserviceversion.yaml
🚧 Files skipped from review as they are similar to previous changes (4)
- api/flowcollector/v1beta2/flowcollector_validation_webhook_test.go
- helm/crds/flows.netobserv.io_flowcollectors.yaml
- bundle/manifests/flows.netobserv.io_flowcollectors.yaml
- config/crd/bases/flows.netobserv.io_flowcollectors.yaml
0fee230 to
b71c894
Compare
b71c894 to
b25daa9
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
internal/controller/flp/flp_pipeline_builder_test.go (1)
118-118: Optional: remove hardcoded Prometheus parameter index from the helper.Using
cfs.Parameters[5]is brittle if pipeline parameter ordering changes. Resolve the Prometheus parameter by name before extracting metrics.♻️ Proposed refactor
func buildAndGetMetricNames(t *testing.T, cfg *flowslatest.FlowCollectorSpec) ([]string, *config.Root) { b := monoBuilder("namespace", cfg) scm, _, dcm, err := b.configMaps() assert.NoError(t, err) cfs, _ := validatePipelineConfig(t, scm, dcm) - names := getSortedMetricsNames(cfs.Parameters[5].Encode.Prom.Metrics) + promIdx := -1 + for i, p := range cfs.Parameters { + if p.Name == "prometheus" { + promIdx = i + break + } + } + assert.NotEqual(t, -1, promIdx, "prometheus stage params not found") + names := getSortedMetricsNames(cfs.Parameters[promIdx].Encode.Prom.Metrics) return names, cfs }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@internal/controller/flp/flp_pipeline_builder_test.go` at line 118, The test currently grabs Prometheus params by position (cfs.Parameters[5]) which is brittle; modify the test to locate the Prometheus parameter by its name/key before calling getSortedMetricsNames so ordering changes won't break the test. Specifically, iterate or use a helper to find the parameter with the Prometheus identifier in cfs.Parameters (the element whose Encode.Prom is populated), then pass that parameter's Encode.Prom.Metrics into getSortedMetricsNames rather than using the hardcoded index; update any local helper used in flp_pipeline_builder_test.go to perform lookups by name instead of index.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@internal/controller/flp/flp_pipeline_builder_test.go`:
- Line 118: The test currently grabs Prometheus params by position
(cfs.Parameters[5]) which is brittle; modify the test to locate the Prometheus
parameter by its name/key before calling getSortedMetricsNames so ordering
changes won't break the test. Specifically, iterate or use a helper to find the
parameter with the Prometheus identifier in cfs.Parameters (the element whose
Encode.Prom is populated), then pass that parameter's Encode.Prom.Metrics into
getSortedMetricsNames rather than using the hardcoded index; update any local
helper used in flp_pipeline_builder_test.go to perform lookups by name instead
of index.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 5e659d93-7ab3-4b65-9d0c-c6bb36d35f96
⛔ Files ignored due to path filters (1)
api/flowcollector/v1beta2/zz_generated.deepcopy.gois excluded by!**/zz_generated.deepcopy.go
📒 Files selected for processing (11)
api/flowcollector/v1beta2/flowcollector_alert_types.goapi/flowcollector/v1beta2/flowcollector_types.goapi/flowcollector/v1beta2/flowcollector_validation_webhook.goapi/flowcollector/v1beta2/flowcollector_validation_webhook_test.goapi/flowcollector/v1beta2/validation_messages.gobundle/manifests/flows.netobserv.io_flowcollectors.yamlbundle/manifests/netobserv-operator.clusterserviceversion.yamlconfig/crd/bases/flows.netobserv.io_flowcollectors.yamldocs/FlowCollector.mdhelm/crds/flows.netobserv.io_flowcollectors.yamlinternal/controller/flp/flp_pipeline_builder_test.go
✅ Files skipped from review due to trivial changes (3)
- api/flowcollector/v1beta2/flowcollector_alert_types.go
- api/flowcollector/v1beta2/validation_messages.go
- docs/FlowCollector.md
🚧 Files skipped from review as they are similar to previous changes (6)
- api/flowcollector/v1beta2/flowcollector_types.go
- api/flowcollector/v1beta2/flowcollector_validation_webhook_test.go
- helm/crds/flows.netobserv.io_flowcollectors.yaml
- bundle/manifests/flows.netobserv.io_flowcollectors.yaml
- api/flowcollector/v1beta2/flowcollector_validation_webhook.go
- config/crd/bases/flows.netobserv.io_flowcollectors.yaml
|
[APPROVALNOTIFIER] This PR is APPROVED Approval requirements bypassed by manually added approval. This pull-request has been approved by: The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Description
Adds a new
additionalIncludeListfield to allow appending metrics to the defaults without breaking backward compatibility.Problem: The original
includeListfield overwrites the default metrics list. Users who want to add a few extra metrics need to specify all defaults + their additions, which is cumbersome.Solution:
includeListbehavior unchanged (overwrites defaults) - backwards compatibleadditionalIncludeListfield that appends to defaultsincludeListtakes precedence and a validation warning is shownUsage Examples:
Append to defaults:
Override defaults (existing behavior):
Changes
additionalIncludeListfield toFLPMetricsAPIGetIncludeList()to support the new fieldDependencies
n/a
Checklist
Summary by CodeRabbit
New Features
Documentation
Tests