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

[Bug]: Invalid order of -XX properties in KAFKA_JVM_PERFORMANCE_OPTS variable #8579

Closed
jakubmalek opened this issue May 29, 2023 · 9 comments · Fixed by #8681
Closed

[Bug]: Invalid order of -XX properties in KAFKA_JVM_PERFORMANCE_OPTS variable #8579

jakubmalek opened this issue May 29, 2023 · 9 comments · Fixed by #8681

Comments

@jakubmalek
Copy link
Contributor

Bug Description

The ordering of JVM performance options is not guaranteed, due use of unordered Map<String, String> in JvmOptions class.
As a consequence following configuration:

jmxOptions:
  -XX:
    UnlockDiagnosticVMOptions: true
    PrintNMTStatistics: true

can result in JVM startup failure when JVM flags are misordered:
java -XX:+PrintNMTStatistics -XX:+UnlockDiagnosticVMOptions

Error: VM option 'PrintNMTStatistics' is diagnostic and must be enabled via -XX:+UnlockDiagnosticVMOptions.
Error: The unlock option must precede 'PrintNMTStatistics'.
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

Steps to reproduce

Configure jvmOptions with to enable UnlockDiagnosticVMOptions and PrintNMTStatistics flags.

Expected behavior

The ordering of performance options should guaranteed.

Strimzi version

0.31.1

Kubernetes version

1.24.9

Installation method

Helm chart

Infrastructure

Azure

Configuration files and logs

No response

Additional context

No response

@scholzj
Copy link
Member

scholzj commented May 29, 2023

IIRC, ordered maps are not supported by YAML / CRDs. So I think this might not be possible. Have you tried directly defining the environment variable using the .spec.kafka.template section as a String?

@jakubmalek
Copy link
Contributor Author

jakubmalek commented May 29, 2023

That is indeed a good point, I forgot about possible issues with the ordering inside the resulting k8s manifest itself.
I'm not sure how many of those VM -XX options requires specific order, but I think the easiest way out (without breaking changes to CRD) would be to include such options in separated configuration section.

But anyway, was able to get it running with proposed use .spec.kafka.template thanks for the hint @scholzj !

spec:
  template:
    connectContainer:
      env:
        - name: JAVA_TOOL_OPTIONS
          value: -XX:+UnlockDiagnosticVMOptions

@scholzj
Copy link
Member

scholzj commented Jun 1, 2023

Triaged on 1.6.2023: It might help to use LinkedHashMap on our side instead of HashMap. It has to be investigated if this really helps or if the ordering breaks even before (e.g. in Kubernetes). If that does not help, API changes would be the only option.

@fvaleri
Copy link
Contributor

fvaleri commented Jun 5, 2023

The -XX property is defined as a JSON schema object, which is parsed as an unordered set of properties mapping a string to a value. As @scholzj said, the ordering information is lost inside Kubernetes, so the only option would be to change the schema to use an array. Alternatively, we can simply document the JAVA_TOOL_OPTIONS workaround.

@scholzj
Copy link
Member

scholzj commented Jun 5, 2023

Ok, so I guess we can re-triage it next week with this new information. I will update the labels.

@jakubmalek
Copy link
Contributor Author

One solution that came to my mind is to apply sorting of XX arguments in ModelUtils#jvmPerformanceOptions method. The sorting can be based on a set of "prioritized" parameters like UnlockDiagnosticVMOptions, that should be placed at the beginning.
The simplest solution could include hardcoded list of "prioritized" flags in more elaborate implementation, the list could be configurable by the user - but I'm not sure if it's really needed.

@scholzj
Copy link
Member

scholzj commented Jun 7, 2023

My understanding is that the options might differ for different versions and JDKs - and likely their dependencies as well. So I wonder if hardcoding such logic might break it for users who use other JDKs. But it would be an option to consider.

@tombentley
Copy link
Member

Triaged on 15/06/2023: We should investigate ensuring that UnlockDiagnosticVMOptions is the first argument if it's present. We think this is the only JVM option where the ordering matters, so it doesn't seem like we're setting a difficult-to-maintain precedent in special-casing this one. It might be necessary to do this in the bash script used to start the broker.

@jakubmalek
Copy link
Contributor Author

I created PR with my proposal of hardcoded priority list used for sorting.
If you prefer to go with bash-script approach feel free to decline it.

jakubmalek added a commit to jakubmalek/strimzi-kafka-operator that referenced this issue Jun 19, 2023
Added ParallelParameterizedTest with dependency to junit-jupiter-params

Signed-off-by: Jakub Malek <[email protected]>
jakubmalek added a commit to jakubmalek/strimzi-kafka-operator that referenced this issue Jun 19, 2023
Signed-off-by: Jakub Malek <[email protected]>
jakubmalek added a commit to jakubmalek/strimzi-kafka-operator that referenced this issue Jun 19, 2023
jakubmalek added a commit to jakubmalek/strimzi-kafka-operator that referenced this issue Jun 19, 2023
…imzi#8579)

Removed ParallelParameterizedTest annotation along with junit-jupiter-params dependency

Signed-off-by: Jakub Malek <[email protected]>
@scholzj scholzj linked a pull request Jun 20, 2023 that will close this issue
3 tasks
scholzj pushed a commit that referenced this issue Jun 20, 2023
Signed-off-by: Jakub Malek <[email protected]>
Signed-off-by: Jakub Małek <[email protected]>
Co-authored-by: Federico Valeri <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants