Load testing Loki with k6 and xk6-loki

Grafana k6 with the xk6-loki extension lets you push and query logs against a self-hosted Loki cluster to test scalability, reliability and performance before go-live or after scaling changes. This page covers what the test does, how to set it up and what to measure.

On this page

Load testing Loki with k6 and xk6-loki: why test before go-live

xk6-loki is a Grafana k6 extension that pushes logs to and queries logs from Loki, so you can test a cluster's scalability, reliability and performance before users depend on it. Because the extension is not part of the standard k6 binary, you build a custom k6 binary with xk6 that includes it. If your Loki cluster is about to take production traffic, or has just changed size, a load test shows how it behaves under the write and read patterns you expect, rather than how it behaves on an empty cluster with a handful of test streams.

A load test answers a different question from a functional test. A functional check confirms that a push returns success and that a LogQL query returns the expected lines. A load test asks what happens when many senders push at once, when several people run wide queries at the same time, and when ingesters, queriers and the object store are all under pressure together. Failures often appear only at that scale: rejected pushes, slow queries, queues that grow until requests time out, or components that restart under memory pressure. Teams usually run a load test at three moments: before go-live, after scaling changes such as adding ingesters, queriers or read replicas, and after changes to limits or caches. Each of those moments can move the bottleneck, so a result from one is not proof for the next.

Before you write any k6 script, confirm what the test must represent: the expected daily volume and peak ingest rate, the label sets your senders will produce, the number of tenants if auth_enabled is set, the query mix your Grafana users will run, and the retention you plan to keep. Ask whoever owns the cluster which limits and cache settings are in force, because the test should run against the same configuration you will operate. Plan for the test to change your configuration, not just measure it, since a failing run usually means a limit, a cache or a sizing decision needs revisiting.

How the k6 test harness reaches the Loki cluster

The test starts in a k6 binary built with the xk6-loki extension, which sends push and query traffic to the Loki entry point through the authenticating reverse proxy. Inside the test environment, Loki's write and read paths use object storage, and the proxy is the trust boundary you should check first, since every request must carry the tenant header. Test metrics and Loki's own metrics go to separate dashboards so you can line results up before and after a change.

Load test traffic path through the proxy into Loki, with separate metric dashboards.

Which test type fits which question

This table compares the five test types a team typically runs against Loki with k6 and xk6-loki, along with the question each answers, the inputs the model needs and the main risk of skipping it. Read each row as a decision: pick the test that matches the change you are about to make, then build the traffic model from the inputs listed.

Test typeQuestion it answersWhat the test model needs from youMain risk if skipped
Push-only ingestionCan distributors and ingesters accept the expected log volume without rejections or lag?Target bytes per second, number of streams, label sets per stream, line sizes and tenant IDs with X-Scope-OrgID setIngestion limits or sender fan-out surface only after go-live, when logs are already being dropped
Query-only loadHow do query latency and throughput hold up for the dashboards and alerts people actually run?Real LogQL queries, time ranges, concurrency per user and the tenants each query targetsSlow dashboards and alert evaluations go unnoticed until an incident needs them
Mixed read and write trafficDo queries slow ingestion, or ingestion slow queries, when both run at the same time?Both push and query profiles at production ratios, plus the query mix and tenant splitSingle-path tests pass while contention between reads and writes causes production failures
Sustained soak runDoes the cluster stay stable over hours, with memory, disk and compaction behaving as expected?Steady traffic profile for a long window, retention settings, and monitoring of Loki's own metrics during the runSlow leaks, growing queues and compaction backlogs only appear after the cluster has been running for a while
Spike testHow does the cluster recover when traffic jumps well above normal for a short period?A burst profile above steady state, expected client retry behavior and per-tenant limits in forceRejections, queue build-up or cascading restarts during a real burst, with no tested recovery path
Post-change regressionDid a scaling, cache or limit change alter throughput or latency compared with the baseline?A stored baseline from an earlier run, the same scripts and data shape, and a clear change under testConfiguration changes are judged by feel, and a regression is found by users rather than by the test

How to set up xk6-loki and run the first test

