Skip to content

Re-enable Agent Detection on Zos #13730

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

Conversation

benjamin-confino
Copy link
Contributor

This resolves #13729

I have tested this locally and can confirm it works in our Z/OS test environment.

@benjamin-confino benjamin-confino requested a review from a team as a code owner April 17, 2025 16:39
Copy link

linux-foundation-easycla bot commented Apr 17, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@benjamin-confino benjamin-confino force-pushed the zos-charset-in-container-resource-fileset branch from 86d86fd to 2530c47 Compare April 17, 2025 17:05
@benjamin-confino
Copy link
Contributor Author

I'm reviewing the process to sign the CLA, I don't forsee any problems.

@benjamin-confino benjamin-confino force-pushed the zos-charset-in-container-resource-fileset branch from 2530c47 to e71b5a4 Compare April 17, 2025 18:04
return Files.lines(path);

String osName = getOsName();
if (!(osName.equalsIgnoreCase("z/OS") || osName.equalsIgnoreCase("OS/390"))) {
Copy link
Contributor

Choose a reason for hiding this comment

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

could switch the if and else parts to get rid of the negation

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 put it this way around because making the default case the base one feels right, but I sense you have different tastes and its your codebase so I'll change it. (I'll test the updated version in our ZOS environment before pushing of course, which takes a bit of time)


// The odds of /proc being UTF-8 but the native encoding saying otherwise is extremely low
// but since UTF-8 is the standard it should be checked.
charsetsToTest.add(StandardCharsets.UTF_8);
Copy link
Contributor

Choose a reason for hiding this comment

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

does z/os ever use utf-8 for this file? assuming it does, when you'd attempt to parse utf-8 encoded file with Cp1047 would that ever fail? is it possible for the code flow to reach a point where it attempts utf-8 at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It cannot, and I did ask if there was any chance of it happening in the future and that's unlikely too. But I put this line in there anyway because I felt that the industry standard charset should always be on the list. If you disagree say the word and I'll remove it.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think you should remove it.

charsetsToTest.add(StandardCharsets.UTF_8);

IOException exception = null;
for (Charset charset : charsetsToTest) {
Copy link
Contributor

Choose a reason for hiding this comment

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

could you elaborate under what circumstances you'd expect parsing with one charset to fail and proceed to the next one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Happy to. I'd expect this to fail on Z/OS if the JVM is configured with a non-default encoding on Z/OS. (I've had to do exactly that in our test environment)

In that case Charset.defaultCharset() will use whatever the user configured, if that is the wrong charset for reading /proc it will fall back to the next item which should pass since its hardcoded to Cp1047.

I did some tests with native.encoding on java17+ and couldn't change it from the default, but I'm not confident that I haven't missed something so its possible a similar scenario exists on java17+.

Copy link
Contributor

@laurit laurit Apr 24, 2025

Choose a reason for hiding this comment

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

Lets assume that the application runs on jdk11 or 8 that relies on Charset.defaultCharset() and uses -Dfile.encoding=ISO-8859-1 (I think I saw somewhere a mention that websphere uses this). Now my guess would be that reading the file will succeed and the fallback to Cp1047 won't happen. The content of the read file will of course be messed up. If that is so then I think we need to come up with a different solution. Do you know is com.ibm.jzos.ZUtil.getDefaultPlatformEncoding() part of the java sdk on z/os? If it is we could add a compile dependency to https://central.sonatype.com/artifact/com.ibm.jzos/ibmjzos And use that to get the platform encoding.

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 tested ISO-8859-1 and you're right, that is a fine catch that made it through all our automated tests. I also asked about getDefaultPlatformEncoding() but it turns out that also cannot guarantee correctness (especially if someone uses setDefaultPlatformEncoding() which is discouraged but has no enforcement against it).

The advice I was given was to keep it simple and just use Cp1047, as that would always be the case for /proc on ZOS. The other option was to read the file tag as /proc is all tagged with Cp1047.

Which of these would you prefer?

Copy link
Contributor

Choose a reason for hiding this comment

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

The advice I was given was to keep it simple and just use Cp1047, as that would always be the case for /proc on ZOS.

That reads to me as you should always use Cp1047 as this is known to be the encoding of that file and wouldn't need to look at native.encoding at all even when it is available. I'm not able to asses whether this is true or not. I'm willing to accept any solution that isn't obviously wrong. That includes unilaterally using Cp1047, falling back to Cp1047 when native.encoding is not available or using getDefaultPlatformEncoding().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I'll unilaterally use Cp1047. I've heard from two different Z/OS developers that /proc is always encoded that way so it should be safe. And it will remove the need for a whole method of fallbacks.

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 ran the reworked version through our test system over the weekend it was fine so I've pushed it here, I've kept it in a separate commit for now for ease of reviewing.

out.write(ibm);
}
ContainerResource.Filesystem fs =
new ContainerResource.Filesystem() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we usually add a constructor that accepts a supplier that can be replaced for testing, see

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can do

  Invert if statement to remove the need for negation
  Remove unneeded null check on return from charset.ForName
  Use a supplier constructor argument for testing

// As a fallback value, add a hardcoded reference to IBM1047 (Canonical name: Cp1047).
Charset ibm1047 = Charset.forName("Cp1047");
if (ibm1047 != null) { // safety check
Copy link
Contributor

Choose a reason for hiding this comment

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

this can't be null either

@benjamin-confino
Copy link
Contributor Author

I ran it through our zos test environment and it passed so I've pushed, I left it in a separate commit for now for ease of reviewing.

@trask trask merged commit 7364927 into open-telemetry:main Apr 28, 2025
86 checks passed
@benjamin-confino
Copy link
Contributor Author

I see this is merged, thank you.

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.

Re-Enable container id detection on z/os
4 participants