Skip to content

Commit

Permalink
feat: Add new throttle corruption
Browse files Browse the repository at this point in the history
  • Loading branch information
VolcanoCookies authored and birme committed May 29, 2023
1 parent 3937608 commit 76836e1
Show file tree
Hide file tree
Showing 13 changed files with 484 additions and 8 deletions.
27 changes: 23 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ To try it out, go to your favourite HLS/MPEG-DASH video player such as `https://
| `/api/v2/manifests/dash/proxy-master.mpd` | GET | Returns a proxy MPD file, based on query parameters |
| `/api/v2/manifests/dash/proxy-segment` | GET | Applies corruption present in query parameter and may return a 302 redirect to the original segment file |
| `/api/v2/segments/proxy-segment` | GET | Applies corruption present in query parameter and may return a 302 redirect to the original segment file |
| `/api/v2/throttle` | GET | Proxies a http request, throttling the response to a specified byte rate |
| `/` | GET | Server health check |

### Query Parameters
Expand All @@ -64,6 +65,7 @@ To try it out, go to your favourite HLS/MPEG-DASH video player such as `https://
| `delay` | Delay the response, in milliseconds, for a specific segment request |
| `statusCode` | Replace the response for a specific segment request with a specified status code response |
| `timeout` | Force a timeout for the response of a specific segment request |
| `throttle` | Send back the segment at a specified speed of bytes per second |

### Load Manifest url params from AWS SSM parameter store instead
- Create a .env file at the root the of project
Expand All @@ -78,7 +80,7 @@ LOAD_PARAMS_FROM_AWS_SSM=true

## Corruptions

Currently, the Chaos Stream Proxy supports 3 types of corruptions for HLS and MPEG-DASH streams. These corruptions may be used in combination with one another.
Currently, the Chaos Stream Proxy supports 4 types of corruptions for HLS and MPEG-DASH streams. These corruptions may be used in combination with one another.

### Specifying Corruption Configurations

Expand All @@ -100,7 +102,7 @@ Delay Corruption:
{
i?: number | "*", // index of target segment in playlist. If "*", then target all segments. (Starts on 0 for HLS / 1 for MPEG-DASH)
sq?: number | "*", // media sequence number of target segment in playlist. If "*", then target all segments
rsq?: number, // relative sequence number from where a livestream is currently at
rsq?: number, // relative sequence number from where a livestream is currently at
ms?: number, // time to delay in milliseconds
br?: number | "*", // apply only to specific bitrate
}
Expand All @@ -112,7 +114,7 @@ Status Code Corruption:
{
i?: number | "*", // index of target segment in playlist. If "*", then target all segments. (Starts on 0 for HLS / 1 for MPEG-DASH)
sq?: number | "*", // media sequence number of target segment in playlist. If "*", then target all segments
rsq?: number, // relative sequence number from where a livestream is currently at
rsq?: number, // relative sequence number from where a livestream is currently at
code?: number, // code to return in http response status header instead of media file
br?: number | "*", // apply only to specific bitrate
}
Expand All @@ -124,11 +126,23 @@ Timeout Corruption:
{
i?: number | "*", // index of target segment in playlist. If "*", then target all segments. (Starts on 0 for HLS / 1 for MPEG-DASH)
sq?: number | "*", // media sequence number of target segment in playlist. If "*", then target all segments
rsq?: number, // relative sequence number from where a livestream is currently at
rsq?: number, // relative sequence number from where a livestream is currently at
br?: number | "*", // apply only to specific bitrate
}
```

Throttle Corruption:
```typescript
{
i?: number | "*", // index of target segment in playlist. If "*", then target all segments. (Starts on 0 for HLS / 1 for MPEG-DASH)
sq?: number | "*", // media sequence number of target segment in playlist. If "*", then target all segments
rsq?: number, // relative sequence number from where a livestream is currently at
br?: number | "*", // apply only to specific bitrate
rate?: number // rate in bytes per second to limit the segment download speed to
}
```


One can either target a segment through the index parameter, `i`, or the sequence number parameter, `sq`, relative sequence numbers, `rsq`, are translated to sequence numbers, . In the case where one has entered both, the **index parameter** will take precedence.

Relative sequence numbers, `rsq`, are translated to sequence numbers, `sq`, and will thus override any provided `sq`.
Expand Down Expand Up @@ -212,6 +226,11 @@ https://chaos-proxy.prod.eyevinn.technology/api/v2/manifests/dash/proxy-master.m
https://chaos-proxy.prod.eyevinn.technology/api/v2/manifests/dash/proxy-master.mpd?url=https://livesim.dashif.org/livesim/testpic_2s/Manifest.mpd&statusCode=[{sq:841164350, code:404}]
```