This sequence takes a team from a confirmed Loki target in a test environment to a baseline run whose results can be checked against the cluster's own metrics. Each step ends with a check that tells the operator whether to continue.

  1. Confirm the Loki version and deployment mode

    Before writing any script, record the exact Loki version, the deployment mode (monolithic, simple scalable or microservices) and whether auth_enabled is set in the test environment. Confirm that this is a non-production cluster with the same storage backend, index store and limits as the target, because load results only mean something when the test matches the system that will run in production. Confirm the Loki version against the releases page and deployment mode against the deployment modes documentation. Check: you can write down the version, mode and tenancy setting in one note that the whole team agrees on, and the test environment is isolated from production writes.

  2. Build a custom k6 binary with xk6-loki

    The xk6-loki extension is not part of the standard k6 binary, so the team builds a custom k6 binary with xk6 that includes it. The engineer who owns the load test installs xk6 on a build machine, runs the build command that adds the xk6-loki extension, and keeps the resulting binary in a versioned location so that later runs use the same build. The official Loki k6 guide describes the extension and its purpose of pushing logs to and querying logs from Loki. Check: running the custom binary with a version flag prints a k6 version, and a minimal script that imports the Loki extension loads without an import error.

  3. Point the script at the write and read endpoints

    Configure the script with the Loki push endpoint and the query endpoint, and route both through the authenticating reverse proxy that fronts the cluster, since Loki has no built-in authentication layer. Keep the endpoint addresses and credentials in environment variables or a secrets store rather than in the script file itself, so the script can be shared without exposing access. Confirm the proxy path and the credential type with the team that operates the proxy. Check: a single test push and a single query made through the proxy both return success responses, and the Loki distributor or gateway logs show the request arriving.

  4. Set the tenant header for multi-tenant clusters

    If the test cluster runs with auth_enabled set to true, every request must carry the X-Scope-OrgID header that identifies the tenant. Add the header to both the push and query requests in the script, and use a tenant that is dedicated to testing so that load does not mix with production data or its limits. Confirm the tenant identifier with the cluster owner. Check: a query sent with the header returns only the test streams, and a request sent without the header is rejected or routed to the expected tenant, which confirms the header is being applied where you intended.

  5. Run a small baseline before the full run

    Start with a low, short load that uses the same script, the same tenant and the same labels as the full test, and run it from the machine or network location that will be used later. The purpose is to confirm that the script generates the intended streams and that the cluster accepts them without rejections. Keep the baseline small enough that it does not disturb other users of the test environment, and record the exact settings used so the full run can be compared against it. Check: the k6 summary shows the expected request count and a low error rate, and no unexpected rejection reasons appear in the cluster's logs.

  6. Compare results with the cluster's own metrics

    Run the full test only after the baseline is clean, then compare the k6 results with what the cluster reports about itself during the same window. Open the Loki dashboards or query the cluster metrics for ingestion rate, discarded samples, query latency, error counts and resource use on ingesters, queriers and the object store. Matching the load generator's view with the server's view shows whether slow responses come from Loki, the proxy or the test client. Check: each k6 result has a matching server-side measurement for the same time window, and any gap between the two is explained before the team changes settings or declares the cluster ready.

How to model representative push and query traffic

A load test is only as useful as its traffic model, so start by writing that model down before any script exists. Describe the stream label sets production uses (which labels senders attach, such as namespace, app, container or environment), roughly how many distinct combinations exist, the average and maximum line sizes, and how many lines each sender batches per push. Then describe the query side: the ratio of pushes to queries, the time ranges users typically request, the LogQL shapes they run most, and which tenants generate most of the reads and writes. Collect these numbers from your own environment, using Loki's own metrics for ingestion volume and your dashboards for query patterns, and treat any figure you cannot measure as an assumption to confirm with the owning team. You do not need production log content to do this. Synthetic lines of the right size and shape exercise the same code paths, provided the label structure is right.

Label choices in the test script decide the index and stream count, which is where most misleading results come from. Loki builds one stream per unique label set, so a script that uses a handful of static labels will look fast because it creates very few streams, while a script that puts a request ID or user ID into a label will create millions of streams and fail for reasons production never reaches. Keep the label keys, their value cardinality and the number of active streams close to what production shows, and put high-variance values in structured metadata where your Loki version and configuration support it. Ask the team that owns the cluster which labels are enforced and which limits apply per tenant, because a test that trips a limit tells you about the limit, not the cluster.

