Replicating logs to Object Storage using 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 described below:
- Logs, for example, from a VM instance, are sent to a Cloud Logging log group.
- The log group settings specify the Data Streams stream where the logs are transmitted automatically.
- 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:
- Prepare your cloud.
- Configure the 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:
- Go to the management console
and log in to Yandex Cloud or create an account if you do not have one yet. - On the Yandex Cloud Billing
page, make sure you have a billing account linked and it has theACTIVE
orTRIAL_ACTIVE
status. If you do not have a billing account, create one.
If you have an active billing account, you can go to the cloud page
Learn more about clouds and folders.
Required paid resources
The cost of data storage support includes:
- Data stream maintenance fees (see Yandex Data Streams pricing).
- Fees for transmitting data between sources and targets (see Yandex Data Transfer pricing).
- Data storage fees (see Yandex Object Storage pricing).
Configure the environment
- Create a service account, e.g.,
logs-sa
, with theeditor
role assigned for the folder. - Set up the transfer of logs to the log group. For example, you can transfer logs from a VM instance 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. - Select Object Storage.
- Click Create bucket.
- Enter the name of the bucket.
- In the Storage class field, select
Cold
. - Click Create bucket.
Create a data stream
- In the management console
, select the folder to create a data stream in. - Select Data Streams.
- Click Create stream.
- Specify an existing serverless YDB database or create a new one. If you have created a new database, click to update the database list.
- Enter the data stream name:
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 Cloud Logging. - Next to the log group where the logs are sent, click
and select Edit. - In the Data stream field, select the
logs-stream
created before. - Click Save.
Create a transfer
- In the management console
, select the folder where you want to create a transfer. - Select Data Transfer.
- Create a source endpoint:
- In the
Endpoints tab, click Create endpoint. - In the Direction field, select
Source
. - Enter the endpoint name, for example,
logs-source
. - In the Database type list, select
Yandex Data Streams
. - Select the database you specified in the settings of the stream you created earlier.
- Enter the stream name:
logs-stream
. - Select the
logs-sa
service account you created earlier. - Under Advanced settings, specify the conversion rules for the
CloudLogging parser
data. - 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, for example,
logs-receiver
. - In the Database type list, select
Object Storage
. - Enter the name of the previously created bucket.
- Select the previously created
logs-sa
service account. - 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 previously created source endpoint,
logs-source
. - Select the previously created target endpoint,
logs-receiver
. - Click Create.
- In the
- Click
next to the created transfer and select Activate.
Wait until the transfer is 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. - Select Data Streams.
- Select the
logs-stream
data stream. - Go to the Monitoring tab and check the stream activity charts.
- Select Data Transfer.
- Select
logs-transfer
. - Go to the Monitoring tab and check the transfer activity charts.
- Select Object Storage.
- Select the previously created bucket.
- Make sure that you have objects in the bucket. Download and review the log files you got.
How to delete the resources you created
To stop paying for the resources you created: