> For the complete documentation index, see [llms.txt](https://docs.cennso.com/components/cdf/latest/llms.txt) (all documentation: [llms.txt](https://docs.cennso.com/llms.txt)). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cennso.com/components/cdf/latest/operation-guides/archive.md).

# Archive CDRs

Charging Data Function (CDF) allows you to store copies of Charging Data Records (CDRs) in an archive service after they are sent to a CGF. Archiving CDRs may be useful for troubleshooting, for example, to check the contents of CDRs when investigating issues.

To enable the archive feature, configure the CDF Sender component using either the `CDFSender` Custom Resource or Helm chart values:

## Archive CDRs (Custom Resource)

```yaml
apiVersion: cdf.cennso.com/v1alpha1
kind: CDFSender
metadata:
  name: cdf-sender
  namespace: default
spec:
  connectionSecretRef:
    name: core-cluster
    namespace: cennso-infra
  targetNamespace: cdf
  config:
    cdmServices:
      archive:
        url: nats://nats.example.com:4222            # CDM server URL
        subject: CDR.archived                        # Subject where archived CDRs are published
        errorSubject: CDR.error                      # Subject for CDR archiving errors
        poolSize: 5                                  # Number of connections to CDM (optional)
        requestTimeout: 3000                         # Wait time for archive response in milliseconds (optional)
        encoding: JSON                               # Encoding format: JSON or ErlangTerm (optional)
        compression: zlib                            # Compression: zlib or none (optional)
        credentialsSecretName: nats-creds-secret     # Kubernetes secret with CDM credentials (optional)
```

## Archive CDRs (Helm chart)

```yaml
sender:
  enabled: true                                      # Enable CDF Sender component
  CGFs:
  - IP: 192.0.2.1                                    # CGF IP address

nats_services:
  work_queue:
    url: nats://queue.example.com                    # CDM server URL for work queue
    subject: CDR.arrived                             # Subject for incoming CDRs
    streamName: CDR                                  # CDM stream name
    consumerName: CDF                                # Consumer name for CDR processing
    poolSize: 8                                      # Number of connections to work queue
  kv_store:
    url: nats://kv.example.com                       # CDM server URL for key-value store
    bucket: CDFbucket                                # Key-value bucket name
    poolSize: 8                                      # Number of connections to key-value store
  archive:
    url: nats://archive.example.com                  # CDM server URL for archive
    subject: CDR.archived                            # Subject where archived CDRs are published
    error_subject: CDR.error                         # Subject for CDR archiving errors
    poolSize: 8                                      # Number of connections to archive
    compression: zlib                                # Compression: zlib or none (optional)
    encoding: JSON                                   # Encoding format: JSON or ErlangTerm (optional)

resources:
  cdf:
    limits:
      cpu: 5000m                                     # Maximum CPU usage
      memory: 1Gi                                    # Maximum memory usage
```

At minimum, you need to specify the following required parameters:

- **url** - the Cennso Data Mesh (CDM) server address where archived CDRs are stored
- **subject** - the CDM subject where CDF publishes archived CDRs
- **errorSubject** - the CDM subject where CDF publishes errors that occur during archiving. This allows you to monitor archiving failures separately.

Optionally, you can also specify the following parameters:

- **encoding** - format for storing CDRs. The possible options are `JSON` (human-readable, larger files) or `ErlangTerm` (compact binary format).
- **compression** - compress archived CDRs to save storage space. Choose `zlib` (compress CDRs) or `none` (no compression). Compression reduces storage costs but uses more CPU when writing and reading CDRs.
- **poolSize** - number of concurrent connections to CDM for archiving. More connections can increase archiving throughput if you have high CDR volumes. For more information, read the [Pool size configuration](https://docs.cennso.com/components/cdf/latest/concepts/cdf-sender.md#pool-size-configuration) section.
- **requestTimeout** - specifies how long (in milliseconds) to wait for CDM to confirm archiving before timing out. Increase this value if you see timeout errors during high load.
- **credentialsSecretName** - name of the Kubernetes secret containing CDM authentication credentials. Required if your CDM server requires authentication.

## Managing archived CDRs

After CDF publishes archived CDRs to the CDM subject, you need to configure CDM stream settings to manage storage space and retention. Configure the CDM stream that corresponds to the subject you specified in the CDF configuration.

CDM stream settings control:

- Storage space limits - how much disk space archived CDRs can use
- Retention periods - how long CDRs are kept before automatic deletion
- Time to Live (TTL) - when individual CDRs expire

For instructions on configuring CDM streams, see the [Cennso Data Mesh](https://docs.cennso.com/cennso/cdm/main.md).
