如何配置生命周期管理以自动删除 Google Cloud Platform 日志记录存储中的日志?

How can I configure the lifecycle management for automatic deletion of logs in Google Cloud Platform's logging storage?

提问人:Borislav Gizdov 提问时间:11/16/2023 最后编辑:Borislav Gizdov 更新时间:11/16/2023 访问量:58

问:

我有几个 Google Cloud 项目积累了大量日志,每月大约 200GB,预计在下一个时期将增加近一倍。最初,我认为通过调整保留设置来管理这一点会很简单:编辑日志存储桶,设置保留期(以天为单位),然后更新存储桶。

我在六个多月前配置了它,将其设置为非生产项目的一天。但是,直到下个月初,似乎什么都没有删除。日志每天继续累积,并且仅在下个月的第一天重置。

在查看了文档和各种 Stack Overflow 问题后,我发现保留期不是日志删除的期限;它实际上是保留日志的持续时间。为了解决这个问题,我们需要为存储桶中的对象建立一个生命周期。不幸的是,有问题的存储桶(_Default日志记录存储桶)是一个系统存储桶,我无法配置它。

即使我删除日志,存储也保持不变,直到下个月才会重置。有没有办法将日志的生命周期设置为小于一个月?gcloud logging logs delete

Logs storage

Retention

编辑:实际上,保留应该删除日志,但我认为这不会发生。我所有项目的日志。

retentionDays   integer

Logs will be retained by default for this amount of time, after which 
they will automatically be deleted. The minimum retention period is 1 
day. If this value is set to zero at bucket creation time, the 
default time of 30 days will be used.

https://cloud.google.com/logging/docs/reference/v2/rest/v2/locations.buckets

google-cloud-platform 日志记录 google-cloud-logging

评论

0赞 Sathi Aiswarya 11/16/2023
如果您无法为默认日志存储桶配置生命周期,可以考虑创建自定义日志存储桶
0赞 Borislav Gizdov 11/16/2023
它具有相同的配置,不可见于云存储,并且您只能配置保留。

答:

0赞 Borislav Gizdov 11/16/2023 #1

我相信我解决了我自己的问题;这是对 Cloud Logging 定价方式的误解。

  • Cloud Logging 不会对存储桶中存储的日志的当前大小收费,而是对已编入索引或已处理的日志收费。这就是为什么存储大小只会增加,即使删除日志也不会下降的原因。

ingestion

这就是为什么它说的是引入,而不是存储。

Logging charges for the pre-indexed volume of logs data that is stored in
 the _Default log bucket and in user-defined log buckets, when the total
 volume exceeds the free monthly allotment. Every write of a log entry to
 the _Default log bucket or to a user-defined log bucket counts toward your
 storage allotment. For example, if you have sinks that route a log entry to
 three log buckets, then that log entry is stored three times.
  • 此外,如果保留时间少于 30 天,因为它是免费的,则保留期微不足道。将数据保留超过 30 天会产生额外的日志存储大小成本。

retantion

计费存储为 0,因为保留期设置为 1 天。

Logging charges retention costs when the logs are retained longer than the
 default retention period. You can't configure the retention period for the
 _Required log bucket. There are no retention costs when logs are stored
 only for the default retention period of the log bucket.

https://cloud.google.com/stackdriver/pricing#storage-pricing