Skip to content

Instantly share code, notes, and snippets.

@yairst
yairst / private_fork.md
Created December 22, 2022 16:15 — forked from 0xjac/private_fork.md
Create a private fork of a public repository

The repository for the assignment is public and Github does not allow the creation of private forks for public repositories.

The correct way of creating a private frok by duplicating the repo is documented here.

For this assignment the commands are:

  1. Create a bare clone of the repository. (This is temporary and will be removed so just do it wherever.)

git clone --bare [email protected]:usi-systems/easytrace.git

@yairst
yairst / approx_dynamic_burn_rate.py
Created January 15, 2022 21:52
Approximated dynamic burn rate based on resampled total number of events in the SLO period
df['aprox dynamic burn rate'] = df['total_hits_last_28_days_resampled'] / (df['hits']) * (EBP / 100)
fig, ax = plt.subplots(figsize=(16, 5))
df_sample.plot(x='date',y='hits', ax=ax, logy=True)
df_sample.plot(x='date',y='dynamic burn rate', ax=ax, logy=True)
df_sample.plot(x='date',y='aprox dynamic burn rate', ax=ax, logy=True, linestyle='--')
ax.grid()
@yairst
yairst / resampling_total_events_in_SLO_period.py
Created January 15, 2022 21:46
Resampling total events in the SLO period
# resample
tmp = df.set_index('date')['total_hits_last_28_days'].asfreq('1D')
tmp.loc[tmp.index[-1] + pd.Timedelta('1D')] = 0 # dummy row in purpose to get all hours in the last day
df['total_hits_last_28_days_resampled'] = tmp.resample('1H').ffill().iloc[:-1].reset_index()['total_hits_last_28_days']
# plot
fig, ax = plt.subplots(figsize=(16, 5))
df_sample.plot(x='date',y='total_hits_last_28_days', ax=ax)
df_sample.plot(x='date',y='total_hits_last_28_days_resampled', ax=ax)
@yairst
yairst / actual_ebp.py
Created January 15, 2022 21:19
Actual percentage of error budget consumption when using Google's static burn rate
df['actual_ebp'] = ((24 * SLO_PERIOD) * df['hits']) / (ALERTING_WIN * df['total_hits_last_28_days']) * EBP
fig, ax = plt.subplots(figsize=(16, 5))
df_sample.plot(x='date', y='ebp', ax=ax)
df_sample.plot(x='date', y='actual_ebp',ax=ax)
plt.ylabel('Percentage of Error Budget\nConsumption Threshold (%)')
ax.grid(axis='y')
@yairst
yairst / static_vs_dynamic_burn_rate.py
Last active January 15, 2022 21:13
static vs dynamic burn rate
import pandas as pd
from matplotlib import pyplot as plt
SLO_PERIOD = 28
EBP = 2 # percent
ALERTING_WIN = 1
df = pd.read_csv('sav_2013_2017.csv', parse_dates=['date'])
# aviod divide by zero
@yairst
yairst / latency90_eb_alert.yml
Last active January 29, 2022 07:26
Prometheus alert definition on error budget of 90% percentile latency SLO
- alert: Latency90ErrorBudgetBurn
expr: |2
job:latency90_eb_http_request_duration_seconds:increase1h > (0.02 * 0.1 * job:http_requests_total:increase30d)
and
job:latency90_eb_http_request_duration_seconds:increase5m > ((0.02 / 12) * 0.1 * job:http_requests_total:increase30d)
for: 0m
labels:
period: 1h
severity: critical
annotations:
- record: job:latency90_eb_http_request_duration_seconds:increase1h
expr: |2
sum by (job) (increase(http_request_duration_seconds_count[1h]))
-
sum by (job) (increase(http_request_duration_seconds_bucket{le="0.45"}[1h]))