Search code examples
pythongoogle-cloud-logginggoogle-cloud-iot

Entries disappeared from google logging after using google cloud logging client


I am using The google logging client in python in order to retrieve some log from my google IoT Core service.

Here is the code I use:

    client = self.create_client()
    log_filter: str = self.set_filter(device_id, timestamp)
    for _ in client.list_entries(filter_=log_filter, page_size=1):
        return False
    return True

The filter I use looks like this:

resource.type:cloudiot_device AND jsonPayload.eventType:DISCONNECT AND resource.labels.device_num_id:my_device_num_id AND timestamp>="down_limit" AND timestamp<="up_limit"

Basically I am trying to get the deconnection event from the log, if I found a corresponding entry then I stop the run.
So the code works but somehow my log seems to be disappearing.

I created unit test and given a device ID and a timestamp I was able to find a corresponding Log entry yesterday but today it does not exists anymore..

Any idea where this might be coming from ?


Solution

  • The Data Access audit logs [1] has a retention of 30 days [2].

    Similar logs for dates more recent than a month still appear in your stackdriver logging.

    As suggested in the documentation, if you want longer retention it's recommended to export audit log entries like any other Logging log entries and keep them for as long as you wish. You can review this link [3] for more information.


    [1]https://cloud.google.com/logging/docs/audit#data-access

    [2] https://cloud.google.com/logging/docs/audit#audit_log_retention

    [3] https://cloud.google.com/logging/docs/export