@unitpad/modules 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,11 @@
1
1
  # Availability and durability
2
- # Nines, downtime budgets, composing components, and real failure rates.
2
+ # Nines, downtime budgets, composing components, error budget burn rate, and real failure rates.
3
3
  # availability_serial / availability_parallel assume independent failures;
4
4
  # correlated failures (same rack, AZ, deploy, config push) make reality worse.
5
5
  # Import with: use availability then use the availability_* values and functions
6
6
  # title: Availability
7
7
  # checked: unverified
8
- # description: Nines and downtime budgets, serial/parallel composition, disk AFR, S3/EC2 durability and SLAs
8
+ # description: Nines and downtime budgets, serial/parallel composition, MTBF/MTTR, error budget burn rate, disk AFR, S3/EC2 durability and SLAs
9
9
  # vendor: aws, backblaze
10
10
 
11
11
  @url("https://en.wikipedia.org/wiki/High_availability")
@@ -23,16 +23,37 @@ fn availability_downtime_year(a: Scalar) -> Time = (1 - a) * 1 year
23
23
  @example("availability_downtime_month(0.999)")
24
24
  fn availability_downtime_month(a: Scalar) -> Time = (1 - a) * 1 month
25
25
 
26
- @url("https://en.wikipedia.org/wiki/Reliability_engineering")
26
+ @url("https://docs.aws.amazon.com/wellarchitected/latest/reliability-pillar/availability.html")
27
27
  @description("Availability of two components in series (both must work): multiply their availability fractions a and b, each from 0 to 1")
28
28
  @example("availability_serial(0.99, 0.999)")
29
29
  fn availability_serial(a: Scalar, b: Scalar) -> Scalar = a * b
30
30
 
31
- @url("https://en.wikipedia.org/wiki/Reliability_engineering")
31
+ @url("https://docs.aws.amazon.com/wellarchitected/latest/reliability-pillar/availability.html")
32
32
  @description("Availability of n independent replicas where any one suffices: 1 - (1 - a)^n. Pass availability a from 0 to 1 and a nonnegative replica count n")
33
33
  @example("availability_parallel(0.99, 3)")
34
34
  fn availability_parallel(a: Scalar, n: Scalar) -> Scalar = 1 - (1 - a)^n
35
35
 
36
+ @url("https://docs.aws.amazon.com/wellarchitected/latest/reliability-pillar/availability.html")
37
+ @description("Availability estimated from mean time between failures and mean time to recover: mtbf / (mtbf + mttr). AWS example: an MTBF of 150 days and an MTTR of 1 hour is about 99.97%")
38
+ @example("availability_from_mtbf(150 days, 1 hour)")
39
+ fn availability_from_mtbf(mtbf: Time, mttr: Time) -> Scalar = mtbf / (mtbf + mttr)
40
+
41
+ # --- Error budget and burn rate (Google SRE Workbook, chapter 5) ---
42
+ @url("https://sre.google/workbook/alerting-on-slos/")
43
+ @description("Burn rate: how fast, relative to the SLO, a service uses its error budget. It is error_rate / (1 - slo), with error_rate from 0 to 1 (pass 0.0072 or 0.72%, not 0.72) and slo as 0.9995 or 99.95%. A burn rate of 1 uses exactly the whole budget over the SLO period. Unreliable at low traffic: one failed request can give a very high burn rate")
44
+ @example("availability_burn_rate(0.72%, 99.95%)")
45
+ fn availability_burn_rate(error_rate: Scalar, slo: Scalar) -> Scalar = error_rate / (1 - slo)
46
+
47
+ @url("https://sre.google/workbook/alerting-on-slos/")
48
+ @description("Fraction of the error budget used when a burn rate holds for a window: burn * window / period. Workbook example: 36 times over 1 hour in a 30-day period uses 5%")
49
+ @example("availability_budget_consumed(36, 1 hour, 30 days)")
50
+ fn availability_budget_consumed(burn: Scalar, window: Time, period: Time) -> Scalar = burn * window / period
51
+
52
+ @url("https://sre.google/workbook/alerting-on-slos/")
53
+ @description("Burn rate at which an alert window uses a given fraction of the budget: consumed * period / window, the formula of availability_budget_consumed solved for the burn rate. Workbook Table 5-8: 2% in 1 hour of a 30-day period is 14.4, and 5% in 6 hours is 6")
54
+ @example("availability_burn_threshold(2%, 1 hour, 30 days)")
55
+ fn availability_burn_threshold(consumed: Scalar, window: Time, period: Time) -> Scalar = consumed * period / window
56
+
36
57
  # --- Measured failure rates ---
37
58
  # highlight: HDD AFR
38
59
  @url("https://www.backblaze.com/blog/backblaze-drive-stats-for-2025/")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unitpad/modules",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "The numbers UnitPad sheets import with `use`: latencies, throughputs, sizes, prices and limits, each with its source.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -35,16 +35,17 @@
35
35
  "provenance": true
36
36
  },
37
37
  "scripts": {
38
+ "prepare": "git rev-parse --git-dir >/dev/null 2>&1 && git config core.hooksPath .githooks || true",
38
39
  "test": "node --test tools/*.test.mjs",
39
40
  "lint": "eslint .",
40
41
  "lint:md": "markdownlint-cli2",
41
42
  "format": "prettier --write .",
42
43
  "format:check": "prettier --check .",
43
44
  "api": "node tools/api.mjs",
44
- "api:update": "node tools/api.mjs --update",
45
+ "api:update": "node tools/api.mjs --update && prettier --write api.json",
45
46
  "api:release": "node tools/api.mjs --release",
46
47
  "values": "node tools/values.mjs",
47
- "values:update": "node tools/values.mjs --update",
48
+ "values:update": "node tools/values.mjs --update && prettier --write values.json",
48
49
  "values:release": "node tools/values.mjs --release",
49
50
  "numbat": "node tools/install-numbat.mjs",
50
51
  "check": "npm run lint && npm run lint:md && npm run format:check && npm test && node tools/check-docs.mjs && node tools/style.mjs && node tools/api.mjs && node tools/values.mjs && node tools/pack-check.mjs",