Skip to content
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

Split the reporter into client and server modules #73

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

mimaison
Copy link
Contributor

@mimaison mimaison commented Feb 27, 2025

This implements Proposal 96 and splits the reporter into 2 modules:

  • client-metrics-reporter
  • server-metrics-reporter

This also adds support for dynamic reconfiguration (#55).

I'm still unsure about the packaging. Running mvn package produces archives under client-metrics-reporter and server-metrics-reporter. Is that sufficient? or do we want a single archive?

@mimaison mimaison added this to the 0.2.0 milestone Mar 4, 2025
@mimaison mimaison requested a review from ppatierno March 4, 2025 13:51
@mimaison
Copy link
Contributor Author

mimaison commented Mar 4, 2025

The CI is failing. I can reproduce locally but not sure I understand why this is happening.

Running:

mvn verify
mvn spotbugs:check

Hits the issue:

[ERROR] Failed to execute goal on project server-metrics-reporter: Could not resolve dependencies for project io.strimzi:server-metrics-reporter:jar:1.0.0-SNAPSHOT
[ERROR] dependency: io.strimzi:client-metrics-reporter:jar:1.0.0-SNAPSHOT (compile)
[ERROR] 	Could not find artifact io.strimzi:client-metrics-reporter:jar:1.0.0-SNAPSHOT
[ERROR] dependency: io.strimzi:client-metrics-reporter:jar:tests:1.0.0-SNAPSHOT (test)
[ERROR] 	Could not find artifact io.strimzi:client-metrics-reporter:jar:tests:1.0.0-SNAPSHOT
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal on project server-metrics-reporter: Could not resolve dependencies for project io.strimzi:server-metrics-reporter:jar:1.0.0-SNAPSHOT
dependency: io.strimzi:client-metrics-reporter:jar:1.0.0-SNAPSHOT (compile)
	Could not find artifact io.strimzi:client-metrics-reporter:jar:1.0.0-SNAPSHOT
dependency: io.strimzi:client-metrics-reporter:jar:tests:1.0.0-SNAPSHOT (test)
	Could not find artifact io.strimzi:client-metrics-reporter:jar:tests:1.0.0-SNAPSHOT

But if I run:

mvn verify spotbugs:check

then it works

@mimaison mimaison requested a review from k-wall March 7, 2025 10:52
README.md Outdated
@@ -37,47 +37,51 @@ The metrics reporter has the following configurations:
### Kafka Brokers
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this say Kafka Brokers and Controllers?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated that section. I think we'll probably want further improvements to the README, it's still a bit bare bones.

@see-quick
Copy link
Member

The CI is failing. I can reproduce locally but not sure I understand why this is happening.

Running:

mvn verify
mvn spotbugs:check

Hits the issue:

[ERROR] Failed to execute goal on project server-metrics-reporter: Could not resolve dependencies for project io.strimzi:server-metrics-reporter:jar:1.0.0-SNAPSHOT
[ERROR] dependency: io.strimzi:client-metrics-reporter:jar:1.0.0-SNAPSHOT (compile)
[ERROR] 	Could not find artifact io.strimzi:client-metrics-reporter:jar:1.0.0-SNAPSHOT
[ERROR] dependency: io.strimzi:client-metrics-reporter:jar:tests:1.0.0-SNAPSHOT (test)
[ERROR] 	Could not find artifact io.strimzi:client-metrics-reporter:jar:tests:1.0.0-SNAPSHOT
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal on project server-metrics-reporter: Could not resolve dependencies for project io.strimzi:server-metrics-reporter:jar:1.0.0-SNAPSHOT
dependency: io.strimzi:client-metrics-reporter:jar:1.0.0-SNAPSHOT (compile)
	Could not find artifact io.strimzi:client-metrics-reporter:jar:1.0.0-SNAPSHOT
dependency: io.strimzi:client-metrics-reporter:jar:tests:1.0.0-SNAPSHOT (test)
	Could not find artifact io.strimzi:client-metrics-reporter:jar:tests:1.0.0-SNAPSHOT

But if I run:

mvn verify spotbugs:check

then it works

I think mvn verify spotbugs:check works because during the verify phase, it shares artifacts in memory but if you try to run:

  1. mvn verify
  2. mvn spotbugs:check

then verify does not install artifacts to local repo .m2 and that those dependencies are not persistent for the next run of the mvn command (i.e., mvn spot bugs:check). To make those dependencies persistent, you should use mvn install -DskipTests I think.

<artifactId>client-metrics-reporter</artifactId>

<dependencies>
<dependency>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For multi module projects, maven best practice is to express shared dependencies in the parent POM using a dependencyManagement section. You can then remove the version numbers from the dependencies in the child poms.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the tip! I already had the versions defined in the parent POM so I removed the versions from the modules.

}

