a. Use the load test tool to hit endpoints that are designed to be slow (without feature flag) and also have real users (with feature flag) experiencing slowness.
b. Or, we can have the load test tool mimic real users by setting the cookie that the feature flag uses.
Since we want to test real user monitoring, we need real user traffic (or at least traffic that is treated as real user traffic by the application). So we might combine:
- A load test that does not set the cookie (so it gets normal performance) to generate baseline traffic without degradation.
- And then we turn on the feature flag for 20% of real users (by setting a cookie in their browser via a script or by gradually rolling out the feature flag).
But note: we want to stress test the sampling and alerting, so we need a significant amount of degraded data points. If we only have 20% of real users degraded, and our real user traffic is low, we might not get enough data points in the 20-minute window.
Alternatively, we can run a load test that sets the cookie to get the degraded experience, and then we have two sets of load test traffic: 80% normal and 20% degraded. This way we control the percentage and we get enough data points.
However, note that the load test traffic will be from the same IPs and might be filtered by the RUM tool as non-human? Some RUM tools try to filter out bot traffic. So we must ensure that the load test traffic is not filtered.
So the best approach might be:
- Use a feature flag that is based on a cookie that we can set via JavaScript. Then we can have a script that runs on the page and sets the cookie for a percentage of users (via a random number). Then we can have the load test tool that does not set the cookie (so it gets normal performance) and then real users that come to the page will set the cookie randomly.
But then we rely on real user traffic. If we don't have enough real users, we won't get enough degraded data points.
Given the complexity, I think the most controlled way is to run the load test in a way that it is not filtered and that it can be split into two groups (with and without delay). Then we can set the percentage of delayed requests in the load test to 20%. And we must ensure that the RUM tool does not filter this traffic.
How to ensure RUM tool doesn't filter? We can check if the RUM tool uses a user agent string to filter bots. We can set the user agent of the load test to a common browser.
Example with k6:
import http from 'k6/http';
import { check, sleep } from 'k6';
export let options = {
stages: [
{ duration: '10m', target: 100 }, // baseline
{ duration: '20m', target: 100 }, // degradation
{ duration: '10m', target: 0 },
],
thresholds: {
// we can set thresholds for the load test itself, but not necessary for the drill
},
};
// We'll set a cookie for the feature flag if needed, or we can use a query param.
// Let's assume the server looks for a cookie named 'slow' with value 'true' to add delay.
// We'll set that cookie for 20% of the virtual users.
export default function() {
let url = 'https://your-website.com';
let cookies = {};
if (Math.random() < 0.2) {
cookies['slow'] = 'true';
}
let res = http.get(url, { cookies: cookies });
check(res, {
'status is 200': (r) => r.status === 200,
});
sleep(1);
}
But note: the server must be designed to read that cookie and add the delay. If not, we can use a query param as in the earlier example.
We will run a load test that:
- In the baseline phase: no delays.
- In the degradation phase: 20% of the requests have a 2s delay (via query param or cookie that the server respects).
- In the recovery phase: no delays.
We will monitor:
- RUM: LCP and INP percentiles (especially 75th) over time.
- Synthetic: The same metrics from synthetic tests (which should not be affected by the load test if they run from a different network and if the server doesn't add delay for synthetic tests? We must ensure synthetic tests are not setting the cookie or query param that triggers delay. So synthetic tests should get normal performance unless the server is degraded for everyone (which we don't want). We want to test that synthetic tests are independent and show the baseline even when real users are experiencing degradation.
But note: if the server is degraded for 20% of requests (by adding 2s delay) and the synthetic tests are not setting the cookie/query param, then they should see normal performance. This is good because it shows that synthetic tests are not affected by the real user load test.
However, if the server is under heavy load from the load test, it might affect the response times for synthetic tests too. So we must ensure that the load test does not saturate the server to the point that synthetic tests are also slowed down. That's why we must keep the load test at a reasonable level (e.g., 100 users might be fine for a large site, but adjust accordingly).
We can also run the load test from a separate environment (like a staging environment) and have synthetic tests run against production? But then the degradation in staging won't affect production synthetic tests. That might be acceptable because we are testing the monitoring of real user traffic in staging? But then we don't have real user traffic in staging.
So the best is to run the drill in production but with a very small load test (so that it doesn't affect real users) and with a feature flag that only affects the load test and a small percentage of real users (if any). But if we don't have real users, we rely on the load test to generate RUM data.
Given the constraints, I propose:
- Run the load test in production but with a very small number of users (e.g., 10-50) and with the delay feature enabled for 20% of them. This will generate a small amount of degraded RUM data.
- Also, we can have a script that runs on the page (for real users) that sets the cookie for 20% of real users (if we have real traffic). But if we don't have real traffic, then the load test is the only source.
However, if we run the load test with 50 users and 20% get delay, that's 10 users with delay. That might be enough to see a shift in the 75th percentile if we have enough total data points (from both load test and real users). But if we have very low traffic, we might not.
Alternatively, we can run the load test with a higher number of users (like 100) and hope that the RUM tool doesn't filter them. Then we get 20 users with delay and 80 without. That might be enough.
We must also consider that the RUM tool might sample only a percentage of users (e.g., 1% of all users). So if we have 100 load test users, we might only get 1 data point from them. That's not enough.
Therefore, we must ensure that the load test users are not sampled out. We can try to set a special cookie or user agent that the RUM tool uses to include all traffic? Some RUM tools allow you to set a cookie to force inclusion.
Alternatively, we can run the load test without the RUM sampling (if we control the RUM tool) by setting a configuration that includes all traffic from the load test IPs.
Given the complexity, it might be better to run the drill in a staging environment that has the same RUM setup and then generate artificial traffic with the load test and also have a way to generate RUM data from the load test (by not sampling it out). Then we can control the entire environment.
But if we must do it in production, we need to:
- Have a way to ensure the load test traffic is included in RUM (maybe by setting a special header or cookie that the RUM tool uses to not sample out).
- Have a way to generate enough data points (by having enough load test traffic).
Given the time, I think we should design the drill for a staging environment that mirrors production and has the same monitoring setup.
Steps for staging:
- Set up a staging environment that is a clone of production (same application, same monitoring setup, same synthetic tests pointing to staging? or we can use production synthetic tests but point them to staging?).
- Run the load test in staging with the same plan (baseline, degradation, recovery).
- Since staging might not have real users, we rely on the load test to generate all the RUM data. So we must make sure the load test is not sampled out by the RUM tool in staging.
How to avoid sampling? We can configure the RUM tool in staging to have a 100% sampling rate for the drill. Or we can set a cookie in the load test that forces 100% sampling.
Then we can see the effect of the degradation on the RUM data and the alerts.
For synthetic tests in staging: we can set up synthetic tests that run against the staging environment. They should not be affected by the load test (if the load test doesn't affect the server's baseline performance for non-delayed requests). But if the load test is heavy, it might slow down even the normal requests. So we must keep the load test at a level that does not affect the baseline.
Alternatively, we can run the load test from a separate network and ensure that the staging server can handle the load without degrading the baseline for non-delayed requests. We are adding 2s delay for 20% of requests, but the other 80% should be normal. So if the server can handle the load, then the 80% should be fine.
We must also consider that the server might be under-provisioned and the load test might cause general slowdown. So we must monitor the server metrics as well.
Given the above, I think the staging drill is more controllable.
Drill Plan for Staging:
Objective: Stress-test Web Vitals sampling, synthetic coverage, and LCP/INP alert fidelity.
Environment: Staging (mirrors production in terms of application, monitoring, and alerting setup).
Pre-requisites:
- RUM tool (e.g., Google Analytics with Web Vitals, or New Relic Browser) is set up and collecting data in staging.
- Alerting for LCP and INP is set up (e.g., 75th percentile LCP > 2.5s for 5 minutes) and sends to a test channel (e.g., a Slack channel for drills).
- Synthetic tests (using a tool like Lighthouse CI, WebPageTest, or a commercial service) are set up for key pages in staging and run every 5 minutes.
- The application in staging has a way to add artificial delay for a percentage of requests (via query param or cookie). We'll use a query param `?delay=2000` to add 2 seconds delay.
Load Test:
- Use k6 to simulate 50 users for 40 minutes (10 baseline, 20 degradation, 10 recovery).
- During degradation, 20% of the users will have the `?delay=2000` query param.
- The load test will hit a key page (e.g., the homepage) and maybe a few other pages.
Example k6 script:
import http from 'k6/http';
import { check, sleep } from 'k6';
export let options = {
stages: [
{ duration: '10m', target: 50 }, // ramp up to 50 users in 10 minutes (baseline)
{ duration: '20m', target: 50 }, // hold at 50 users (degradation)
{ duration: '10m', target: 0 }, // ramp down
],
};
export default function() {
let url = 'https://staging.your-website.com';
let addDelay = Math.random() < 0.2; // 20% chance
if (addDelay) {
url += '?delay=2000';
}
let res = http.get(url);
check(res, {
'status is 200': (r) => r.status === 200,
});
sleep(1);
}
Note: We must set the user agent to a common browser (e.g., Chrome) so that the RUM tool doesn't filter it as a bot.
Monitoring during drill:
- RUM dashboard (e.g., in Google Analytics) for the staging property. We'll look at LCP and INP over time, broken down by page and by network conditions (if possible). We are interested in the 75th percentile.
- Synthetic test results (from the synthetic monitoring tool) for the same pages. We should see that during the degradation phase, the synthetic tests (which do not add the delay) show normal values, while the RUM data shows a split (80% normal, 20% delayed). The 75th percentile in RUM should be somewhere in between (depending on the distribution).
- Alerting channel (e.g., Slack) for any LCP or INP alerts.
Expected Results:
Baseline:
- RUM 75th percentile LCP and INP are within normal range for staging.
- Synthetic tests show normal values.
- No alerts.
Degradation:
- RUM: The 75th percentile LCP and INP should increase because 20% of the data points are delayed by 2s. The exact increase depends on the distribution of the normal and delayed values. For LCP, if normal is 1s and delayed is 3s, then the 75th percentile might be around 1.4s (because 80% are 1s and 20% are 3s, so the 75th percentile is 1s because 80% are below 1s? Actually, we have to consider the distribution. If we have 80% at 1s and 20% at 3s, then the 75th percentile is 1s because 80% of the data is at or below 1s. So we might not cross the threshold of 2.5s. We need to adjust the delay or the percentage to cross the threshold.
Therefore, we might need to adjust the delay or the percentage to ensure that the 75th percentile crosses the threshold. Let's calculate:
If we have 80% at 1s and 20% at 3s, then the 75th percentile is 1s (because 75% of the data is below 1.2s? Actually, we have to order the data. The 75th percentile is the value below which 75% of the data falls. With 80% at 1s and 20% at 3s, the 75th percentile is 1s because 80% are at 1s (which is less than 3s) and 80% > 75%. So the 75th percentile is 1s.
To get the 75th percentile above 2.5s, we need at least 25% of the data to be above 2.5s? Not exactly. Let's say we have x% at 3s and (100-x)% at 1s. The 75th percentile will be 1s if x <= 25% (because 75% of the data is at 1s). If x > 25%, then the 75th percentile will be 3s because more than 25% are at 3s, so the 75th percentile falls in the 3s group.
So to have the 75th percentile at 3s, we need more than 25% of the data at 3s. Therefore, we need to adjust the percentage of delayed requests to be above 25% or increase the delay so that the normal values are also affected? But we want only 20% to be delayed. So with 20% delayed at 3s and 80% at 1s, the 75th percentile is 1s.
So we won't cross the threshold of 2.5s with these numbers.
We have two options:
Option 1: Increase the percentage of delayed requests to 30% (so that 30% are at 3s and 70% at 1s). Then the 75th percentile would be 3s because 70% < 75%? Wait, 70% are at 1s, so the 30% at 3s are above. The 75th percentile is the value at which 75% of the data is below. With 70% at 1s and 30% at 3s, the 75th percentile is 3s because to get 75% we need to include 5% from the 30% group, so the value is 3s.
Option 2: Increase the delay so that the delayed values are much higher, and even with 20% we might get the 75th percentile above 2.5s? Let's say normal is 1s and delayed is 10s. Then with 20% at 10s and 80% at 1s, the 75th percentile is still 1s because 80% are at 1s. So the percentage matters more.
Therefore, we need to have more than 25% of the data points above the threshold to have the 75th percentile above the threshold.
So we must adjust the drill to have at least 30% of the load test requests delayed (or have real user traffic that is delayed at a higher percentage) to trigger the alert.
Alternatively, we can set a lower threshold for the drill (e.g., 1.5s for LCP) so that we can trigger with a smaller percentage. But we want to test the actual production thresholds.
Given that, we might need to run the load test with a higher number of users and a higher percentage of delayed requests to cross the threshold.
Let's adjust:
- Use 100 users in the load test.
- During degradation, 30% of the requests have a 2s delay (so normal LCP might be 1s, delayed becomes 3s? Actually, the delay we add is server response delay, which might not directly equal LCP delay. LCP is when the largest element is rendered. Adding 2s to the server response might add 2s to LCP, but not exactly because the browser might start rendering before the server response? Actually, LCP is the time when the largest content element is rendered. If we delay the server response by 2s, then the browser cannot start rendering until it gets the response, so LCP will be delayed by about 2s.
So if normal LCP is 1s, then delayed LCP becomes 3s.
With 30% at 3s and 70% at 1s, the 75th percentile is 3s (because 70% are below 3s, but we need 75% below, so we have to go to the next value which is 3s). So 75th percentile is 3s, which is above 2.5s.
So we change the load test to 100 users and 30% delayed.
New k6 script:
import http from 'k6/http';
import { check, sleep } from 'k6';
export let options = {
stages: [
{ duration: '10m', target: 100 }, // ramp up to 100 users in 10 minutes (baseline)
{ duration: '20m', target: 100 }, // hold at 100 users (degradation)
{ duration: '10m', target: 0 }, // ramp down
],
};
export default function() {
let url = 'https://staging.your-website.com';
let addDelay = Math.random() < 0.3; // 30% chance
if (addDelay) {
url += '?delay=2000';
}
let res = http.get(url);
check(res, {
'status is 200': (r) => r.status === 200,
});
sleep(1);
}
But note: we must also consider that the RUM tool might not capture every request. So we need to ensure that the load test is generating enough data points that are captured by RUM.
We must also consider that the synthetic tests are running every 5 minutes. They should not be affected because they don't set the delay query param.
3. Alert Fidelity:
- We expect the alert to trigger during the degradation phase (once the 75th percentile LCP crosses 2.5s and stays for 5 minutes).
- We expect the alert to clear during the recovery phase (when the 75th percentile goes back below 2.5s).
4. Synthetic Coverage:
- We expect the synthetic tests to show normal values (because they don't have the delay) and to run successfully throughout.
5. Web Vitals Sampling:
- We expect the RUM data to reflect the 30% of delayed requests. We should see two clusters in the LCP distribution: one around 1s and one around 3s.
Let's adjust the drill plan accordingly.
Final Drill Plan for Staging:
- Pre-requisites as above.
- Load test: 100 users, 30% delayed by 2s, running for 40 minutes (10 baseline, 20 degradation, 10 recovery).
- RUM sampling set to 100% for the load test IPs (or 100% overall in staging).
- Monitor RUM, synthetic, and alerts.
If we don't have 30% delayed traffic, we might not trigger the alert. So we must adjust the percentage or the delay until we see the alert trigger.
We can also adjust the threshold for the drill (temporarily) to a lower value (e.g., 1.5s) to see the alert trigger with a smaller delay, but then we are not testing the actual threshold. So it's better to adjust the load test to cross the actual threshold.
Given the above, we have a plan.
Let's write the drill steps:
Step 1: Pre-drill setup (done by engineering)
- Ensure staging environment is ready and mirrors production.
- Set up RUM and synthetic monitoring for staging.
- Set up alerts for LCP and INP with production thresholds (e.g., 75th percentile LCP > 2500ms, INP > 200ms) but send to a test channel.
- Configure RUM to have 100% sampling for the load test IPs (or 100% overall in staging).
- Deploy the feature that adds delay based on query param (if not already present).
Step 2: Baseline (10 minutes)
- Start the load test without any delay (so all requests are normal).
- Verify:
a. RUM is collecting data and LCP/INP are within expected baseline for staging.
b. Synthetic tests are running and showing normal values.
c. No alerts are triggered.
Step 3: Degradation (20 minutes)
- Switch the load test to add 2s delay to 30% of the requests.
- Wait for at least 5 minutes (the alerting window) and check:
a. RUM: 75th percentile LCP and INP should increase and cross the thresholds.
b. Synthetic: Still normal (because they don't set the delay query param).
c. Alerts: Should trigger and be sent to the test channel.
Step 4: Recovery (10 minutes)
- Switch the load test back to no delay.
- Wait for 5 minutes and check:
a. RUM: 75th percentile LCP and INP return to baseline.
b. Synthetic: Still normal.
c. Alerts: Should clear (if we have recovery alerts) or stop firing.
Step 5: Post-drill analysis
- Check the RUM data distribution during degradation: we expect to see two clusters.
- Check synthetic test results during degradation: they should not show the delay (unless the server was generally slowed down by the load, which we don't want).
- Check alert logs: one alert triggered during degradation and cleared during recovery.
Step 6: Cleanup
- Reset any configuration changes (like RUM sampling rate) if needed.
Note: If the alert does not trigger, we might need to adjust the percentage or the delay. We can run the degradation phase again with a higher percentage (e.g., 40%) or higher delay (e.g., 3s) until we trigger the alert.
Also, we must ensure that the load test does not cause the server to be so overloaded that even the non-delayed requests become slow. We must monitor server metrics (CPU, memory, response times) to ensure that the baseline remains stable.
This drill will test:
- Sampling: We are generating a known percentage of delayed requests and we check if the RUM data reflects that.
- Synthetic coverage: We check that synthetic tests are running and not affected by the load test.
- Alert fidelity: We check that the alert triggers only when the threshold is crossed and clears when it's back to normal.
We can extend this drill to multiple pages and multiple types of delays (e.g., blocking resources for INP) but the above is a good start.
Let's write the drill in a way that it can be repeated and the results can be compared.
We'll create a runbook for this drill.
Runbook:
Title: Web Vitals Monitoring Drill
Objective:
To verify that our Web Vitals monitoring (RUM) correctly samples and reports LCP and INP under load, that synthetic monitoring provides independent coverage, and that alerts for LCP and INP fire with fidelity.
Environment: Staging (URL: https://staging.example.com)
Prerequisites:
- RUM tool (e.g., New Relic Browser) configured and collecting data for staging.
- Synthetic monitoring (e.g., Lighthouse CI) configured for key pages in staging and running every 5 minutes.
- Alerting for LCP and INP (75th percentile, 5-minute window) set up and routed to a test channel (e.g., #drill-alerts).
- Application in staging has a query parameter `delay` that, when set to a number (milliseconds), adds that much delay to the server response for the page.
- RUM sampling rate set to 100% for the load test IPs (or 100% overall in staging).
Tools:
- k6 for load testing (script provided below).
- Access to RUM dashboard for staging.
- Access to synthetic test results.
- Access to alert logs.
Procedure:
1. Baseline (10 minutes):
a. Start the k6 load test with the baseline script (no delay).
b. Monitor the RUM dashboard: LCP and INP 75th percentile should be stable and within normal range for staging.
c. Check that synthetic tests are passing and reporting normal values.
d. Verify no alerts in the test channel.
2. Degradation (20 minutes):
a. Stop the baseline load test.
b. Start the degradation load test (30% of requests with 2s delay).
c. Wait 5 minutes and then check:
- RUM: 75th percentile LCP and INP should have increased and crossed the thresholds (LCP > 2500ms, INP > 200ms). The exact values will depend on the baseline and the percentage. We expect the 75th percentile LCP to be around 3s (if baseline was 1s and 30% are at 3s) and INP similarly.
- Synthetic: Should still show baseline values (around 1s for LCP, and low INP) because they don't set the delay.
- Alert: Should have triggered in the test channel.
d. Continue for 15 more minutes and ensure the alert persists (if it's a "firing" alert) or that no recovery is seen.
3. Recovery (10 minutes):
a. Stop the degradation load test.
b. Start the recovery load test (no delay).
c. Wait 5 minutes and check:
- RUM: 75th percentile LCP and INP return to baseline.
- Synthetic: Still normal.
- Alert: Should clear (if we have recovery alerts) or stop firing.
4. Analysis:
a. From the RUM data, we should see during degradation:
- A bimodal distribution for LCP: one peak at the baseline (e.g., 1s) and one at the delayed value (e.g., 3s).
- The 75th percentile should be at the delayed value (if more than 25% are delayed) or in between.
b. Synthetic tests should not show the delayed values.
c. Alert should have fired only during degradation and cleared during recovery.
k6 scripts:
baseline.js:
import http from 'k6/http';
import { check, sleep } from 'k6';
export let options = {
stages: [
{ duration: '10m', target: 100 },
{ duration: '20m', target: 100 },
{ duration: '10m', target: 0 },
],
};
export default function() {
let url = 'https://staging.example.com';
let res = http.get(url, {
headers: { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36' }
});
check(res, {
'status is 200': (r) => r.status === 200,
});
sleep(1);
}
degradation.js:
import http from 'k6/http';
import { check, sleep } from 'k6';
export let options = {
stages: [
{ duration: '10m', target: 100 },
{ duration: '20m', target: 100 },
{ duration: '10m', target: 0 },
],
};
export default function() {
let url = 'https://staging.example.com';
let addDelay = Math.random() < 0.3; // 30% chance
if (addDelay) {
url += '?delay=2000';
}
let res = http.get(url, {
headers: { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36' }
});
check(res, {
'status is 200': (r) => r.status === 200,
});
sleep(1);
}
Note: The recovery phase uses the same script as baseline.
We run the baseline script for the first 10 minutes, then degradation for 20, then recovery for 10.
However, note that the k6 script above runs for 40 minutes total (10+20+10). We can run it as one script with stages, but we want to change the behavior between phases. So we can run three separate scripts or one script that changes behavior based on time? It's easier to run three separate scripts.
Alternatively, we can have one script that uses an environment variable to set the percentage of delayed requests. Then we can change the environment variable and restart k6? But we want a continuous run.
Since we are running for 40 minutes, we can have one script that changes the behavior after 10 minutes and then after 30 minutes. We can use the `__VU` and `__ITER` to determine the phase? Or we can use the `options` to set stages and then in the function check the current stage? k6 doesn't provide the current stage in the function.
Alternatively, we can run three separate k6 processes with the appropriate scripts.
Given the simplicity, we can run:
Phase 1 (baseline): k6 run baseline.js --duration 10m
Phase 2 (degradation): k6 run degradation.js --duration 20m
Phase 3 (recovery): k6 run baseline.js --duration 10m
But note: the stages in the script are set to 10m, 20m, 10m. So we can run the degradation script for 40 minutes and it will automatically go through the stages? But in the degradation script, we want 30% delay only in the second stage. We can modify the degradation script to:
import http from 'k6/http';
import { check, sleep } from 'k6';
export let options = {
stages: [
{ duration: '10m', target: 100 }, // baseline (0% delay)
{ duration: '20m', target: 100 }, // degradation (30% delay)
{ duration: '10m', target: 0 }, // ramp down (0% delay)
],
};
export default function() {
let url = 'https://staging.example.com';
let addDelay = false;
// We are in the second stage (from 10m to 30m) if we have more than 10 minutes of total runtime?
// But we don't have the total runtime in the function.
// Instead, we can use the `__VU` and `__ITER` to approximate? Not reliable.
// Alternatively, we can set an environment variable that changes after 10 minutes? But k6 doesn't support that.
// Given the complexity, it's easier to run three separate scripts.
So we run:
Phase 1: baseline.js for 10 minutes.
Phase 2: degradation.js for 20 minutes (with 30% delay throughout).
Phase 3: baseline.js for 10 minutes.
But note: in phase 2 we want 30% delay throughout, and in phase 1 and 3 we want 0%.
So we can have:
baseline.js: always 0% delay.
degradation.js: always 30% delay.
And run:
k6 run baseline.js --vus 100 --duration 10m
k6 run degradation.js --vus 100 --duration 20m
k6 run baseline.js --vus 100 --duration 10m
This is simple and clear.
However, we must ensure that the load test is continuous in terms of user sessions? Not necessarily because we are testing monitoring over time, and we are generating independent requests.
So we can do that.
Step 7: After the drill, we must reset the RUM sampling rate if we changed it.
This drill plan should cover the three aspects.
Let me know if there are any questions.</think>