Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions path/to/internal/bpf/c/disk_io.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# complete code
#include <linux/bpf.h>
#include "kerno.h"

struct kerno_backpressure {
__u32 should_emit;
};

SEC("classifier")
int kerno_backpressure_cls(struct xdp_md *ctx) {
struct kerno_backpressure *backpressure = (struct kerno_backpressure *)ctx->data;
if (backpressure->should_emit == 0) {
return XDP_DROP;
}
return XDP_PASS;
}
16 changes: 16 additions & 0 deletions path/to/internal/bpf/c/disk_io_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# complete code
#include <linux/bpf.h>
#include "kerno_test.h"

struct kerno_backpressure {
__u32 should_emit;
};

SEC("classifier")
int kerno_backpressure_cls(struct xdp_md *ctx) {
struct kerno_backpressure *backpressure = (struct kerno_backpressure *)ctx->data;
if (backpressure->should_emit == 0) {
return XDP_DROP;
}
return XDP_PASS;
}
7 changes: 7 additions & 0 deletions path/to/internal/bpf/c/headers/kerno.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# complete code
#ifndef KERNO_H
#define KERNO_H

#define KERNO_BACKPRESSURE 1

#endif
5 changes: 5 additions & 0 deletions path/to/internal/bpf/c/headers/kerno_test.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# complete code
#ifndef KERNO_TEST_H
#define KERNO_TEST_H

#endif
14 changes: 14 additions & 0 deletions path/to/internal/cli/spinner.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# complete code

Check failure on line 1 in path/to/internal/cli/spinner.go

View workflow job for this annotation

GitHub Actions / Test

illegal character U+0023 '#'

Check failure on line 1 in path/to/internal/cli/spinner.go

View workflow job for this annotation

GitHub Actions / Integration

illegal character U+0023 '#'
import time
import random

class Spinner:
def __init__(self):
self.running = True

def start(self):
while self.running:
time.sleep(1)

def stop(self):
self.running = False
12 changes: 12 additions & 0 deletions path/to/internal/cli/spinner_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# complete code
import unittest
import time
import random

class SpinnerTest(unittest.TestCase):
def test_spinner(self):
spinner = Spinner()
spinner.start()
time.sleep(1)
spinner.stop()
self.assertFalse(spinner.running)
15 changes: 15 additions & 0 deletions path/to/internal/cli/start.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# complete code
import time
import random

class Start:
def __init__(self, rate_limiter, sampler):
self.rate_limiter = rate_limiter
self.sampler = sampler

def start(self):
while True:
if self.rate_limiter.is_allowed():
self.sampler.sample()
else:
time.sleep(1)
12 changes: 12 additions & 0 deletions path/to/internal/cli/start_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# complete code
import unittest
import time
import random

class StartTest(unittest.TestCase):
def test_start(self):
rate_limiter = RateLimiter(500000, 1)
sampler = Sampler(1.0)
start = Start(rate_limiter, sampler)
start.start()
self.assertTrue(True)
17 changes: 17 additions & 0 deletions path/to/internal/collector/aggregator/histogram.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# complete code

Check failure on line 1 in path/to/internal/collector/aggregator/histogram.go

View workflow job for this annotation

GitHub Actions / Test

illegal character U+0023 '#'

Check failure on line 1 in path/to/internal/collector/aggregator/histogram.go

View workflow job for this annotation

GitHub Actions / Integration

illegal character U+0023 '#'
import time
import random

class Histogram:
def __init__(self, buckets):
self.buckets = buckets
self.values = [0] * buckets

def update(self, value):
bucket = int(value / (self.buckets - 1) * (self.buckets - 1))
self.values[bucket] += 1

def get_percentile(self, percentile):
values = sorted(self.values)
index = int((percentile / 100) * (len(values) - 1))
return (index + 1) / (len(values) - 1) * (self.buckets - 1)
10 changes: 10 additions & 0 deletions path/to/internal/collector/aggregator/histogram_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# complete code
import unittest
import time
import random

class HistogramTest(unittest.TestCase):
def test_histogram(self):
histogram = Histogram(10)
histogram.update(5)
self.assertEqual(histogram.get_percentile(50), 5)
24 changes: 24 additions & 0 deletions path/to/internal/collector/aggregator/lru.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# complete code
import time
import random

class LRU:
def __init__(self, capacity):
self.capacity = capacity
self.cache = {}

def get(self, key):
if key in self.cache:
value = self.cache[key]
del self.cache[key]
self.cache[key] = value
return value
return None

def set(self, key, value):
if key in self.cache:
del self.cache[key]
elif len(self.cache) >= self.capacity:
random_key = random.choice(list(self.cache.keys()))
del self.cache[random_key]
self.cache[key] = value
10 changes: 10 additions & 0 deletions path/to/internal/collector/aggregator/lru_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# complete code
import unittest
import time
import random