6. LIVE: Example of MPEG-DASH with a segment download speed limited to 10kB/s on all segments
```
https://chaos-proxy.prod.eyevinn.technology/api/v2/manifests/dash/proxy-master.mpd?url=https://f53accc45b7aded64ed8085068f31881.egress.mediapackage-vod.eu-north-1.amazonaws.com/out/v1/1c63bf88e2664639a6c293b4d055e6bb/64651f16da554640930b7ce2cd9f758b/66d211307b7d43d3bd515a3bfb654e1c/manifest.mpd&throttle=[{i:*,rate:10000}]
```

## Development Environment

To deploy and update development environment create and push a tag with the suffix `-dev`, for example `my-feat-test-dev`. If you run `npm run deploy:dev` it will automatically create a tag based on git revision with the `-dev` suffix and push it.
Expand Down
66 changes: 66 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"nock": "^13.2.4",
"node-cache": "^5.1.2",
"node-fetch": "^2.5.7",
"stream-throttle": "^0.1.3",
"xml2js": "^0.4.19"
},
"devDependencies": {
Expand All @@ -41,6 +42,7 @@
"@types/jest": "^27.4.0",
"@types/node": "^17.0.18",
"@types/node-fetch": "^2.5.7",
"@types/stream-throttle": "^0.1.1",
"@types/xml2js": "^0.4.11",
"@typescript-eslint/eslint-plugin": "^5.13.0",
"@typescript-eslint/parser": "^5.13.0",
Expand Down
7 changes: 6 additions & 1 deletion src/manifests/handlers/dash/segment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import delaySCC from '../../utils/corruptions/delay';
import statusCodeSCC from '../../utils/corruptions/statusCode';
import timeoutSCC from '../../utils/corruptions/timeout';
import throttleSCC from '../../utils/corruptions/throttle';
import path from 'path';
import dashManifestUtils from '../../utils/dashManifestUtils';
import { corruptorConfigUtils } from '../../utils/configs';
Expand Down Expand Up @@ -54,7 +55,11 @@ export default async function dashSegmentHandler(
// Break down Corruption Objects
// Send source URL with a corruption json (if it is appropriate) to segmentHandler...
const configUtils = corruptorConfigUtils(urlSearchParams);
configUtils.register(delaySCC).register(statusCodeSCC).register(timeoutSCC);
configUtils
.register(delaySCC)
.register(statusCodeSCC)
.register(timeoutSCC)
.register(throttleSCC);
const [error, allMutations] = configUtils.getAllManifestConfigs(
reqSegmentIndexInt,
true
Expand Down
7 changes: 6 additions & 1 deletion src/manifests/handlers/hls/media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import delaySCC from '../../utils/corruptions/delay';
import statusCodeSCC from '../../utils/corruptions/statusCode';
import timeoutSCC from '../../utils/corruptions/timeout';
import throttleSCC from '../../utils/corruptions/throttle';
import path from 'path';
import hlsManifestUtils from '../../utils/hlsManifestUtils';
import { corruptorConfigUtils } from '../../utils/configs';
Expand Down Expand Up @@ -46,7 +47,11 @@ export default async function hlsMediaHandler(
const manifestUtils = hlsManifestUtils();
const configUtils = corruptorConfigUtils(reqQueryParams);

configUtils.register(delaySCC).register(statusCodeSCC).register(timeoutSCC);
configUtils
.register(delaySCC)
.register(statusCodeSCC)
.register(timeoutSCC)
.register(throttleSCC);

const [error, allMutations] = configUtils.getAllManifestConfigs(
mediaM3U.get('mediaSequence')
Expand Down
Loading

0 comments on commit 76836e1

Please sign in to comment.