Match the senders as well as the volume. The test should push through the same agent you plan to run in production, whether that is Grafana Alloy, an OpenTelemetry Collector, Fluent Bit or another client, because each one batches, retries and compresses differently and sends different label sets by default. Replaying traffic directly through the HTTP push API skips that behavior and can overstate or understate what the cluster will see. Where the rollout includes more than one sender type, weight the mix to match the planned fleet, and confirm with each team how often they flush and how large their batches are. Record these settings in the test plan so that a later rerun after a scaling change compares like with like.

What to measure on the cluster and in k6

A load test only proves something if you can see what the cluster did while k6 was pushing and querying. The cards below pair each client-side result with the Loki signals that explain it, so a failed run points you to a cause rather than a single number.

Push success and rejections

Count accepted pushes on the k6 side and compare them with what Loki reports as accepted and discarded on the write path. A bad result is a growing gap between sent and stored entries, or rejections that climb as the test runs. Rejection reasons tell you whether the limit, the stream shape or the cluster caused the drop. Confirm the discarded-sample and ingestion metric names for your Loki version before the run.

Loki k6 docs

Query latency and failures

Record p50, p95 and p99 latency and error rates for each LogQL query class you simulate, such as a narrow label selector and a broad regex filter over a long range. A bad result is tail latency that grows with range size or errors that appear only under concurrent load. Separate these query classes in the k6 scenario so one slow pattern does not hide the rest.

Queueing and backpressure

Watch how long queries wait before a querier picks them up, and whether the query-frontend queue grows during the test. A bad result is a queue that keeps growing after load stops, which means queriers cannot drain the work they were given. Confirm the queue and scheduler metric names in your version, and note the concurrency settings in effect during the run so results can be compared later.

Object storage behavior

Measure request rates, latency and error responses from the object store during both writes and reads. A bad result is rising storage latency or throttling that lines up with ingest or query slowdowns, which points to the bucket or its network path rather than Loki compute. Ask your storage team for the provider-side metrics for the same window, since Loki's own counters may not show throttling clearly.

Loki storage docs

Resource saturation on components

Track CPU, memory, disk and network for distributors, ingesters, queriers and the query-frontend or scheduler, plus memory growth in ingesters. A bad result is one component pinned at its limit while others idle, or memory that does not return to baseline after the test ends. Compare each component against its own requests and limits, and confirm the metric names exposed by your deployment.

Client-side k6 request metrics

Use k6's built-in request duration, failure rate and iteration metrics, tagged per scenario, to confirm what the client experienced. A bad result is a k6 failure threshold crossed while cluster metrics look healthy, which usually means the load generator or network path is the bottleneck. Run k6 from a location with a network path representative of real senders, and check the generator's own CPU before trusting the numbers.

How the test changes before go-live and after scaling

Before a new cluster takes production traffic, the test goal is to confirm that the cluster meets the ingestion and query targets your organization wrote down, under a load shape that resembles expected peaks rather than an idealized average. The baseline is the stated requirement itself: daily volume, peak push rate, number of concurrent dashboard and alert queries, and the acceptable query latency. Repeat a sustained push test, a peak burst, and a set of representative queries of different time ranges, run for long enough to fill caches and trigger compaction. The decision is whether to accept the cluster, add capacity before launch, or narrow the first set of senders.

  • Sustained push at expected volume: hold the production-shaped rate long enough to observe steady-state ingester memory and flush behavior.
  • Peak burst: push above the expected peak to find where rejections begin and confirm that senders receive clear errors.
  • Representative queries: replay the dashboards and alert rules planned for launch, with the time ranges people actually use.
  • Long soak: run the mixed workload for an extended period to catch slow growth in memory, disk or compaction backlog.

Check that the results match the written targets and that no rejection or error rate appears at expected load.

Security and operational risks of load testing Loki

A load test sends large volumes of data and queries into a system that holds real logs and real credentials. The four risks below share one root cause: the test runs with the same access and reach as production, so each control has to be decided before the first run.

Keeping tests off production tenants

Load test pushes write synthetic streams under tenant IDs that customers, teams or environments already use, which pollutes dashboards, alerts and per-tenant limits. Use a dedicated test tenant and confirm that nothing in your ruler, alerting or dashboards reads from it. Confirm who is allowed to start a run and whether a production tenant ID can ever appear in the test configuration. Set a separate tenant for every run so results never mix with live data.

Loki multi-tenancy docs

Protecting k6 credentials and tokens

Test scripts often carry bearer tokens, basic auth passwords or X-Scope-OrgID values, and a k6 run can write them into logs, CI output or result files. Store them in your secrets manager, inject them at run time and scope them to the test tenant only. Confirm where k6 output, summaries and cloud or dashboard exports are stored, who can read them and how long they are kept.

Testing through the production proxy path

Loki has no built-in authentication layer, so access control depends entirely on the authenticating reverse proxy in front of it, such as nginx, HAProxy, OAuth2 Proxy or Pomerium. A test that connects straight to the distributor or query-frontend skips that layer and can show performance numbers that production will never see, or hide a proxy bottleneck. Confirm that the test enters through the same proxy design, timeouts and rate limits used in production, and that the proxy logs capture test traffic.

Loki authentication docs

Cleaning up test data from storage

Load tests can write gigabytes of chunks and index entries into object storage, and retention is disabled by default, so that data stays until someone removes it. Before the run, decide whether the test tenant gets its own retention rule, and confirm that the compactor and retention settings apply to it. Confirm who signs off on deletion, how the test tenant's objects are identified in the bucket, and that cleanup is recorded so storage costs and audit trails stay accurate.

Questions buyers ask before a Loki load test

What drives the cost and effort of a Loki load test?

The cost is driven by how many components and workload shapes must be tested, not by the k6 tool itself. The main drivers are the deployment mode in use, whether the test covers push load, query load or both, how many tenants and label shapes must be simulated, and how many test runs are needed to explain what breaks. A single-server or monolithic cluster is simpler to exercise than a simple scalable or microservices deployment with separate read, write and backend targets. Each additional scenario, such as long-range queries during peak ingestion, adds scripting and analysis work. Ask any provider for a quote that lists the scenarios, the environment used, the metrics collected and the written deliverable, so the scope can be compared with your own estimate.

How long does a Loki load test cycle take, and what sets that duration?

The duration depends on the number of scenarios, how long each run must hold steady to show a real trend, and how many cycles are needed to tune limits and retest. Preparation includes building a custom k6 binary with xk6 and the xk6-loki extension, writing scripts that match your log shapes, and agreeing the pass criteria. Each run then needs a warm-up period, a sustained load phase and time to read the results. Scaling changes, such as adding queriers or changing caches, usually mean another cycle. Ask for a written timeline with the number of runs, the environment, and the point at which results are reviewed with your team.

What does the work need from our team before it starts?

The work needs four inputs: access to a cluster that matches production closely enough to be meaningful, a dedicated test environment that will not affect live tenants, read access to Loki and Grafana metrics during each run, and realistic sample log shapes. Sample shapes include label sets, line lengths, the volume per stream, and the queries your people actually run in Grafana. Without representative samples, the results describe a workload you do not have. Confirm with your platform team who can grant cluster and metrics access, how test traffic reaches the cluster, and whether network paths and load balancers match production.

Can our internal team run a Loki load test without a partner?

An internal team can run a test if it has people who know Loki's write path, read path and storage well enough to interpret what the metrics show. The team also needs working knowledge of Go for building k6 with xk6, JavaScript for k6 scripts, and enough Kubernetes or server administration to run the environment. The hardest part is not generating load but deciding which component is the bottleneck, which usually requires reading ingestion and query metrics together. If those skills are spread across several people, a fixed-scope engagement can cover the test design and analysis while your team keeps ownership of the environment and the findings.

Do results from a test environment carry over to production?

They carry over only as far as the test environment matches production in topology, resource sizing, object storage, network path and configuration. Results from a smaller cluster or a different object store can show trends, such as where queries slow as concurrency rises, but they cannot predict exact production limits. Differences in tenant count, retention settings, cache configuration and limits all change the outcome. Document every difference between the two environments in the test report, and treat any production limit as provisional until a run on a comparable setup, or a controlled production check, confirms it.

