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

Native compilation with GraalVM #23642

Open
ValTheBoss opened this issue Oct 14, 2024 · 4 comments
Open

Native compilation with GraalVM #23642

ValTheBoss opened this issue Oct 14, 2024 · 4 comments
Labels
priority: p3 Desirable enhancement or fix. May not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@ValTheBoss
Copy link

There is an issue when using native compilation with GraalVM. I'm trying to use the Admin SDK API Client Library for directory operations.

Environment details

  • Admin SDK API Client Library, version directory_v1-rev20240924-2.0.0
  • Java Temurin 21
  • Native compilation of a Spring Boot 3.3.4 app using by default at this time :
    • paketo-buildpacks/ca-certificates 3.8.6
    • paketo-buildpacks/bellsoft-liberica 10.9.0
    • paketo-buildpacks/syft 2.1.0
    • paketo-buildpacks/executable-jar 6.11.3
    • paketo-buildpacks/spring-boot 5.31.2
    • paketo-buildpacks/native-image 5.14.4

Steps to reproduce

Fresh Spring Boot 3.3.4 project.

Maven configuration

<dependency>
  <groupId>com.google.apis</groupId>
  <artifactId>google-api-services-admin-directory</artifactId>
  <version>directory_v1-rev20240924-2.0.0</version>
</dependency>
...
<plugin>
  <groupId>org.graalvm.buildtools</groupId>
  <artifactId>native-maven-plugin</artifactId>
</plugin>

Build Directory service

private Directory buildDirectoryService(@Nonnull final String gcpKey, @Nonnull final String serviceAccountUser) throws IOException, GeneralSecurityException {
    final ServiceAccountCredentials sourceCredentials =
        ServiceAccountCredentials.fromStream(...)
        .toBuilder()
        .setServiceAccountUser(serviceAccountUser)
        .setScopes(ImmutableSet.of(
            DirectoryScopes.ADMIN_DIRECTORY_GROUP_READONLY,
            DirectoryScopes.ADMIN_DIRECTORY_USER_READONLY
        ))
        .build();

    return new Directory.Builder(Utils.getDefaultTransport(), Utils.getDefaultJsonFactory(), new HttpCredentialsAdapter(sourceCredentials))
        .setApplicationName("MY_APP")
        .build();
  }

Add reflection hints for ErrorInfo.class

@Configuration
@ImportRuntimeHints(NativeImageHints.class)
class NativeImageHints implements RuntimeHintsRegistrar {
  @Override
  public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
    hints.reflection().registerType(ErrorInfo.class, (type) -> type.withConstructor(Collections.emptyList(), ExecutableMode.INVOKE));
  }
}

Directory api call

final Users batch = directory
            .users()
            .list()
            .setMaxResults(100)
            .setDomain("my-domain.com")
            .execute();

Build and run image

mvn clean spring-boot:build-image -e --no-transfer-progress -P native -D skipTests=true
docker run -p 8080:8080 my-app:0.0.1-SNAPSHOT

Result of directory execute()

2024-10-14T12:44:13.891Z  INFO 1 --- [my-app] [nio-8080-exec-1] c.google.api.client.http.HttpTransport   : {
  "error": {
    "code": 400,
    "message": "Bad Request",
    "errors": [
      {
        "message": "Bad Request",
        "domain": "global",
        "reason": "badRequest"
      }
    ]
  }
}

Reason
If I launch the app in DEBUG logging mode, I can see that the URL for the API query is not properly prepared :

curl -v --compressed 
-H 'Accept-Encoding: gzip' 
-H 'Authorization: <Not Logged>' 
-H 'User-Agent: MY_APP Google-API-Java-Client/2.7.0 Google-HTTP-Java-Client/1.45.0 (gzip)' 
-H 'x-goog-api-client: gl-java/21.0.4-graalvm gdcl/2.7.0 linux/6.8.0' -- 'https://admin.googleapis.com/admin/directory/v1/users'

instead of

curl -v --compressed 
-H 'Accept-Encoding: gzip' 
-H 'Authorization: <Not Logged>' 
-H 'User-Agent: MY_APP Google-API-Java-Client/2.7.0 Google-HTTP-Java-Client/1.45.0 (gzip)' 
-H 'x-goog-api-client: gl-java/21.0.4-graalvm gdcl/2.7.0 linux/6.8.0' -- 'https://admin.googleapis.com/admin/directory/v1/users?domain=my-domain.com&maxResults=100'
@diegomarquezp diegomarquezp added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. priority: p2 Moderately-important priority. Fix may not be included in next release. labels Oct 21, 2024
@Phakrada666
Copy link

Phakrada666 commented Oct 24, 2024

<dependency>
  <groupId>com.google.apis</groupId>
  <artifactId>google-api-services-admin-directory</artifactId>
  <version>directory_v1-rev20240924-2.0.0</version>
</dependency>
...
<plugin>
  <groupId>org.graalvm.buildtools</groupId>
  <artifactId>native-maven-plugin</artifactId>
</plugin>

@diegomarquezp
Copy link
Contributor

Thanks for reporting this @ValTheBoss. It's certainly strange that the parameters don't get sent in the native image. Do you have by any chance the reproducer project handy so we can look into it?
Also, for faster response times, please refer to our support hub.

@Phakrada666, looks like you are sharing the dependencies listed in the bug as well. Are you also running into the same issue?

@Phakrada666
Copy link

Phakrada666 commented Oct 24, 2024

2024-10-14T12:44:13.891Z  INFO 1 --- [my-app] [nio-8080-exec-1] c.google.api.client.http.HttpTransport   : {
  "error": {
    "code": 400,
    "message": "Bad Request",
    "errors": [
      {
        "message": "Bad Request",
        "domain": "global",
        "reason": "badRequest"
      }
    ]
  }
}

@reza-cb
Copy link

reza-cb commented Nov 17, 2024

Any updates on this issue? I am encountering the same problem when using google-api-services-sheets (v4-rev20241008-2.0.0) to read a spreadsheet.

Here is the code snippet:

final var sheetValues = sheetsService.spreadsheets().values()
        .get(spreadsheetId, "Teacher!A:C")
        .execute();

This returns the following error:

The requested URL /v4/spreadsheets//values/ was not found on this server. That’s all we know.

at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:118)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:37)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest$3.interceptResponse(AbstractGoogleClientRequest.java:479)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1111)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:565)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:506)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:616)

I suspect the issue might be related to the URL construction, particularly the double slashes (//) in the endpoint. Could you please advise if this is a bug or if I need to adjust my implementation?

The same code works fine on JVM but fails on GraalVM

@diegomarquezp diegomarquezp added priority: p3 Desirable enhancement or fix. May not be included in next release. and removed priority: p2 Moderately-important priority. Fix may not be included in next release. labels Jan 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p3 Desirable enhancement or fix. May not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

4 participants