googleads / google-ads-java

Google Ads API Client Library for Java
Apache License 2.0
171 stars 177 forks source link

We have just migrated from v13 to v16 for google ads api and seeing error. #779

Closed adityaalemnisk closed 8 months ago

adityaalemnisk commented 8 months ago

What is your question? We have just migrated from v13 to v16 for google ads api and seeing error.

Screenshot 2024-02-29 at 5 19 52 AM

We have just migrated from v13 to v16 for google ads api and seeing error when userDataServiceClient = googleAdsClient.getLatestVersion().createUserDataServiceClient(); is called. code implementation :

Screenshot 2024-02-29 at 11 04 48 AM
jradcliff commented 8 months ago

Hi,

I've tried to reproduce the issue you're seeing, but I'm not getting that error.

  1. Is there any additional information from your logs? I see the image shows there were details about an error before the portion in the screenshot. If you could copy/paste any other log information as text (instead of as a screenshot) that'd be helpful.

  2. When does this error occur? Within the loop, when the process is shutting down, or at some other time?

As an aside, I recommend reusing the UserDataServiceClient instead of creating a new instance for every iteration of the loop. The way you're doing it still works, but it's much more efficient to reuse a single service client across requests. You can still send those requests to different customer_ids using a single service client as long as the OAuth credentials or login_customer_id doesn't change.

Thanks, Josh, Google Ads API Team

adityaalemnisk commented 8 months ago

Here is the complete error

Mar 01, 2024 6:52:40 AM io.grpc.internal.ManagedChannelOrphanWrapper$ManagedChannelReference cleanQueue SEVERE: ~~~ Previous channel ManagedChannelImpl{logId=67, target=googleads.googleapis.com:443} was garbage collected without being shut down! ~~~ Make sure to call shutdown()/shutdownNow() java.lang.RuntimeException: ManagedChannel allocation site at io.grpc.internal.ManagedChannelOrphanWrapper$ManagedChannelReference.(ManagedChannelOrphanWrapper.java:102) at io.grpc.internal.ManagedChannelOrphanWrapper.(ManagedChannelOrphanWrapper.java:60) at io.grpc.internal.ManagedChannelOrphanWrapper.(ManagedChannelOrphanWrapper.java:51) at io.grpc.internal.ManagedChannelImplBuilder.build(ManagedChannelImplBuilder.java:662) at io.grpc.ForwardingChannelBuilder2.build(ForwardingChannelBuilder2.java:254) at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.createSingleChannel(InstantiatingGrpcChannelProvider.java:442) at com.google.api.gax.grpc.ChannelPool.(ChannelPool.java:107) at com.google.api.gax.grpc.ChannelPool.create(ChannelPool.java:85) at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.createChannel(InstantiatingGrpcChannelProvider.java:243) at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.getTransportChannel(InstantiatingGrpcChannelProvider.java:237) at com.google.api.gax.rpc.ClientContext.create(ClientContext.java:226) at com.google.ads.googleads.v16.services.stub.GrpcUserDataServiceStub.create(GrpcUserDataServiceStub.java:63) at com.google.ads.googleads.v16.services.stub.UserDataServiceStubSettings.createStub(UserDataServiceStubSettings.java:99) at com.google.ads.googleads.v16.services.UserDataServiceClient.(UserDataServiceClient.java:157) at com.google.ads.googleads.v16.services.UserDataServiceClient.create(UserDataServiceClient.java:139) at com.google.ads.googleads.lib.catalog.GeneratedCatalog$V16Client.createUserDataServiceClient(GeneratedCatalog.java:1777) at com.lemnisk.cdpaudience.uploader.GoogleAdsAudienceUploader.sendDataToGoogle(GoogleAdsAudienceUploader.java:194) at com.lemnisk.cdpaudience.uploader.GoogleAdsAudienceUploader.sendDataToGoogleInBatch(GoogleAdsAudienceUploader.java:104) at com.lemnisk.cdpaudience.uploader.GoogleAdsAudienceUploader.addUsers(GoogleAdsAudienceUploader.java:85) at com.lemnisk.cdpaudience.uploader.SegmentChannelFileProcessor.run(SegmentChannelFileProcessor.java:180) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748)

CrashReporter : Already enabled! CrashReporter : Already enabled!


