This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Capture off-CPU stack traces for 30 seconds, then generate flame graph | |
| # Requires: bpftrace, stackcollapse-bpftrace.pl, flamegraph.pl | |
| bpftrace -e ' | |
| tracepoint:sched:sched_switch { | |
| if (args->prev_state == TASK_INTERRUPTIBLE || | |
| args->prev_state == TASK_UNINTERRUPTIBLE) { | |
| @offcpu[args->prev_pid, ustack] = nsecs; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "bytes" | |
| "encoding/json" | |
| "fmt" | |
| "log" | |
| "strings" | |
| "github.com/elastic/go-elasticsearch/v8" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package flags | |
| import ( | |
| "crypto/sha256" | |
| "encoding/binary" | |
| "strings" | |
| ) | |
| type Context struct { | |
| UserID string |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| FROM alpine:3.19 | |
| RUN apk add --no-cache pgbouncer | |
| COPY pgbouncer.ini /etc/pgbouncer/pgbouncer.ini | |
| COPY userlist.txt /etc/pgbouncer/userlist.txt | |
| RUN chown -R nobody:nobody /etc/pgbouncer | |
| USER nobody |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func (cb *CircuitBreaker) Execute(fn func() error) error { | |
| cb.mu.Lock() | |
| state := cb.currentState() | |
| if state == StateOpen { | |
| cb.mu.Unlock() | |
| return ErrCircuitOpen | |
| } | |
| cb.mu.Unlock() | |
| err := fn() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Install Redis Stack (includes RedisBloom, RedisSearch, RedisJSON) | |
| docker run -p 6379:6379 redis/redis-stack-server:latest | |
| # Create a Bloom filter: 1M capacity, 0.1% false positive rate | |
| redis-cli BF.RESERVE crawled_urls 0.001 1000000 | |
| # Add and test items | |
| redis-cli BF.ADD crawled_urls "https://example.com/page-1" | |
| redis-cli BF.EXISTS crawled_urls "https://example.com/page-1" # returns 1 | |
| redis-cli BF.EXISTS crawled_urls "https://never-seen.com" # returns 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func VersionMiddleware(next http.Handler) http.Handler { | |
| return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | |
| version := r.Header.Get("API-Version") | |
| if version == "" { | |
| version = "2024-01" // default to latest stable | |
| } | |
| supported := map[string]bool{ | |
| "2023-06": true, | |
| "2024-01": true, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func TenantMiddleware(store TenantStore) func(http.Handler) http.Handler { | |
| return func(next http.Handler) http.Handler { | |
| return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | |
| host := r.Host // e.g. "acme.app.io" | |
| subdomain := strings.Split(host, ".")[0] | |
| tenant, err := store.GetBySubdomain(r.Context(), subdomain) | |
| if err != nil || tenant == nil { | |
| http.Error(w, "tenant not found", http.StatusNotFound) | |
| return |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func serviceIdentityFromRequest(r *http.Request) (string, error) { | |
| if r.TLS == nil || len(r.TLS.PeerCertificates) == 0 { | |
| return "", fmt.Errorf("no client certificate presented") | |
| } | |
| cert := r.TLS.PeerCertificates[0] | |
| for _, uri := range cert.URIs { | |
| if uri.Scheme == "spiffe" { | |
| return uri.String(), nil | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| version: "3.8" | |
| services: | |
| zookeeper: | |
| image: confluentinc/cp-zookeeper:7.5.0 | |
| environment: | |
| ZOOKEEPER_CLIENT_PORT: 2181 | |
| kafka: | |
| image: confluentinc/cp-kafka:7.5.0 | |
| depends_on: [zookeeper] |