How often should we retest Loki under load?

Retest before go-live and after any change that alters how load is distributed or how much capacity exists. Common triggers include a new deployment mode or major version, changes to caches, query scheduling, autoscaling or rollout strategy, a significant rise in ingestion volume or tenant count, and new limit values. Teams that run Loki at scale often also repeat a smaller set of runs on a fixed schedule so that gradual drift is caught early. Agree the trigger list and the minimum scenario set with your team in writing, so a retest is a routine step rather than an emergency response.

Limits to confirm before you trust the results

A load test only tells you what the environment it ran in can show. The four or five items below are the assumptions that most often make results look better or worse than production will be. Confirm each one in writing before you size capacity or sign off a go-live based on the numbers.

Extension and Loki release match

The xk6-loki extension has to work with the Loki release you actually run, not the one you last read about. The supplied releases page lists v3.7.8 as the latest release, so check the extension's compatibility notes against the exact version in your cluster, including any patch level you have pinned. If your production cluster runs an older release, test against that release. Results from a newer build do not transfer to an older query path or write path.

Loki releases

Test environment mirrors production

Confirm that the test cluster uses the same deployment mode as production: monolithic, simple scalable or microservices. Loki's documentation notes that simple scalable mode is being deprecated and will be removed with Loki 4.0, so a test on a mode you plan to leave will not predict your future load. Also match replica counts, resource limits, and the number of distributors, ingesters, and queriers. A smaller test cluster can show headroom that disappears at full scale.

Deployment modes docs

Object store choice affects results

Loki's documentation does not typically recommend S3-compatible stores such as MinIO, or the local filesystem, for production. If your test runs on one of these, read latency and throughput numbers as a floor for the test setup, not a forecast for a managed store such as Amazon S3, Google Cloud Storage or Azure Blob Storage. Compare request latency, error rates, and retry behavior on the store you will run in production before you rely on query timings.

Loki storage docs

Go toolchain for the xk6 build

The xk6-loki extension is built into a custom k6 binary with xk6, so the build machine needs a Go toolchain version that xk6 and the k6 release you choose both support. Confirm the required Go version in the extension and xk6 documentation, then pin it in your build image. Record the k6 and extension versions alongside the results. A binary built on a different toolchain can behave differently, and you cannot reproduce a run you cannot rebuild.

Traffic model matches your volumes

A load test is only as realistic as its traffic model. Confirm the push rate, stream count, label set, line size, and query mix against your own log volumes, not a generic profile. Illustrative example: a test that pushes many small streams will stress the ingesters differently than one that pushes a few large streams. Ask which teams, dashboards, and alert rules will generate queries, and at what time of day. Rerun the model after any major change in sources or retention.

How DeployOpen scopes and delivers Loki load tests

DeployOpen plans and runs k6 and xk6-loki load tests against a Loki cluster in your own infrastructure, starting from the push and query profile your logs really produce. Engagements are fixed-scope, so the test targets, environment, deliverables and timeline are agreed in writing before any load is generated.

How we scope

  • Agree the Loki deployment mode, cluster topology and the environment the test will run against
  • Document expected push rates, query patterns, tenants and retention settings before writing any scenario
  • Define pass criteria for ingestion, query latency and storage behavior, and record them in the written scope

How we build

  • Build a custom k6 binary with xk6 that includes the xk6-loki extension for your test scenarios
  • Write push and query scripts that match agreed label sets, stream counts and query mixes
  • Run dry runs in a non-production environment to validate the generator before any production-like load

How we hand over

  • Deliver the k6 scripts, custom binary build steps and configuration in a Git repository you control
  • Provide a test report with measured results against the agreed pass criteria and the conditions used
  • Document how to rerun the tests after scaling changes, configuration updates or Loki version upgrades

How we support

  • Offer ongoing support, upgrades and continuous testing as a retainer if you want regular re-testing
  • Retest after fixes or configuration changes so the report reflects the cluster you actually run
  • Quote follow-up work from a written scope so changes to test targets stay visible and agreed

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.