Replicating logs to Yandex Object Storage using Yandex Data Streams
With Yandex Data Streams, you can set up automatic replication of service and user application logs to Yandex Object Storage.
The solution works as follows:
- Your Cloud Logging log group receives logs, e.g., from a VM.
- The log group is set up to automatically forward logs to a specific data stream in Data Streams.
- A Data Transfer transfer is set up to fetch data from the stream and save it to an Object Storage bucket.
To set up log replication:
- Get your cloud ready.
- Set up your environment.
- Create a bucket.
- Create a data stream.
- Connect the stream to the log group.
- Create a transfer.
- Test sending and receiving data.
If you no longer want to store logs, delete the resources allocated to them.
Getting started
Sign up for Yandex Cloud and create a billing account:
- Navigate to the management console
and log in to Yandex Cloud or create a new account. - On the Yandex Cloud Billing
page, make sure you have a billing account linked and it has theACTIVEorTRIAL_ACTIVEstatus. If you do not have a billing account, create one and link a cloud to it.
If you have an active billing account, you can create or select a folder for your infrastructure on the cloud page
Learn more about clouds and folders here.
Required paid resources
-
Data Streams (see Data Streams pricing). The cost depends on the pricing model:
- Based on allocated resources: You pay a fixed hourly rate for the established throughput limit and message retention period, and additionally for the number of units of actually written data.
- On-demand: You pay for the performed read/write operations, the amount of read or written data, and the actual storage used for messages that are still within their retention period.
-
Managed Service for YDB database, operating in serverless mode: data operations, amount of stored data and backups (see Managed Service for YDB pricing).
-
Object Storage bucket: use of storage, data operations (see Object Storage pricing).
Set up your environment
- Create a service account, e.g.,
logs-sa, with theeditorrole for the folder. - Set up the transfer of logs to the log group. For example, you can transfer logs from a VM or add test records to the log group.
Create a bucket
- In the management console
, select the folder where you want to create a bucket. - Go to Object Storage.
- Click Create bucket.
- Enter a name for the bucket.
- In the Storage class field, select
Cold. - Click Create bucket.
Create a data stream
- In the management console
, select the folder where you want to create a data stream. - Go to Data Streams.
- Click Create stream.
- Specify an existing serverless database in YDB or create a new one. If you have created a new database, click to update the database list.
- Name the data stream, e.g.,
logs-stream. - Click Create.
Wait for the stream to start. Once the stream is ready for use, its status will change from Creating to Active.
Connect the stream to the log group
- In the management console
, select the folder with the log group. - Go to Cloud Logging.
- Next to the log group receiving the logs, click
and select Edit. - In the Data stream field, select
logs-streamyou created earlier. - Click Save.
Create a transfer
- In the management console
, select the folder where you want to create a transfer. - Go to Data Transfer.
- Create a source endpoint:
- In the
Endpoints tab, click Create endpoint. - In the Direction field, select
Source. - Enter the endpoint name, e.g.,
logs-source. - From the Database type list, select
Yandex Data Streams. - Select the database you specified in the settings of the stream you created earlier.
- Name the data stream:
logs-stream. - Select the
logs-saservice account you created earlier. - Under Advanced settings, specify the conversion rules for the
CloudLogging parserdata. - Click Create.
- In the
- Create a target endpoint:
- In the
Endpoints tab, click Create endpoint. - In the Direction field, select
Target. - Enter the endpoint name, e.g.,
logs-receiver. - From the Database type list, select
Object Storage. - Enter the name of the previously created bucket.
- Select the
logs-saservice account you created earlier. - In the Serialization format field, select
JSON. - Click Create.
- In the
- Create a transfer:
- In the
Transfers tab, click Create transfer. - Enter the transfer name, e.g.,
logs-transfer. - Select the
logs-sourcesource endpoint you created earlier. - Select the
logs-receivertarget endpoint you created earlier. - Click Create.
- In the
- Click
next to the new transfer and select Activate.
Wait until the transfer gets activated. Once the transfer is ready for use, its status will change from Creating to Replicating.
Test sending and receiving data
- In the management console
, navigate to the folder with the new data stream, transfer, and bucket. - Go to Data Streams.
- Select the data stream named
logs-stream. - Go to the Monitoring tab and check the stream activity charts.
- Go to Data Transfer.
- Select the
logs-transfertransfer. - Go to the Monitoring tab and check the transfer activity charts.
- Go to Object Storage.
- Select the previously created bucket.
- Make sure that you have objects in the bucket. Download and review the log files you got.
Delete the resources you created
To reduce the consumption of resources, delete those you do not need: