|
| 1 | +// Module included in the following assemblies: |
| 2 | +// |
| 3 | +:_content-type: PROCEDURE |
| 4 | +[id="logging-loki-retention_{context}"] |
| 5 | += Enabling stream-based retention with Loki |
| 6 | +With Logging version 5.6 and higher, you can configure retention policies based on log streams. Rules for these may be set globally, per tenant, or both. If you configure both, tenant rules apply before global rules. |
| 7 | + |
| 8 | +. To enable stream-based retention, create or edit the `LokiStack` custom resource (CR): |
| 9 | + |
| 10 | +include::snippets/logging-create-apply-cr-snip.adoc[lines=9..12] |
| 11 | + |
| 12 | +. You can refer to the examples below to configure your LokiStack CR. |
| 13 | + |
| 14 | +.Example global stream-based retention |
| 15 | +[source,yaml] |
| 16 | +---- |
| 17 | +apiVersion: loki.grafana.com/v1 |
| 18 | +kind: LokiStack |
| 19 | +metadata: |
| 20 | + name: lokistack-sample |
| 21 | + namespace: openshift-logging |
| 22 | +spec: |
| 23 | + limits: |
| 24 | + global: <1> |
| 25 | + retention: <2> |
| 26 | + days: 20 |
| 27 | + streams: |
| 28 | + - days: 4 |
| 29 | + priority: 1 |
| 30 | + selector: '{kubernetes_namespace_name=~"test.+"}' <3> |
| 31 | + - days: 1 |
| 32 | + priority: 1 |
| 33 | + selector: '{log_type="infrastructure"}' |
| 34 | + managementState: Managed |
| 35 | + replicationFactor: 1 |
| 36 | + size: 1x.small |
| 37 | + storage: |
| 38 | + schemas: |
| 39 | + - effectiveDate: "2020-10-11" |
| 40 | + version: v11 |
| 41 | + secret: |
| 42 | + name: gcs-secret |
| 43 | + type: gcstest |
| 44 | + storageClassName: standard |
| 45 | + tenants: |
| 46 | + mode: openshift-logging |
| 47 | +---- |
| 48 | +<1> Sets retention policy for all log streams. *Note: This field does not impact the retention period for stored logs in object storage.* |
| 49 | +<2> Retention is enabled in the cluster when this block is added to the CR. |
| 50 | +<3> Contains the link:https://grafana.com/docs/loki/latest/logql/query_examples/#query-examples[LogQL query] used to define the log stream. |
| 51 | + |
| 52 | +.Example per-tenant stream-based retention |
| 53 | +[source,yaml] |
| 54 | +---- |
| 55 | +apiVersion: loki.grafana.com/v1 |
| 56 | +kind: LokiStack |
| 57 | +metadata: |
| 58 | + name: lokistack-sample |
| 59 | + namespace: openshift-logging |
| 60 | +spec: |
| 61 | + limits: |
| 62 | + global: |
| 63 | + retention: |
| 64 | + days: 20 |
| 65 | + tenants: <1> |
| 66 | + application: |
| 67 | + retention: |
| 68 | + days: 1 |
| 69 | + streams: |
| 70 | + - days: 4 |
| 71 | + selector: '{kubernetes_namespace_name=~"test.+"}' <2> |
| 72 | + infrastructure: |
| 73 | + retention: |
| 74 | + days: 5 |
| 75 | + streams: |
| 76 | + - days: 1 |
| 77 | + selector: '{kubernetes_namespace_name=~"openshift-cluster.+"}' |
| 78 | + managementState: Managed |
| 79 | + replicationFactor: 1 |
| 80 | + size: 1x.small |
| 81 | + storage: |
| 82 | + schemas: |
| 83 | + - effectiveDate: "2020-10-11" |
| 84 | + version: v11 |
| 85 | + secret: |
| 86 | + name: gcs-secret |
| 87 | + type: gcs |
| 88 | + storageClassName: standard |
| 89 | + tenants: |
| 90 | + mode: openshift-logging |
| 91 | +---- |
| 92 | +<1> Sets retention policy by tenant. Valid tenant types are `application`, `audit`, and `infrastructure`. |
| 93 | +<2> Contains the link:https://grafana.com/docs/loki/latest/logql/query_examples/#query-examples[LogQL query] used to define the log stream. |
| 94 | + |
| 95 | +. Then apply your configuration: |
| 96 | + |
| 97 | +include::snippets/logging-create-apply-cr-snip.adoc[lines=14..17] |
| 98 | + |
| 99 | +[NOTE] |
| 100 | +==== |
| 101 | +This is not for managing the retention for stored logs. Global retention periods for stored logs to a supported maximum of 30 days is configured with your object storage. |
| 102 | +==== |
0 commit comments