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

[GCP Logging] GCP project id from quarkus config is not considered #770

Merged

Conversation

SimonScholz
Copy link
Contributor

The quarkus.google.cloud.project-id config property is not considered when using LoggingOptions default instance.

I got the following stacktrace even though I specified the quarkus.google.cloud.project-id config property and even tried to use QUARKUS_GOOGLE_CLOUD_PROJECT_ID as env variable:

LogManager error of type WRITE_FAILURE: Failed to write logs
java.lang.IllegalArgumentException: A project ID is required for this service but could not be determined from the builder or the environment.  Please set a project ID using the builder.
        at com.google.common.base.Preconditions.checkArgument(Preconditions.java:143)
        at com.google.cloud.ServiceOptions.<init>(ServiceOptions.java:340)
        at com.google.cloud.logging.LoggingOptions.<init>(LoggingOptions.java:118)
        at com.google.cloud.logging.LoggingOptions$Builder.build(LoggingOptions.java:112)
        at com.google.cloud.logging.LoggingOptions.getDefaultInstance(LoggingOptions.java:57)
        at io.quarkiverse.googlecloudservices.logging.runtime.cdi.LoggingProducer.create(LoggingProducer.java:39)

The problem is that LoggingOptions.getDefaultInstance() is already trying to find a project id in various ways (but not considering quarkus.google.cloud.project-id) and if that fails the call to the inherited ServiceOptions constructor will raise an IllegalArgumentException due to this:

    @InternalApi("This class should only be extended within google-cloud-java")
    protected ServiceOptions(Class<? extends ServiceFactory<ServiceT, OptionsT>> serviceFactoryClass, Class<? extends ServiceRpcFactory<OptionsT>> rpcFactoryClass, Builder<ServiceT, OptionsT, ?> builder, ServiceDefaults<ServiceT, OptionsT> serviceDefaults) {
        this.projectId = builder.projectId != null ? builder.projectId : this.getDefaultProject();
        if (this.projectIdRequired()) {
            Preconditions.checkArgument(this.projectId != null, "A project ID is required for this service but could not be determined from the builder or the environment.  Please set a project ID using the builder.");
        }

So in my case the builder.projectId is null and therefore the IllegalArgumentException is thrown.

I resolved the issue on my side by adding GOOGLE_CLOUD_PROJECT=my-gcp-project-id as system environment variable, but IMHO your GcpBootstrapConfiguration, aka quarkus.google.cloud.project-id config property, should also be considered here ;)

quarkus.google.cloud.project-id is not considered when using
LoggingOptions default instace
@SimonScholz SimonScholz requested a review from a team as a code owner February 11, 2025 21:47
@SimonScholz
Copy link
Contributor Author

Btw. this will also actually resolve this issue:

#421

Copy link
Collaborator

@loicmathieu loicmathieu left a comment

Choose a reason for hiding this comment

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

LGTM, thanks

@loicmathieu loicmathieu merged commit f8c857f into quarkiverse:main Feb 12, 2025
1 check passed
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.

2 participants