lithnet / googleapps-managementagent

Google Workspace Management Agent for MIM 2016
MIT License
12 stars 4 forks source link

Too many requests #72

Closed briuccio closed 2 years ago

briuccio commented 2 years ago

Hello, I got an error when trying to manage shared contacts. Below the error I got from the logs when trying to export:

An exception has occurred in PutExportEntry Type: Google.GData.Client.GDataRequestException

Message: Execution of request failed: https://www.google.com/m8/feeds/contacts/xxxxx/full/yyyyyy Source: Google.GData.Client TargetSite: Void Execute() StackTrace: at Google.GData.Client.GDataRequest.Execute() at Google.GData.Client.Service.Query(Uri queryUri, DateTime ifModifiedSince, String etag, Int64& contentLength) at Google.GData.Client.Service.Query(FeedQuery feedQuery) at Google.GData.Client.Service.Get(String entryUri) at Lithnet.GoogleApps.ContactRequestFactory.<>c__DisplayClass4_1.b__0() at Lithnet.GoogleApps.ApiExtensions.InvokeWithRateLimit[T](Func`1 t, String bucketName, Int32 consumeTokens) at Lithnet.GoogleApps.ContactRequestFactory.GetContact(String id) at Lithnet.GoogleApps.MA.ApiInterfaceContact.GetInstance(CSEntryChange csentry) in D:\dev\git\lithnet\googleapps-managementagent\src\Lithnet.GoogleApps.MA\ApiInterfaces\ApiInterfaceContact.cs:line 54 at Lithnet.GoogleApps.MA.ExportProcessor.PutCSEntryChangeUpdate(CSEntryChange csentry, CSEntryChange deltaCSEntry, MASchemaType maType, SchemaType type, IManagementAgentParameters config) in D:\dev\git\lithnet\googleapps-managementagent\src\Lithnet.GoogleApps.MA\ExportProcessor.cs:line 167 at Lithnet.GoogleApps.MA.ExportProcessor.PutCSEntryChangeObject(CSEntryChange csentry, SchemaType type, IManagementAgentParameters config) in D:\dev\git\lithnet\googleapps-managementagent\src\Lithnet.GoogleApps.MA\ExportProcessor.cs:line 48 at Lithnet.GoogleApps.MA.ExportProcessor.PutCSEntryChange(CSEntryChange csentry, SchemaType type, IManagementAgentParameters config) in D:\dev\git\lithnet\googleapps-managementagent\src\Lithnet.GoogleApps.MA\ExportProcessor.cs:line 17 at Lithnet.GoogleApps.MA.ManagementAgent.PutExportEntry(PutExportEntriesResults results, CSEntryChange csentry) in D:\dev\git\lithnet\googleapps-managementagent\src\Lithnet.GoogleApps.MA\ManagementAgent.cs:line 179



Inner exception details Type: System.Net.WebException Status: ProtocolError

Message: The remote server returned an error: (429) Too Many Requests. Source: System TargetSite: System.Net.WebResponse GetResponse() StackTrace: at System.Net.HttpWebRequest.GetResponse() at Google.GData.Client.GDataRequest.Execute()


It also happens when trying to import contacts:

12/6/2021 5:25:55 PM: Opening import connection. Page size 100 12/6/2021 5:25:57 PM: Import task started for object type 'contact' 12/6/2021 5:25:57 PM: Background full import from Google started 12/6/2021 5:25:57 PM: Import task failed for object type 'contact'. Duration 00:00:00.2764545


An exception has occurred in b__2 Type: System.AggregateException

Message: One or more errors occurred. Source: StackTrace:



Inner exception details Type: Google.GData.Client.GDataRequestException

Message: Execution of request failed: https://www.google.com/m8/feeds/contacts/xxxxxx/full?max-results=1000 Source: Google.GData.Client TargetSite: Void Execute() StackTrace: at Google.GData.Client.GDataRequest.Execute() at Google.GData.Client.Service.Query(Uri queryUri, DateTime ifModifiedSince, String etag, Int64& contentLength) at Google.GData.Client.Service.Query(FeedQuery feedQuery) at Google.GData.Contacts.ContactsService.Query(ContactsQuery feedQuery) at Lithnet.GoogleApps.ContactRequestFactory.<>cDisplayClass3_1.b0() at Lithnet.GoogleApps.ApiExtensions.InvokeWithRateLimit[T](Func`1 t, String bucketName, Int32 consumeTokens) at Lithnet.GoogleApps.ContactRequestFactory.d3.MoveNext() at Lithnet.GoogleApps.MA.ApiInterfaceContact.<>c__DisplayClass21_0.b0() in D:\dev\git\lithnet\googleapps-managementagent\src\Lithnet.GoogleApps.MA\ApiInterfaces\ApiInterfaceContact.cs:line 185 at System.Threading.Tasks.Task.Execute()



Inner exception details Type: System.Net.WebException Status: ProtocolError

Message: The remote server returned an error: (429) Too Many Requests. Source: System TargetSite: System.Net.WebResponse GetResponse() StackTrace: at System.Net.HttpWebRequest.GetResponse() at Google.GData.Client.GDataRequest.Execute()

ryannewington commented 2 years ago

@briuccio

You'll need to set the rate limit in the miiserver.exe.config file to match that set for your API in the google developer console.

Add the new <section...> value shown below within the existing <configSections> element, or create the <configSections> element if it doesnt exist. Then add the complete <lithnet-google-ma> section as shown below. You may need to tweak the value until the rate limit error goes away.

<configuration>
  <configSections>
    <section name="lithnet-google-ma" type="Lithnet.GoogleApps.MA.MAConfigurationSection, Lithnet.GoogleApps.MA" />
  </configSections>

  <lithnet-google-ma>
    <contacts-api rate-limit="1500" pool-size="30" />
  </lithnet-google-ma>

...
/<configuration>
IAmStevenJohnson commented 2 years ago

@ryannewington

Is the "rate limit" you mentioned here the same as the "Queries per minute per user" in the Google Developer Console? If so, ours is currently set at 600, so would we enter that as the rate-limit parameter? Or should we request a higher limit? I ask because we get this same error when provisioning a lot of contact objects.

ryannewington commented 2 years ago

@IAmStevenJohnson The default rate limit is set to 1500, so the reason you are seeing errors is the MA is trying to send more requests than your project API limits allow.

You can either set the MA to use only 600, which will stop the errors, by reducing the throughput, or you can increase the project API limits.

If the goal is to get rid of the errors, set the MA to 600 to match your project limit. If performance is an issue, increase the project limit and adjust the MA limit to match.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs.

briuccio commented 2 years ago

Hello Ryan, I pick back this ticket to ask you which tag need to be insert to limit groups api call?

<configuration>
  <configSections>
    <section name="lithnet-google-ma" type="Lithnet.GoogleApps.MA.MAConfigurationSection, Lithnet.GoogleApps.MA" />
  </configSections>

  <lithnet-google-ma>
    <**contacts-api rate-limit**="1500" pool-size="30" />
  </lithnet-google-ma>
ryannewington commented 2 years ago

Groups come under the directory API, but group settings comes under its own

<lithnet-google-ma http-debug-enabled="true" export-threads="30">
    <directory-api rate-limit="1500" pool-size="35" export-threads-group-member="5" import-threads-group-member="10" batch-size-group-member="100" />
    <groupssettings-api rate-limit="1500" pool-size="30" />
    <contacts-api rate-limit="1500" pool-size="30" />
  </lithnet-google-ma>