This file contains 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
# This is a GitLab CI configuration to build the project as a docker image | |
# The file is generic enough to be dropped in a project containing a working Dockerfile | |
# Author: Florent CHAUVEAU <[email protected]> | |
# Mentioned here: https://blog.callr.tech/building-docker-images-with-gitlab-ci-best-practices/ | |
# do not use "latest" here, if you want this to work in the future | |
image: docker:20 | |
stages: | |
- build |
This file contains 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
// ConvertTS converts a UNIX timestamp string (with sub second precision) "epoch" into a time.Time | |
// (c) Florent CHAUVEAU <[email protected]> | |
func ConvertTS(ts string) time.Time { | |
value := strings.SplitN(ts, ".", 2) | |
var sec int64 | |
var nsec int64 | |
if len(value) == 0 { |
This file contains 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
-- Redis script to implement a leaky bucket | |
-- see https://medium.com/callr-techblog/rate-limiting-for-distributed-systems-with-redis-and-lua-eeea745cb260 | |
-- (c) Florent CHAUVEAU <[email protected]> | |
local ts = tonumber(ARGV[1]) | |
local cps = tonumber(ARGV[2]) | |
local key = KEYS[1] | |
-- remove tokens < min (older than now() -1s) | |
local min = ts -1 |
This file contains 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
-- Redis script to get the size of a token bucket | |
-- see https://medium.com/callr-techblog/rate-limiting-for-distributed-systems-with-redis-and-lua-eeea745cb260 | |
-- (c) Florent CHAUVEAU <[email protected]> | |
local ts = tonumber(ARGV[1]) | |
local key = KEYS[1] | |
-- remove tokens < min (older than now() -1s) | |
local min = ts -1 |
This file contains 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
-- Redis script to add an event to a token bucket | |
-- see https://medium.com/callr-techblog/rate-limiting-for-distributed-systems-with-redis-and-lua-eeea745cb260 | |
-- (c) Florent CHAUVEAU <[email protected]> | |
local ts = tonumber(ARGV[1]) | |
-- set the token bucket to 1 second (rolling) | |
local min = ts -1 | |
-- iterate overs keys |