Skip to content

Instantly share code, notes, and snippets.

apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
annotations:
platform.opendatahub.io/instance.generation: "1"
platform.opendatahub.io/instance.name: default-gateway
platform.opendatahub.io/instance.uid: cc1a2d0e-6f48-47f7-9608-58ab710fa8e8
platform.opendatahub.io/type: Open Data Hub
platform.opendatahub.io/version: 0.0.0
labels:
apiVersion: v1
data:
envoy.yaml: |
static_resources:
listeners:
- name: http
address:
socket_address:
address: 0.0.0.0
port_value: 8080
apiVersion: v1
kind: Namespace
metadata:
name: apigw
---
apiVersion: v1
kind: Namespace
metadata:
name: sample
@lphiri
lphiri / hash_ring.py
Created August 18, 2022 14:59 — forked from reorx/hash_ring.py
Consistent hash implementation in Python.
# -*- coding: utf-8 -*-
"""
hash_ring
~~~~~~~~~~~~~~
Implements consistent hashing that can be used when
the number of server nodes can increase or decrease (like in memcached).
Consistent hashing is a scheme that provides a hash table functionality
in a way that the adding or removing of one slot
does not significantly change the mapping of keys to slots.

Scaling your API with rate limiters

The following are examples of the four types rate limiters discussed in the accompanying blog post. In the examples below I've used pseudocode-like Ruby, so if you're unfamiliar with Ruby you should be able to easily translate this approach to other languages. Complete examples in Ruby are also provided later in this gist.

In most cases you'll want all these examples to be classes, but I've used simple functions here to keep the code samples brief.

Request rate limiter

This uses a basic token bucket algorithm and relies on the fact that Redis scripts execute atomically. No other operations can run between fetching the count and writing the new count.

@lphiri
lphiri / get_token.py
Created February 2, 2022 12:55
Red Hat RHOAS service account token
import requests
from requests.auth import HTTPBasicAuth
url= "https://identity.api.openshift.com/auth/realms/rhoas/protocol/openid-connect/token"
service_account_id=<YOUR_CLIENT_ID>
service_account_secret=<YOUR_CLIENT_SECRET>
payload = 'grant_type=client_credentials'
headers = {
'Content-Type': 'application/x-www-form-urlencoded'
}
response = requests.request('POST',url, headers=headers,data=payload,
@lphiri
lphiri / franken.md
Created April 27, 2017 14:21 — forked from johnpmitsch/franken.md
vagrant downstream satellite frankenbox