Size chunks and index difference in s3

Hello Loki Team,

I have a setup for Promtail, Loki, and Grafana. I have 2 VMs and 1 Dell S3 ECS bucket with a size of 300GB.

VM 1:
VM 2:

I’m currently using Loki version 2.8.2 and Standalone mode on two VM. Below is my Loki config:

auth_enabled: false
  http_listen_port: 3100
  grpc_listen_port: 9096
  grpc_server_max_concurrent_streams: 1000
  grpc_server_max_recv_msg_size: 104857600
  grpc_server_max_send_msg_size: 104857600
  http_server_idle_timeout: 120s
  http_server_write_timeout: 1m 
  path_prefix: /etc/loki/
  replication_factor: 1
      store: memberlist
      insecure: false
      bucketnames: bucket
      access_key_id: clickhouse_test_user
      secret_access_key: secret-key
  abort_if_cluster_join_fails: false
  bind_port: 7946
    - from: "2023-01-03"
        prefix: chunk_
        period: 24h
        period: 24h
        prefix: index_
      object_store: s3
      schema: v11
      store: boltdb-shipper
    - from: "2023-06-24"
      store: tsdb
      object_store: s3
      schema: v12
        prefix: index_
        period: 24h
        prefix: chunk_
        period: 24h
    active_index_directory: /etc/loki/index
    build_per_tenant_index: true
    cache_location: /etc/loki/index_cache
    shared_store: s3
    active_index_directory: /etc/loki/tsdb-index
    cache_location: /etc/loki/tsdb-cache
    shared_store: s3
    insecure: false
    bucketnames: bucket
    access_key_id: clickhouse_test_user
    secret_access_key: secret-key
    s3forcepathstyle: true
    max_send_msg_size: 104857600
  parallelism: 9
  match_max_concurrent: true
  working_directory: /etc/loki/
  shared_store: s3
  compaction_interval: 5m
      bucketnames: bucket
  enforce_metric_name: false
  reject_old_samples: true
  reject_old_samples_max_age: 48h
  max_global_streams_per_user: 100000
  max_entries_limit_per_query: 50000
  ingestion_rate_mb: 8190000000
  ingestion_rate_strategy: global
  ingestion_burst_size_mb: 81900000000
  max_line_size: 50000000
  per_stream_rate_limit: 100000000000
  per_stream_rate_limit_burst: 1000000000 
  query_timeout: 10m
  split_queries_by_interval: 30m
  max_cache_freshness_per_query: '10m'
  align_queries_with_step: true
  max_retries: 5
  cache_results: true
      enable_fifocache: true
        size: 10024
        validity: 24h
  log_queries_longer_than: 3s
  max_body_size: 10485760
  query_stats_enabled: false
  max_outstanding_per_tenant: 1024
  querier_forget_delay: 0s
  scheduler_address: ""
  scheduler_dns_lookup_period: 10s
  scheduler_worker_concurrency: 5
  compress_responses: true
      store: memberlist
        store: memberlist
      replication_factor: 1
  chunk_idle_period: 30m
  chunk_block_size: 262144
  chunk_target_size: 1572864
  chunk_retain_period: 0s
  max_transfer_retries: 0
  chunk_encoding: gzip
  max_chunk_age: 3h
  max_look_back_period: 0s
        timeout: 5m
    max_concurrent: 16
    max_recv_msg_size: 67108864
  remote_timeout: 1s
  max_outstanding_requests_per_tenant: 32768

I have a problem that I’m trying to understand. I have a file with 5 GB size with 55,521,300 logs lines. These logs were generated using Flog and Promtail is reading the file and sending it to Loki. However, when I set the chunk encoding to either none, snappy or gzip, I end up with the same total size (2GB) in my S3 bucket. This happens regardless of the compression settings I use.

I’m trying to understand why this is the case. Any help would be greatly appreciated.

is this correct ?
The behavior you’re experiencing could be due to several factors.

Firstly, when Loki receives log data, it processes the data and splits it into chunks. These chunks are not direct representations of the input log data. They are processed and formatted in a specific way that makes them efficient for Loki to query. This process involves deduplication, indexing, and other operations. Therefore, the size of the chunk data in S3 may not have a direct relationship with the size of the input log data.

Secondly, the chunk encoding setting (none, snappy, or gzip) in Loki controls the encoding of the chunks that Loki creates. The chunk encoding is not meant to significantly reduce the size of the data, but rather it’s used for efficient querying and to reduce the cost of storing and transferring data. While the gzip encoding typically provides a higher compression ratio than snappy, the difference may not be significant for certain types of data, and the compression ratio can also depend on the specifics of the data being compressed.

Thirdly, the total size of the data in the S3 bucket includes not only the chunk data but also the index data. Loki uses an index to quickly locate the chunks that match a given query. The size of the index data can also contribute to the total size of the data in S3.

Therefore, the total size of the data in S3 depends on many factors and is not solely determined by the chunk encoding setting. It’s also worth noting that Loki’s primary design goal is not to minimize storage costs, but to provide fast, efficient querying of log data.

In order to understand more about this behavior, you might want to consider the following:

  1. Check the logs for Loki and Promtail for any errors or warnings. There might be issues with the processing or uploading of chunks that could give you some clues.
  2. Monitor the metrics exposed by Loki and Promtail. These can give you insights into the rate of chunk creation, the rate of chunk uploads to S3, and other aspects of the system’s behavior.
  3. Experiment with different types of log data. The size of the chunk data in S3 can depend on the specifics of the log data. For example, log data with a lot of repeated content might compress more effectively than log data with a lot of unique content.
  4. Experiment with different configurations of Loki. The behavior of Loki can be influenced by many different configuration settings. You might want to experiment with different settings to see if you can find a configuration that gives you the results you’re looking for.
  5. Consider reaching out to the Loki community or the Grafana Labs support team for help. They might be able to provide more specific advice based on their experience with similar setups.

Lastly, it’s worth noting that the metrics and logging data typically have a very different lifecycle and access pattern compared to other types of data. It’s often accessed frequently shortly after it’s generated but then rarely accessed again after a certain period of time. This makes it a good candidate for lifecycle policies in S3, where the data is moved to cheaper storage classes after a certain period of time, which can help to reduce storage costs.