@Override
public void contextChange(MetricsContext metricsContext) {
String prefix = metricsContext.contextLabels().get(MetricsContext.NAMESPACE);
if (!PREFIXES.contains(prefix)) {
throw new IllegalStateException("ClientMetricsReporter should only be used in Kafka servers");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ClientMetricsReporter should only be used by clients?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, fixed.


private static final Logger LOG = LoggerFactory.getLogger(AbstractReporter.class);

private final Map<Object, MetricWrapper> allowedMetrics = new ConcurrentHashMap<>();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't find the naming of otherMetrics too clear. It took me a while to grok what was going on:

You keep track of the otherMetrics so that in the case the allow list is changed, you can start to report on the newly matched metrics. You only need to do this if the implementation is reconfigurable.

Can I ask for a few more comments (class level)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with Keith, it would be better to have some comments.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I renamed otherMetrics to disallowedMetrics. I also added a few comments to this class to clarify its role. Let me know if some parts are still not clear.

* Update the allowed metrics based on the current allowlist pattern.
*/
public void updateAllowedMetrics() {
if (!isReconfigurable()) return;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are guaranteed that this method is called by a single thread, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes in KRaft mode this should be called by a single thread. While this runs the addMetric() and removeMetric() methods could be called from another thread but that should be fine with ConcurrentHashMaps.

/**
* MetricsReporter implementation that expose Kafka server metrics in the Prometheus format.
*/
public class ServerKafkaMetricsReporter extends ClientMetricsReporter {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The class hierarchy is giving me pause for thought. Is ServerKafkaMetricsReporter really a ClientMetricsReporter. I wonder whether the common stuff should be pushed to the abstract class with only ServerKafkaMetricsReporter knowing about reconfigurability and 'otherMetric' tracking.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it's a bit complicated.

The allowedMetrics logic is shared across all 3 reporters (ClientMetricsReporter, ServerKafkaMetricsReporter and ServerYammerMetricsReporter) so it makes sense to have that in the abstract class.

For the reconfiguration logic (otherMetric) it's used by both ServerKafkaMetricsReporter and ServerYammerMetricsReporter. So it's still 2 out of 3 reporters hence why I put it there too. Otherwise we'd need a server abstract reporter but that seems overkill.

@mimaison
Copy link
Contributor Author

I think mvn verify spotbugs:check works because during the verify phase, it shares artifacts in memory but if you try to run:

1. mvn verify

2. mvn spotbugs:check

then verify does not install artifacts to local repo .m2 and that those dependencies are not persistent for the next run of the mvn command (i.e., mvn spot bugs:check). To make those dependencies persistent, you should use mvn install -DskipTests I think.

So what do you recommend? Should I add a step to run mvn install, or run verify and spotbugs:check together? What do other Strimzi projects do?

@ppatierno
Copy link
Member

I was looking at the bridge as simpler compared to the operator. We have the verify and spotbugs as two separated stages anyway, you can see here:

https://github.com/strimzi/strimzi-kafka-bridge/blob/main/.azure/templates/jobs/build_java.yaml#L27

where the java_verify is a make target running mvn verify.
and then here:

https://github.com/strimzi/strimzi-kafka-bridge/blob/main/.azure/templates/jobs/build_java.yaml#L35

where the spotbugs is a make target running mvn spotbugs:check.

Signed-off-by: Mickael Maison <[email protected]>
@mimaison
Copy link
Contributor Author

I was looking at the bridge as simpler compared to the operator. We have the verify and spotbugs as two separated stages anyway, you can see here:

https://github.com/strimzi/strimzi-kafka-bridge/blob/main/.azure/templates/jobs/build_java.yaml#L27

where the java_verify is a make target running mvn verify. and then here:

https://github.com/strimzi/strimzi-kafka-bridge/blob/main/.azure/templates/jobs/build_java.yaml#L35

where the spotbugs is a make target running mvn spotbugs:check.

I'm not sure I follow. What do you suggest doing?

@see-quick
Copy link
Member

see-quick commented Mar 14, 2025

I think mvn verify spotbugs:check works because during the verify phase, it shares artifacts in memory but if you try to run:

1. mvn verify

2. mvn spotbugs:check

then verify does not install artifacts to local repo .m2 and that those dependencies are not persistent for the next run of the mvn command (i.e., mvn spot bugs:check). To make those dependencies persistent, you should use mvn install -DskipTests I think.

So what do you recommend? Should I add a step to run mvn install, or run verify and spotbugs:check together? What do other Strimzi projects do?

Well we simply do

      # Build the Java code without tests
      - bash: "make java_install"
        displayName: "Build Java code"
        env:
          MVN_ARGS: "-DskipTests -e -V -B"
          CURL_ARGS: "-s"

      # Run different checks on the code
      - bash: "make spotbugs"
        displayName: "Run Spotbugs"
        env:
          MVN_ARGS: "-e -V -B"

where make java_install, which will trigger java_build and then it would trigger ./build.sh and inside build.sh where in makefile we define

.PHONY: build clean release all $(SUBDIRS) $(DOCKER_TARGETS) spotbugs

so Spotbugs is part of the building process (but last to execute). I would go with mvn verify + spotbugs in one step IMHO in your case.

@mimaison
Copy link
Contributor Author

I would go with mvn verify + spotbugs in one step IMHO in your case.

Yes that seems the simplest option to me. But I wanted to see what other projects did and understand if there was a good reason to have separated steps.

Signed-off-by: Mickael Maison <[email protected]>
@mimaison
Copy link
Contributor Author

mimaison commented Mar 14, 2025

I merged both steps but it's not triggering the CI now
The yaml was broken, I fixed it (2c20f98) and the CI is running now.

Signed-off-by: Mickael Maison <[email protected]>
@k-wall
Copy link

k-wall commented Mar 19, 2025

lgtm - thanks @mimaison

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants