Use role-based default allowlists for Strimzi Metrics Reporter - #12966
Use role-based default allowlists for Strimzi Metrics Reporter#12966saksham869 wants to merge 1 commit into
Conversation
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
04f0516 to
c698ea9
Compare
scholzj
left a comment
There was a problem hiding this comment.
Thanks for the PR. I had a look and left some comments. However, I wonder if in general the correct way forward would be to:
- In the
StrimziMetricsReporterModelconstructor, pass only the configuration and if the allow list is set, validate and store it. Otherwise, just storenull - Change
getAllowListto something likegetAllowListOrDefaultwhere you pass the default as the parameter. It would check if the allow list is not null and return it. If it is null, it would return the default.
That way, you do not to have multiple instances of the object with different defaults etc. And the impact on the other classes should be minimal as they anyway have the defaults in the constsnt.
PS: Ideally you should use the PR template we have for the PR description.
| validate(config); | ||
| this.allowList = config.getValues() != null && config.getValues().getAllowList() != null | ||
| ? config.getValues().getAllowList() : defaultAllowList; | ||
| boolean hasCustomList = config.getValues() != null && config.getValues().getAllowList() != null; |
There was a problem hiding this comment.
Can this be directly this.customAllowList?
| private static final List<String> MIXED_DEFAULT_METRICS_ALLOW_LIST = Stream.concat( | ||
| BROKER_DEFAULT_METRICS_ALLOW_LIST.stream(), | ||
| CONTROLLER_DEFAULT_METRICS_ALLOW_LIST.stream() | ||
| ).distinct().toList(); |
There was a problem hiding this comment.
Why can't you just create a new list and add both lists to it? Or maybe even better, join them on demand when needed instead of keeping it as a constant?
|
@saksham869 Any chance/plans to get back to this? Thanks. |
Hi @scholzj , yes — I'm actively working on the refactor based on your feedback. Implementing the |
|
Great, thanks. |
c698ea9 to
8a174ca
Compare
Split the single DEFAULT_METRICS_ALLOW_LIST into three role-specific lists: BROKER_DEFAULT_METRICS_ALLOW_LIST, CONTROLLER_DEFAULT_METRICS_ALLOW_LIST, and MIXED_DEFAULT_METRICS_ALLOW_LIST (union of both). When no custom allowlist is configured, each Kafka node pool now receives only the metrics relevant to its role. Broker-only nodes get broker metrics, controller-only nodes get controller metrics, and mixed nodes get the union of both. Adds isCustomAllowList() to StrimziMetricsReporterModel and a new StrimziMetricsReporterModel(List<String>) constructor for direct default injection. Adds metricsForPool(KafkaPool) helper in KafkaCluster to select the appropriate model per pool. Closes strimzi#12181 Signed-off-by: saksham869 <[email protected]>
8a174ca to
8d089ae
Compare
scholzj
left a comment
There was a problem hiding this comment.
Thanks for the changes. I think they look good.
One thing I noticed through:
- The default metrics are now always defined in a different class from where they are used. So, I think it would make sense to move them to the configuration builder classes and use them locally?
- It would save us the effort to pass them through the builder methods
- The
KafkaBrokerConfigurationBuilderalready has thenodefield that can be used to decide which metric to use.
- It would also simplify the tesst as the broker/controler stuff will be now testable from the
KafkaBrokerConfigrationBuildertests directly without the need to test it inKafkaClusterTest.
What do you think?
| for (String s : CONTROLLER_DEFAULT_METRICS_ALLOW_LIST) { | ||
| if (!mixed.contains(s)) { | ||
| mixed.add(s); | ||
| } | ||
| } |
There was a problem hiding this comment.
I assume you do this to avoid duplicates? I wonder if we should use Sets instead of Lists for the defaults 🤔. But maybe that is something to fix separately.
Description
Closes #12181
Currently, the Strimzi Metrics Reporter uses a single default allowlist for all Kafka nodes regardless of their role. This means broker-only metrics are sent to controller nodes and controller-only metrics are sent to broker nodes.
Changes
DEFAULT_METRICS_ALLOW_LISTinto three role-specific lists:BROKER_DEFAULT_METRICS_ALLOW_LIST— broker-only metricsCONTROLLER_DEFAULT_METRICS_ALLOW_LIST— controller-only metricsMIXED_DEFAULT_METRICS_ALLOW_LIST— union of both (for mixed nodes)metricsForPool(KafkaPool)helper inKafkaClusterto select the appropriate model per pool at config generation timeisCustomAllowList()toStrimziMetricsReporterModelto distinguish user-configured vs default allowlistsStrimziMetricsReporterModel(List<String>)constructor for direct default injectiontestStrimziMetricsReporterDefaultAllowListIsRoleBasedverifying role-based defaults per poolType of change
Checklist