I see the image shows there were details about an error before the portion in the screenshot ---> thats the same error as pasted above. Its repeating itself When does this error occur? Within the loop, when the process is shutting down, or at some other time? ---> its coming again and again whenever this is called

 try (UserDataServiceClient userDataServiceClient =
            googleAdsClient.getLatestVersion().createUserDataServiceClient())

The error is coming when createUserDataServiceClient is called. I had tried to move it outside the loop but then also I was receiving the same error. I tried to use shutdown/shutdownNow as suggest by the error but it didnt do anything. The above error is coming for v14, v15 and v16. With v13 I am getting the response --->

{    request_error: UNKNOWN_ENUM_VALUE_RequestError_38  }  message: "Version v13 is deprecated. Requests to this version will be blocked."}

Our application works like we have multiple clients with different credentials and there is a file reader class which is called by a thread pool. The file reader class reads multiple files and calls the class google uploader service.

jradcliff commented 8 months ago

Hi,

Could you share your dependencies as described in our Advanced usage guide? It's possible that your runtime has inconsistent/incompatible dependencies that are leading to that error.

Another option is to change your dependency on this library from:

com.google.api-ads:google-ads:30.0.0

to:

com.google.api-ads:google-ads-shadowjar:30.0.0

And see if that resolves the issue. If it does, that means that the error is stemming from a dependency conflict.

Thanks, Josh

adityaalemnisk commented 8 months ago

Hi, These are the dependencies we were using

        <dependency>
            <groupId>com.google.api-ads</groupId>
            <artifactId>ads-lib</artifactId>
            <version>4.15.1</version>
            <exclusions>
                <exclusion>
                    <groupId>com.google.guava</groupId>
                    <artifactId>guava</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>commons-configuration</groupId>
                    <artifactId>commons-configuration</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.apache.httpcomponents</groupId>
                    <artifactId>httpclient</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.apache.httpcomponents</groupId>
                    <artifactId>httpcore</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>com.google.api-ads</groupId>
            <artifactId>google-ads</artifactId>
            <version>30.0.0</version>
        </dependency>
            <dependency>
            <groupId>com.google.http-client</groupId>
            <artifactId>google-http-client-jackson2</artifactId>
            <version>1.23.0</version>
            <exclusions>
                <exclusion>
                    <groupId>org.apache.httpcomponents</groupId>
                    <artifactId>httpclient</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.apache.httpcomponents</groupId>
                    <artifactId>httpcore</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

On using the shaded version of google-ads the issue is resolved and I am able to see successful uploads.

Can you also help me with the maximum number of users that we can upload for a single account with basic access using UserDataServiceClient. What I understand from the documentation is that we can have 15K api calls per day and with UserDataServiceClient we can have 10 unique user identifiers with ADD operation in a single api call that takes up the total to 150K users uploaded per account per day.

jradcliff commented 8 months ago

Hi,

Thanks for trying out the shaded jar. Before switching to that, I would recommend removing the following section entirely because the com.google.api-ads:ads_lib library is for the old AdWords API that shut down over a year ago:

        <dependency>
            <groupId>com.google.api-ads</groupId>
            <artifactId>ads-lib</artifactId>
            <version>4.15.1</version>
            <exclusions>
                <exclusion>
                    <groupId>com.google.guava</groupId>
                    <artifactId>guava</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>commons-configuration</groupId>
                    <artifactId>commons-configuration</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.apache.httpcomponents</groupId>
                    <artifactId>httpclient</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.apache.httpcomponents</groupId>
                    <artifactId>httpcore</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

I would not be surprised if removing that dependency on com.google.api-ads:ads-lib fixes the problem without having to use the shaded jar. I'd only recommend using the shaded jar if you can't resolve dependency problems in any other way.

Regarding limits with Basic Access, you can have 15,000 API operations per day. With UserDataService, each request counts as 1 operation, so that's equivalent to 15,000 UserDataService requests per day if that's the only type of request you're sending.

https://developers.google.com/google-ads/api/docs/best-practices/quotas

Each UserDataService request can have up to 10 operations. So combined with the 15,000 requests/day limit, that means you can add or remove 15,000 * 10 = 150,000 members from user lists each day. However, if you're approaching that limit, you may want to use the asynchronous OfflineUserDataJob approach instead, as it's going to be much more efficient than using UserDataService.

Thanks, Josh

adityaalemnisk commented 8 months ago

Hi Josh, Thanks for your help. I was able to resolve the error using shadow-jar mentioned in the advanced usage.