API Activity retention time

Hello

I wonder how to configure Tyk gateway in order to set the retention time about API analytics for API activity. I have read the documentation but it’s not clear for me. I have set TYK_GW_ANALYTICSCONFIG_STORAGEEXPIRATIONTIME configuration key but I’m not sur if it’s enough and about the gateway behavior.

Do I need to set others variable ?
What is the recommandation/advices about the maximum storage expiration time ?

Regards

Hi @ibe,

Thank you for your post and for your patience.

TYK_GW_ANALYTICSCONFIG_STORAGEEXPIRATIONTIME controls the TTL of analytics records in Redis before the Pump forwards them to persistent storage/backend. This may not directly align with your goal, as we understand it.

To configure an expiry for analytics records, you can set the data_expires value (in seconds) on the organization key:

Gateway API – POST or PUT

POST http://<gateway>/tyk/org/keys/<org-id>
{
  "data_expires": 0,
  "org_id": "<org-id>"
}

Then, ensure TYK_GW_ENFORCEORGDATAAGE is enabled on the Gateway.

This sets the expireAt field in the analytics records.

Databases, like MongoDB, can automatically remove records when due, if an index exists on the expireAt field (or using expireAfterSeconds). Please see Time-Based Capping docs.

For other databases, such as Postgres, you can use this field to run scripts or cleanup jobs based on the expiry condition.

Hope this helps.

Best regards,