class LRUTest(unittest.TestCase):
def test_lru(self):
lru = LRU(10)
lru.set("key", "value")
self.assertEqual(lru.get("key"), "value")
36 changes: 36 additions & 0 deletions path/to/internal/collector/aggregator/ratelimit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# complete code
import time
import random

class RateLimiter:
def __init__(self, budget, interval):
self.budget = budget
self.interval = interval
self.tokens = budget
self.last_update = time.time()

def update(self):
now = time.time()
elapsed = now - self.last_update
self.tokens = min(self.tokens + (elapsed / self.interval) * self.budget, self.budget)
self.last_update = now

def is_allowed(self):
self.update()
return self.tokens > 0

class Sampler:
def __init__(self, target_overhead_pct):
self.target_overhead_pct = target_overhead_pct
self.sample_rate = 1.0 / target_overhead_pct

def sample(self):
return random.random() < self.sample_rate

class RateLimiterAndSampler:
def __init__(self, rate_limiter, sampler):
self.rate_limiter = rate_limiter
self.sampler = sampler

def is_allowed(self):
return self.rate_limiter.is_allowed() or self.sampler.sample()
11 changes: 11 additions & 0 deletions path/to/internal/collector/aggregator/ratelimit_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# complete code
import unittest
import time
import random

class RateLimiterTest(unittest.TestCase):
def test_rate_limiter(self):
rate_limiter = RateLimiter(500000, 1)
self.assertTrue(rate_limiter.is_allowed())
time.sleep(1)
self.assertFalse(rate_limiter.is_allowed())
13 changes: 13 additions & 0 deletions path/to/internal/collector/cgroup_memory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# complete code

Check failure on line 1 in path/to/internal/collector/cgroup_memory.go

View workflow job for this annotation

GitHub Actions / Test

illegal character U+0023 '#'

Check failure on line 1 in path/to/internal/collector/cgroup_memory.go

View workflow job for this annotation

GitHub Actions / Integration

illegal character U+0023 '#'
import time
import random

class CGroupMemory:
def __init__(self):
self.drops = 0

def increment_drop(self):
self.drops += 1

def get_drop_count(self):
return self.drops
10 changes: 10 additions & 0 deletions path/to/internal/collector/cgroup_memory_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# complete code
import unittest
import time
import random

class CGroupMemoryTest(unittest.TestCase):
def test_cgroup_memory(self):
cgroup_memory = CGroupMemory()
cgroup_memory.increment_drop()
self.assertEqual(cgroup_memory.get_drop_count(), 1)
14 changes: 14 additions & 0 deletions path/to/internal/collector/collector.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# complete code
import time
import random

class Collector:
def __init__(self, rate_limiter, sampler):
self.rate_limiter = rate_limiter
self.sampler = sampler

def record(self, event):
if self.rate_limiter.is_allowed():
self.sampler.sample()
else:
time.sleep(1)
20 changes: 20 additions & 0 deletions path/to/internal/config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# complete code

Check failure on line 1 in path/to/internal/config/config.go

View workflow job for this annotation

GitHub Actions / Lint

illegal character U+0023 '#' (typecheck)

Check failure on line 1 in path/to/internal/config/config.go

View workflow job for this annotation

GitHub Actions / Test

illegal character U+0023 '#'

Check failure on line 1 in path/to/internal/config/config.go

View workflow job for this annotation

GitHub Actions / Integration

illegal character U+0023 '#'
import time
import random

class Config:
def __init__(self):
self.rate_limits = {
"syscall_latency": 500000,
"sched_delay": 200000
}
self.sampling = {
"enabled": True,
"target_overhead_pct": 1.0
}

def get_rate_limit(self, key):
return self.rate_limits.get(key, 0)

def get_sampling_config(self):
return self.sampling
10 changes: 10 additions & 0 deletions path/to/internal/metrics/bridge.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# complete code

Check failure on line 1 in path/to/internal/metrics/bridge.go

View workflow job for this annotation

GitHub Actions / Test

illegal character U+0023 '#'

Check failure on line 1 in path/to/internal/metrics/bridge.go

View workflow job for this annotation

GitHub Actions / Integration

illegal character U+0023 '#'
import time
import random

class Bridge:
def __init__(self, metrics):
self.metrics = metrics

def get_metrics(self):
return self.metrics.get_drop_count(), self.metrics.get_sampled_count()
10 changes: 10 additions & 0 deletions path/to/internal/metrics/bridge_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# complete code
import unittest
import time
import random

class BridgeTest(unittest.TestCase):
def test_bridge(self):
metrics = Metrics()
bridge = Bridge(metrics)
self.assertEqual(bridge.get_metrics(), (0, 0))
20 changes: 20 additions & 0 deletions path/to/internal/metrics/metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# complete code
import time
import random

class Metrics:
def __init__(self):
self.drop_count = 0
self.sampled_count = 0

def increment_drop_count(self):
self.drop_count += 1

def increment_sampled_count(self):
self.sampled_count += 1

def get_drop_count(self):
return self.drop_count

def get_sampled_count(self):
return self.sampled_count
Loading